aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf52840
diff options
context:
space:
mode:
authorAlex Moon <[email protected]>2025-04-18 15:08:18 -0400
committerAlex Moon <[email protected]>2025-04-18 15:14:18 -0400
commit77d355e0ecb3f5eab4a563981552fdb69175c8c5 (patch)
tree9d00c7e1cdbce3f0d01c49c022f4620286ee25ad /examples/nrf52840
parentca40dc7ff75cabaa6c52c98b4712cc3f64696d62 (diff)
Make the nrf Twim RAM buffer a instance variable instead of stack allocated
Diffstat (limited to 'examples/nrf52840')
-rw-r--r--examples/nrf52840/src/bin/twim.rs4
-rw-r--r--examples/nrf52840/src/bin/twim_lowpower.rs2
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::*;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_nrf::twim::{self, Twim}; 10use embassy_nrf::twim::{self, Twim};
11use embassy_nrf::{bind_interrupts, peripherals}; 11use embassy_nrf::{bind_interrupts, peripherals};
12use static_cell::ConstStaticCell;
12use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
13 14
14const ADDRESS: u8 = 0x50; 15const 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...");