/** ************************************************************************************************** * @file i2c.h * @author Kerem Yollu & Edwin Koch * @date 18.07.2022 * @version 1.0 ************************************************************************************************** * @brief I2C communitation based on the Standart I2C Protocol V7 Defined by NXP/Philips : * following third Party Protocols based on I2C Bus are not going to be implemented : C-BUS SMBUS PMBUS IPMI DDC ATCA * This will also not have a I3C support for the forseable futrue. * * **Detailed Description :** * * I2C communitation based on the Standart I2C Protocol V7 Defined by NXP/Philips : * following third Party Protocols based on I2C Bus are not going to be implemented : C-BUS SMBUS PMBUS IPMI DDC ATCA * This will also not have a I3C support for the forseable futrue. * * @todo * - 18.07.2021 : Implement the i2c.c. ************************************************************************************************** */ #ifndef _I2C_H_ #define _I2C_H_ #ifdef __cplusplus extern "C" { #endif #include #define I2C_STATE_RESET 1 // Not Initialized #define I2C_STATE_READY 2 // Ready #define I2C_STATE_TX 4 // Transmitting #define I2C_STATE_RX 5 // Receiving #define I2C_STATE_LISTEN 6 // Listening #define I2C_STATE_ABORT 7 // Aborted by user #define I2C_STATE_TIMEOUT 8 // Timeout #define I2C_STATE_ERROR 9 // Error happened #define I2C_SPEED_STANDART 1 // Sm 100 kbits/s This mode will be choosen for the constructor. #define I2C_SPEED_FAST 2 // Fm 400 kbits/s #define I2C_SPEED_FAST_PLUS 3 // Fm+ 1 Mbits/s #define I2C_SPEED_HIGH_SPEED 4 // Hs 3.4 Mbits/s #define I2C_SPEED_ULTRA_FAST 5 // UFm 5 Mbits/s #define I2C_ADDRESS_7B 1 // 7 bits addressing mode #define I2C_ADDRESS_10B 2 // 10 bits addressing mode #define I2C_MODE_MASTER 1 // Single Master Mode #define I2C_MODE_SLAVE 2 // Slave Mode #define I2C_MODE_MULTI_MASTER 3 // Multy Master Mode /* Creator from the CPP Version PLease keep it to define the main init sequence.*/ //ll_i2c(uint16_t address, uint8_t channel, uint8_t mode, uint8_t adressMode); // Creat i2c abject witha agiven channel address & mode speed is by default the slowest. void i2cRead(uint8_t *reg, uint8_t *buffer, uint8_t ®Lenght, uint8_t &bufferLenght); // Defined by me : Read a given number of bytes void i2cWrite(uint8_t *reg, uint8_t *data, uint8_t ®Lenght, 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 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 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 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 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 void i2cSetSpeed(uint8_t speed); // I2C Standart void i2cSetAddress(uint16_t &address); // I2C Standart void i2cSetAddressMode(); // I2C Standart 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 } #endif #endif // _I2C_H_