From 71dfee8d4360a3e2007b8ccb53d7d3af840de4ea Mon Sep 17 00:00:00 2001 From: openshwprojects Date: Fri, 15 Apr 2022 11:02:05 +0200 Subject: [PATCH] fix warnings p1 --- src/drv_bl0942.c | 4 +- src/drv_i2c_public.h | 5 +- src/drv_public.h | 7 + src/drv_tuyaMCU.c | 2 + src/drv_uart.h | 14 ++ src/i2c/drv_i2c_local.h | 9 ++ src/i2c/drv_i2c_main.c | 6 +- src/i2c/drv_i2c_mcp23017.c | 7 +- src/new_pins.c | 277 +----------------------------------- src/new_repeatingEvents.c | 2 + src/new_tokenizer.c | 6 +- src/new_tokenizer.h | 6 + src/ntp_time.c | 4 +- src/user_main.c | 60 ++------ windowsTest_msvc2008.vcproj | 258 ++++++++++++++++----------------- 15 files changed, 205 insertions(+), 462 deletions(-) create mode 100644 src/drv_public.h diff --git a/src/drv_bl0942.c b/src/drv_bl0942.c index b119a6086..a1d0cf415 100644 --- a/src/drv_bl0942.c +++ b/src/drv_bl0942.c @@ -25,9 +25,9 @@ float realVoltage, realCurrent, realPower; int BL0942_TryToGetNextBL0942Packet() { int cs; - int len, i; + int i; int c_garbage_consumed = 0; - byte a, b, version, command, lena, lenb; + byte a; float newPower, newCurrent, newVoltage; byte checksum; int BL0942_PACKET_LEN = 23; diff --git a/src/drv_i2c_public.h b/src/drv_i2c_public.h index f45f147b7..3d1c92d61 100644 --- a/src/drv_i2c_public.h +++ b/src/drv_i2c_public.h @@ -2,4 +2,7 @@ void DRV_I2C_Init(); -void DRV_I2C_EverySecond(); +void DRV_I2C_EverySecond(); +void I2C_OnChannelChanged(int channel,int iVal); + + diff --git a/src/drv_public.h b/src/drv_public.h new file mode 100644 index 000000000..dbebc7c9d --- /dev/null +++ b/src/drv_public.h @@ -0,0 +1,7 @@ + + + +void DRV_Generic_Init(); +#include "httpserver/new_http.h" +void DRV_AppendInformationToHTTPIndexPage(http_request_t *request); +void DRV_OnEverySecond(); \ No newline at end of file diff --git a/src/drv_tuyaMCU.c b/src/drv_tuyaMCU.c index cfe4ed569..82f360b98 100644 --- a/src/drv_tuyaMCU.c +++ b/src/drv_tuyaMCU.c @@ -6,6 +6,8 @@ #include "drv_tuyaMCU.h" #include "drv_uart.h" #include +#include "ntp_time.h" +#include "new_tokenizer.h" #define TUYA_CMD_HEARTBEAT 0x00 diff --git a/src/drv_uart.h b/src/drv_uart.h index e69de29bb..5d2fae03c 100644 --- a/src/drv_uart.h +++ b/src/drv_uart.h @@ -0,0 +1,14 @@ + + + +void UART_InitReceiveRingBuffer(int size); +int UART_GetDataSize(); +byte UART_GetNextByte(int index); +void UART_ConsumeBytes(int idx); +void UART_AppendByteToCircularBuffer(int rc); +void UART_SendByte(byte b); +void UART_InitUART(int baud); + + + + diff --git a/src/i2c/drv_i2c_local.h b/src/i2c/drv_i2c_local.h index 581ad31bd..a0f5f6a5f 100644 --- a/src/i2c/drv_i2c_local.h +++ b/src/i2c/drv_i2c_local.h @@ -56,8 +56,17 @@ void DRV_I2C_Write(byte addr, byte data); void DRV_I2C_Read(byte addr, byte *data); int DRV_I2C_Begin(int dev_adr, int busID); void DRV_I2C_Close(); + +i2cBusType_t DRV_I2C_ParseBusType(const char *s); +i2cDevice_t *DRV_I2C_FindDevice(int busType,int address); +i2cDevice_t *DRV_I2C_FindDeviceExt(int busType,int address, int devType); + // drv_i2c_mcp23017.c +void DRV_I2C_MCP23017_RunDevice(i2cDevice_t *dev); int DRV_I2C_MCP23017_MapPinToChannel(const void *context, const char *cmd, const char *args); +// drv_i2c_tc74.c +void DRV_I2C_TC74_RunDevice(i2cDevice_t *dev); + #endif // __DRV_I2C_LOCAL_H__ \ No newline at end of file diff --git a/src/i2c/drv_i2c_main.c b/src/i2c/drv_i2c_main.c index 8e46b1f9b..dfcfb9679 100644 --- a/src/i2c/drv_i2c_main.c +++ b/src/i2c/drv_i2c_main.c @@ -4,6 +4,8 @@ #include "../new_cmd.h" #include "../logging/logging.h" #include "drv_i2c_local.h" +#include "../drv_i2c_public.h" +#include "../new_tokenizer.h" #if PLATFORM_BK7231T @@ -96,7 +98,7 @@ void DRV_I2C_AddDevice_MCP23017_Internal(int busType,int address) { dev->base.next = 0; memset(dev->pinMapping,0xff,sizeof(dev->pinMapping)); - DRV_I2C_AddNextDevice(dev); + DRV_I2C_AddNextDevice((i2cDevice_t*)dev); } i2cDevice_t *DRV_I2C_FindDevice(int busType,int address) { i2cDevice_t *dev; @@ -131,7 +133,7 @@ void DRV_I2C_AddDevice_TC74_Internal(int busType,int address, int targetChannel) dev->base.next = 0; dev->targetChannel = targetChannel; - DRV_I2C_AddNextDevice(dev); + DRV_I2C_AddNextDevice((i2cDevice_t*)dev); } int DRV_I2C_AddDevice_TC74(const void *context, const char *cmd, const char *args) { const char *i2cModuleStr; diff --git a/src/i2c/drv_i2c_mcp23017.c b/src/i2c/drv_i2c_mcp23017.c index 03668ac07..b3b5eaeac 100644 --- a/src/i2c/drv_i2c_mcp23017.c +++ b/src/i2c/drv_i2c_mcp23017.c @@ -2,7 +2,8 @@ #include "../new_pins.h" #include "../new_cfg.h" #include "../new_cmd.h" -#include "../logging/logging.h" +#include "../logging/logging.h" +#include "../new_tokenizer.h" #include "drv_i2c_local.h" // addresses, banks, etc, defines #include "drv_i2c_mcp23017.h" @@ -129,7 +130,7 @@ int DRV_I2C_MCP23017_MapPinToChannel(const void *context, const char *cmd, const busType = DRV_I2C_ParseBusType(i2cModuleStr); - mcp = DRV_I2C_FindDeviceExt( busType, address,I2CDEV_MCP23017); + mcp = (i2cDevice_MCP23017_t *)DRV_I2C_FindDeviceExt( busType, address,I2CDEV_MCP23017); if(mcp == 0) { addLogAdv(LOG_INFO, LOG_FEATURE_I2C,"DRV_I2C_MCP23017_MapPinToChannel: no such device exists\n" ); return 0; @@ -138,7 +139,7 @@ int DRV_I2C_MCP23017_MapPinToChannel(const void *context, const char *cmd, const mcp->pinMapping[targetPin] = targetChannel; // send refresh - DRV_I2C_MCP23017_OnChannelChanged(mcp, targetChannel, CHANNEL_Get(targetChannel)); + DRV_I2C_MCP23017_OnChannelChanged((i2cDevice_t*)mcp, targetChannel, CHANNEL_Get(targetChannel)); return 1; } diff --git a/src/new_pins.c b/src/new_pins.c index 4747df802..24b850938 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -6,6 +6,8 @@ #include "httpserver/new_http.h" #include "logging/logging.h" #include "new_cmd.h" +#include "new_tokenizer.h" +#include "drv_i2c_public.h" //According to your need to modify the constants. @@ -77,282 +79,7 @@ typedef struct item_pins_config }ITEM_PINS_CONFIG,*ITEM_PINS_CONFIG_PTR; -void testI2C() -{ - bk_i2c_device_t def; - def.address = 0xAA; - def.address_width = I2C_ADDRESS_WIDTH_7BIT; - def.speed_mode = I2C_STANDARD_SPEED_MODE; - - BkI2cInitialize(&def); - - -} -int TC74_readTemp_method1(int adr) -{ - bk_i2c_device_t def; - byte buffer[9]; - int t; - - - def.address = adr; - def.address_width = I2C_ADDRESS_WIDTH_7BIT; - def.speed_mode = I2C_STANDARD_SPEED_MODE; - - BkI2cInitialize(&def); - - // I2C1_start(); - //I2C1_Wr(adr); // Status = 0 if got an ACK - // I2C1_Wr(0x00); // Status = 0 if got an ACK - //I2C1_Repeated_Start(); // issue I2C signal repeated start - // I2C1_Wr(adr+1); // Status = 0 if got an ACK - // delay_ms(10); - // t = I2C1_Rd(1); - // I2C1_stop(); - - return t; - -} - - -///*/*/*int TC74_readTemp_method2(int adr) -//{ -// byte buffer[9]; -// int t; -// uint32_t status; -// uint32_t oflag; -// oflag = I2C_DEF_DIV; -// -// //i2c1_init(); -// i2c_hdl = ddev_open("i2c1", &status, oflag); -// if(DD_HANDLE_UNVALID == i2c_hdl){ -// addLogAdv(LOG_INFO, LOG_FEATURE_I2C,"TC74_readTemp_method2 ddev_open failed, status %i!\n",status); -// return -1; -// } -// -// addLogAdv(LOG_INFO, LOG_FEATURE_I2C,"TC74_readTemp_method2 ddev_open OK!\n"); -// -// //I2C1_start(); -// //i2c1_open(0); -// //I2C1_Wr(adr); // Status = 0 if got an ACK -// //I2C1_Wr(0x00); // Status = 0 if got an ACK -// buffer[0] = adr; -// buffer[1] = 0x00; -// camera_intf_sccb_write(adr,0x00); -// //ddev_write(i2c_hdl,buffer,2,0); -// //i2c1_write((char*)buffer, 2, 0); -// //I2C1_Repeated_Start(); // issue I2C signal repeated start -// // ???? -// //I2C1_Wr(adr+1); // Status = 0 if got an ACK -// buffer[0] = adr+1; -// //ddev_write(i2c_hdl,buffer,1,0); -// //delay_ms(10); -// //t = I2C1_Rd(1); -// //ddev_read(i2c_hdl,buffer,1,0); -// //i2c1_read((char*)buffer, 1, 0); -// camera_intf_sccb_read(adr,&buffer[0]); -// t = buffer[0]; -// //I2C1_stop(); -// //i2c1_close(); -// -// ddev_close(i2c_hdl); -// return t; -// -//}*/*/*/ - int attempt; - - -// dac i2c interface -#define I2C_CLK 26 -#define I2C_DAT 27 - -typedef struct Codec_RegCfg_s -{ - unsigned int map; - unsigned char reg; -}Codec_ES8374_RegCfg_t; - -// 0-output&pullup, 1--input -static void gpio_config_c( UINT32 index, UINT32 mode ) -{ - volatile UINT32 *gpio_cfg_addr; - UINT32 val; - UINT32 tmp; - if(index >GPIONUM) - return; - gpio_cfg_addr = (volatile UINT32 *)(REG_GPIO_CFG_BASE_ADDR + index * 4); - tmp =mode; - mode &= 0xff; - - if(mode == 1) - val =0x0c; - else - { - val = 0x30; - if(tmp>>8) - val |= 1<<1; - } - REG_WRITE(gpio_cfg_addr, val); -} - - - -static void gpio_output_c(UINT32 index, UINT32 val) -{ - UINT32 reg_val; - volatile UINT32 *gpio_cfg_addr; - - gpio_cfg_addr = (volatile UINT32 *)(REG_GPIO_CFG_BASE_ADDR + index * 4); - reg_val = REG_READ(gpio_cfg_addr); - - reg_val &= ~GCFG_OUTPUT_BIT; - reg_val |= (val & 0x01) << GCFG_OUTPUT_POS; - REG_WRITE(gpio_cfg_addr, reg_val); -} - -static UINT32 DATA_INPUT(void) -{ - UINT32 val = 0; - volatile UINT32 *gpio_cfg_addr; - - gpio_cfg_addr = (volatile UINT32 *)(REG_GPIO_CFG_BASE_ADDR + I2C_DAT * 4); - val = REG_READ(gpio_cfg_addr); - - return (val & 1); -} - - -static void CLK_OUTPUT_HIGH(void) -{ - gpio_output_c(I2C_CLK,1); -} -static void CLK_OUTPUT_LOW(void) -{ - gpio_output_c(I2C_CLK,0); -} - -static void DATA_OUTPUT_HIGH(void) -{ - gpio_output_c(I2C_DAT,1); -} - -static void DATA_OUTPUT_LOW(void) -{ - gpio_output_c(I2C_DAT,0); -} - -static void SET_DATA_INPUT(void) -{ - gpio_config_c(I2C_DAT,1); -} - -static void set_data_output(void) -{ - UINT32 mode; - UINT32 val = DATA_INPUT(); - mode = (val<<8) ; - gpio_config_c(I2C_DAT,mode); -} - -/*1 equals about 5 us*/ -static void es8374_codec_i2c_delay(int us) -{ - volatile int i, j; - for(i = 0; i < us; i++) - { - j = 50; - while(j--); - } -} - -static void es8374_codec_i2c_start(void) -{ - // start bit - CLK_OUTPUT_HIGH(); - DATA_OUTPUT_HIGH(); - es8374_codec_i2c_delay(1); - DATA_OUTPUT_LOW(); - es8374_codec_i2c_delay(1); -} - -static void es8374_codec_i2c_stop(void) -{ - //stop bit - CLK_OUTPUT_LOW(); - es8374_codec_i2c_delay(1); - CLK_OUTPUT_HIGH(); - es8374_codec_i2c_delay(1); - DATA_OUTPUT_HIGH(); - es8374_codec_i2c_delay(1); -} - - -static void es8374_codec_i2c_write_byte(unsigned char data) -{ - int i; - - //data 0-7bit - for(i = 7; i >= 0; i--) - { - CLK_OUTPUT_LOW(); - if(data & (0x1 << i)) // msb first, rising change and falling lock in codec - DATA_OUTPUT_HIGH(); - else - DATA_OUTPUT_LOW(); - es8374_codec_i2c_delay(1); - CLK_OUTPUT_HIGH(); - es8374_codec_i2c_delay(1); - } - //receive ack, bit9 - CLK_OUTPUT_LOW(); - SET_DATA_INPUT(); - - es8374_codec_i2c_delay(1); - - CLK_OUTPUT_HIGH(); - es8374_codec_i2c_delay(1); - set_data_output(); -} -int TC74_readTemp_method3(int adr) -{ - int t; - - - es8374_codec_i2c_start(); - es8374_codec_i2c_write_byte(adr); // Status = 0 if got an ACK - es8374_codec_i2c_write_byte(0x00); // Status = 0 if got an ACK - es8374_codec_i2c_start(); // issue I2C signal repeated start - es8374_codec_i2c_write_byte(adr+1); // Status = 0 if got an ACK - delay_ms(10); - t = I2C1_Rd(1); - es8374_codec_i2c_stop(); - return t; - -} -static void I2CWRNBYTE_CODEC(unsigned char reg, unsigned char val) -{ - UINT8 i2c_address = 0x20; - - es8374_codec_i2c_start(); - es8374_codec_i2c_write_byte(i2c_address); - es8374_codec_i2c_write_byte(reg); - es8374_codec_i2c_write_byte(val); - es8374_codec_i2c_stop(); -} - - -void testI2C_method1() -{ - char buffer[8]; - - - i2c1_open(0); - - i2c1_write(buffer, 2, 0); - i2c1_close(); - -} #endif diff --git a/src/new_repeatingEvents.c b/src/new_repeatingEvents.c index e17a89d83..ecd319cb3 100644 --- a/src/new_repeatingEvents.c +++ b/src/new_repeatingEvents.c @@ -1,9 +1,11 @@ #include "new_common.h" +#include "new_tokenizer.h" #include "httpserver/new_http.h" #include "logging/logging.h" #include "new_pins.h" #include "new_cfg.h" +#include "new_cmd.h" typedef struct repeatingEvent_s { char *command; diff --git a/src/new_tokenizer.c b/src/new_tokenizer.c index 9aaff1c77..b559bae60 100644 --- a/src/new_tokenizer.c +++ b/src/new_tokenizer.c @@ -8,8 +8,8 @@ #define MAX_ARGS 32 static char g_buffer[MAX_CMD_LEN]; -static char *g_args[MAX_ARGS]; -static char *g_argsFrom[MAX_ARGS]; +static const char *g_args[MAX_ARGS]; +static const char *g_argsFrom[MAX_ARGS]; static int g_numArgs = 0; bool isWhiteSpace(char ch) { @@ -43,9 +43,7 @@ int Tokenizer_GetArgInteger(int i) { return atoi(s); } void Tokenizer_TokenizeString(const char *s) { - int r = 0; char *p; - int i; while(isWhiteSpace(*s)) { s++; diff --git a/src/new_tokenizer.h b/src/new_tokenizer.h index e69de29bb..d7bfbe075 100644 --- a/src/new_tokenizer.h +++ b/src/new_tokenizer.h @@ -0,0 +1,6 @@ + +int Tokenizer_GetArgsCount(); +const char *Tokenizer_GetArg(int i); +const char *Tokenizer_GetArgFrom(int i); +int Tokenizer_GetArgInteger(int i); +void Tokenizer_TokenizeString(const char *s); \ No newline at end of file diff --git a/src/ntp_time.c b/src/ntp_time.c index f4b1f08f3..d08b8b6dc 100644 --- a/src/ntp_time.c +++ b/src/ntp_time.c @@ -4,6 +4,8 @@ #include "new_common.h" #include +#include "new_tokenizer.h" +#include "new_cmd.h" #ifdef WINDOWS @@ -166,7 +168,7 @@ void NTP_SendRequest(bool bBlocking) { void NTP_CheckForReceive() { byte *ptr; int i, recv_len; - struct tm * ptm; + //struct tm * ptm; unsigned short highWord; unsigned short lowWord; unsigned int secsSince1900; diff --git a/src/user_main.c b/src/user_main.c index 5fa468a4a..0e95ad5c2 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -9,23 +9,15 @@ * @Date: 2021-01-23 16:33:00 * @LastEditTime: 2021-01-27 17:00:00 */ - -#define _TUYA_DEVICE_GLOBAL - -/* Includes ------------------------------------------------------------------*/ -#include "uni_log.h" -#include "gw_intf.h" -#include "wlan_ui_pub.h" - -#include "lwip/sockets.h" -#include "lwip/ip_addr.h" -#include "lwip/inet.h" +// +//#include "lwip/sockets.h" +//#include "lwip/ip_addr.h" +//#include "lwip/inet.h" #include "mem_pub.h" #include "str_pub.h" #include "ethernet_intf.h" - -/* Private includes ----------------------------------------------------------*/ +#include "drv_public.h" // overall config variables for app - like BK_LITTLEFS #include "obk_config.h" @@ -56,14 +48,17 @@ static int g_secondsElapsed = 0; static int g_openAP = 0; static int g_connectToWiFi = 0; -int bSafeMode = 0; +static int bSafeMode = 0; // reset in this number of seconds -int g_reset = 0; +static int g_reset = 0; +beken_timer_t g_main_timer_1s; // save config in this number of seconds int g_savecfg = 0; +int g_bHasWiFiConnected = 0; + #define LOG_FEATURE LOG_FEATURE_MAIN // from wlan_ui.c @@ -78,7 +73,6 @@ int Time_getUpTimeSeconds() { return g_secondsElapsed; } -int g_bHasWiFiConnected = 0; // receives status change notifications about wireless - could be useful // ctxt is pointer to a rw_evt_type void wl_status( void *ctxt ){ @@ -176,36 +170,8 @@ void connect_to_wifi(const char *oob_ssid,const char *connect_key) } -beken_timer_t led_timer; -#if 0 -// OpenSHWProjects 2022 04 11 -// I tried to implement ADC but it seems that BkAdcInitialize and BkAdcTakeSample -// are missing from the precompiled Bekken library... -int adc_init = 0; -#include "../../beken378/func/user_driver/BkDriverADC.h" -void run_adc_test(){ - OSStatus test; - int adc; - short res; - int val; - uint32_t sampling_cycle; - uint16_t output; - sampling_cycle = 1000; - adc = 3; - if(adc_init == 0) { - adc_init = 1; - // undefined reference to `BkAdcInitialize' - test = BkAdcInitialize( adc, sampling_cycle ); - ADDLOGF_INFO("Adc init res %i\n", test); - } - // undefined reference to `BkAdcTakeSample' - test = BkAdcTakeSample( adc, &output ); - val = output; - ADDLOGF_INFO("BkAdcTakeSample res %i value %i\n", test, val); -} -#endif static void app_led_timer_handler(void *data) { // run_adc_test(); @@ -214,7 +180,7 @@ static void app_led_timer_handler(void *data) DRV_OnEverySecond(); g_secondsElapsed ++; - ADDLOGF_INFO("Timer is %i free mem %d\n", g_secondsElapsed, xPortGetFreeHeapSize()); + ADDLOGF_INFO("Timer is %i free mem %d\n", g_secondsElapsed, xPortGetFreeHeapSize()); // print network info if (!(g_secondsElapsed % 10)){ @@ -441,13 +407,13 @@ void user_main(void) } } - err = rtos_init_timer(&led_timer, + err = rtos_init_timer(&g_main_timer_1s, 1 * 1000, app_led_timer_handler, (void *)0); ASSERT(kNoErr == err); - err = rtos_start_timer(&led_timer); + err = rtos_start_timer(&g_main_timer_1s); ASSERT(kNoErr == err); ADDLOGF_DEBUG("started timer\r\n"); } diff --git a/windowsTest_msvc2008.vcproj b/windowsTest_msvc2008.vcproj index f86995369..be2cfe3c6 100644 --- a/windowsTest_msvc2008.vcproj +++ b/windowsTest_msvc2008.vcproj @@ -167,37 +167,6 @@ RelativePath=".\src\drv_bl0942.c" > - - - - - - - - - - - - - @@ -222,18 +191,6 @@ /> - - - - - @@ -270,26 +227,10 @@ /> - - - - - - - @@ -322,18 +263,6 @@ /> - - - - - @@ -346,10 +275,6 @@ /> - - @@ -366,26 +291,14 @@ RelativePath=".\src\new_cfg.c" > - - - - - - @@ -398,30 +311,6 @@ /> - - - - - - - - - - @@ -446,26 +335,14 @@ RelativePath=".\src\new_pins.c" > - - - - - - @@ -474,10 +351,6 @@ RelativePath=".\src\ntp_time.c" > - - @@ -733,6 +606,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +