i2cdrv.c
Go to the documentation of this file.00001
00018 #include <stddef.h>
00019 #include "em_cmu.h"
00020 #include "em_gpio.h"
00021 #include "bsp.h"
00022 #include "i2cdrv.h"
00023 #include "i2cdrvconfig.h"
00024
00025
00026
00027
00028
00029
00041 void I2CDRV_Init(const I2C_Init_TypeDef *init)
00042 {
00043 int i;
00044
00045 #ifndef BSP_STK
00046 BSP_PeripheralAccess(BSP_I2C, true);
00047 #endif
00048 CMU_ClockEnable(cmuClock_HFPER, true);
00049 CMU_ClockEnable(cmuClock_I2C0, true);
00050
00051
00052
00053 GPIO_PinModeSet(I2CDRV_SCL_PORT, I2CDRV_SCL_PIN, gpioModeWiredAndPullUp, 1);
00054 GPIO_PinModeSet(I2CDRV_SDA_PORT, I2CDRV_SDA_PIN, gpioModeWiredAndPullUp, 1);
00055
00056
00057
00058 for (i = 0; i < 9; i++)
00059 {
00060
00061
00062
00063
00064
00065
00066 GPIO_PinOutSet(I2CDRV_SCL_PORT, I2CDRV_SCL_PIN);
00067 GPIO_PinOutClear(I2CDRV_SCL_PORT, I2CDRV_SCL_PIN);
00068 }
00069
00070
00071 I2C0->ROUTE = I2C_ROUTE_SDAPEN |
00072 I2C_ROUTE_SCLPEN |
00073 (I2CDRV_PORT_LOCATION << _I2C_ROUTE_LOCATION_SHIFT);
00074
00075 I2C_Init(I2C0, init);
00076 }
00077
00078
00079
00091 I2C_TransferReturn_TypeDef I2CDRV_Transfer(I2C_TransferSeq_TypeDef *seq)
00092 {
00093 I2C_TransferReturn_TypeDef ret;
00094 uint32_t timeout = I2CDRV_TRANSFER_TIMEOUT;
00095
00096 ret = I2C_TransferInit(I2C0, seq);
00097 while (ret == i2cTransferInProgress && timeout--)
00098 {
00099 ret = I2C_Transfer(I2C0);
00100 }
00101
00102 return(ret);
00103 }