aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-12-03 09:52:03 -0800
committerGitHub <[email protected]>2025-12-03 09:52:03 -0800
commit8798306fb2c124efc06443c2913c3d7a4919dd83 (patch)
tree2ab37822bd40cf90abe3aecafac539b6cb4cfeaa /examples
parent717346f21a4cf4993c2a1f046e26b6bf647d89cb (diff)
I2c Async (#50)
* I2c Async Signed-off-by: Felipe Balbi <[email protected]> * Fix i2c read bug Signed-off-by: Felipe Balbi <[email protected]> * Introduce wait_for() Signed-off-by: Felipe Balbi <[email protected]> * Review comments Signed-off-by: Felipe Balbi <[email protected]> * more review comments Signed-off-by: Felipe Balbi <[email protected]> * review comments Signed-off-by: Felipe Balbi <[email protected]> * review comments Signed-off-by: Felipe Balbi <[email protected]> * convert async fn to impl Future Signed-off-by: Felipe Balbi <[email protected]> --------- Signed-off-by: Felipe Balbi <[email protected]> Co-authored-by: Felipe Balbi <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/src/bin/i2c-async.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/src/bin/i2c-async.rs b/examples/src/bin/i2c-async.rs
new file mode 100644
index 000000000..47b5f3cbe
--- /dev/null
+++ b/examples/src/bin/i2c-async.rs
@@ -0,0 +1,39 @@
1#![no_std]
2#![no_main]
3
4use embassy_executor::Spawner;
5use embassy_time::Timer;
6use hal::bind_interrupts;
7use hal::clocks::config::Div8;
8use hal::config::Config;
9use hal::i2c::controller::{self, I2c, Speed};
10use hal::i2c::InterruptHandler;
11use hal::peripherals::LPI2C3;
12use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
13
14bind_interrupts!(
15 struct Irqs {
16 LPI2C3 => InterruptHandler<LPI2C3>;
17 }
18);
19
20#[embassy_executor::main]
21async fn main(_spawner: Spawner) {
22 let mut config = Config::default();
23 config.clock_cfg.sirc.fro_lf_div = Div8::from_divisor(1);
24
25 let p = hal::init(config);
26
27 defmt::info!("I2C example");
28
29 let mut config = controller::Config::default();
30 config.speed = Speed::Standard;
31 let mut i2c = I2c::new_async(p.LPI2C3, p.P3_27, p.P3_28, Irqs, config).unwrap();
32 let mut buf = [0u8; 2];
33
34 loop {
35 i2c.async_write_read(0x48, &[0x00], &mut buf).await.unwrap();
36 defmt::info!("Buffer: {:02x}", buf);
37 Timer::after_secs(1).await;
38 }
39}