|
PebbleOS
|
Bus and device definitions shared by boards, the common I2C code and the bus HALs. More...
Data Structures | |
| struct | I2CTransfer |
| Transfer in progress on a bus. More... | |
| struct | I2CBusState |
| Bus runtime state, owned by the common I2C code. More... | |
| struct | I2CBus |
| I2C bus, defined by the board. More... | |
| struct | I2CSlavePort |
| Device on an I2C bus, defined by the board. More... | |
Enumerations | |
| enum | I2CTransferEvent { I2CTransferEvent_Timeout , I2CTransferEvent_TransferComplete , I2CTransferEvent_NackReceived , I2CTransferEvent_Error } |
| Transfer outcome reported by a HAL. More... | |
| enum | I2CTransferDirection { I2CTransferDirection_Read , I2CTransferDirection_Write } |
| Transfer direction. More... | |
| enum | I2CTransferType { I2CTransferType_SendRegisterAddress , I2CTransferType_NoRegisterAddress } |
| Transfer type. More... | |
| enum | I2CTransferState { I2CTransferState_WriteAddressTx , I2CTransferState_WriteRegAddress , I2CTransferState_RepeatStart , I2CTransferState_WriteAddressRx , I2CTransferState_WaitForData , I2CTransferState_ReadData , I2CTransferState_WriteData , I2CTransferState_EndWrite , I2CTransferState_Complete } |
| Transfer state, for HALs that drive the transfer byte by byte. More... | |
Functions | |
| void | i2c_init (I2CBus *bus) |
| Initialize a bus. | |
| void | i2c_handle_transfer_event (I2CBus *device, I2CTransferEvent event) |
| Report the outcome of the current transfer. | |
Bus and device definitions shared by boards, the common I2C code and the bus HALs.
The common code runs one transfer at a time per bus: it fills I2CBusState::transfer, starts it through the I2C HAL and waits for the HAL to report the outcome with i2c_handle_transfer_event().
| struct I2CTransfer |
Transfer in progress on a bus.
| Data Fields | ||
|---|---|---|
| uint8_t * | data | Data to write or buffer to read into. |
| uint16_t | device_address | Device address, as in I2CSlavePort::address. |
| I2CTransferDirection | direction | Transfer direction. |
| bool | dma | data follows the i2c_read_register_block_dma() rules, so the HAL may use DMA. |
| uint32_t | idx | Index of the next data byte, for HALs that use it. |
| uint8_t | register_address | Register address, for I2CTransferType_SendRegisterAddress. |
| uint32_t | size | Number of data bytes. |
| I2CTransferState | state | Transfer state, for HALs that use it. |
| I2CTransferType | type | Transfer type. |
| struct I2CBusState |
Bus runtime state, owned by the common I2C code.
| Data Fields | ||
|---|---|---|
| struct pbl_mutex | bus_mutex | Serializes bus access. |
| struct pbl_sem | event_semaphore | Signaled when the current transfer ends. |
| I2CTransfer | transfer | Current transfer. |
| I2CTransferEvent | transfer_event | Outcome of the current transfer, set by i2c_handle_transfer_event(). |
| int | transfer_nack_count | NACKs received during the current transfer. |
| RtcTicks | transfer_start_ticks | Start time of the current transfer. |
| int | user_count | Number of i2c_use() users. |
| struct I2CBus |
I2C bus, defined by the board.
| Data Fields | ||
|---|---|---|
| const struct I2CBusHal *const | hal | HAL-specific configuration. |
| const char * | name | Bus name, for logging. |
| I2CBusState *const | state | Runtime state. |
| struct I2CSlavePort |
Device on an I2C bus, defined by the board.
| Data Fields | ||
|---|---|---|
| uint16_t | address | Device address: 8-bit (7-bit address shifted left by one) on nRF5, 7-bit on SF32LB. |
| const I2CBus * | bus | Bus the device is connected to. |
| enum I2CTransferDirection |
| enum I2CTransferEvent |
| enum I2CTransferState |
Transfer state, for HALs that drive the transfer byte by byte.
| enum I2CTransferType |
| void i2c_handle_transfer_event | ( | I2CBus * | device, |
| I2CTransferEvent | event | ||
| ) |
Report the outcome of the current transfer.
Called by the HAL, typically from its interrupt handler.
| device | Bus the transfer ran on. |
| event | Transfer outcome. |