diff options
Diffstat (limited to 'tests/rp/src/bin/i2c.rs')
| -rw-r--r-- | tests/rp/src/bin/i2c.rs | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/tests/rp/src/bin/i2c.rs b/tests/rp/src/bin/i2c.rs index 9615007bd..2c835bd5a 100644 --- a/tests/rp/src/bin/i2c.rs +++ b/tests/rp/src/bin/i2c.rs | |||
| @@ -1,23 +1,21 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #[cfg(feature = "rp2040")] | ||
| 3 | teleprobe_meta::target!(b"rpi-pico"); | 4 | teleprobe_meta::target!(b"rpi-pico"); |
| 5 | #[cfg(feature = "rp235xb")] | ||
| 6 | teleprobe_meta::target!(b"pimoroni-pico-plus-2"); | ||
| 4 | 7 | ||
| 5 | use defmt::{assert_eq, info, panic, unwrap}; | 8 | use defmt::{assert_eq, info, panic}; |
| 6 | use embassy_embedded_hal::SetConfig; | 9 | use embassy_embedded_hal::SetConfig; |
| 7 | use embassy_executor::{Executor, Spawner}; | 10 | use embassy_executor::Spawner; |
| 8 | use embassy_rp::clocks::{PllConfig, XoscConfig}; | 11 | use embassy_rp::clocks::{PllConfig, XoscConfig}; |
| 9 | use embassy_rp::config::Config as rpConfig; | 12 | use embassy_rp::config::Config as rpConfig; |
| 10 | use embassy_rp::multicore::{spawn_core1, Stack}; | ||
| 11 | use embassy_rp::peripherals::{I2C0, I2C1}; | 13 | use embassy_rp::peripherals::{I2C0, I2C1}; |
| 12 | use embassy_rp::{bind_interrupts, i2c, i2c_slave}; | 14 | use embassy_rp::{bind_interrupts, i2c, i2c_slave}; |
| 13 | use embedded_hal_1::i2c::Operation; | 15 | use embedded_hal_1::i2c::Operation; |
| 14 | use embedded_hal_async::i2c::I2c; | 16 | use embedded_hal_async::i2c::I2c; |
| 15 | use static_cell::StaticCell; | ||
| 16 | use {defmt_rtt as _, panic_probe as _, panic_probe as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _, panic_probe as _, panic_probe as _}; |
| 17 | 18 | ||
| 18 | static mut CORE1_STACK: Stack<1024> = Stack::new(); | ||
| 19 | static EXECUTOR1: StaticCell<Executor> = StaticCell::new(); | ||
| 20 | |||
| 21 | use crate::i2c::AbortReason; | 19 | use crate::i2c::AbortReason; |
| 22 | 20 | ||
| 23 | bind_interrupts!(struct Irqs { | 21 | bind_interrupts!(struct Irqs { |
| @@ -106,7 +104,7 @@ async fn device_task(mut dev: i2c_slave::I2cSlave<'static, I2C1>) -> ! { | |||
| 106 | } | 104 | } |
| 107 | 105 | ||
| 108 | async fn controller_task(con: &mut i2c::I2c<'static, I2C0, i2c::Async>) { | 106 | async fn controller_task(con: &mut i2c::I2c<'static, I2C0, i2c::Async>) { |
| 109 | info!("Device start"); | 107 | info!("Controller start"); |
| 110 | 108 | ||
| 111 | { | 109 | { |
| 112 | let buf = [0xCA, 0x11]; | 110 | let buf = [0xCA, 0x11]; |
| @@ -180,7 +178,7 @@ async fn controller_task(con: &mut i2c::I2c<'static, I2C0, i2c::Async>) { | |||
| 180 | } | 178 | } |
| 181 | 179 | ||
| 182 | #[embassy_executor::main] | 180 | #[embassy_executor::main] |
| 183 | async fn main(_core0_spawner: Spawner) { | 181 | async fn main(spawner: Spawner) { |
| 184 | let mut config = rpConfig::default(); | 182 | let mut config = rpConfig::default(); |
| 185 | // Configure clk_sys to 48MHz to support 1kHz scl. | 183 | // Configure clk_sys to 48MHz to support 1kHz scl. |
| 186 | // In theory it can go lower, but we won't bother to test below 1kHz. | 184 | // In theory it can go lower, but we won't bother to test below 1kHz. |
| @@ -210,14 +208,7 @@ async fn controller_task(con: &mut i2c::I2c<'static, I2C0, i2c::Async>) { | |||
| 210 | config.addr = DEV_ADDR as u16; | 208 | config.addr = DEV_ADDR as u16; |
| 211 | let device = i2c_slave::I2cSlave::new(p.I2C1, d_sda, d_scl, Irqs, config); | 209 | let device = i2c_slave::I2cSlave::new(p.I2C1, d_sda, d_scl, Irqs, config); |
| 212 | 210 | ||
| 213 | spawn_core1( | 211 | spawner.must_spawn(device_task(device)); |
| 214 | p.CORE1, | ||
| 215 | unsafe { &mut *core::ptr::addr_of_mut!(CORE1_STACK) }, | ||
| 216 | move || { | ||
| 217 | let executor1 = EXECUTOR1.init(Executor::new()); | ||
| 218 | executor1.run(|spawner| unwrap!(spawner.spawn(device_task(device)))); | ||
| 219 | }, | ||
| 220 | ); | ||
| 221 | 212 | ||
| 222 | let c_sda = p.PIN_21; | 213 | let c_sda = p.PIN_21; |
| 223 | let c_scl = p.PIN_20; | 214 | let c_scl = p.PIN_20; |
