atmega_hal/
i2c.rs

1//! I2C
2//!
3//! # Example
4//!
5//! Complete example source code can be found in the repository:
6//! [`atmega2560-i2cdetect.rs`](https://github.com/Rahix/avr-hal/blob/main/examples/atmega2560/src/bin/atmega2560-i2cdetect.rs)
7//!
8//! ```
9//! let dp = atmega_hal::Peripherals::take().unwrap();
10//! let pins = atmega_hal::pins!(dp);
11//!
12//! let mut i2c = I2c::new(
13//!     dp.TWI,
14//!     pins.pd1.into_pull_up_input(),
15//!     pins.pd0.into_pull_up_input(),
16//!     50_000,
17//! );
18//!
19//! i2c.i2cdetect(&mut serial, atmega_hal::i2c::Direction::Read).unwrap();
20//! ```
21
22#[allow(unused_imports)]
23use crate::port;
24pub use avr_hal_generic::i2c::*;
25
26#[cfg(any(
27    feature = "atmega128a",
28    feature = "atmega1280",
29    feature = "atmega2560",
30    feature = "atmega32u4"
31))]
32pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
33    crate::Atmega,
34    crate::pac::TWI,
35    port::Pin<port::mode::Input, port::PD1>,
36    port::Pin<port::mode::Input, port::PD0>,
37    CLOCK,
38>;
39#[cfg(any(
40    feature = "atmega128a",
41    feature = "atmega1280",
42    feature = "atmega2560",
43    feature = "atmega32u4"
44))]
45avr_hal_generic::impl_i2c_twi! {
46    hal: crate::Atmega,
47    peripheral: crate::pac::TWI,
48    sda: port::PD1,
49    scl: port::PD0,
50}
51
52#[cfg(any(feature = "atmega16", feature = "atmega164pa"))]
53pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
54    crate::Atmega,
55    crate::pac::TWI,
56    port::Pin<port::mode::Input, port::PC1>,
57    port::Pin<port::mode::Input, port::PC0>,
58    CLOCK,
59>;
60#[cfg(any(feature = "atmega16", feature = "atmega164pa"))]
61avr_hal_generic::impl_i2c_twi! {
62    hal: crate::Atmega,
63    peripheral: crate::pac::TWI,
64    sda: port::PC1,
65    scl: port::PC0,
66}
67
68#[cfg(any(
69    feature = "atmega328p",
70    feature = "atmega168",
71    feature = "atmega48p",
72    feature = "atmega8",
73    feature = "atmega88p"
74))]
75pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
76    crate::Atmega,
77    crate::pac::TWI,
78    port::Pin<port::mode::Input, port::PC4>,
79    port::Pin<port::mode::Input, port::PC5>,
80    CLOCK,
81>;
82#[cfg(any(
83    feature = "atmega328p",
84    feature = "atmega168",
85    feature = "atmega48p",
86    feature = "atmega8",
87    feature = "atmega88p"
88))]
89avr_hal_generic::impl_i2c_twi! {
90    hal: crate::Atmega,
91    peripheral: crate::pac::TWI,
92    sda: port::PC4,
93    scl: port::PC5,
94}
95
96#[cfg(any(feature = "atmega328pb"))]
97pub type I2c0<CLOCK> = avr_hal_generic::i2c::I2c<
98    crate::Atmega,
99    crate::pac::TWI0,
100    port::Pin<port::mode::Input, port::PC4>,
101    port::Pin<port::mode::Input, port::PC5>,
102    CLOCK,
103>;
104#[cfg(any(feature = "atmega328pb"))]
105avr_hal_generic::impl_i2c_twi! {
106    hal: crate::Atmega,
107    peripheral: crate::pac::TWI0,
108    sda: port::PC4,
109    scl: port::PC5,
110}
111#[cfg(any(feature = "atmega328pb"))]
112pub type I2c1<CLOCK> = avr_hal_generic::i2c::I2c<
113    crate::Atmega,
114    crate::pac::TWI1,
115    port::Pin<port::mode::Input, port::PE0>,
116    port::Pin<port::mode::Input, port::PE1>,
117    CLOCK,
118>;
119#[cfg(any(feature = "atmega328pb"))]
120avr_hal_generic::impl_i2c_twi! {
121    hal: crate::Atmega,
122    peripheral: crate::pac::TWI1,
123    sda: port::PE0,
124    scl: port::PE1,
125}
126
127#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
128pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
129    crate::Atmega,
130    crate::pac::TWI,
131    port::Pin<port::mode::Input, port::PC1>,
132    port::Pin<port::mode::Input, port::PC0>,
133    CLOCK,
134>;
135#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
136avr_hal_generic::impl_i2c_twi! {
137    hal: crate::Atmega,
138    peripheral: crate::pac::TWI,
139    sda: port::PC1,
140    scl: port::PC0,
141}