Merge pull request #4113 from alexmoon/twim-ram-buffer
Make the nrf Twim RAM buffer a instance variable instead of stack allocated
This commit is contained in:
@@ -9,6 +9,7 @@ use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::twim::{self, Twim};
|
||||
use embassy_nrf::{bind_interrupts, peripherals};
|
||||
use static_cell::ConstStaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const ADDRESS: u8 = 0x50;
|
||||
@@ -22,7 +23,8 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
info!("Initializing TWI...");
|
||||
let config = twim::Config::default();
|
||||
let mut twi = Twim::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config);
|
||||
static RAM_BUFFER: ConstStaticCell<[u8; 16]> = ConstStaticCell::new([0; 16]);
|
||||
let mut twi = Twim::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config, RAM_BUFFER.take());
|
||||
|
||||
info!("Reading...");
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ async fn main(_p: Spawner) {
|
||||
loop {
|
||||
info!("Initializing TWI...");
|
||||
let config = twim::Config::default();
|
||||
let mut ram_buffer = [0u8; 16];
|
||||
|
||||
// Create the TWIM instance with borrowed singletons, so they're not consumed.
|
||||
let mut twi = Twim::new(
|
||||
@@ -38,6 +39,7 @@ async fn main(_p: Spawner) {
|
||||
p.P0_03.reborrow(),
|
||||
p.P0_04.reborrow(),
|
||||
config,
|
||||
&mut ram_buffer,
|
||||
);
|
||||
|
||||
info!("Reading...");
|
||||
|
||||
Reference in New Issue
Block a user