Mini can app
Dependencies: mbed mbed-STM32F103C8T6
i2c_base.cpp
00001 #include "wiced_types.h" 00002 #include "i2c_base.h" 00003 extern void DebugWrite(const char* str); 00004 00005 void cleanI2CLines(I2C* dev, PinName sda, PinName scl) 00006 { 00007 delete dev; 00008 dev = new I2C(sda, scl); 00009 // wiced_rtos_lock_mutex(&i2c_mutex); 00010 // toggle 00011 /* 00012 int limit = 260; 00013 while (limit-- > 0) 00014 { 00015 wiced_bool_t SDAstate = wiced_gpio_input_get(WICED_GPIO_12); 00016 wiced_bool_t SCLstate = wiced_gpio_input_get(WICED_GPIO_11); 00017 wiced_gpio_init(WICED_GPIO_11, OUTPUT_PUSH_PULL); 00018 wiced_gpio_init(WICED_GPIO_12, INPUT_HIGH_IMPEDANCE); 00019 //printf("SDA is %d, SCL is %d\r\n", SDAstate, SCLstate); 00020 if ((SDAstate == WICED_TRUE) && (SCLstate == WICED_TRUE)) 00021 { 00022 break; 00023 } 00024 else 00025 { 00026 printf("Pulsing SCL\r\n"); 00027 // pulse SDA 00028 wiced_gpio_output_low(WICED_GPIO_11); 00029 wiced_rtos_delay_milliseconds(10); 00030 wiced_gpio_output_high(WICED_GPIO_11); 00031 wiced_rtos_delay_milliseconds(10); 00032 } 00033 } 00034 00035 // need to return to input/HI mode or doesn't init properly. 00036 wiced_gpio_init(WICED_GPIO_11, INPUT_HIGH_IMPEDANCE); 00037 wiced_gpio_init(WICED_GPIO_12, OUTPUT_OPEN_DRAIN_PULL_UP); 00038 */ 00039 // wiced_rtos_unlock_mutex(&i2c_mutex); 00040 } 00041 00042 wiced_result_t readRegs(unsigned char addr, unsigned char * data, unsigned char len, I2C* i2c_dev, const int addr7bit, int* failcount, wiced_bool_t writeThenRead, 00043 wiced_bool_t swap) 00044 { 00045 int addr8bit = addr7bit << 1; 00046 int result = 0; 00047 if (writeThenRead) { 00048 // not implemented yet 00049 DebugWrite("Not implemented yet\r\n"); 00050 result = 1; 00051 00052 } else { 00053 const char t[1] = {addr}; 00054 result = i2c_dev->write(addr8bit, t, 1, true); 00055 result = i2c_dev->read(addr8bit, (char *)data, len); 00056 } 00057 00058 if (result > 0) { 00059 return WICED_ERROR; 00060 } 00061 return WICED_SUCCESS; 00062 } 00063 00064 wiced_result_t writeRegs(unsigned char addr, unsigned char * data, unsigned char len, I2C* i2c_dev, const int addr7bit, int* i2cfailcount, wiced_bool_t swap) 00065 { 00066 uint8_t command[4]; 00067 int addr8bit = addr7bit << 1; 00068 int result = 1; 00069 command[0] = addr; 00070 if (len == 1) 00071 { 00072 command[1] = (data[0] & 0xFF); 00073 } 00074 result = i2c_dev->write(addr8bit, (char *)command, len+1); 00075 if (result > 0) { 00076 return WICED_ERROR; 00077 } 00078 return WICED_SUCCESS; 00079 }
Generated on Fri Jul 15 2022 20:08:26 by
1.7.2