diff options
| author | Ulf Lilleengen <[email protected]> | 2025-04-30 11:40:40 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-04-30 11:40:40 +0200 |
| commit | 5f0196cb29be2edd2de300f8a42a031062441f1a (patch) | |
| tree | 1de57d944426e30f687fae1005dba1084e56c06e /examples | |
| parent | 1d2f0add77f7344f0060150f1ff4d56f50d5eed5 (diff) | |
| parent | fb7504c2930a3f177a33f1dcc736da0d548d6e97 (diff) | |
Merge pull request #4113 from alexmoon/twim-ram-buffer
Make the nrf Twim RAM buffer a instance variable instead of stack allocated
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf52840/src/bin/twim.rs | 4 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/twim_lowpower.rs | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/examples/nrf52840/src/bin/twim.rs b/examples/nrf52840/src/bin/twim.rs index ceaafd784..e30a3855d 100644 --- a/examples/nrf52840/src/bin/twim.rs +++ b/examples/nrf52840/src/bin/twim.rs | |||
| @@ -9,6 +9,7 @@ use defmt::*; | |||
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_nrf::twim::{self, Twim}; | 10 | use embassy_nrf::twim::{self, Twim}; |
| 11 | use embassy_nrf::{bind_interrupts, peripherals}; | 11 | use embassy_nrf::{bind_interrupts, peripherals}; |
| 12 | use static_cell::ConstStaticCell; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 14 | ||
| 14 | const ADDRESS: u8 = 0x50; | 15 | const ADDRESS: u8 = 0x50; |
| @@ -22,7 +23,8 @@ async fn main(_spawner: Spawner) { | |||
| 22 | let p = embassy_nrf::init(Default::default()); | 23 | let p = embassy_nrf::init(Default::default()); |
| 23 | info!("Initializing TWI..."); | 24 | info!("Initializing TWI..."); |
| 24 | let config = twim::Config::default(); | 25 | let config = twim::Config::default(); |
| 25 | let mut twi = Twim::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config); | 26 | static RAM_BUFFER: ConstStaticCell<[u8; 16]> = ConstStaticCell::new([0; 16]); |
| 27 | let mut twi = Twim::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config, RAM_BUFFER.take()); | ||
| 26 | 28 | ||
| 27 | info!("Reading..."); | 29 | info!("Reading..."); |
| 28 | 30 | ||
diff --git a/examples/nrf52840/src/bin/twim_lowpower.rs b/examples/nrf52840/src/bin/twim_lowpower.rs index 8a6f958eb..f7380e20d 100644 --- a/examples/nrf52840/src/bin/twim_lowpower.rs +++ b/examples/nrf52840/src/bin/twim_lowpower.rs | |||
| @@ -30,6 +30,7 @@ async fn main(_p: Spawner) { | |||
| 30 | loop { | 30 | loop { |
| 31 | info!("Initializing TWI..."); | 31 | info!("Initializing TWI..."); |
| 32 | let config = twim::Config::default(); | 32 | let config = twim::Config::default(); |
| 33 | let mut ram_buffer = [0u8; 16]; | ||
| 33 | 34 | ||
| 34 | // Create the TWIM instance with borrowed singletons, so they're not consumed. | 35 | // Create the TWIM instance with borrowed singletons, so they're not consumed. |
| 35 | let mut twi = Twim::new( | 36 | let mut twi = Twim::new( |
| @@ -38,6 +39,7 @@ async fn main(_p: Spawner) { | |||
| 38 | p.P0_03.reborrow(), | 39 | p.P0_03.reborrow(), |
| 39 | p.P0_04.reborrow(), | 40 | p.P0_04.reborrow(), |
| 40 | config, | 41 | config, |
| 42 | &mut ram_buffer, | ||
| 41 | ); | 43 | ); |
| 42 | 44 | ||
| 43 | info!("Reading..."); | 45 | info!("Reading..."); |
