1#[cfg(feature = "i2c-blocking")]
2pub mod blocking;
3
4#[cfg(feature = "i2c-nonblocking")]
5pub mod nonblocking;
6
7#[cfg(feature = "i2c-nonblocking")]
8pub use nonblocking::*;
9
10pub mod config;
11
12use crate::rcc::*;
13pub use config::Config;
14
15#[derive(Debug, Clone, Copy)]
16pub enum SlaveAddressMask {
17 MaskNone = 0,
18 MaskOneBit,
19 MaskTwoBits,
20 MaskThreeBits,
21 MaskFourBits,
22 MaskFiveBits,
23 MaskSixBits,
24 MaskAllBits,
25}
26
27#[derive(Debug, Clone, Copy)]
28pub enum I2cResult<'a> {
29 Data(u16, I2cDirection, &'a [u8]), Addressed(u16, I2cDirection), }
32
33#[derive(Debug, Clone, Copy)]
34pub enum I2cDirection {
35 MasterReadSlaveWrite = 0,
36 MasterWriteSlaveRead = 1,
37}
38
39#[derive(Debug, Clone, Copy)]
40pub enum Event {
41 AddressMatch,
42 Rxne,
43}
44
45#[derive(Debug, Clone, Copy)]
47pub enum Error {
48 Overrun,
49 Nack,
50 PECError,
51 BusError,
52 ArbitrationLost,
53 IncorrectFrameSize(usize),
54}
55
56pub trait SDAPin<I2C> {
58 fn setup(&self);
59 fn release(self) -> Self;
60}
61
62pub trait SCLPin<I2C> {
64 fn setup(&self);
65 fn release(self) -> Self;
66}
67
68pub trait I2cExt<I2C> {
69 fn i2c<SDA, SCL>(
70 self,
71 sda: SDA,
72 scl: SCL,
73 config: impl Into<Config>,
74 rcc: &mut Rcc,
75 ) -> I2c<I2C, SDA, SCL>
76 where
77 SDA: SDAPin<I2C>,
78 SCL: SCLPin<I2C>;
79}
80
81#[cfg(feature = "i2c-blocking")]
83pub struct I2c<I2C, SDA, SCL> {
84 i2c: I2C,
85 sda: SDA,
86 scl: SCL,
87}
88
89#[cfg(feature = "i2c-nonblocking")]
90pub struct I2c<I2C, SDA, SCL> {
91 i2c: I2C,
92 sda: SDA,
93 scl: SCL,
94 address: u16,
95 watchdog: u16, index: usize,
97 length: usize,
98 errors: usize, length_write_read: usize, data: [u8; 255], }