Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] massively overengineered GPIO driver service #172

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions platforms/allwinner-d1/boards/src/bin/lichee-rv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate alloc;
use core::time::Duration;
use mnemos_d1_core::{
dmac::Dmac,
drivers::{spim::kernel_spim1, twi, uart::kernel_uart},
drivers::{spim::kernel_spim1, twi, uart::kernel_uart, gpio},
plic::Plic,
timer::Timers,
Ram, D1,
Expand All @@ -26,43 +26,33 @@ fn main() -> ! {
}

let mut p = unsafe { d1_pac::Peripherals::steal() };
let uart = unsafe { kernel_uart(&mut p.CCU, &mut p.GPIO, p.UART0) };
let spim = unsafe { kernel_spim1(p.SPI_DBI, &mut p.CCU, &mut p.GPIO) };
let i2c0 = unsafe { twi::I2c0::lichee_rv_dock(p.TWI2, &mut p.CCU, &mut p.GPIO) };
let uart = unsafe { kernel_uart(&mut p.CCU, p.UART0) };
let spim = unsafe { kernel_spim1(p.SPI_DBI, &mut p.CCU) };
let i2c0 = unsafe { twi::I2c0::lichee_rv_dock(p.TWI2, &mut p.CCU) };
let timers = Timers::new(p.TIMER);
let dmac = Dmac::new(p.DMAC, &mut p.CCU);
let plic = Plic::new(p.PLIC);

let d1 = D1::initialize(timers, uart, spim, dmac, plic, i2c0);

p.GPIO.pc_cfg0.modify(|_r, w| {
w.pc1_select().output();
w
});
p.GPIO.pc_dat.modify(|_r, w| {
w.pc_dat().variant(0b0000_0010);
w
});
let d1 = D1::initialize(timers, uart, spim, dmac, plic, i2c0, p.GPIO);

d1.initialize_sharp_display();

// Initialize LED loop
d1.kernel
.initialize(async move {
let mut pin = {
let mut gpio = gpio::GpioClient::from_registry(d1.kernel).await;
gpio.claim_output(gpio::PinC::C1).await.expect("can't claim C1 as output!")
};
loop {
p.GPIO.pc_dat.modify(|_r, w| {
w.pc_dat().variant(0b0000_0010);
w
});
pin.set(true);
d1.kernel.sleep(Duration::from_millis(250)).await;
p.GPIO.pc_dat.modify(|_r, w| {
w.pc_dat().variant(0b0000_0000);
w
});
pin.set(false);
d1.kernel.sleep(Duration::from_millis(250)).await;
}
})
.unwrap();


d1.run()
}
35 changes: 12 additions & 23 deletions platforms/allwinner-d1/boards/src/bin/mq-pro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::time::Duration;
use mnemos_beepy::i2c_puppet::{HsvColor, I2cPuppetClient, I2cPuppetServer};
use mnemos_d1_core::{
dmac::Dmac,
drivers::{spim::kernel_spim1, twi, uart::kernel_uart},
drivers::{spim::kernel_spim1, twi, uart::kernel_uart, gpio},
plic::Plic,
timer::Timers,
Ram, D1,
Expand All @@ -27,37 +27,26 @@ fn main() -> ! {
}

let mut p = unsafe { d1_pac::Peripherals::steal() };
let uart = unsafe { kernel_uart(&mut p.CCU, &mut p.GPIO, p.UART0) };
let spim = unsafe { kernel_spim1(p.SPI_DBI, &mut p.CCU, &mut p.GPIO) };
let i2c0 = unsafe { twi::I2c0::mq_pro(p.TWI0, &mut p.CCU, &mut p.GPIO) };
let uart = unsafe { kernel_uart(&mut p.CCU, p.UART0) };
let spim = unsafe { kernel_spim1(p.SPI_DBI, &mut p.CCU) };
let i2c0 = unsafe { twi::I2c0::mq_pro(p.TWI0, &mut p.CCU) };
let timers = Timers::new(p.TIMER);
let dmac = Dmac::new(p.DMAC, &mut p.CCU);
let plic = Plic::new(p.PLIC);

let d1 = D1::initialize(timers, uart, spim, dmac, plic, i2c0);

p.GPIO.pd_cfg2.modify(|_r, w| {
w.pd18_select().output();
w
});
p.GPIO.pd_dat.modify(|_r, w| {
w.pd_dat().variant(1 << 18);
w
});

let d1 = D1::initialize(timers, uart, spim, dmac, plic, i2c0, p.GPIO);

// Initialize LED loop
d1.kernel
.initialize(async move {
let mut pin = {
let mut gpio = gpio::GpioClient::from_registry(d1.kernel).await;
gpio.claim_output(gpio::PinD::D18).await.expect("can't claim D18 as output!")
};
loop {
p.GPIO.pd_dat.modify(|_r, w| {
w.pd_dat().variant(1 << 18);
w
});
pin.set(true);
d1.kernel.sleep(Duration::from_millis(250)).await;
p.GPIO.pd_dat.modify(|_r, w| {
w.pd_dat().variant(0);
w
});
pin.set(false);
d1.kernel.sleep(Duration::from_millis(250)).await;
}
})
Expand Down
Loading