29#ifdef LIBOPENCM3_I2C_H
31#ifndef LIBOPENCM3_I2C_COMMON_V2_H
32#define LIBOPENCM3_I2C_COMMON_V2_H
57#define I2C_CR1(i2c_base) MMIO32((i2c_base) + 0x00)
58#define I2C1_CR1 I2C_CR1(I2C1)
59#define I2C2_CR1 I2C_CR1(I2C2)
62#define I2C_CR2(i2c_base) MMIO32((i2c_base) + 0x04)
63#define I2C1_CR2 I2C_CR2(I2C1)
64#define I2C2_CR2 I2C_CR2(I2C2)
67#define I2C_OAR1(i2c_base) MMIO32((i2c_base) + 0x08)
68#define I2C1_OAR1 I2C_OAR1(I2C1)
69#define I2C2_OAR1 I2C_OAR1(I2C2)
72#define I2C_OAR2(i2c_base) MMIO32((i2c_base) + 0x0c)
73#define I2C1_OAR2 I2C_OAR2(I2C1)
74#define I2C2_OAR2 I2C_OAR2(I2C2)
77#define I2C_TIMINGR(i2c_base) MMIO32((i2c_base) + 0x10)
78#define I2C1_TIMINGR I2C_TIMINGR(I2C1)
79#define I2C2_TIMINGR I2C_TIMINGR(I2C2)
82#define I2C_TIMEOUTR(i2c_base) MMIO32((i2c_base) + 0x14)
83#define I2C1_TIMEOUTR I2C_TIMEOUTR(I2C1)
84#define I2C2_TIMEOUTR I2C_TIMEOUTR(I2C2)
87#define I2C_ISR(i2c_base) MMIO32((i2c_base) + 0x18)
88#define I2C1_ISR I2C_ISR(I2C1)
89#define I2C2_ISR I2C_ISR(I2C2)
92#define I2C_ICR(i2c_base) MMIO32((i2c_base) + 0x1C)
93#define I2C1_ICR I2C_ICR(I2C1)
94#define I2C2_ICR I2C_ICR(I2C2)
97#define I2C_PECR(i2c_base) MMIO32((i2c_base) + 0x20)
98#define I2C1_PECR I2C_PECR(I2C1)
99#define I2C2_PECR I2C_PECR(I2C2)
102#define I2C_RXDR(i2c_base) MMIO32((i2c_base) + 0x24)
103#define I2C1_RXDR I2C_RXDR(I2C1)
104#define I2C2_RXDR I2C_RXDR(I2C2)
107#define I2C_TXDR(i2c_base) MMIO32((i2c_base) + 0x28)
108#define I2C1_TXDR I2C_TXDR(I2C1)
109#define I2C2_TXDR I2C_TXDR(I2C2)
113#define I2C3_CR1 I2C_CR1(I2C3)
114#define I2C3_CR2 I2C_CR2(I2C3)
115#define I2C3_OAR1 I2C_OAR1(I2C3)
116#define I2C3_OAR2 I2C_OAR2(I2C3)
117#define I2C3_DR I2C_DR(I2C3)
118#define I2C3_SR1 I2C_SR1(I2C3)
119#define I2C3_SR2 I2C_SR2(I2C3)
120#define I2C3_CCR I2C_CCR(I2C3)
121#define I2C3_TRISE I2C_TRISE(I2C3)
127#define I2C_CR1_PECEN (1 << 23)
130#define I2C_CR1_ALERTEN (1 << 22)
133#define I2C_CR1_SMBDEN (1 << 21)
136#define I2C_CR1_SMBHEN (1 << 20)
139#define I2C_CR1_GCEN (1 << 19)
142#define I2C_CR1_WUPEN (1 << 18)
145#define I2C_CR1_NOSTRETCH (1 << 17)
148#define I2C_CR1_SBC (1 << 16)
151#define I2C_CR1_RXDMAEN (1 << 15)
154#define I2C_CR1_TXDMAEN (1 << 14)
157#define I2C_CR1_ANFOFF (1 << 12)
160#define I2C_CR1_DNF_MASK 0xF
161#define I2C_CR1_DNF_SHIFT 8
164#define I2C_CR1_ERRIE (1 << 7)
167#define I2C_CR1_TCIE (1 << 6)
170#define I2C_CR1_STOPIE (1 << 5)
173#define I2C_CR1_NACKIE (1 << 4)
176#define I2C_CR1_ADDRIE (1 << 3)
179#define I2C_CR1_RXIE (1 << 2)
182#define I2C_CR1_TXIE (1 << 1)
185#define I2C_CR1_PE (1 << 0)
190#define I2C_CR2_PECBYTE (1 << 26)
193#define I2C_CR2_AUTOEND (1 << 25)
196#define I2C_CR2_RELOAD (1 << 24)
199#define I2C_CR2_NBYTES_SHIFT 16
200#define I2C_CR2_NBYTES_MASK (0xFF << I2C_CR2_NBYTES_SHIFT)
203#define I2C_CR2_NACK (1 << 15)
206#define I2C_CR2_STOP (1 << 14)
209#define I2C_CR2_START (1 << 13)
212#define I2C_CR2_HEAD10R (1 << 12)
215#define I2C_CR2_ADD10 (1 << 11)
218#define I2C_CR2_RD_WRN (1 << 10)
220#define I2C_CR2_SADD_7BIT_SHIFT 1
221#define I2C_CR2_SADD_10BIT_SHIFT 0
222#define I2C_CR2_SADD_7BIT_MASK (0x7F << I2C_CR2_SADD_7BIT_SHIFT)
223#define I2C_CR2_SADD_10BIT_MASK 0x3FF
228#define I2C_OAR1_OA1EN_DISABLE (0x0 << 15)
229#define I2C_OAR1_OA1EN_ENABLE (0x1 << 15)
232#define I2C_OAR1_OA1MODE (1 << 10)
233#define I2C_OAR1_OA1MODE_7BIT 0
234#define I2C_OAR1_OA1MODE_10BIT 1
241#define I2C_OAR1_OA1 (1 << 10)
242#define I2C_OAR1_OA1_7BIT 0
243#define I2C_OAR1_OA1_10BIT 1
248#define I2C_OAR2_OA2EN (1 << 15)
251#define I2C_OAR2_OA2MSK_NO_MASK (0x0 << 8)
252#define I2C_OAR2_OA2MSK_OA2_7_OA2_2 (0x1 << 8)
253#define I2C_OAR2_OA2MSK_OA2_7_OA2_3 (0x2 << 8)
254#define I2C_OAR2_OA2MSK_OA2_7_OA2_4 (0x3 << 8)
255#define I2C_OAR2_OA2MSK_OA2_7_OA2_5 (0x4 << 8)
256#define I2C_OAR2_OA2MSK_OA2_7_OA2_6 (0x5 << 8)
257#define I2C_OAR2_OA2MSK_OA2_7 (0x6 << 8)
258#define I2C_OAR2_OA2MSK_NO_CMP (0x7 << 8)
265#define I2C_TIMINGR_PRESC_SHIFT 28
266#define I2C_TIMINGR_PRESC_MASK (0xF << 28)
269#define I2C_TIMINGR_SCLDEL_SHIFT 20
270#define I2C_TIMINGR_SCLDEL_MASK (0xF << I2C_TIMINGR_SCLDEL_SHIFT)
273#define I2C_TIMINGR_SDADEL_SHIFT 16
274#define I2C_TIMINGR_SDADEL_MASK (0xF << I2C_TIMINGR_SDADEL_SHIFT)
277#define I2C_TIMINGR_SCLH_SHIFT 8
278#define I2C_TIMINGR_SCLH_MASK (0xFF << I2C_TIMINGR_SCLH_SHIFT)
281#define I2C_TIMINGR_SCLL_SHIFT 0
282#define I2C_TIMINGR_SCLL_MASK (0xFF << I2C_TIMINGR_SCLL_SHIFT)
287#define I2C_TIEMOUTR_TEXTEN (1 << 31)
293#define I2C_TIEMOUTR_TIMOUTEN (1 << 15)
296#define I2C_TIEMOUTR_TIDLE_SCL_LOW (0x0 << 12)
297#define I2C_TIEMOUTR_TIDLE_SCL_SDA_HIGH (0x1 << 12)
310#define I2C_ISR_DIR_READ (0x1 << 16)
311#define I2C_ISR_DIR_WRITE (0x0 << 16)
314#define I2C_ISR_BUSY (1 << 15)
317#define I2C_ISR_ALERT (1 << 13)
320#define I2C_ISR_TIMEOUT (1 << 12)
323#define I2C_ISR_PECERR (1 << 11)
326#define I2C_ISR_OVR (1 << 10)
329#define I2C_ISR_ARLO (1 << 9)
332#define I2C_ISR_BERR (1 << 8)
335#define I2C_ISR_TCR (1 << 7)
338#define I2C_ISR_TC (1 << 6)
341#define I2C_ISR_STOPF (1 << 5)
344#define I2C_ISR_NACKF (1 << 4)
347#define I2C_ISR_ADDR (1 << 3)
350#define I2C_ISR_RXNE (1 << 2)
353#define I2C_ISR_TXIS (1 << 1)
356#define I2C_ISR_TXE (1 << 0)
361#define I2C_ICR_ALERTCF (1 << 13)
364#define I2C_ICR_TIMOUTCF (1 << 12)
367#define I2C_ICR_PECCF (1 << 11)
370#define I2C_ICR_OVRCF (1 << 10)
373#define I2C_ICR_ARLOCF (1 << 9)
376#define I2C_ICR_BERRCF (1 << 8)
379#define I2C_ICR_STOPCF (1 << 5)
382#define I2C_ICR_NACKCF (1 << 4)
385#define I2C_ICR_ADDRCF (1 << 3)
446void i2c_transfer7(uint32_t i2c, uint8_t addr,
const uint8_t *w,
size_t wn, uint8_t *r,
size_t rn);
454#warning "i2c_common_v2.h should not be included explicitly, only via i2c.h"
void i2c_disable_interrupt(uint32_t i2c, uint32_t interrupt)
I2C Disable Interrupt.
void i2c_set_7bit_address(uint32_t i2c, uint8_t addr)
void i2c_enable_analog_filter(uint32_t i2c)
void i2c_enable_interrupt(uint32_t i2c, uint32_t interrupt)
I2C Enable Interrupt.
void i2c_set_digital_filter(uint32_t i2c, uint8_t dnf_setting)
Set the I2C digital filter.
void i2c_set_10bit_addr_mode(uint32_t i2c)
void i2c_set_7bit_addr_mode(uint32_t i2c)
void i2c_disable_analog_filter(uint32_t i2c)
void i2c_set_10bit_address(uint32_t i2c, uint16_t addr)
void i2c_set_prescaler(uint32_t i2c, uint8_t presc)
void i2c_set_data_setup_time(uint32_t i2c, uint8_t s_time)
void i2c_disable_stretching(uint32_t i2c)
void i2c_send_start(uint32_t i2c)
I2C Send Start Condition.
void i2c_peripheral_disable(uint32_t i2c)
I2C Peripheral Disable.
void i2c_set_bytes_to_transfer(uint32_t i2c, uint32_t n_bytes)
bool i2c_is_start(uint32_t i2c)
void i2c_set_write_transfer_dir(uint32_t i2c)
bool i2c_received_data(uint32_t i2c)
void i2c_set_own_7bit_slave_address(uint32_t i2c, uint8_t slave)
I2C Set the 7 bit Slave Address for the Peripheral.
void i2c_set_scl_high_period(uint32_t i2c, uint8_t period)
void i2c_disable_autoend(uint32_t i2c)
void i2c_send_stop(uint32_t i2c)
I2C Send Stop Condition.
void i2c_peripheral_enable(uint32_t i2c)
I2C Peripheral Enable.
void i2c_enable_rxdma(uint32_t i2c)
I2C Enable reception DMA.
void i2c_set_data_hold_time(uint32_t i2c, uint8_t h_time)
i2c_speeds
I2C speed modes.
void i2c_set_own_10bit_slave_address(uint32_t i2c, uint16_t slave)
I2C Set the 10 bit Slave Address for the Peripheral.
bool i2c_transmit_int_status(uint32_t i2c)
void i2c_disable_rxdma(uint32_t i2c)
I2C Disable reception DMA.
void i2c_enable_autoend(uint32_t i2c)
void i2c_enable_stretching(uint32_t i2c)
void i2c_set_read_transfer_dir(uint32_t i2c)
void i2c_send_data(uint32_t i2c, uint8_t data)
I2C Send Data.
uint8_t i2c_get_data(uint32_t i2c)
I2C Get Data.
void i2c_clear_stop(uint32_t i2c)
I2C Clear Stop Flag.
bool i2c_busy(uint32_t i2c)
void i2c_set_scl_low_period(uint32_t i2c, uint8_t period)
void i2c_disable_txdma(uint32_t i2c)
I2C Disable transmission DMA.
void i2c_enable_txdma(uint32_t i2c)
I2C Enable transmission DMA.
bool i2c_transfer_complete(uint32_t i2c)
void i2c_transfer7(uint32_t i2c, uint8_t addr, const uint8_t *w, size_t wn, uint8_t *r, size_t rn)
Run a write/read transaction to a given 7bit i2c address If both write & read are provided,...
bool i2c_nack(uint32_t i2c)
void i2c_set_speed(uint32_t i2c, enum i2c_speeds speed, uint32_t clock_megahz)
Set the i2c communication speed.