simple TCA9554 driver, enabled by default on 4MB ESP32, for Waveshare barrd

* TCA9554

* fx

* proj

* makeff

* io

* better

* fx

* TCA9554 almoisy

* test

* fx
This commit is contained in:
openshwprojects
2025-08-22 09:07:28 +02:00
committed by GitHub
parent 4d42d8bf43
commit e6dbea6007
7 changed files with 106 additions and 0 deletions

View File

@ -261,6 +261,7 @@
<ClCompile Include="src\driver\drv_spi_flash.c" />
<ClCompile Include="src\driver\drv_ssdp.c" />
<ClCompile Include="src\driver\drv_tasmotaDeviceGroups.c" />
<ClCompile Include="src\driver\drv_tca9554.c" />
<ClCompile Include="src\driver\drv_tclAC.c" />
<ClCompile Include="src\driver\drv_test.c" />
<ClCompile Include="src\driver\drv_test_charts.c" />

View File

@ -407,6 +407,7 @@
<ClCompile Include="src\driver\drv_soft_spi.c" />
<ClCompile Include="src\driver\drv_spi_flash.c" />
<ClCompile Include="src\hal\win32\hal_ota_win32.c" />
<ClCompile Include="src\driver\drv_tca9554.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\base64\base64.h" />

View File

@ -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

View File

@ -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();

View File

@ -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",

87
src/driver/drv_tca9554.c Normal file
View File

@ -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;
}

View File

@ -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