Skip to content
Snippets Groups Projects
Commit 9355e705 authored by zdmx's avatar zdmx :crab:
Browse files

Split crates working

parent 409052a9
Branches
No related tags found
1 merge request!4Split project into multiple crates
...@@ -25,7 +25,7 @@ use flow3_rs::{ ...@@ -25,7 +25,7 @@ use flow3_rs::{
static CLOCKS: StaticCell<Clocks> = StaticCell::new(); static CLOCKS: StaticCell<Clocks> = StaticCell::new();
pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) { pub async fn init_flow3r() -> (Flow3r, InputRunner, CaptouchRunner) {
let peripherals = Peripherals::take(); let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split(); let mut system = peripherals.SYSTEM.split();
let clocks = CLOCKS.init(ClockControl::boot_defaults(system.clock_control).freeze()); let clocks = CLOCKS.init(ClockControl::boot_defaults(system.clock_control).freeze());
...@@ -86,7 +86,7 @@ pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) { ...@@ -86,7 +86,7 @@ pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) {
// Create shared I2C Bus // Create shared I2C Bus
//let i2c_busmanager = shared_bus::new_xtensa!(I2C<'static, I2C0> = i2c).unwrap(); let i2c_busmanager = shared_bus::new_xtensa!(I2C<'static, I2C0> = i2c).unwrap();
// Init SPI + DMA // Init SPI + DMA
...@@ -162,7 +162,7 @@ pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) { ...@@ -162,7 +162,7 @@ pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) {
let rng = Rng::new(peripherals.RNG); let rng = Rng::new(peripherals.RNG);
/*let input_runner = InputRunner::new( let input_runner = InputRunner::new(
i2c_busmanager.acquire_i2c(), i2c_busmanager.acquire_i2c(),
io.pins.gpio8, io.pins.gpio8,
io.pins.gpio0, io.pins.gpio0,
...@@ -174,7 +174,7 @@ pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) { ...@@ -174,7 +174,7 @@ pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) {
i2c_busmanager.acquire_i2c(), i2c_busmanager.acquire_i2c(),
io.pins.gpio16, io.pins.gpio16,
io.pins.gpio15, io.pins.gpio15,
);*/ );
// Init Flow3r components // Init Flow3r components
...@@ -186,5 +186,5 @@ pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) { ...@@ -186,5 +186,5 @@ pub async fn init_flow3r() -> (Flow3r, I2C<'static, I2C0> ) {
let flow3r = Flow3r::new(None, Some(captouch), Some(display), None, Some(inputs), Some(leds), Some(uart0), Some(uart1), Some(rng)); let flow3r = Flow3r::new(None, Some(captouch), Some(display), None, Some(inputs), Some(leds), Some(uart0), Some(uart1), Some(rng));
(flow3r, i2c) (flow3r, input_runner, captouch_runner)
} }
\ No newline at end of file
...@@ -23,22 +23,16 @@ pub fn start_runtime<S>(main: fn(Flow3r) -> SpawnToken<S>) -> ! ...@@ -23,22 +23,16 @@ pub fn start_runtime<S>(main: fn(Flow3r) -> SpawnToken<S>) -> !
#[embassy_executor::task] #[embassy_executor::task]
async fn init_runtime(main: fn(Flow3r) -> SpawnToken<*mut ()>) { async fn init_runtime(main: fn(Flow3r) -> SpawnToken<*mut ()>) {
let (flow3r, mut i2c) = init_flow3r().await; let (flow3r, input_runner, captouch_runner) = init_flow3r().await;
let addr = 0x60 | ((true as u8) << 3) | ((true as u8) << 2) | ((true as u8) << 1) | (false as u8);
let mut buf = [0u8;1];
i2c.read(addr, &mut buf).unwrap();
println!("buf {}", buf[0]);
// Spawn background tasks // Spawn background tasks
let spawner = Spawner::for_current_executor().await; let spawner = Spawner::for_current_executor().await;
/*spawner spawner
.spawn(input_task(input_runner)) .spawn(input_task(input_runner))
.unwrap();*/ .unwrap();
/*spawner spawner
.spawn(captouch_task(captouch_runner)) .spawn(captouch_task(captouch_runner))
.unwrap();*/ .unwrap();
// Hand over to main task // Hand over to main task
spawner.spawn(main(flow3r)).unwrap(); spawner.spawn(main(flow3r)).unwrap();
......
...@@ -15,7 +15,7 @@ use crate::demo_tasks::{display_demo, imu_demo, captouch_demo}; ...@@ -15,7 +15,7 @@ use crate::demo_tasks::{display_demo, imu_demo, captouch_demo};
pub async fn main_menu(mut flow3r: Flow3r) -> ! { pub async fn main_menu(mut flow3r: Flow3r) -> ! {
let mut inputs = flow3r.take_inputs().split(); let mut inputs = flow3r.take_inputs().split();
let mut display = flow3r.take_display(); let mut display = flow3r.take_display();
let mut imu = flow3r.take_imu(); // let mut imu = flow3r.take_imu();
println!("main menu running"); println!("main menu running");
...@@ -47,7 +47,7 @@ pub async fn main_menu(mut flow3r: Flow3r) -> ! { ...@@ -47,7 +47,7 @@ pub async fn main_menu(mut flow3r: Flow3r) -> ! {
.await .await
{ {
Either3::First(_) => { Either3::First(_) => {
start_current_app(apps[selected], &mut display, &mut imu).await; start_current_app(apps[selected], &mut display).await;
display display
.fill_solid(&display.bounding_box(), Rgb565::BLACK) .fill_solid(&display.bounding_box(), Rgb565::BLACK)
.unwrap(); .unwrap();
...@@ -111,10 +111,9 @@ async fn play_transition_animation<'a>( ...@@ -111,10 +111,9 @@ async fn play_transition_animation<'a>(
} }
} }
async fn start_current_app(app: &str, display: &mut Display, imu: &mut ImuHandler) { async fn start_current_app(app: &str, display: &mut Display) {
match app { match app {
"input_test" => display_demo(display).await, "input_test" => display_demo(display).await,
"imu_test" => imu_demo(display, imu).await,
"captouch_test" => captouch_demo(display).await, "captouch_test" => captouch_demo(display).await,
_ => (), _ => (),
} }
......
...@@ -63,34 +63,34 @@ impl Flow3r { ...@@ -63,34 +63,34 @@ impl Flow3r {
} }
pub fn take_captouch(&mut self) -> Captouch { pub fn take_captouch(&mut self) -> Captouch {
self.captouch.take().expect("can only take badgelink once!") self.captouch.take().expect("can only take captouch once!")
} }
pub fn take_display(&mut self) -> Display { pub fn take_display(&mut self) -> Display {
self.display.take().expect("can only take badgelink once!") self.display.take().expect("can only take display once!")
} }
pub fn take_inputs(&mut self) -> Inputs { pub fn take_inputs(&mut self) -> Inputs {
self.inputs.take().expect("can only take badgelink once!") self.inputs.take().expect("can only take inputs once!")
} }
pub fn take_imu(&mut self) -> ImuHandler { pub fn take_imu(&mut self) -> ImuHandler {
self.imu.take().expect("can only take badgelink once!") self.imu.take().expect("can only take imu once!")
} }
pub fn take_leds(&mut self) -> Leds { pub fn take_leds(&mut self) -> Leds {
self.leds.take().expect("can only take badgelink once!") self.leds.take().expect("can only take leds once!")
} }
pub fn take_uart_left(&mut self) -> BadgenetUartLeft { pub fn take_uart_left(&mut self) -> BadgenetUartLeft {
self.uart0.take().expect("can only take badgelink once!") self.uart0.take().expect("can only take uart left once!")
} }
pub fn take_uart_right(&mut self) -> BadgenetUartRight { pub fn take_uart_right(&mut self) -> BadgenetUartRight {
self.uart1.take().expect("can only take badgelink once!") self.uart1.take().expect("can only take uart right once!")
} }
pub fn take_rng(&mut self) -> Rng { pub fn take_rng(&mut self) -> Rng {
self.rng.take().expect("can only take badgelink once!") self.rng.take().expect("can only take uart rng once!")
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment