diff --git a/openBeken_win32_mvsc2017.vcxproj b/openBeken_win32_mvsc2017.vcxproj index 7648b8a5c..a4eb06f8e 100644 --- a/openBeken_win32_mvsc2017.vcxproj +++ b/openBeken_win32_mvsc2017.vcxproj @@ -261,6 +261,7 @@ + diff --git a/openBeken_win32_mvsc2017.vcxproj.filters b/openBeken_win32_mvsc2017.vcxproj.filters index aefd8e02f..f96af96e9 100644 --- a/openBeken_win32_mvsc2017.vcxproj.filters +++ b/openBeken_win32_mvsc2017.vcxproj.filters @@ -407,6 +407,7 @@ + diff --git a/platforms/obk_main.cmake b/platforms/obk_main.cmake index 62747aa43..23c28a842 100644 --- a/platforms/obk_main.cmake +++ b/platforms/obk_main.cmake @@ -120,6 +120,7 @@ set(OBKM_SRC ${OBK_SRCS}driver/drv_spidma.c ${OBK_SRCS}driver/drv_ssdp.c ${OBK_SRCS}driver/drv_tasmotaDeviceGroups.c + ${OBK_SRCS}driver/drv_tca9554.c ${OBK_SRCS}driver/drv_tclAC.c ${OBK_SRCS}driver/drv_test.c ${OBK_SRCS}driver/drv_test_drivers.c diff --git a/src/driver/drv_local.h b/src/driver/drv_local.h index 3ea200409..35df47d2c 100644 --- a/src/driver/drv_local.h +++ b/src/driver/drv_local.h @@ -186,6 +186,10 @@ void MAX6675_RunEverySecond(void); void MAX31855_Init(); void MAX31855_RunEverySecond(); +void TCA9554_Init(); +void TCA9554_OnEverySecond(); +void TCA9554_OnChannelChanged(int ch, int value); + void PWMG_Init(); void Freeze_Init(); diff --git a/src/driver/drv_main.c b/src/driver/drv_main.c index ba7c8b724..29392cb8b 100644 --- a/src/driver/drv_main.c +++ b/src/driver/drv_main.c @@ -46,6 +46,13 @@ static driver_t g_drivers[] = { //drvdetail:"requires":""} { "tmSensor", TuyaMCU_Sensor_Init, TuyaMCU_Sensor_RunEverySecond, NULL, NULL, NULL, NULL, NULL, false }, #endif +#if ENABLE_DRIVER_TCA9554 + //drvdetail:{"name":"TCA9554", + //drvdetail:"title":"TODO", + //drvdetail:"descr":"TCA9554.", + //drvdetail:"requires":""} + { "TCA9554", TCA9554_Init, TCA9554_OnEverySecond, NULL, NULL, NULL, TCA9554_OnChannelChanged , NULL, false }, +#endif #if ENABLE_DRIVER_FREEZE //drvdetail:{"name":"FREEZE", //drvdetail:"title":"TODO", diff --git a/src/driver/drv_tca9554.c b/src/driver/drv_tca9554.c new file mode 100644 index 000000000..4d944c30d --- /dev/null +++ b/src/driver/drv_tca9554.c @@ -0,0 +1,87 @@ +#include "../new_common.h" +#include "../new_pins.h" +#include "../new_cfg.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" +#include "../mqtt/new_mqtt.h" +#include "../logging/logging.h" +#include "drv_local.h" +#include "drv_uart.h" +#include "../httpserver/new_http.h" +#include "../hal/hal_pins.h" + +// default for ESP32-S3-ETH-8DI-8RO +static int tca_adr = (0x20 << 1); +#define TCA_CHANNELS 8 + +static softI2C_t tcI2C; +static int tca_firstChannel; +static int tca_values = 0; + +// startDriver TCA9554 [SCL] [SDA] [FirstChannel] [Adr] +// startDriver TCA9554 41 42 8 +// backlog stopDriver *; startDriver TCA9554 41 42 8 64 +/* +startDriver TCA9554 41 42 0 +setChannelType 0 Toggle +setChannelType 1 Toggle +setChannelType 2 Toggle +setChannelType 3 Toggle +setChannelType 4 Toggle +setChannelType 5 Toggle +setChannelType 6 Toggle +setChannelType 7 Toggle + + +*/ +void TCA9554_Init() { + tcI2C.pin_clk = Tokenizer_GetArgIntegerDefault(1, 41); + tcI2C.pin_data = Tokenizer_GetArgIntegerDefault(2, 42); + tca_firstChannel = Tokenizer_GetArgIntegerDefault(3, 8); + tca_adr = Tokenizer_GetArgIntegerDefault(4, tca_adr); + + Soft_I2C_PreInit(&tcI2C); + + rtos_delay_milliseconds(1); + Soft_I2C_Start(&tcI2C, tca_adr); + Soft_I2C_WriteByte(&tcI2C, 0x03); + Soft_I2C_WriteByte(&tcI2C, 0x00); + Soft_I2C_Stop(&tcI2C); +} +void TCA9954_ApplyChanges() { + Soft_I2C_Start(&tcI2C, tca_adr); + Soft_I2C_WriteByte(&tcI2C, 0x01); + Soft_I2C_WriteByte(&tcI2C, tca_values); + Soft_I2C_Stop(&tcI2C); +} +void TCA9554_OnChannelChanged(int ch, int value) { + if (ch >= tca_firstChannel && ch < (tca_firstChannel + TCA_CHANNELS)) { + int local = ch - tca_firstChannel; + if (value) { + tca_values |= (1 << local); // set bit + } + else { + tca_values &= ~(1 << local); // clear bit + } + TCA9954_ApplyChanges(); // write changes to TCA9554 + } +} + +void TCA9554_OnEverySecond() +{ + //static int x = 0; + //// launch measurement on sensor. + //Soft_I2C_Start(&tcI2C, tca_adr); + //Soft_I2C_WriteByte(&tcI2C, 0x03); + //Soft_I2C_WriteByte(&tcI2C, 0x00); + //Soft_I2C_Stop(&tcI2C); + + //rtos_delay_milliseconds(12); + //Soft_I2C_Start(&tcI2C, tca_adr); + //Soft_I2C_WriteByte(&tcI2C, 0x01); + //Soft_I2C_WriteByte(&tcI2C, x); + //Soft_I2C_Stop(&tcI2C); + + //x = ~x; +} + diff --git a/src/obk_config.h b/src/obk_config.h index 0a877d1ae..719873553 100644 --- a/src/obk_config.h +++ b/src/obk_config.h @@ -116,6 +116,7 @@ #endif +#define ENABLE_DRIVER_TCA9554 1 #define ENABLE_DRIVER_PINMUTEX 1 #define ENABLE_DRIVER_TESTSPIFLASH 1 @@ -392,6 +393,10 @@ #define ENABLE_OBK_BERRY 1 #endif +#if (OBK_VARIANT == OBK_VARIANT_ESP4M) +#define ENABLE_DRIVER_TCA9554 1 +#endif + #elif PLATFORM_TR6260 // #define ENABLE_SEND_POSTANDGET 1