parent
35e266cb2e
commit
ec539bc930
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
|
||||
#include "user.h"
|
||||
//#define IIC_DBG(X,Y...)
|
||||
|
||||
#define IIC_DBG DBG
|
||||
enum
|
||||
{
|
||||
|
@ -81,10 +81,18 @@ static int32_t prvI2C_DummyCB(void *pData, void *pParam)
|
|||
|
||||
static void I2C_IrqHandle(int32_t IrqLine, void *pData)
|
||||
{
|
||||
int32_t result = ERROR_NONE;
|
||||
I2C_TypeDef *I2C = prvI2C.RegBase;
|
||||
uint32_t Source = I2C->IC_TX_ABRT_SOURCE;
|
||||
uint32_t State = I2C->IC_RAW_INTR_STAT;
|
||||
uint32_t RegValue = I2C->IC_CLR_INTR;
|
||||
|
||||
if (Source & 0x0000ffff)
|
||||
{
|
||||
result = -ERROR_OPERATION_FAILED;
|
||||
goto I2C_DONE;
|
||||
}
|
||||
|
||||
switch(prvI2C.State)
|
||||
{
|
||||
case I2C_STATE_WRITE_ADDRESS:
|
||||
|
@ -144,20 +152,29 @@ static void I2C_IrqHandle(int32_t IrqLine, void *pData)
|
|||
}
|
||||
break;
|
||||
default:
|
||||
// IIC_DBG("%x, %u", State, prvI2C.State);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
I2C_DONE:
|
||||
I2C->IC_INTR_MASK = 0;
|
||||
prvI2C_Done(ERROR_NONE);
|
||||
prvI2C_Done(result);
|
||||
}
|
||||
|
||||
static void I2C_IrqHandleRegQueue(int32_t IrqLine, void *pData)
|
||||
{
|
||||
int32_t result = ERROR_NONE;
|
||||
I2C_TypeDef *I2C = prvI2C.RegBase;
|
||||
uint32_t Source = I2C->IC_TX_ABRT_SOURCE;
|
||||
uint32_t State = I2C->IC_RAW_INTR_STAT;
|
||||
uint32_t RegValue = I2C->IC_CLR_INTR;
|
||||
|
||||
if (Source & 0x0000ffff)
|
||||
{
|
||||
|
||||
result = -ERROR_OPERATION_FAILED;
|
||||
goto I2C_DONE;
|
||||
}
|
||||
|
||||
if (State & I2C_IT_TXE)
|
||||
{
|
||||
if (prvI2C.DataBuf.Pos >= prvI2C.DataBuf.MaxLen)
|
||||
|
@ -189,7 +206,7 @@ static void I2C_IrqHandleRegQueue(int32_t IrqLine, void *pData)
|
|||
return;
|
||||
I2C_DONE:
|
||||
I2C->IC_INTR_MASK = 0;
|
||||
prvI2C_Done(ERROR_NONE);
|
||||
prvI2C_Done(result);
|
||||
}
|
||||
|
||||
void I2C_GlobalInit(void)
|
||||
|
|
|
@ -112,6 +112,8 @@ int air105_hw_i2c_init(void)
|
|||
prv_air105_i2c.ops = &air105_i2c_ops;
|
||||
prv_air105_i2c.priv = 0;
|
||||
I2C_MasterSetup(0, 400000);
|
||||
GPIO_Iomux(GPIOE_06, 2);
|
||||
GPIO_Iomux(GPIOE_07, 2);
|
||||
#ifdef I2C_BUS_NAME
|
||||
rt_i2c_bus_device_register(&prv_air105_i2c, I2C_BUS_NAME);
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue