@ -73,6 +73,23 @@ typedef enum{
i2cCLockStrechingDisable /*!< We assume that the master and slave have compatible Clock frequencies */
} i2cClockStreching_t ;
/*! typedef for the i2c states*/
typedef enum
{
i2cNotInitialized , /*!< Peripheral is not yet Initialized */
i2cReady , /*!< Peripheral Initialized and ready for use */
i2cBusy , /*!< An internal process is ongoing */
i2cTransmitting , /*!< Data Transmission process is ongoing */
i2cRecieving , /*!< Data Reception process is ongoing */
i2cListening , /*!< Address Listen Mode is ongoing */
i2cListeningAndTransmitting , /*!< Address Listen Mode and Data Transmission process is ongoing */
i2cListeningAndRecieveing , /*!< Address Listen Mode and Data Reception process is ongoing*/
i2cAbort , /*!< Abort user request ongoing */
i2cTimeout , /*!< Timeout state */
i2cError /*!< Error */
} i2cState_t ;
/*! Struture a an i2c channel with all the required propereties*/
typedef struct
{
uint16_t adress ; /*!< First and Main address of the device */
@ -81,22 +98,34 @@ typedef struct
i2cMode_t mode ; /*!< Master, Slave or Multymaster Modes */
i2cSpeed_t speed ; /*!< Bus Speed */
i2cClockStreching_t streching ; /*!< Clock Streching enablede or disabled*/
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 . */
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. */
uint16_t adressSecond ; /*!< Second adress if dual adresse mode is configured*/
i2cState_t state ;
} i2cChannelDefinition_t ;
/**
* @ brief Initilize the I2C Hardware
*/
int8_t i2cInit ( i2cChannelDefinition_t i2cChannel ) ;
int8_t i2cInit ( i2cCh_t i2cChannel ) ;
/**
* @ brief De - Initilize the I2C Hardware
*/
int8_t i2cDeInit ( i2cChannelDefinition_t i2cChannel ) ;
/**
* @ brief Send as read request or the amount eo register that is indicated
* @ param devAddress is the address of the device to which the read command will be sent
* @ param registerAddress is the regiter to be red from the device
* @ param data is the data to be red
* @ param lenght of the data count to be red
*/
void i2cRead ( uint8_t * devAddress , uint8_t * registerAddress , uint8_t * data , uint8_t * dataLenght ) ;
void i2cWrite ( uint8_t * devAddress , uint8_t * registerAddress , uint8_t * data , uint8_t * dataLenght ) ;
void i2cRead ( uint8_t * reg , uint8_t * buffer , uint8_t * regLenght , uint8_t * bufferLenght ) ; // Defined by me : Read a given number of bytes
void i2cWrite ( uint8_t * reg , uint8_t * data , uint8_t * regLenght , uint8_t * dataLenght ) ; // Defined by me : Send a given number of bytes
uint8_t i2cTestDeviceSpeed ( ) ; // Defined by me : Cycle trough different modes until device cnat't answer fast enought
uint8_t i2cTestDeviceSpeed ( ) ; // Defined by me : Cycle trough different modes until device cant't answer fast enought
uint8_t i2cDiscoverDevices ( ) ; // Defined by me : Scan the awailable address range on standart mode to find devices
void i2cInitChannelAsMaster ( ) ; // Hardware Specific : Initilise the hardware channel in master mode
@ -111,16 +140,15 @@ void i2cArbitration(); // I2C Standart : Arbitration for multimaster mode to de
void i2cSoftReset ( ) ; // I2C Standart : Software reset not supported by all hardware.
void i2cBusClear ( ) ; // I2C Standart : in case if SCL is stuck
void i2cSetSpeed ( uint8_t speed ) ; // I2C Standart
void i2cSetAddress ( uint16_t address ) ; // I2C Standart
void i2cSetAddressMode ( ) ; // I2C Standart
void i2cSetSpeed ( uint8_t speed ) ;
void i2cSetAddress ( uint16_t address ) ;
void i2cSetAddressMode ( ) ;
void i2cSetTimeout ( uint8_t timeout ) ; // Hardware specific
void i2cSetInterrupt ( ) ; // Hardware Specific
void i2cSetDma ( ) ; // Hardware specific
void i2cThrowError ( int16_t error ) ; // Defined by me : Private error function for error handling
void i2cPointReg ( uint8_t reg ) ; // Defined by me : Points to the register to be red from
# ifdef __cplusplus
}