1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! I2C
//!
//! # Example
//!
//! Complete example source code can be found in the repository:
//! [`atmega2560-i2cdetect.rs`](https://github.com/Rahix/avr-hal/blob/main/examples/atmega2560/src/bin/atmega2560-i2cdetect.rs)
//!
//! ```
//! let dp = atmega_hal::Peripherals::take().unwrap();
//! let pins = atmega_hal::pins!(dp);
//!
//! let mut i2c = I2c::new(
//!     dp.TWI,
//!     pins.pd1.into_pull_up_input(),
//!     pins.pd0.into_pull_up_input(),
//!     50_000,
//! );
//!
//! i2c.i2cdetect(&mut serial, atmega_hal::i2c::Direction::Read).unwrap();
//! ```

#[allow(unused_imports)]
use crate::port;
pub use avr_hal_generic::i2c::*;

#[cfg(any(
    feature = "atmega128a",
    feature = "atmega1280",
    feature = "atmega2560",
    feature = "atmega32u4"
))]
pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
    crate::Atmega,
    crate::pac::TWI,
    port::Pin<port::mode::Input, port::PD1>,
    port::Pin<port::mode::Input, port::PD0>,
    CLOCK,
>;
#[cfg(any(
    feature = "atmega128a",
    feature = "atmega1280",
    feature = "atmega2560",
    feature = "atmega32u4"
))]
avr_hal_generic::impl_i2c_twi! {
    hal: crate::Atmega,
    peripheral: crate::pac::TWI,
    sda: port::PD1,
    scl: port::PD0,
}

#[cfg(any(feature = "atmega164pa"))]
pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
    crate::Atmega,
    crate::pac::TWI,
    port::Pin<port::mode::Input, port::PC1>,
    port::Pin<port::mode::Input, port::PC0>,
    CLOCK,
>;
#[cfg(any(feature = "atmega164pa"))]
avr_hal_generic::impl_i2c_twi! {
    hal: crate::Atmega,
    peripheral: crate::pac::TWI,
    sda: port::PC1,
    scl: port::PC0,
}

#[cfg(any(
    feature = "atmega328p",
    feature = "atmega168",
    feature = "atmega48p",
    feature = "atmega8"
))]
pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
    crate::Atmega,
    crate::pac::TWI,
    port::Pin<port::mode::Input, port::PC4>,
    port::Pin<port::mode::Input, port::PC5>,
    CLOCK,
>;
#[cfg(any(
    feature = "atmega328p",
    feature = "atmega168",
    feature = "atmega48p",
    feature = "atmega8"
))]
avr_hal_generic::impl_i2c_twi! {
    hal: crate::Atmega,
    peripheral: crate::pac::TWI,
    sda: port::PC4,
    scl: port::PC5,
}

#[cfg(any(feature = "atmega328pb"))]
pub type I2c0<CLOCK> = avr_hal_generic::i2c::I2c<
    crate::Atmega,
    crate::pac::TWI0,
    port::Pin<port::mode::Input, port::PC4>,
    port::Pin<port::mode::Input, port::PC5>,
    CLOCK,
>;
#[cfg(any(feature = "atmega328pb"))]
avr_hal_generic::impl_i2c_twi! {
    hal: crate::Atmega,
    peripheral: crate::pac::TWI0,
    sda: port::PC4,
    scl: port::PC5,
}
#[cfg(any(feature = "atmega328pb"))]
pub type I2c1<CLOCK> = avr_hal_generic::i2c::I2c<
    crate::Atmega,
    crate::pac::TWI1,
    port::Pin<port::mode::Input, port::PE0>,
    port::Pin<port::mode::Input, port::PE1>,
    CLOCK,
>;
#[cfg(any(feature = "atmega328pb"))]
avr_hal_generic::impl_i2c_twi! {
    hal: crate::Atmega,
    peripheral: crate::pac::TWI1,
    sda: port::PE0,
    scl: port::PE1,
}

#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
    crate::Atmega,
    crate::pac::TWI,
    port::Pin<port::mode::Input, port::PC1>,
    port::Pin<port::mode::Input, port::PC0>,
    CLOCK,
>;
#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
avr_hal_generic::impl_i2c_twi! {
    hal: crate::Atmega,
    peripheral: crate::pac::TWI,
    sda: port::PC1,
    scl: port::PC0,
}