The one owner of the shared I2C bus for the peripheral drivers. More...
Go to the source code of this file.
Macros | |
| #define | PROTOCORE_I2C_HZ 100000u |
| Bus clock for the shared peripheral bus; 100 kHz standard mode. | |
| #define | PROTOCORE_I2C_TIMEOUT_MS 50u |
| Per-transfer timeout in milliseconds. | |
| #define | PROTOCORE_I2C_BUS 0u |
| Controller the plain verbs drive. | |
| #define | PROTOCORE_I2C_HZ_STANDARD 100000u |
| Standard-mode, fast-mode and fast-mode-plus bus clocks. | |
| #define | PROTOCORE_I2C_HZ_FAST 400000u |
| #define | PROTOCORE_I2C_HZ_FAST_PLUS 1000000u |
| #define | PROTOCORE_I2C_ADDR10(a) |
| Wrap a 10-bit address so a transfer verb puts the two-byte form on the wire. | |
| #define | PROTOCORE_I2C_SCAN_FIRST 0x08u |
| Lowest and highest 7-bit addresses a scan reports; 0x00 - 0x07 and 0x78 - 0x7F are reserved. | |
| #define | PROTOCORE_I2C_SCAN_LAST 0x77u |
Functions | |
| EMBED_BEGIN_DECLS EMBED_INLINE embed_bool | protocore_i2c_begin_on (uint8_t bus, int sda, int scl, uint32_t hz) |
| EMBED_INLINE embed_bool | protocore_i2c_begin (void) |
| EMBED_INLINE embed_bool | protocore_i2c_write_on (uint8_t bus, uint16_t addr, const uint8_t *buf, size_t len) |
| EMBED_INLINE embed_bool | protocore_i2c_write (uint16_t addr, const uint8_t *buf, size_t len) |
| EMBED_INLINE embed_bool | protocore_i2c_read_on (uint8_t bus, uint16_t addr, uint8_t *buf, size_t len) |
| EMBED_INLINE embed_bool | protocore_i2c_read (uint16_t addr, uint8_t *buf, size_t len) |
| EMBED_INLINE embed_bool | protocore_i2c_write_read_on (uint8_t bus, uint16_t addr, const uint8_t *w, size_t wlen, uint8_t *r, size_t rlen) |
| EMBED_INLINE embed_bool | protocore_i2c_write_read (uint16_t addr, const uint8_t *w, size_t wlen, uint8_t *r, size_t rlen) |
| EMBED_INLINE embed_bool | protocore_i2c_set_clock_on (uint8_t bus, uint32_t hz) |
| EMBED_INLINE embed_bool | protocore_i2c_set_clock (uint32_t hz) |
| EMBED_INLINE embed_bool | protocore_i2c_probe_on (uint8_t bus, uint16_t addr) |
| EMBED_INLINE embed_bool | protocore_i2c_probe (uint16_t addr) |
| EMBED_INLINE size_t | protocore_i2c_scan_on (uint8_t bus, uint8_t *out, size_t cap) |
| EMBED_INLINE size_t | protocore_i2c_scan (uint8_t *out, size_t cap) |
| EMBED_INLINE embed_bool | protocore_i2c_general_call_on (uint8_t bus, const uint8_t *buf, size_t len) |
| EMBED_INLINE embed_bool | protocore_i2c_general_call (const uint8_t *buf, size_t len) |
| EMBED_INLINE embed_bool | protocore_i2c_recover_on (uint8_t bus, int sda, int scl) |
| EMBED_INLINE embed_bool | protocore_i2c_recover (void) |
The one owner of the shared I2C bus for the peripheral drivers.
The sensor / peripheral drivers (RTC, SHT3x, MPR121, ADS1115, INA219, PCA9685, VL53L0X, LDC1614, FDC2214) share one bus and bring it up through these verbs. The pins come from PROTOCORE_I2C_SDA_PIN / PROTOCORE_I2C_SCL_PIN (default -1 = the platform default GPIO 21 / 22). Re-begin is idempotent, so per-driver calls are harmless.
This covers the master half of the protocol. The three transfer shapes a driver reaches for are a write, a read, and a register read, which is a write and a read joined by a repeated start. The rest of what the bus can express is here too: a bus scan, an address probe, the general call, 10-bit addressing, a per-transfer clock, and recovery of a bus a device is holding low.
Every verb has a plain form on the default bus (PROTOCORE_I2C_BUS) and an _on form naming a controller, so a board with two I2C controllers drives both through one owner.
An address is 7-bit unless it is wrapped in PROTOCORE_I2C_ADDR10, which selects the 10-bit form.
The bodies compile wherever the platform states a bus.
Definition in file i2c.h.
| #define PROTOCORE_I2C_HZ 100000u |
| #define PROTOCORE_I2C_TIMEOUT_MS 50u |
| #define PROTOCORE_I2C_BUS 0u |
Controller the plain verbs drive.
Definition at line 48 of file i2c.h.
Referenced by protocore_i2c_general_call(), protocore_i2c_probe(), protocore_i2c_read(), protocore_i2c_scan(), protocore_i2c_write(), and protocore_i2c_write_read().
| #define PROTOCORE_I2C_HZ_STANDARD 100000u |
| #define PROTOCORE_I2C_ADDR10 | ( | a | ) |
| #define PROTOCORE_I2C_SCAN_FIRST 0x08u |
Lowest and highest 7-bit addresses a scan reports; 0x00 - 0x07 and 0x78 - 0x7F are reserved.
Definition at line 60 of file i2c.h.
Referenced by protocore_i2c_scan_on().
| #define PROTOCORE_I2C_SCAN_LAST 0x77u |
Definition at line 61 of file i2c.h.
Referenced by protocore_i2c_scan_on().
| EMBED_BEGIN_DECLS EMBED_INLINE embed_bool protocore_i2c_begin_on | ( | uint8_t | bus, |
| int | sda, | ||
| int | scl, | ||
| uint32_t | hz ) |
| EMBED_INLINE embed_bool protocore_i2c_write_on | ( | uint8_t | bus, |
| uint16_t | addr, | ||
| const uint8_t * | buf, | ||
| size_t | len ) |
Definition at line 207 of file i2c.h.
Referenced by protocore_i2c_general_call_on(), and protocore_i2c_write().
| EMBED_INLINE embed_bool protocore_i2c_write | ( | uint16_t | addr, |
| const uint8_t * | buf, | ||
| size_t | len ) |
Definition at line 216 of file i2c.h.
References PROTOCORE_I2C_BUS, and protocore_i2c_write_on().
| EMBED_INLINE embed_bool protocore_i2c_read_on | ( | uint8_t | bus, |
| uint16_t | addr, | ||
| uint8_t * | buf, | ||
| size_t | len ) |
Definition at line 221 of file i2c.h.
Referenced by protocore_i2c_read().
| EMBED_INLINE embed_bool protocore_i2c_read | ( | uint16_t | addr, |
| uint8_t * | buf, | ||
| size_t | len ) |
Definition at line 230 of file i2c.h.
References PROTOCORE_I2C_BUS, and protocore_i2c_read_on().
| EMBED_INLINE embed_bool protocore_i2c_write_read_on | ( | uint8_t | bus, |
| uint16_t | addr, | ||
| const uint8_t * | w, | ||
| size_t | wlen, | ||
| uint8_t * | r, | ||
| size_t | rlen ) |
Definition at line 235 of file i2c.h.
Referenced by protocore_i2c_write_read().
| EMBED_INLINE embed_bool protocore_i2c_write_read | ( | uint16_t | addr, |
| const uint8_t * | w, | ||
| size_t | wlen, | ||
| uint8_t * | r, | ||
| size_t | rlen ) |
Definition at line 247 of file i2c.h.
References PROTOCORE_I2C_BUS, and protocore_i2c_write_read_on().
| EMBED_INLINE embed_bool protocore_i2c_set_clock_on | ( | uint8_t | bus, |
| uint32_t | hz ) |
| EMBED_INLINE embed_bool protocore_i2c_set_clock | ( | uint32_t | hz | ) |
| EMBED_INLINE embed_bool protocore_i2c_probe_on | ( | uint8_t | bus, |
| uint16_t | addr ) |
Definition at line 265 of file i2c.h.
Referenced by protocore_i2c_probe(), and protocore_i2c_scan_on().
| EMBED_INLINE embed_bool protocore_i2c_probe | ( | uint16_t | addr | ) |
Definition at line 272 of file i2c.h.
References PROTOCORE_I2C_BUS, and protocore_i2c_probe_on().
| EMBED_INLINE size_t protocore_i2c_scan_on | ( | uint8_t | bus, |
| uint8_t * | out, | ||
| size_t | cap ) |
Definition at line 277 of file i2c.h.
References protocore_i2c_probe_on(), PROTOCORE_I2C_SCAN_FIRST, and PROTOCORE_I2C_SCAN_LAST.
Referenced by protocore_i2c_scan().
| EMBED_INLINE size_t protocore_i2c_scan | ( | uint8_t * | out, |
| size_t | cap ) |
Definition at line 291 of file i2c.h.
References PROTOCORE_I2C_BUS, and protocore_i2c_scan_on().
| EMBED_INLINE embed_bool protocore_i2c_general_call_on | ( | uint8_t | bus, |
| const uint8_t * | buf, | ||
| size_t | len ) |
Definition at line 296 of file i2c.h.
References protocore_i2c_write_on().
Referenced by protocore_i2c_general_call().
| EMBED_INLINE embed_bool protocore_i2c_general_call | ( | const uint8_t * | buf, |
| size_t | len ) |
Definition at line 301 of file i2c.h.
References PROTOCORE_I2C_BUS, and protocore_i2c_general_call_on().
| EMBED_INLINE embed_bool protocore_i2c_recover_on | ( | uint8_t | bus, |
| int | sda, | ||
| int | scl ) |