/* * File: i2c.h */ #ifndef I2C_H #define I2C_H #ifdef __cplusplus extern "C" { #endif #define GPIOA29_I2C0_SDA (1 << 29) #define GPIOA30_I2C0_SCL (1 << 30) #define GPIOD22_I2C1_SDA (1 << 22) #define GPIOD23_I2C1_SCL (1 << 23) #define GPIOD24_I2C2_SDA (1 << 24) #define GPIOD25_I2C2_SCL (1 << 25) #define I2C0_BASE 0x3802C000 #define I2C0(a) (*(volatile unsigned int *)(I2C0_BASE + (a))) #define I2C1_BASE 0x3802D000 #define I2C1(a) (*(volatile unsigned int *)(I2C1_BASE + (a))) #define I2C2_BASE 0x3802E000 #define I2C2(a) (*(volatile unsigned int *)(I2C2_BASE + (a))) #define IC_CON 0x0 #define IC_TAR 0x4 #define IC_SAR 0x8 #define IC_HS_MADD 0xC #define IC_DATA_CMD 0x10 #define IC_SS_SCL_HCNT 0x14 #define IC_SS_SCL_LCNT 0x18 #define IC_FS_SCL_HCNT 0x1C #define IC_FS_SCL_LCNT 0x20 #define IC_HS_SCL_HCNT 0x24 #define IC_HS_SCL_LCNT 0x28 #define IC_INTR_STAT 0x2C #define IC_INTR_MASK 0x30 #define IC_RAW_INTR_STAT 0x34 #define IC_RX_TL 0x38 #define IC_TX_TL 0x3C #define IC_CLR_INTR 0x40 #define IC_CLR_RX_UNDER 0x44 #define IC_CLR_RX_OVER 0x48 #define IC_CLR_TX_OVER 0x4C #define IC_CLR_RD_REQ 0x50 #define IC_CLR_TX_ABR 0x54 #define IC_CLR_RX_DONE 0x58 #define IC_CLR_ACTIVITY 0x5C #define IC_CLR_STOP_DET 0x60 #define IC_CLR_START_DET 0x64 #define IC_CLR_GEN_CALL 0x68 #define IC_ENABLE 0x6C #define IC_STATUS 0x70 #define IC_TXFLR 0x74 #define IC_RXFLR 0x78 #define IC_SDA_HOLD 0x7C #define IC_TX_ABRT_SOURSE 0x80 #define IC_SLV_DATA_NACK_ONLY 0x84 #define IC_DMA_CR 0x88 #define IC_DMA_TDLR 0x8C #define IC_DMA_RDLR 0x90 #define IC_SDA_SETUP 0x94 #define IC_ACK_GENERAL_CALL 0x98 #define IC_ENABLE_STATUS 0x9C #define IC_FS_SPKLEN 0xA0 #define IC_HS_SPKLEN 0xA4 #define I2C_REG_8BIT_ADDRESS 8 // Size of register address #define I2C_REG_16BIT_ADDRESS 16 #define I2C_REG_24BIT_ADDRESS 24 #define I2C_REG_32BIT_ADDRESS 32 #define ALC5623_I2C_SLAVE_ADDR 0x1a #define MMPF0100_SLAVE_ADDR 0x08 #define MMPF0100_SW3AMODE_ADDR 0x3F #define MMPF0100_SW3BMODE_ADDR 0x46 #define MMPF0100_DDR_POWER_VAL 0x08 void init_I2C(unsigned int slave_addr); int readI2CBytes(unsigned int adrSize, unsigned int regNum, void *dest, int size); int writeI2CBytes(unsigned int adrSize, unsigned int regNum, void *src, int size); unsigned char readI2CRegByte(unsigned int adrSize, unsigned int regNum); unsigned short readI2CRegShort(unsigned int adrSize, unsigned int regNum); unsigned int readI2CRegInt(unsigned int adrSize, unsigned int regNum); unsigned long long readI2CRegLongLong(unsigned int adrSize, unsigned int regNum); int writeI2CRegByte(unsigned int adrSize, unsigned int regNum, unsigned char regVal); int writeI2CRegShort(unsigned int adrSize, unsigned int regNum, unsigned short regVal); int writeI2CRegInt(unsigned int adrSize, unsigned int regNum, unsigned int regVal); int writeI2CRegLongLong(unsigned int adrSize, unsigned int regNum, unsigned long long regVal); void i2c_delay(); #ifdef __cplusplus } #endif #endif /* I2C_H */