APM:Libraries
Classes | Macros | Typedefs | Functions | Variables
i2c.h File Reference
#include <hal_types.h>
#include <hal.h>
#include "dma.h"
Include dependency graph for i2c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  I2C_DMA
 
struct  I2c_state
 
struct  i2c_dev
 I2C device type. More...
 

Macros

#define I2C_50KHz_SPEED   50000
 
#define I2C_75KHz_SPEED   75000
 
#define I2C_100KHz_SPEED   100000
 
#define I2C_250KHz_SPEED   250000
 
#define I2C_400KHz_SPEED   400000
 
#define I2C_BIT_MASK   ((uint32_t)0x00FFFFFF)
 
#define I2C_BIT_SMBALERT   ((uint32_t)0x0008000)
 
#define I2C_BIT_TIMEOUT   ((uint32_t)0x4000)
 
#define I2C_BIT_PECERR   ((uint32_t)0x1000)
 
#define I2C_BIT_OVR   ((uint32_t)0x0800)
 
#define I2C_BIT_AF   ((uint32_t)0x0400)
 
#define I2C_BIT_ARLO   ((uint32_t)0x0200)
 
#define I2C_BIT_BERR   ((uint32_t)0x0100)
 
#define I2C_BIT_TXE   ((uint32_t)0x0080)
 
#define I2C_BIT_RXNE   ((uint32_t)0x0040)
 
#define I2C_BIT_STOPF   ((uint32_t)0x0010)
 
#define I2C_BIT_ADD10   ((uint32_t)0x0008)
 
#define I2C_BIT_BTF   ((uint32_t)0x0004)
 
#define I2C_BIT_ADDR   ((uint32_t)0x0002)
 
#define I2C_BIT_SB   ((uint32_t)0x0001)
 
#define I2C_IE_BUF   ((uint16_t)0x0400)
 
#define I2C_IE_EVT   ((uint16_t)0x0200)
 
#define I2C_IE_ERR   ((uint16_t)0x0100)
 
#define I2C_BIT_DUALF   ((uint32_t)0x0080)
 
#define I2C_BIT_SMBHOST   ((uint32_t)0x0040)
 
#define I2C_BIT_SMBDEFAULT   ((uint32_t)0x0020)
 
#define I2C_BIT_GENCALL   ((uint32_t)0x0010)
 
#define I2C_BIT_TRA   ((uint32_t)0x0004)
 
#define I2C_BIT_BUSY   ((uint32_t)0x0002)
 
#define I2C_BIT_MSL   ((uint32_t)0x0001)
 
#define I2C_NACKPosition_Next   ((uint16_t)0x0800)
 
#define I2C_NACKPosition_Current   ((uint16_t)0xF7FF)
 
#define I2C_Direction_Transmitter   ((uint8_t)0x00)
 
#define I2C_Direction_Receiver   ((uint8_t)0x01)
 
#define I2C_TIMEOUT   (300)
 
#define I2C_SMALL_TIMEOUT   (50)
 
#define I2C_OK   0
 
#define I2C_NO_DEVICE   1
 
#define I2C_ERROR   2
 
#define I2C_BUS_BUSY   2
 
#define I2C_ERR_WRITE   6
 
#define I2C_NO_REGISTER   8
 
#define I2C_BUS_ERR   99
 
#define I2C_ERR_STOP   98
 
#define I2C_STOP_BERR   97
 
#define I2C_STOP_BUSY   96
 
#define I2C_ERR_TIMEOUT   95
 
#define I2C_ERR_REGISTER   94
 
#define I2C_ERR_OVERRUN   93
 
#define I2C_ERR_STOP_TIMEOUT   92
 
#define I2C_DMA_BUSY   103
 
#define I2C_PENDING   255
 
#define I2C_DMA_ERROR   100
 
#define DMA_BUFSIZE   8
 

Typedefs

typedef struct I2C_DMA I2C_dma
 
typedef struct I2c_state i2c_state
 
typedef struct i2c_dev i2c_dev
 I2C device type. More...
 

Functions

void i2c_init (const i2c_dev *dev, uint16_t address, uint32_t speed)
 
void i2c_deinit (const i2c_dev *dev)
 DeInitializes peripherals used by the I2C driver. More...
 
uint32_t i2c_write (const i2c_dev *dev, uint8_t addr, const uint8_t *tx_buff, uint8_t txlen)
 
uint32_t i2c_read (const i2c_dev *dev, uint8_t addr, const uint8_t *tx_buff, uint8_t txlen, uint8_t *rx_buff, uint8_t rxlen)
 
void i2c_lowLevel_deinit (const i2c_dev *dev)
 DeInitializes peripherals used by the I2C driver. More...
 
void i2c_master_release_bus (const i2c_dev *dev)
 
bool i2c_bus_reset (const i2c_dev *dev)
 
static void i2c_set_isr_handler (const i2c_dev *dev, Handler h)
 
static void i2c_clear_isr_handler (const i2c_dev *dev)
 
static void i2c_send_address (const i2c_dev *dev, uint8_t address, uint8_t direction)
 

Variables

uint32_t i2c_bit_time
 
const i2c_dev *const _I2C1
 
const i2c_dev *const _I2C2
 
const i2c_dev *const _I2C3
 

Macro Definition Documentation

◆ DMA_BUFSIZE

#define DMA_BUFSIZE   8

Definition at line 80 of file i2c.h.

◆ I2C_100KHz_SPEED

#define I2C_100KHz_SPEED   100000

Definition at line 10 of file i2c.h.

◆ I2C_250KHz_SPEED

#define I2C_250KHz_SPEED   250000

Definition at line 11 of file i2c.h.

Referenced by F4Light::I2CDevice::init().

◆ I2C_400KHz_SPEED

#define I2C_400KHz_SPEED   400000

Definition at line 12 of file i2c.h.

Referenced by F4Light::I2CDevice::init().

◆ I2C_50KHz_SPEED

#define I2C_50KHz_SPEED   50000

Definition at line 8 of file i2c.h.

◆ I2C_75KHz_SPEED

#define I2C_75KHz_SPEED   75000

Definition at line 9 of file i2c.h.

◆ I2C_BIT_ADD10

#define I2C_BIT_ADD10   ((uint32_t)0x0008)

Definition at line 28 of file i2c.h.

◆ I2C_BIT_ADDR

#define I2C_BIT_ADDR   ((uint32_t)0x0002)

Definition at line 30 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_BIT_AF

#define I2C_BIT_AF   ((uint32_t)0x0400)

Definition at line 22 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_BIT_ARLO

#define I2C_BIT_ARLO   ((uint32_t)0x0200)

Definition at line 23 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev(), and F4Light::I2CDevice::wait_stop_done().

◆ I2C_BIT_BERR

#define I2C_BIT_BERR   ((uint32_t)0x0100)

Definition at line 24 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev(), and F4Light::I2CDevice::wait_stop_done().

◆ I2C_BIT_BTF

#define I2C_BIT_BTF   ((uint32_t)0x0004)

Definition at line 29 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_BIT_BUSY

#define I2C_BIT_BUSY   ((uint32_t)0x0002)

Definition at line 44 of file i2c.h.

Referenced by F4Light::I2CDevice::wait_stop_done().

◆ I2C_BIT_DUALF

#define I2C_BIT_DUALF   ((uint32_t)0x0080)

Definition at line 39 of file i2c.h.

◆ I2C_BIT_GENCALL

#define I2C_BIT_GENCALL   ((uint32_t)0x0010)

Definition at line 42 of file i2c.h.

◆ I2C_BIT_MASK

#define I2C_BIT_MASK   ((uint32_t)0x00FFFFFF)

Definition at line 15 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev(), and F4Light::I2CDevice::wait_stop_done().

◆ I2C_BIT_MSL

#define I2C_BIT_MSL   ((uint32_t)0x0001)

Definition at line 45 of file i2c.h.

◆ I2C_BIT_OVR

#define I2C_BIT_OVR   ((uint32_t)0x0800)

Definition at line 21 of file i2c.h.

◆ I2C_BIT_PECERR

#define I2C_BIT_PECERR   ((uint32_t)0x1000)

Definition at line 20 of file i2c.h.

◆ I2C_BIT_RXNE

#define I2C_BIT_RXNE   ((uint32_t)0x0040)

Definition at line 26 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_BIT_SB

#define I2C_BIT_SB   ((uint32_t)0x0001)

Definition at line 31 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_BIT_SMBALERT

#define I2C_BIT_SMBALERT   ((uint32_t)0x0008000)

Definition at line 18 of file i2c.h.

◆ I2C_BIT_SMBDEFAULT

#define I2C_BIT_SMBDEFAULT   ((uint32_t)0x0020)

Definition at line 41 of file i2c.h.

◆ I2C_BIT_SMBHOST

#define I2C_BIT_SMBHOST   ((uint32_t)0x0040)

Definition at line 40 of file i2c.h.

◆ I2C_BIT_STOPF

#define I2C_BIT_STOPF   ((uint32_t)0x0010)

Definition at line 27 of file i2c.h.

◆ I2C_BIT_TIMEOUT

#define I2C_BIT_TIMEOUT   ((uint32_t)0x4000)

Definition at line 19 of file i2c.h.

Referenced by F4Light::I2CDevice::wait_stop_done().

◆ I2C_BIT_TRA

#define I2C_BIT_TRA   ((uint32_t)0x0004)

Definition at line 43 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_BIT_TXE

#define I2C_BIT_TXE   ((uint32_t)0x0080)

Definition at line 25 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_BUS_BUSY

#define I2C_BUS_BUSY   2

Definition at line 64 of file i2c.h.

Referenced by F4Light::I2CDevice::transfer().

◆ I2C_BUS_ERR

#define I2C_BUS_ERR   99

Definition at line 67 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev(), and F4Light::I2CDevice::transfer().

◆ I2C_Direction_Receiver

#define I2C_Direction_Receiver   ((uint8_t)0x01)

Definition at line 52 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev(), and Soft_I2C::tick().

◆ I2C_Direction_Transmitter

#define I2C_Direction_Transmitter   ((uint8_t)0x00)

Definition at line 51 of file i2c.h.

Referenced by Soft_I2C::_start(), i2c_send_address(), and F4Light::I2CDevice::isr_ev().

◆ I2C_DMA_BUSY

#define I2C_DMA_BUSY   103

Definition at line 75 of file i2c.h.

◆ I2C_DMA_ERROR

#define I2C_DMA_ERROR   100

Definition at line 77 of file i2c.h.

◆ I2C_ERR_OVERRUN

#define I2C_ERR_OVERRUN   93

Definition at line 73 of file i2c.h.

◆ I2C_ERR_REGISTER

#define I2C_ERR_REGISTER   94

Definition at line 72 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_ERR_STOP

#define I2C_ERR_STOP   98

Definition at line 68 of file i2c.h.

Referenced by F4Light::I2CDevice::transfer(), and F4Light::I2CDevice::wait_stop_done().

◆ I2C_ERR_STOP_TIMEOUT

#define I2C_ERR_STOP_TIMEOUT   92

Definition at line 74 of file i2c.h.

Referenced by F4Light::I2CDevice::wait_stop_done().

◆ I2C_ERR_TIMEOUT

#define I2C_ERR_TIMEOUT   95

◆ I2C_ERR_WRITE

#define I2C_ERR_WRITE   6

Definition at line 65 of file i2c.h.

Referenced by Soft_I2C::tick().

◆ I2C_ERROR

#define I2C_ERROR   2

◆ I2C_IE_BUF

#define I2C_IE_BUF   ((uint16_t)0x0400)

Definition at line 34 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_IE_ERR

#define I2C_IE_ERR   ((uint16_t)0x0100)

Definition at line 36 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_IE_EVT

#define I2C_IE_EVT   ((uint16_t)0x0200)

Definition at line 35 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

◆ I2C_NACKPosition_Current

#define I2C_NACKPosition_Current   ((uint16_t)0xF7FF)

Definition at line 49 of file i2c.h.

◆ I2C_NACKPosition_Next

#define I2C_NACKPosition_Next   ((uint16_t)0x0800)

Definition at line 48 of file i2c.h.

Referenced by F4Light::I2CDevice::i2c_read(), and F4Light::I2CDevice::i2c_write().

◆ I2C_NO_DEVICE

#define I2C_NO_DEVICE   1

Definition at line 62 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev(), Soft_I2C::tick(), and F4Light::I2CDevice::transfer().

◆ I2C_NO_REGISTER

#define I2C_NO_REGISTER   8

Definition at line 66 of file i2c.h.

Referenced by Soft_I2C::tick().

◆ I2C_OK

#define I2C_OK   0

◆ I2C_PENDING

#define I2C_PENDING   255

◆ I2C_SMALL_TIMEOUT

#define I2C_SMALL_TIMEOUT   (50)

Definition at line 58 of file i2c.h.

Referenced by F4Light::I2CDevice::wait_stop_done().

◆ I2C_STOP_BERR

#define I2C_STOP_BERR   97

Definition at line 69 of file i2c.h.

Referenced by F4Light::I2CDevice::transfer(), and F4Light::I2CDevice::wait_stop_done().

◆ I2C_STOP_BUSY

#define I2C_STOP_BUSY   96

Definition at line 70 of file i2c.h.

Referenced by F4Light::I2CDevice::transfer().

◆ I2C_TIMEOUT

#define I2C_TIMEOUT   (300)

Definition at line 57 of file i2c.h.

Typedef Documentation

◆ i2c_dev

typedef struct i2c_dev i2c_dev

I2C device type.

◆ I2C_dma

typedef struct I2C_DMA I2C_dma

◆ i2c_state

typedef struct I2c_state i2c_state

Function Documentation

◆ i2c_bus_reset()

bool i2c_bus_reset ( const i2c_dev dev)

Definition at line 271 of file i2c.c.

Referenced by F4Light::I2CDevice::_do_bus_reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2c_clear_isr_handler()

static void i2c_clear_isr_handler ( const i2c_dev dev)
inlinestatic

Definition at line 140 of file i2c.h.

Referenced by F4Light::I2CDevice::finish_transfer().

Here is the caller graph for this function:

◆ i2c_deinit()

void i2c_deinit ( const i2c_dev dev)

DeInitializes peripherals used by the I2C driver.

Parameters
None
Return values
None

Definition at line 199 of file i2c.c.

Referenced by F4Light::I2CDevice::_do_bus_reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2c_init()

void i2c_init ( const i2c_dev dev,
uint16_t  address,
uint32_t  speed 
)

Definition at line 166 of file i2c.c.

Referenced by F4Light::I2CDevice::init(), read_calibration_data(), and setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2c_lowLevel_deinit()

void i2c_lowLevel_deinit ( const i2c_dev dev)

DeInitializes peripherals used by the I2C driver.

Parameters
None
Return values
None

< GPIO configuration

< Configure I2C pins: SCL

< Configure I2C pins: SDA

Definition at line 87 of file i2c.c.

Referenced by i2c_deinit().

Here is the caller graph for this function:

◆ i2c_master_release_bus()

void i2c_master_release_bus ( const i2c_dev dev)

Definition at line 248 of file i2c.c.

Referenced by i2c_bus_reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2c_read()

uint32_t i2c_read ( const i2c_dev dev,
uint8_t  addr,
const uint8_t *  tx_buff,
uint8_t  txlen,
uint8_t *  rx_buff,
uint8_t  rxlen 
)

Referenced by F4Light::I2CDevice::get_device().

Here is the caller graph for this function:

◆ i2c_send_address()

static void i2c_send_address ( const i2c_dev dev,
uint8_t  address,
uint8_t  direction 
)
inlinestatic

Definition at line 145 of file i2c.h.

Referenced by F4Light::I2CDevice::isr_ev().

Here is the caller graph for this function:

◆ i2c_set_isr_handler()

static void i2c_set_isr_handler ( const i2c_dev dev,
Handler  h 
)
inlinestatic

Definition at line 128 of file i2c.h.

Referenced by F4Light::I2CDevice::i2c_read(), and F4Light::I2CDevice::i2c_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2c_write()

uint32_t i2c_write ( const i2c_dev dev,
uint8_t  addr,
const uint8_t *  tx_buff,
uint8_t  txlen 
)

Referenced by F4Light::I2CDevice::get_device().

Here is the caller graph for this function:

Variable Documentation

◆ _I2C1

const i2c_dev* const _I2C1

◆ _I2C2

const i2c_dev* const _I2C2

◆ _I2C3

const i2c_dev* const _I2C3

Referenced by i2c_send_address().

◆ i2c_bit_time

uint32_t i2c_bit_time

Definition at line 80 of file i2c.c.

Referenced by i2c_init(), F4Light::I2CDevice::i2c_read(), and F4Light::I2CDevice::i2c_write().