I2C Driver

The I2C driver is used for allowing a project to have access to and control basic I2C master functionality of an end device.

Data Structures

ATMO_I2C_Peripheral_t

I2C Peripheral Configuration

Member Name Type Description
operatingMode ATMO_I2C_OperatingMode_t I2C Operating Mode
baudRate ATMO_I2C_BaudRate_t I2C Baud Rate
localAddress uint16_t Peripheral address for slave mode (Future)

Type Definitions

Name Definition Description
ATMO_I2C_DriverInstance_t typedef struct ATMO_I2C_DriverInstance_t ATMO_I2C_DriverInstance_t  

Enumerations

enum ATMO_I2C_OperatingMode_t

I2C Operating Mode

Name Value
ATMO_I2C_OperatingMode_Uninitialized 0x00u
ATMO_I2C_OperatingMode_Master 0x01u
ATMO_I2C_OperatingMode_Slave 0x02u
ATMO_I2C_OperatingMode_Invalid 0xFFu

enum ATMO_I2C_BaudRate_t

I2C Baud Rate

Name Value
ATMO_I2C_BaudRate_Uninitialized 0x00u
ATMO_I2C_BaudRate_Low_Speed_Mode 0x01u
ATMO_I2C_BaudRate_Standard_Mode 0x02u
ATMO_I2C_BaudRate_Fast_Mode 0x03u
ATMO_I2C_BaudRate_Fast_Mode_Plus 0x04u
ATMO_I2C_BaudRate_High_Speed_Mode 0x05u
ATMO_I2C_BaudRate_Ultra_Speed_Mode 0x06u
ATMO_I2C_BaudRate_10kHz 0x81u
ATMO_I2C_BaudRate_100kHz 0x82u
ATMO_I2C_BaudRate_400kHz 0x83u
ATMO_I2C_BaudRate_1000kHz 0x84u
ATMO_I2C_BaudRate_3400kHz 0x85u
ATMO_I2C_BaudRate_5000kHz 0x86u
ATMO_I2C_BaudRate_Invalid 0xFFu

enum ATMO_I2C_Status_t

I2C Driver Return Enumerations

Name Value Description
ATMO_I2C_Status_Success 0x00u Common - Operation was successful
ATMO_I2C_Status_Fail 0x01u Common - Operation failed
ATMO_I2C_Status_Initialized 0x02u Common - Peripheral already initialized
ATMO_I2C_Status_Invalid 0x03u Common - Invalid operation or result
ATMO_I2C_Status_NotSupported 0x04u Common - Feature not supported by platform
ATMO_I2C_Status_Unknown 0x05u Common - Some other status not defined
ATMO_I2C_Status_Busy 0x06u Common - Transfer in progress
ATMO_I2C_Status_Timeout 0x20u Master - Transfer timed out
ATMO_I2C_Status_ReceivedNak 0x21u Master - Received NAK from slave device
ATMO_I2C_Status_NoReceiveInProgress 0x22u Master - No transfer in progress when attempting to abort receive
ATMO_I2C_Status_NoSendInProgress 0x23u Master - No transfer in progress when attempting to abort send
ATMO_I2C_Status_ArbitrationLost 0x24u Master - Lost arbitration in multi-master mode
ATMO_I2C_Status_TxUnderrun 0x40u Slave - TX Underrun error
ATMO_I2C_Status_RxOverrun 0x41u Slave - RX Overrun error
ATMO_I2C_Status_Idle 0x42u Slave - Bus is Idle

Functions

ATMO_Status_t ATMO_I2C_AddDriverInstance(const ATMO_I2C_DriverInstance_t *driverInstance, ATMO_DriverInstanceData_t *driverInstanceData, ATMO_DriverInstanceHandle_t *instanceNumber)

This routine will add an instance of a driver for I2C into the I2C driver handler.

Parameter Direction Type
instanceNumber N/A ATMO_DriverInstanceHandle_t *
driverInstanceData N/A ATMO_DriverInstanceData_t *
driverInstance N/A const ATMO_I2C_DriverInstance_t *
Return Type
ATMO_Status_t

ATMO_I2C_Status_t ATMO_I2C_Init(ATMO_DriverInstanceHandle_t instance)

This routine initializes the specified I2C peripheral instance. The specific configuration settings are either hard-coded in the platform driver or are pulled from a configuration header file.

Parameter Direction Type
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_I2C_Status_t

ATMO_I2C_Status_t ATMO_I2C_DeInit(ATMO_DriverInstanceHandle_t instance)

This routine de-initializes the specified I2C peripheral instance.

Parameter Direction Type
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_I2C_Status_t

ATMO_I2C_Status_t ATMO_I2C_SetConfiguration(ATMO_DriverInstanceHandle_t instance, const ATMO_I2C_Peripheral_t *config)

This routine configures the specified I2C peripheral instance. It is similar to the init function except the peripheral configuration settings are passed in via the config structure.

Parameter Direction Type
config N/A const ATMO_I2C_Peripheral_t *
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_I2C_Status_t

ATMO_I2C_Status_t ATMO_I2C_MasterWrite(ATMO_DriverInstanceHandle_t instance, uint16_t slaveAddress, const uint8_t *cmdBytes, uint16_t numCmdBytes, const uint8_t *writeBytes, uint16_t numWriteBytes, unsigned int timeoutMs)

This routine will send one or more bytes to a slave device via the specified I2C peripheral. This is a blocking operation and the function will not return until the I2C transfer completes or the timeout expires.

Parameter Direction Type
timeoutMs N/A unsigned int
numWriteBytes N/A uint16_t
writeBytes N/A const uint8_t *
numCmdBytes N/A uint16_t
cmdBytes N/A const uint8_t *
slaveAddress N/A uint16_t
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_I2C_Status_t

ATMO_I2C_Status_t ATMO_I2C_MasterRead(ATMO_DriverInstanceHandle_t instance, uint16_t slaveAddress, const uint8_t *cmdBytes, uint16_t numCmdBytes, uint8_t *readBytes, uint16_t numReadBytes, unsigned int timeoutMs)

This routine will read one or more bytes from a slave device via the specified I2C peripheral. If the command buffer has a valid pointer (i.e. not NULL) and the number of command bytes is greater than zero then the values in the command buffer are first sent to the device followed by a repeated START condition. Otherwise a repeated START condition will not be generated. This is a blocking operation and the function will not return until the I2C transfer completes or the timeout expires.

Parameter Direction Type
timeoutMs N/A unsigned int
numReadBytes N/A uint16_t
readBytes N/A uint8_t *
numCmdBytes N/A uint16_t
cmdBytes N/A const uint8_t *
slaveAddress N/A uint16_t
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_I2C_Status_t

uint32_t ATMO_I2C_BaudToHz(ATMO_I2C_BaudRate_t baudRate)

Convert baud rate enum to its value in hz

Parameter Direction Type
baudRate in ATMO_I2C_BaudRate_t
Return Type
uint32_t