libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
i2c_common_v1.h File Reference
#include <stddef.h>
#include <stdint.h>
Include dependency graph for i2c_common_v1.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define I2C1   I2C1_BASE
 
#define I2C2   I2C2_BASE
 
#define I2C_CR1(i2c_base)   MMIO32((i2c_base) + 0x00)
 
#define I2C1_CR1   I2C_CR1(I2C1)
 
#define I2C2_CR1   I2C_CR1(I2C2)
 
#define I2C_CR2(i2c_base)   MMIO32((i2c_base) + 0x04)
 
#define I2C1_CR2   I2C_CR2(I2C1)
 
#define I2C2_CR2   I2C_CR2(I2C2)
 
#define I2C_OAR1(i2c_base)   MMIO32((i2c_base) + 0x08)
 
#define I2C1_OAR1   I2C_OAR1(I2C1)
 
#define I2C2_OAR1   I2C_OAR1(I2C2)
 
#define I2C_OAR2(i2c_base)   MMIO32((i2c_base) + 0x0c)
 
#define I2C1_OAR2   I2C_OAR2(I2C1)
 
#define I2C2_OAR2   I2C_OAR2(I2C2)
 
#define I2C_DR(i2c_base)   MMIO32((i2c_base) + 0x10)
 
#define I2C1_DR   I2C_DR(I2C1)
 
#define I2C2_DR   I2C_DR(I2C2)
 
#define I2C_SR1(i2c_base)   MMIO32((i2c_base) + 0x14)
 
#define I2C1_SR1   I2C_SR1(I2C1)
 
#define I2C2_SR1   I2C_SR1(I2C2)
 
#define I2C_SR2(i2c_base)   MMIO32((i2c_base) + 0x18)
 
#define I2C1_SR2   I2C_SR2(I2C1)
 
#define I2C2_SR2   I2C_SR2(I2C2)
 
#define I2C_CCR(i2c_base)   MMIO32((i2c_base) + 0x1c)
 
#define I2C1_CCR   I2C_CCR(I2C1)
 
#define I2C2_CCR   I2C_CCR(I2C2)
 
#define I2C_TRISE(i2c_base)   MMIO32((i2c_base) + 0x20)
 
#define I2C1_TRISE   I2C_TRISE(I2C1)
 
#define I2C2_TRISE   I2C_TRISE(I2C2)
 
#define I2C_CR1_SWRST   (1 << 15)
 
#define I2C_CR1_ALERT   (1 << 13)
 
#define I2C_CR1_PEC   (1 << 12)
 
#define I2C_CR1_POS   (1 << 11)
 
#define I2C_CR1_ACK   (1 << 10)
 
#define I2C_CR1_STOP   (1 << 9)
 
#define I2C_CR1_START   (1 << 8)
 
#define I2C_CR1_NOSTRETCH   (1 << 7)
 
#define I2C_CR1_ENGC   (1 << 6)
 
#define I2C_CR1_ENPEC   (1 << 5)
 
#define I2C_CR1_ENARP   (1 << 4)
 
#define I2C_CR1_SMBTYPE   (1 << 3)
 
#define I2C_CR1_SMBUS   (1 << 1)
 
#define I2C_CR1_PE   (1 << 0)
 
#define I2C_CR2_LAST   (1 << 12)
 
#define I2C_CR2_DMAEN   (1 << 11)
 
#define I2C_CR2_ITBUFEN   (1 << 10)
 
#define I2C_CR2_ITEVTEN   (1 << 9)
 
#define I2C_CR2_ITERREN   (1 << 8)
 
#define I2C_OAR1_ADDMODE   (1 << 15)
 
#define I2C_OAR1_ADDMODE_7BIT   0
 
#define I2C_OAR1_ADDMODE_10BIT   1
 
#define I2C_OAR2_ENDUAL   (1 << 0)
 
#define I2C_SR1_SMBALERT   (1 << 15)
 
#define I2C_SR1_TIMEOUT   (1 << 14)
 
#define I2C_SR1_PECERR   (1 << 12)
 
#define I2C_SR1_OVR   (1 << 11)
 
#define I2C_SR1_AF   (1 << 10)
 
#define I2C_SR1_ARLO   (1 << 9)
 
#define I2C_SR1_BERR   (1 << 8)
 
#define I2C_SR1_TxE   (1 << 7)
 
#define I2C_SR1_RxNE   (1 << 6)
 
#define I2C_SR1_STOPF   (1 << 4)
 
#define I2C_SR1_ADD10   (1 << 3)
 
#define I2C_SR1_BTF   (1 << 2)
 
#define I2C_SR1_ADDR   (1 << 1)
 
#define I2C_SR1_SB   (1 << 0)
 
#define I2C_SR2_DUALF   (1 << 7)
 
#define I2C_SR2_SMBHOST   (1 << 6)
 
#define I2C_SR2_SMBDEFAULT   (1 << 5)
 
#define I2C_SR2_GENCALL   (1 << 4)
 
#define I2C_SR2_TRA   (1 << 2)
 
#define I2C_SR2_BUSY   (1 << 1)
 
#define I2C_SR2_MSL   (1 << 0)
 
#define I2C_CCR_FS   (1 << 15)
 
#define I2C_CCR_DUTY   (1 << 14)
 
#define I2C_CCR_DUTY_DIV2   0
 
#define I2C_CCR_DUTY_16_DIV_9   1
 
#define I2C_WRITE   0
 
#define I2C_READ   1
 

Enumerations

enum  i2c_cr2_freq_values {
  I2C_CR2_FREQ_2MHZ = 2 , I2C_CR2_FREQ_3MHZ , I2C_CR2_FREQ_4MHZ , I2C_CR2_FREQ_5MHZ ,
  I2C_CR2_FREQ_6MHZ , I2C_CR2_FREQ_7MHZ , I2C_CR2_FREQ_8MHZ , I2C_CR2_FREQ_9MHZ ,
  I2C_CR2_FREQ_10MHZ , I2C_CR2_FREQ_11MHZ , I2C_CR2_FREQ_12MHZ , I2C_CR2_FREQ_13MHZ ,
  I2C_CR2_FREQ_14MHZ , I2C_CR2_FREQ_15MHZ , I2C_CR2_FREQ_16MHZ , I2C_CR2_FREQ_17MHZ ,
  I2C_CR2_FREQ_18MHZ , I2C_CR2_FREQ_19MHZ , I2C_CR2_FREQ_20MHZ , I2C_CR2_FREQ_21MHZ ,
  I2C_CR2_FREQ_22MHZ , I2C_CR2_FREQ_23MHZ , I2C_CR2_FREQ_24MHZ , I2C_CR2_FREQ_25MHZ ,
  I2C_CR2_FREQ_26MHZ , I2C_CR2_FREQ_27MHZ , I2C_CR2_FREQ_28MHZ , I2C_CR2_FREQ_29MHZ ,
  I2C_CR2_FREQ_30MHZ , I2C_CR2_FREQ_31MHZ , I2C_CR2_FREQ_32MHZ , I2C_CR2_FREQ_33MHZ ,
  I2C_CR2_FREQ_34MHZ , I2C_CR2_FREQ_35MHZ , I2C_CR2_FREQ_36MHZ , I2C_CR2_FREQ_37MHZ ,
  I2C_CR2_FREQ_38MHZ , I2C_CR2_FREQ_39MHZ , I2C_CR2_FREQ_40MHZ , I2C_CR2_FREQ_41MHZ ,
  I2C_CR2_FREQ_42MHZ
}
 
enum  i2c_speeds { i2c_speed_sm_100k , i2c_speed_fm_400k , i2c_speed_fmp_1m , i2c_speed_unknown }
 I2C speed modes. More...
 

Functions

void i2c_peripheral_enable (uint32_t i2c)
 I2C Peripheral Enable. More...
 
void i2c_peripheral_disable (uint32_t i2c)
 I2C Peripheral Disable. More...
 
void i2c_send_start (uint32_t i2c)
 I2C Send Start Condition. More...
 
void i2c_send_stop (uint32_t i2c)
 I2C Send Stop Condition. More...
 
void i2c_clear_stop (uint32_t i2c)
 I2C Clear Stop Flag. More...
 
void i2c_set_own_7bit_slave_address (uint32_t i2c, uint8_t slave)
 I2C Set the 7 bit Slave Address for the Peripheral. More...
 
void i2c_set_own_10bit_slave_address (uint32_t i2c, uint16_t slave)
 I2C Set the 10 bit Slave Address for the Peripheral. More...
 
void i2c_set_own_7bit_slave_address_two (uint32_t i2c, uint8_t slave)
 I2C Set the secondary 7 bit Slave Address for the Peripheral. More...
 
void i2c_enable_dual_addressing_mode (uint32_t i2c)
 I2C Enable dual addressing mode for the Peripheral. More...
 
void i2c_disable_dual_addressing_mode (uint32_t i2c)
 I2C Disable dual addressing mode for the Peripheral. More...
 
void i2c_set_clock_frequency (uint32_t i2c, uint8_t freq)
 I2C Set Peripheral Clock Frequency. More...
 
void i2c_send_data (uint32_t i2c, uint8_t data)
 I2C Send Data. More...
 
void i2c_set_fast_mode (uint32_t i2c)
 I2C Set Fast Mode. More...
 
void i2c_set_standard_mode (uint32_t i2c)
 I2C Set Standard Mode. More...
 
void i2c_set_ccr (uint32_t i2c, uint16_t freq)
 I2C Set Bus Clock Frequency. More...
 
void i2c_set_trise (uint32_t i2c, uint16_t trise)
 I2C Set the Rise Time. More...
 
void i2c_send_7bit_address (uint32_t i2c, uint8_t slave, uint8_t readwrite)
 I2C Send the 7-bit Slave Address. More...
 
uint8_t i2c_get_data (uint32_t i2c)
 I2C Get Data. More...
 
void i2c_enable_interrupt (uint32_t i2c, uint32_t interrupt)
 I2C Enable Interrupt. More...
 
void i2c_disable_interrupt (uint32_t i2c, uint32_t interrupt)
 I2C Disable Interrupt. More...
 
void i2c_enable_ack (uint32_t i2c)
 I2C Enable ACK. More...
 
void i2c_disable_ack (uint32_t i2c)
 I2C Disable ACK. More...
 
void i2c_nack_next (uint32_t i2c)
 I2C NACK Next Byte. More...
 
void i2c_nack_current (uint32_t i2c)
 I2C NACK Next Byte. More...
 
void i2c_set_dutycycle (uint32_t i2c, uint32_t dutycycle)
 I2C Set clock duty cycle. More...
 
void i2c_enable_dma (uint32_t i2c)
 I2C Enable DMA. More...
 
void i2c_disable_dma (uint32_t i2c)
 I2C Disable DMA. More...
 
void i2c_set_dma_last_transfer (uint32_t i2c)
 I2C Set DMA last transfer. More...
 
void i2c_clear_dma_last_transfer (uint32_t i2c)
 I2C Clear DMA last transfer. More...
 
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, the read will use repeated start. More...
 
void i2c_set_speed (uint32_t i2c, enum i2c_speeds speed, uint32_t clock_megahz)
 Set the i2c communication speed. More...