Added the state machine for the i2c trasnmition states and started with the functions implementation on a lower layer

i2c
key 3 years ago
parent 206f119a12
commit e17d96755f

@ -73,54 +73,82 @@ typedef enum{
i2cCLockStrechingDisable /*!< We assume that the master and slave have compatible Clock frequencies */ i2cCLockStrechingDisable /*!< We assume that the master and slave have compatible Clock frequencies */
}i2cClockStreching_t; }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 typedef struct
{ {
uint16_t adress; /*!< First and Main address of the device */ uint16_t adress; /*!< First and Main address of the device */
i2cAddressSize_t adressSize; /*!< 10 or 7 bit adress size */ i2cAddressSize_t adressSize; /*!< 10 or 7 bit adress size */
i2cAddressCount_t addresCount; /*!< SIngle or multiple */ i2cAddressCount_t addresCount; /*!< SIngle or multiple */
i2cMode_t mode; /*!< Master, Slave or Multymaster Modes */ i2cMode_t mode; /*!< Master, Slave or Multymaster Modes */
i2cSpeed_t speed;/*!< Bus Speed */ i2cSpeed_t speed; /*!< Bus Speed */
i2cClockStreching_t streching; /*!< Clock Streching enablede or disabled*/ i2cClockStreching_t streching; /*!< Clock Streching enablede or disabled*/
uint32_t timing; /*!< Specifies the I2C timing The timings must be configured 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. */
in order to guarantee a correct data hold and setup time, used in master uint16_t adressSecond; /*!< Second adress if dual adresse mode is configured*/
and slave modes. */ i2cState_t state;
uint16_t adressSecond; /*!< Second adress if dual adresse mode is configured*/
}i2cChannelDefinition_t; }i2cChannelDefinition_t;
/** /**
* @brief Initilize the I2C Hardware * @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 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 void i2cInitChannelAsMaster(); // Hardware Specific : Initilise the hardware channel in master mode
void i2cInitChannelAsSlave(); // Hardware Specific : Initilise the hardware channel in slavic mode (@life of boris) void i2cInitChannelAsSlave(); // Hardware Specific : Initilise the hardware channel in slavic mode (@life of boris)
void i2cFreeChannel(); // Hardware Specific : Free the hardware channel for othe recousrces void i2cFreeChannel(); // Hardware Specific : Free the hardware channel for othe recousrces
void i2cClockSynchronise();// I2C Standart : Clock Syncronization void i2cClockSynchronise(); // I2C Standart : Clock Syncronization
void i2cReadDeviceInfo(); // I2c Standart : 3 Bytes (24 bits) | 12 Bits : Manufacturer info | 9 Bits: Part Identification | 3 Bits DIE Rev. void i2cReadDeviceInfo(); // I2c Standart : 3 Bytes (24 bits) | 12 Bits : Manufacturer info | 9 Bits: Part Identification | 3 Bits DIE Rev.
void i2cAbortTransmit(); // I2c Standart : Stop Communication for multimaster mode 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 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 i2cArbitration(); // I2C Standart : Arbitration for multimaster mode to define the right master.
void i2cSoftReset(); // I2C Standart : Software reset not supported by all hardware. void i2cSoftReset(); // I2C Standart : Software reset not supported by all hardware.
void i2cBusClear(); // I2C Standart : in case if SCL is stuck void i2cBusClear(); // I2C Standart : in case if SCL is stuck
void i2cSetSpeed(uint8_t speed); // I2C Standart void i2cSetSpeed(uint8_t speed);
void i2cSetAddress(uint16_t address); // I2C Standart void i2cSetAddress(uint16_t address);
void i2cSetAddressMode(); // I2C Standart void i2cSetAddressMode();
void i2cSetTimeout(uint8_t timeout); // Hardware specific void i2cSetTimeout(uint8_t timeout); // Hardware specific
void i2cSetInterrupt(); // Hardware Specific void i2cSetInterrupt(); // Hardware Specific
void i2cSetDma(); // Hardware specific void i2cSetDma(); // Hardware specific
void i2cThrowError(int16_t error); // Defined by me : Private error function for error handling 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 #ifdef __cplusplus
} }

Loading…
Cancel
Save