|
|
|
@ -76,12 +76,12 @@ typedef enum{
|
|
|
|
|
/*! Enum for clock strechning activation. Can only be implmented as Slave
|
|
|
|
|
* for more information : https://www.i2c-bus.org/clock-stretching/ */
|
|
|
|
|
typedef enum{
|
|
|
|
|
i2cClockStrechingDisable, /*!< We assume that the master and slave have compatible
|
|
|
|
|
i2cClockStretchingDisable, /*!< We assume that the master and slave have compatible
|
|
|
|
|
Clock frequencies **DEFAULT** */
|
|
|
|
|
i2cClockStrechingEnable /*!< In situations where an I2C slave is not able to co-operate
|
|
|
|
|
i2cClockStretchingEnable /*!< In situations where an I2C slave is not able to co-operate
|
|
|
|
|
with the clock speed given by the master and needs to slow down.
|
|
|
|
|
This is done by a mechanism referred to as clock stretching. */
|
|
|
|
|
}i2cClockStreching_t;
|
|
|
|
|
}i2cClockStretching_t;
|
|
|
|
|
|
|
|
|
|
/*! Enum for diffenrent wake up methodes wehnin sleep mode */
|
|
|
|
|
typedef enum{
|
|
|
|
@ -106,8 +106,15 @@ typedef enum
|
|
|
|
|
{
|
|
|
|
|
i2cNotInitialized, /*!< Default Peripheral is not yet Initialized **DEFAULT** */
|
|
|
|
|
i2cInitialized, /*!< I2C CHannle is initilized but not neceserly ready */
|
|
|
|
|
i2cStartGenrated, /*!< Generated the star condition */
|
|
|
|
|
i2cSlaveAddressSent, /*!< The Salve Address Was Sent to the bus */
|
|
|
|
|
i2cOutputBufferFull, /*!< The output buffer of the I2C Periferal is Full */
|
|
|
|
|
i2cOutputBufferEmpty, /*!< The output buffer of the I2C Periferal is Empty */
|
|
|
|
|
i2cInputBufferFull, /*!< The input buffer of the I2C Periferal Is Full */
|
|
|
|
|
i2cInputBufferEmpty, /*!< The input buffer of the I2C Periferal Is Empty */
|
|
|
|
|
i2cReady, /*!< Peripheral Initialized and ready for use */
|
|
|
|
|
i2cBusy, /*!< An internal process is ongoing */
|
|
|
|
|
i2cSlaveNotFound, /*!< Desired Slave was not able to be found */
|
|
|
|
|
i2cTransmitting, /*!< Data Transmission process is ongoing */
|
|
|
|
|
i2cRecieving, /*!< Data Reception process is ongoing */
|
|
|
|
|
i2cListening, /*!< Address Listen Mode is ongoing */
|
|
|
|
@ -123,17 +130,13 @@ typedef struct i2c_t
|
|
|
|
|
{
|
|
|
|
|
i2cCh_t channelNo; /*!< The harware channel to be used */
|
|
|
|
|
i2cMode_t mode; /*!< Master, Slave or Multymaster Modes */
|
|
|
|
|
uint16_t address; /*!< First and Main address of the device */
|
|
|
|
|
uint16_t addressSecond; /*!< Second address if dual addresse mode is configured */
|
|
|
|
|
uint16_t mainAddress; /*!< First and Main address of the device */
|
|
|
|
|
uint16_t secondAddress; /*!< Second address if dual addresse mode is configured */
|
|
|
|
|
i2cAddressCount_t addressCount; /*!< Single or multiple */
|
|
|
|
|
i2cAddressSize_t addressSize; /*!< 10 or 7 bit address size */
|
|
|
|
|
i2cSpeed_t speed; /*!< Bus Speed */
|
|
|
|
|
i2cOpperationMode_t opperationMode; /*!< Blocking or non blocking polling, Int or DMA */
|
|
|
|
|
i2cClockStreching_t streching; /*!< Clock Streching enable onyl in slave mode */
|
|
|
|
|
uint32_t timing; /*!< Specifies the I2C timing. The timings must be
|
|
|
|
|
configured in order to guarantee a correct
|
|
|
|
|
data hold and setup time,
|
|
|
|
|
used in master and slave modes. */
|
|
|
|
|
i2cClockStretching_t stretching; /*!< Clock Stretching enable onyl in slave mode */
|
|
|
|
|
i2cWakeUpTypes_t wakeOn; /*!< Define on which type of action the i2c channel should
|
|
|
|
|
wake up. Only if de prefiral goes to sleep */
|
|
|
|
|
i2cState_t state; /*!< The current sitate of the I2C Bus */
|
|
|
|
@ -150,13 +153,13 @@ typedef struct i2c_t
|
|
|
|
|
void i2cInit( i2c_t *i2cHardware, /*!< Pointer to I2C hardware Object */
|
|
|
|
|
i2cCh_t channelNo, /*!< The harware channel to be used */
|
|
|
|
|
i2cMode_t mode, /*!< Master, Slave or Multymaster Modes */
|
|
|
|
|
uint16_t address, /*!< First and Main address of the device */
|
|
|
|
|
uint16_t addressSecond, /*!< Second address if dual addresse mode is configured */
|
|
|
|
|
uint16_t mainAddress, /*!< First and Main address of the device */
|
|
|
|
|
uint16_t secondAddress, /*!< Second address if dual addresse mode is configured */
|
|
|
|
|
i2cAddressCount_t addressCount, /*!< Single or multiple */
|
|
|
|
|
i2cAddressSize_t addressSize, /*!< 10 or 7 bit address size */
|
|
|
|
|
i2cSpeed_t speed, /*!< Bus Speed */
|
|
|
|
|
i2cOpperationMode_t opperationMode, /*!< Blocking or non blocking polling, Int or DMA */
|
|
|
|
|
i2cClockStreching_t streching, /*!< Clock Streching enable onyl in slave mode */
|
|
|
|
|
i2cClockStretching_t stretching, /*!< Clock Stretching enable onyl in slave mode */
|
|
|
|
|
i2cWakeUpTypes_t wakeOn /*!< Wake up condition */
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -176,11 +179,17 @@ void i2cSetMode(i2c_t *i2cHardware, i2cMode_t mode);
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set the i2c channles mode as Master Slave or Multymaster
|
|
|
|
|
* @param i2cHardware is the i2c hardware channel
|
|
|
|
|
* @param size Is the Adress isze to be used 7 Bit or 10 Bit
|
|
|
|
|
* @param addressOne The forst address for the device
|
|
|
|
|
* @param addressTwo The second address for the device only if dual address mode is not defined
|
|
|
|
|
*/
|
|
|
|
|
void i2cSetAddress(i2c_t *i2cHardware, i2cAddressSize_t size, uint16_t addressOne, uint16_t addressTwo);
|
|
|
|
|
void i2cSetAddress(i2c_t *i2cHardware, uint16_t mainAddress, uint16_t secondAddress);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set the i2c Address Lenght, 7 bit or 8 bit, Master or slave doesn't make any difference
|
|
|
|
|
* @param i2cHardware is the i2c hardware channel
|
|
|
|
|
* @param size Is the Adress isze to be used 7 Bit or 10 Bit
|
|
|
|
|
*/
|
|
|
|
|
void i2cSetAddressLenght(i2c_t *i2cHardware, i2cAddressSize_t size);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Stets the Communication speed
|
|
|
|
@ -196,13 +205,13 @@ void i2cSetSpeed(i2c_t *i2cHardware, i2cSpeed_t speed);
|
|
|
|
|
*/
|
|
|
|
|
void i2cSetOpperation(i2c_t *i2cHardware, i2cOpperationMode_t opperation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Sets the finetuning of the Timings for the communication some standards as
|
|
|
|
|
* SMBUS have different timing requirements
|
|
|
|
|
* @brief Ebales or disables clock stretching functionalities
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
* @param The value to be written in the register. This will heavily depend on the hardware
|
|
|
|
|
*/
|
|
|
|
|
void i2cSetTimings(i2c_t *i2cHardware, uint32_t timing);
|
|
|
|
|
void i2cSetClockStretch(i2c_t *i2cHardware, i2cClockStretching_t stretching);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set the wakeup mode
|
|
|
|
@ -211,6 +220,12 @@ void i2cSetTimings(i2c_t *i2cHardware, uint32_t timing);
|
|
|
|
|
*/
|
|
|
|
|
void i2cSetWakeup(i2c_t *i2cHardware, i2cWakeUpTypes_t wake);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Configures Hardware implmente filters if there are any.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cConfigureFilters(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set the timeout to close the i2c wait time if a communication fails.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
@ -218,7 +233,6 @@ void i2cSetWakeup(i2c_t *i2cHardware, i2cWakeUpTypes_t wake);
|
|
|
|
|
*/
|
|
|
|
|
void i2cSetTimeout(i2c_t *i2cHardware, uint8_t timeout);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Resets the i2c Periferal to it's inital state.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
@ -226,10 +240,28 @@ void i2cSetTimeout(i2c_t *i2cHardware, uint8_t timeout);
|
|
|
|
|
void i2cPeriferalReset(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Resets the i2c to it's inital state.
|
|
|
|
|
* @brief Resets the i2c Harware and register to it's factory deflauts.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cReset(i2c_t *i2cHardware);
|
|
|
|
|
void i2cHardwareReset(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Enables I2C Hardware BUS & Clock & Pins
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cEnableHardware(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Enables I2C Periferal core.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cEnablePeriferal(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Disables I2C Periferal core.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cDisablePeriferal(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************************
|
|
|
|
|
I2C Communication functions independen of opperating mode
|
|
|
|
@ -269,7 +301,7 @@ void i2cRead(i2c_t *i2cHardware, uint16_t *devAddress, uint8_t *registerAddress,
|
|
|
|
|
* @param registerAddress is the regiter to be red from the device
|
|
|
|
|
* @param data is the data whic has been red
|
|
|
|
|
*/
|
|
|
|
|
void i2cMasterRecieve(i2c_t *i2cHardware, uint8_t devAddress, uint8_t registerAddress, uint8_t *data);
|
|
|
|
|
void i2cMasterRecieve(i2c_t *i2cHardware, uint16_t slaveAddress, uint8_t registerAddress, uint8_t *data);
|
|
|
|
|
/**
|
|
|
|
|
* @brief Sends a Single Byte as master to the given devices register.
|
|
|
|
|
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
|
|
|
|
@ -300,12 +332,85 @@ void i2cSlaveRecieve(i2c_t *i2cHardware, uint16_t *devAddress, uint8_t *register
|
|
|
|
|
*/
|
|
|
|
|
void i2cSlaveSend(i2c_t *i2cHardware, uint16_t *devAddress, uint8_t *registerAddress, uint8_t *data);
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************************
|
|
|
|
|
I2C Hardware functions
|
|
|
|
|
***************************************************************************************************/
|
|
|
|
|
/**
|
|
|
|
|
* @brief Initiates a Start condition.
|
|
|
|
|
* @brief Checks if the device is ready for any type of communication
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cSendStart(i2c_t *i2cHardware);
|
|
|
|
|
void i2cIsPeriferalReady(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Checks if the device is ready for any type of communication
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cWaitForPeriferal(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Generates a Start condition.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cGenerateStart(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Generates a Start condition.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cGenerateStop(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Generates a NACK condition.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cGenerateNack(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Generates a ACK condition.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cGenerateAck(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Initiates the communication protocl by sending the slave address on the bus and waits
|
|
|
|
|
* for an ACK (aknowledge)
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
* @param slaveAddress The address of the slave to be communicated
|
|
|
|
|
*/
|
|
|
|
|
void i2cSendSlaveAddress(i2c_t *i2cHardware, uint16_t slaveAddress);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Send the register that we want to read or write.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
* @param registerAddress the register that need to be accessed
|
|
|
|
|
*/
|
|
|
|
|
void i2cSendRegisterAddress(i2c_t *i2cHardware, uint8_t registerAddress);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Initiates a Write command with the previously set slave address.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cInitiateWriteCommand(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Initiates a read command with the previously set slave address.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cInitiateReadCommand(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Is the output buffer empty. This allso meas that the data that was in the ouput buffer
|
|
|
|
|
* is sent to the i2c BUS.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cIsOutputBufferEmpty(i2c_t *i2cHardware);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Is the output buffer empty. This allso meas that the data that was in the ouput buffer
|
|
|
|
|
* is sent to the i2c BUS.
|
|
|
|
|
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
|
|
|
|
|
*/
|
|
|
|
|
void i2cIsInputBufferEmpty(i2c_t *i2cHardware);
|
|
|
|
|
/**************************************************************************************************
|
|
|
|
|
I2C Communication functions Polling / Blocking Mode
|
|
|
|
|
***************************************************************************************************/
|
|
|
|
@ -346,11 +451,10 @@ void i2cSlaveRecievePolling(i2c_t *i2cHardware, uint16_t *devAddress, uint8_t *r
|
|
|
|
|
void i2cSlaveSendPolling(i2c_t *i2cHardware, uint16_t *devAddress, uint8_t *registerAddress, uint8_t *data);
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************************
|
|
|
|
|
I2C Arbitration Functions for Multymaster mode and slaves clock streching
|
|
|
|
|
I2C Arbitration Functions for Multymaster mode and slaves clock stretching
|
|
|
|
|
***************************************************************************************************/
|
|
|
|
|
void i2cClockSynchronise(); // I2C Standart : Clock Syncronization
|
|
|
|
|
void i2cAbortTransmit(); // I2c Standart : Stop Communication for multimaster mode
|
|
|
|
|
void i2cClockStretch(); // I2C Standart : Optional For Pausing Communication because treatement takes longer than the communication
|
|
|
|
|
void i2cArbitration(); // I2C Standart : Arbitration for multimaster mode to define the right master.
|
|
|
|
|
void i2cSoftReset(); // I2C Standart : Software reset not supported by all hardware.
|
|
|
|
|
void i2cBusClear(); // I2C Standart : in case if SCL is stuck
|
|
|
|
|