aboutsummaryrefslogtreecommitdiff
path: root/src/i2c/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/i2c/mod.rs')
-rw-r--r--src/i2c/mod.rs43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/i2c/mod.rs b/src/i2c/mod.rs
index a1f842029..9a014224a 100644
--- a/src/i2c/mod.rs
+++ b/src/i2c/mod.rs
@@ -3,7 +3,7 @@
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4 4
5use embassy_hal_internal::PeripheralType; 5use embassy_hal_internal::PeripheralType;
6use embassy_sync::waitqueue::AtomicWaker; 6use maitake_sync::WaitCell;
7use paste::paste; 7use paste::paste;
8 8
9use crate::clocks::periph_helpers::Lpi2cConfig; 9use crate::clocks::periph_helpers::Lpi2cConfig;
@@ -22,6 +22,8 @@ pub mod controller;
22pub enum Error { 22pub enum Error {
23 /// Clock configuration error. 23 /// Clock configuration error.
24 ClockSetup(ClockError), 24 ClockSetup(ClockError),
25 /// FIFO Error
26 FifoError,
25 /// Reading for I2C failed. 27 /// Reading for I2C failed.
26 ReadFail, 28 ReadFail,
27 /// Writing to I2C failed. 29 /// Writing to I2C failed.
@@ -47,11 +49,32 @@ pub struct InterruptHandler<T: Instance> {
47 49
48impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandler<T> { 50impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandler<T> {
49 unsafe fn on_interrupt() { 51 unsafe fn on_interrupt() {
50 let waker = T::waker(); 52 if T::regs().mier().read().bits() != 0 {
51 53 T::regs().mier().write(|w| {
52 waker.wake(); 54 w.tdie()
53 55 .disabled()
54 todo!() 56 .rdie()
57 .disabled()
58 .epie()
59 .disabled()
60 .sdie()
61 .disabled()
62 .ndie()
63 .disabled()
64 .alie()
65 .disabled()
66 .feie()
67 .disabled()
68 .pltie()
69 .disabled()
70 .dmie()
71 .disabled()
72 .stie()
73 .disabled()
74 });
75
76 T::wait_cell().wake();
77 }
55 } 78 }
56} 79}
57 80
@@ -64,7 +87,7 @@ impl<T: GpioPin> sealed::Sealed for T {}
64 87
65trait SealedInstance { 88trait SealedInstance {
66 fn regs() -> &'static pac::lpi2c0::RegisterBlock; 89 fn regs() -> &'static pac::lpi2c0::RegisterBlock;
67 fn waker() -> &'static AtomicWaker; 90 fn wait_cell() -> &'static WaitCell;
68} 91}
69 92
70/// I2C Instance 93/// I2C Instance
@@ -85,9 +108,9 @@ macro_rules! impl_instance {
85 unsafe { &*pac::[<Lpi2c $n>]::ptr() } 108 unsafe { &*pac::[<Lpi2c $n>]::ptr() }
86 } 109 }
87 110
88 fn waker() -> &'static AtomicWaker { 111 fn wait_cell() -> &'static WaitCell {
89 static WAKER: AtomicWaker = AtomicWaker::new(); 112 static WAIT_CELL: WaitCell = WaitCell::new();
90 &WAKER 113 &WAIT_CELL
91 } 114 }
92 } 115 }
93 116