diff --git a/src/driver/drv_local.h b/src/driver/drv_local.h index 7f24a7ff1..bae23f405 100644 --- a/src/driver/drv_local.h +++ b/src/driver/drv_local.h @@ -43,6 +43,7 @@ void TM1637_Init(); void GN6932_Init(); +void TM1638_Init(); bool DRV_IsRunning(const char* name); @@ -100,6 +101,8 @@ typedef struct softI2C_s { short pin_data; // I really have to place it here for a GN6932 driver, which is an SPI version of TM1637 short pin_stb; + // I must somehow be able to tell which proto we have? + //short protocolType; } softI2C_t; void Soft_I2C_SetLow(uint8_t pin); diff --git a/src/driver/drv_main.c b/src/driver/drv_main.c index 6a09abab1..3e096364e 100644 --- a/src/driver/drv_main.c +++ b/src/driver/drv_main.c @@ -241,6 +241,11 @@ static driver_t g_drivers[] = { //drvdetail:"descr":"Driver for 7-segment LED display with DIO/CLK/STB interface. See [this topic](https://www.elektroda.com/rtvforum/topic3971252.html) for details.", //drvdetail:"requires":""} { "GN6932", GN6932_Init, NULL, NULL, NULL, NULL, NULL, false }, + //drvdetail:{"name":"TM1638", + //drvdetail:"title":"TODO", + //drvdetail:"descr":"Driver for 7-segment LED display with DIO/CLK/STB interface. TM1638 is very similiar to GN6932 and TM1637. See [this topic](https://www.elektroda.com/rtvforum/viewtopic.php?p=20553628#20553628) for details.", + //drvdetail:"requires":""} + { "TM1638", TM1638_Init, NULL, NULL, NULL, NULL, NULL, false }, //drvdetail:{"name":"SHT3X", //drvdetail:"title":"TODO", //drvdetail:"descr":"Humidity/temperature sensor. See [SHT Sensor tutorial topic here](https://www.elektroda.com/rtvforum/topic3958369.html), also see [this sensor teardown](https://www.elektroda.com/rtvforum/topic3945688.html)", diff --git a/src/driver/drv_tm_gn_display_shared.c b/src/driver/drv_tm_gn_display_shared.c index 58bc500c4..ec8aa3702 100644 --- a/src/driver/drv_tm_gn_display_shared.c +++ b/src/driver/drv_tm_gn_display_shared.c @@ -41,6 +41,7 @@ static byte g_digits[] = { static byte g_remap[16] = { 2,1,0,5,4,3,8,7,6 }; +static byte g_doTM1638RowsToColumnsSwap = 0; static byte g_numDigits = sizeof(g_digits) / sizeof(g_digits[0]); static byte *tmgn_buffer = 0; static int g_totalDigits = 6; @@ -156,7 +157,7 @@ static void TM_GN_WriteCommand(softI2C_t *i2c, byte command, const byte *data, i TM_GN_WriteByte(i2c, command); // write data, if available if (data && dataSize) { - if (true) { + if (g_doTM1638RowsToColumnsSwap && dataSize == 16) { for (j = 0; j < 8; j++) { tmp = 0; for (i = 0; i < 8; i++) { @@ -475,6 +476,8 @@ goto again void TM_GN_Display_SharedInit() { int i; + g_doTM1638RowsToColumnsSwap = 0; + if (PIN_FindPinIndexForRole(IOR_TM1637_CLK, -1) != -1) { g_i2c.pin_clk = PIN_FindPinIndexForRole(IOR_TM1637_CLK, 16); g_i2c.pin_data = PIN_FindPinIndexForRole(IOR_TM1637_DIO, 14); @@ -486,14 +489,22 @@ void TM_GN_Display_SharedInit() { HAL_PIN_SetOutputValue(g_i2c.pin_clk, true); HAL_PIN_SetOutputValue(g_i2c.pin_data, true); - g_totalDigits = 6; + g_totalDigits = 6; } else { - g_i2c.pin_clk = PIN_FindPinIndexForRole(IOR_GN6932_CLK, 17); - g_i2c.pin_data = PIN_FindPinIndexForRole(IOR_GN6932_DAT, 15); - g_i2c.pin_stb = PIN_FindPinIndexForRole(IOR_GN6932_STB, 28); - addLogAdv(LOG_INFO, LOG_FEATURE_MAIN, "TM/GN driver: using SPI mode (GN6932)"); - + if (PIN_FindPinIndexForRole(IOR_TM1638_CLK, -1) != -1) { + g_i2c.pin_clk = PIN_FindPinIndexForRole(IOR_TM1638_CLK, 17); + g_i2c.pin_data = PIN_FindPinIndexForRole(IOR_TM1638_DAT, 15); + g_i2c.pin_stb = PIN_FindPinIndexForRole(IOR_TM1638_STB, 28); + addLogAdv(LOG_INFO, LOG_FEATURE_MAIN, "TM/GN driver: using SPI mode (TM1638)"); + g_doTM1638RowsToColumnsSwap = 1; + } + else { + g_i2c.pin_clk = PIN_FindPinIndexForRole(IOR_GN6932_CLK, 17); + g_i2c.pin_data = PIN_FindPinIndexForRole(IOR_GN6932_DAT, 15); + g_i2c.pin_stb = PIN_FindPinIndexForRole(IOR_GN6932_STB, 28); + addLogAdv(LOG_INFO, LOG_FEATURE_MAIN, "TM/GN driver: using SPI mode (GN6932)"); + } // GN6932 has no remap for (i = 0; i < sizeof(g_remap); i++) { g_remap[i] = i; diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index c4bf6fd6b..f60120300 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -455,6 +455,9 @@ const char* htmlPinRoleNames[] = { "GN6932_CLK", "GN6932_DAT", "GN6932_STB", + "TM1638_CLK", + "TM1638_DAT", + "TM1638_STB", "error", "error", "error", diff --git a/src/new_pins.h b/src/new_pins.h index 07429d020..e2de930c9 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -509,6 +509,27 @@ typedef enum ioRole_e { //iodetail:"file":"new_pins.h", //iodetail:"driver":""} IOR_GN6932_STB, + //iodetail:{"name":"TM1638_CLK", + //iodetail:"title":"TODO", + //iodetail:"descr":"QQQ", + //iodetail:"enum":"TM1638_CLK", + //iodetail:"file":"new_pins.h", + //iodetail:"driver":""} + IOR_TM1638_CLK, + //iodetail:{"name":"TM1638_DAT", + //iodetail:"title":"TODO", + //iodetail:"descr":"QQQ", + //iodetail:"enum":"TM1638_DAT", + //iodetail:"file":"new_pins.h", + //iodetail:"driver":""} + IOR_TM1638_DAT, + //iodetail:{"name":"TM1638_STB", + //iodetail:"title":"TODO", + //iodetail:"descr":"QQQ", + //iodetail:"enum":"TM1638_STB", + //iodetail:"file":"new_pins.h", + //iodetail:"driver":""} + IOR_TM1638_STB, //iodetail:{"name":"Total_Options", //iodetail:"title":"TODO", //iodetail:"descr":"Current total number of available IOR roles", diff --git a/src/user_main.c b/src/user_main.c index 4d982e0bc..3765c6a04 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -986,6 +986,14 @@ void Main_Init_BeforeDelay_Unsafe(bool bAutoRunScripts) { { #ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("GN6932"); +#endif + } + if ((PIN_FindPinIndexForRole(IOR_TM1638_CLK, -1) != -1) && + (PIN_FindPinIndexForRole(IOR_TM1638_DAT, -1) != -1) && + (PIN_FindPinIndexForRole(IOR_TM1638_STB, -1) != -1)) + { +#ifndef OBK_DISABLE_ALL_DRIVERS + DRV_StartDriver("TM1638"); #endif } }