You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.1 KiB
115 lines
3.1 KiB
#include "i2c.h"
|
|
|
|
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 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 */
|
|
i2cClockStretching_t stretching, /*!< Clock Stretching enable onyl in slave mode */
|
|
i2cWakeUpTypes_t wakeOn) /*!< Wake up condition */
|
|
{
|
|
i2cHardware->channelNo = channelNo;
|
|
i2cHardware->mode = mode;
|
|
i2cHardware->mainAddress = mainAddress;
|
|
i2cHardware->secondAddress = secondAddress;
|
|
i2cHardware->addressCount = addressCount;
|
|
i2cHardware->addressSize = addressSize;
|
|
i2cHardware->speed = speed;
|
|
i2cHardware->opperationMode = opperationMode;
|
|
i2cHardware->stretching = stretching;
|
|
i2cHardware->wakeOn = wakeOn;
|
|
i2cHardware->state = i2cNotInitialized;
|
|
|
|
i2cEnableHardware(i2cHardware);
|
|
|
|
i2cDisablePeriferal(i2cHardware);
|
|
|
|
i2cConfigureFilters(i2cHardware);
|
|
|
|
i2cSetClockStretch(i2cHardware, stretching);
|
|
|
|
i2cSetSpeed(i2cHardware, speed);
|
|
|
|
i2cSetMode(i2cHardware, opperationMode);
|
|
|
|
i2cSetAddressLenght(i2cHardware, addressSize);
|
|
|
|
i2cSetAddress(i2cHardware, mainAddress, secondAddress);
|
|
|
|
i2cEnablePeriferal(i2cHardware);
|
|
|
|
i2cHardware->state = i2cInitialized;
|
|
}
|
|
|
|
|
|
void i2cDeInit(i2c_t *i2cHardware)
|
|
{
|
|
|
|
}
|
|
|
|
void i2cWrite( i2c_t *i2cHardware,
|
|
uint16_t *devAddress,
|
|
uint8_t *registerAddress,
|
|
uint8_t *data,
|
|
uint8_t dataLenght)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
// this function still doesn't implment 10 bit oopeartion TODO
|
|
void i2cMasterRecieve(i2c_t *i2cHardware, uint16_t slaveAddress, uint8_t registerAddress, uint8_t *data)
|
|
{
|
|
// Wait until no communication is ongoign
|
|
i2cWaitForPeriferal(i2cHardware);
|
|
|
|
i2cHardware->state = i2cTransmitting;
|
|
|
|
i2cInitiateWriteCommand(i2cHardware);
|
|
|
|
i2cSendSlaveAddress(i2cHardware, slaveAddress);
|
|
|
|
i2cSendRegisterAddress(i2cHardware,registerAddress);
|
|
|
|
//Is the tranfes complete ?
|
|
while(!(I2C_BASE->ISR & (I2C_ISR_TC)));
|
|
|
|
i2cHardware->state = i2cRecieving;
|
|
|
|
i2cInitiateReadCommand(i2cHardware);
|
|
|
|
i2cSendSlaveAddress(i2cHardware, slaveAddress);
|
|
|
|
//Wait for the input buffer to be full
|
|
while(!(I2C_BASE->ISR & (I2C_ISR_RXNE)));
|
|
|
|
i2cGenerateNack(i2cHardware);
|
|
|
|
i2cGenerateStop(i2cHardware);
|
|
|
|
//read dtaa from the input register to clear it out
|
|
*data = I2C_BASE->RXDR;
|
|
|
|
i2cHardware->state = i2cReady;
|
|
}
|
|
|
|
|
|
void i2cMasterSend(i2c_t *i2cHardware, uint16_t *devAddress, uint8_t *registerAddress, uint8_t *data)
|
|
{
|
|
|
|
}
|
|
|
|
void i2cSlaveRecieve(i2c_t *i2cHardware, uint16_t *devAddress, uint8_t *registerAddress, uint8_t *data)
|
|
{
|
|
|
|
}
|
|
|
|
void i2cSlaveSend(i2c_t *i2cHardware, uint16_t *devAddress, uint8_t *registerAddress, uint8_t *data)
|
|
{
|
|
|
|
}
|