I2C driver API
[I2C driver]
Defines | |
| #define | i2c_init(args...) PP_CAT(i2c_init ## _, COUNT_PARMS(args)) (args) |
| Initialize I2C module. | |
| #define | i2c_start_w(args...) PP_CAT(i2c_start_w ## _, COUNT_PARMS(args)) (args) |
| Start a write session. | |
| #define | i2c_start_r(args...) PP_CAT(i2c_start_r ## _, COUNT_PARMS(args)) (args) |
| Start a read session. | |
Functions | |
| void | i2c_hw_init (I2c *i2c, int dev, uint32_t clock) |
| Initialize I2C module. | |
| void | i2c_hw_bitbangInit (I2c *i2c, int dev) |
| Initialize i2c module. | |
I2C interface functions | |
|
| |
| void | i2c_start_r_4 (I2c *i2c, uint16_t slave_addr, size_t size, int flags) |
| Start a read session. | |
| void | i2c_start_w_4 (I2c *i2c, uint16_t slave_addr, size_t size, int flags) |
| Start a write session. | |
| uint8_t | i2c_getc (I2c *i2c) |
| Read a byte from I2C bus. | |
| void | i2c_putc (I2c *i2c, uint8_t data) |
| Write the byte data into I2C port i2c. | |
| void | i2c_write (I2c *i2c, const void *_buf, size_t count) |
| Write count bytes to port i2c, reading from _buf. | |
| void | i2c_read (I2c *i2c, void *_buf, size_t count) |
| Read count bytes into buffer _buf from device i2c. | |
| int | i2c_error (I2c *i2c) |
| Return the error condition of the bus and clear errors. | |
| #define | i2c_init_3(i2c, dev, clock) |
| Initialize I2C context structure. | |
I2C error flags | |
|
| |
| #define | I2C_OK 0 |
| I2C no errors flag. | |
| #define | I2C_DATA_NACK BV(4) |
| I2C generic error. | |
| #define | I2C_ERR BV(3) |
| I2C generic error. | |
| #define | I2C_ARB_LOST BV(2) |
| I2C arbitration lost error. | |
| #define | I2C_START_TIMEOUT BV(0) |
| I2C timeout error on start. | |
| #define | I2C_NO_ACK BV(1) |
| I2C no ack for sla start. | |
I2C command flags | |
|
| |
| #define | I2C_NOSTOP 0 |
| Do not program the stop for current transition. | |
| #define | I2C_STOP BV(0) |
| Program the stop for current transition. | |
Define Documentation
| #define i2c_init | ( | args... | ) | PP_CAT(i2c_init ## _, COUNT_PARMS(args)) (args) |
Initialize I2C module.
To initialize the module you can write this code:
I2c ctx; i2c_init(&ctx, 0, CONFIG_I2C_FREQ);
This macro expands in two versions, depending on the number of parameters, to maintain compatibility with old API:
Do NOT use the above functions directly, use i2c_init().
- Note:
- Use the version with 3 parameters, the other one is only for legacy code.
| #define i2c_init_3 | ( | i2c, | |||
| dev, | |||||
| clock | ) |
((((dev) >= I2C_BITBANG0) | ((dev) == I2C_BITBANG_OLD)) ? \ i2c_hw_bitbangInit((i2c), (dev)) : i2c_hw_init((i2c), (dev), (clock)))
Initialize I2C context structure.
- Parameters:
-
i2c I2C context structure dev Number of device to be initialized. You can use I2C_BITBANG0 and similar if you want to activate the bitbang driver. clock Peripheral clock
| #define i2c_start_r | ( | args... | ) | PP_CAT(i2c_start_r ## _, COUNT_PARMS(args)) (args) |
Start a read session.
To start a read session, use the following code:
i2c_start_r(i2c, dev, bytes, I2C_STOP);
This macro expands in two versions, depending on the number of parameters:
- i2c_start_r_4(I2c *i2c, uint16_t slave_addr, size_t size, int flags)
- i2c_builtin_start_r(uint8_t id): Deprecated API, don't use in new projects
- i2c_bitbang_start_r(uint8_t id): Deprecated API, don't use in new projects
Do NOT use the above functions directly, use i2c_start_r().
- Note:
- Use the version with 4 parameters, the others are only for legacy code
| #define i2c_start_w | ( | args... | ) | PP_CAT(i2c_start_w ## _, COUNT_PARMS(args)) (args) |
Start a write session.
To start a write session, use the following code:
i2c_start_w(i2c, dev, bytes, I2C_STOP);
This macro expands in two versions, depending on the number of parameters:
- i2c_start_w_4(I2c *i2c, uint16_t slave_addr, size_t size, int flags)
- i2c_builtin_start_w(uint8_t id): Deprecated API, don't use in new projects
- i2c_bitbang_start_w(uint8_t id): Deprecated API, don't use in new projects
Do NOT use the above functions directly, use i2c_start_w().
- Note:
- Use the version with 4 parameters, the others are only for legacy code
Function Documentation
| uint8_t i2c_getc | ( | I2c * | i2c | ) | [inline] |
| void i2c_putc | ( | I2c * | i2c, | |
| uint8_t | data | |||
| ) | [inline] |
| void i2c_read | ( | I2c * | i2c, | |
| void * | _buf, | |||
| size_t | count | |||
| ) | [inline] |
| void i2c_start_r_4 | ( | I2c * | i2c, | |
| uint16_t | slave_addr, | |||
| size_t | size, | |||
| int | flags | |||
| ) | [inline] |
| void i2c_start_w_4 | ( | I2c * | i2c, | |
| uint16_t | slave_addr, | |||
| size_t | size, | |||
| int | flags | |||
| ) | [inline] |
