From c4ce5df5410e96f79b90897a8bb8174a36b53ff8 Mon Sep 17 00:00:00 2001 From: Vinzenz82 Date: Tue, 19 Sep 2023 21:30:23 +0200 Subject: [PATCH 1/7] now possible with LL --- TM1638_platform.c | 64 ++++++++++++++++++++++++++++++++++++----------- TM1638_platform.h | 8 +++--- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/TM1638_platform.c b/TM1638_platform.c index 5212a20..a958fd0 100644 --- a/TM1638_platform.c +++ b/TM1638_platform.c @@ -54,22 +54,39 @@ #if defined(TM1638_PLATFORM_STM32) void TM1638_SetGPIO_OUT(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; + // GPIO_InitTypeDef GPIO_InitStruct = {0}; + // GPIO_InitStruct.Pin = GPIO_Pin; + // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + // GPIO_InitStruct.Pull = GPIO_NOPULL; + // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + // HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); + + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + GPIO_InitStruct.Pin = GPIO_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOx, &GPIO_InitStruct); } void TM1638_SetGPIO_IN_PU(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; + // GPIO_InitTypeDef GPIO_InitStruct = {0}; + // GPIO_InitStruct.Pin = GPIO_Pin; + // GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + // GPIO_InitStruct.Pull = GPIO_PULLUP; + // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + // HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); + + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + GPIO_InitStruct.Pin = GPIO_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; + LL_GPIO_Init(GPIOx, &GPIO_InitStruct); } #elif defined(TM1638_PLATFORM_ESP32_IDF) void TM1638_SetGPIO_OUT(gpio_num_t GPIO_Pad) @@ -155,7 +172,13 @@ TM1638_DioWrite(uint8_t Level) else TM1638_DIO_PORT &= ~(1< Date: Sat, 23 Sep 2023 12:28:33 +0200 Subject: [PATCH 2/7] added new func TM1638_SetMultipleDigit_CHAR --- TM1638.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- TM1638.h | 21 +++++- 2 files changed, 217 insertions(+), 3 deletions(-) diff --git a/TM1638.c b/TM1638.c index 0fc1dea..71a7897 100644 --- a/TM1638.c +++ b/TM1638.c @@ -64,7 +64,7 @@ /** * @brief Convert HEX number to Seven-Segment code */ -const uint8_t HexTo7Seg[16] = +const uint8_t HexTo7Seg[16+24] = { 0x3F, // 0 0x06, // 1 @@ -81,7 +81,32 @@ const uint8_t HexTo7Seg[16] = 0x39, // C 0x5E, // d 0x79, // E - 0x71 // F + 0x71, // F + 0x6F, // g + 0x3D, // G + 0x74, // h + 0x76, // H + 0x05, // i + 0x06, // I + 0x0D, // j + 0x30, // l + 0x38, // L + 0x54, // n + 0x37, // N + 0x5C, // o + 0x3F, // O + 0x73, // P + 0x67, // q + 0x50, // r + 0x6D, // S + 0x78, // t + 0x1C, // u + 0x3E, // U + 0x66, // y + 0x08, // _ + 0x40, // - + 0x01 // high bar + }; @@ -507,6 +532,11 @@ TM1638_SetMultipleDigit_HEX(TM1638_Handler_t *Handler, const uint8_t *DigitData, DigitDataHEX[i] = HexTo7Seg[0x0F] | DecimalPoint; break; + case 0x40: + DigitDataHEX[i] = HexTo7Seg[0x10] | DecimalPoint; + break; + + default: DigitDataHEX[i] = 0; break; @@ -518,6 +548,171 @@ TM1638_SetMultipleDigit_HEX(TM1638_Handler_t *Handler, const uint8_t *DigitData, (const uint8_t *)DigitDataHEX, StartAddr, Count); } +TM1638_Result_t +TM1638_SetMultipleDigit_CHAR(TM1638_Handler_t *Handler, const uint8_t *DigitData, + uint8_t StartAddr, uint8_t Count) +{ + uint8_t DigitDataHEX[10]; + uint8_t DecimalPoint = 0; + + for (uint8_t i = 0; i < Count; i++) + { + DecimalPoint = DigitData[i] & 0x80; + + // numbers 0 - 9 + if ((DigitData[i] & 0x7F) >= (uint8_t)'0' && (DigitData[i] & 0x7F) <= (uint8_t)'9') + { + DigitDataHEX[i] = HexTo7Seg[(DigitData[i]-48) & 0x7F] | DecimalPoint; + } + else + { + switch (DigitData[i] & 0x7F) + { + case 'A': + case 'a': + DigitDataHEX[i] = HexTo7Seg[0x0A] | DecimalPoint; + break; + + case 'B': + case 'b': + DigitDataHEX[i] = HexTo7Seg[0x0B] | DecimalPoint; + break; + + case 'C': + case 'c': + DigitDataHEX[i] = HexTo7Seg[0x0C] | DecimalPoint; + break; + + case 'D': + case 'd': + DigitDataHEX[i] = HexTo7Seg[0x0D] | DecimalPoint; + break; + + case 'E': + case 'e': + DigitDataHEX[i] = HexTo7Seg[0x0E] | DecimalPoint; + break; + + case 'F': + case 'f': + DigitDataHEX[i] = HexTo7Seg[0x0F] | DecimalPoint; + break; + + case 'g': + DigitDataHEX[i] = HexTo7Seg[0x10] | DecimalPoint; + break; + + case 'G': + DigitDataHEX[i] = HexTo7Seg[0x11] | DecimalPoint; + break; + + case 'h': + DigitDataHEX[i] = HexTo7Seg[0x12] | DecimalPoint; + break; + + case 'H': + DigitDataHEX[i] = HexTo7Seg[0x13] | DecimalPoint; + break; + + case 'i': + DigitDataHEX[i] = HexTo7Seg[0x14] | DecimalPoint; + break; + + case 'I': + DigitDataHEX[i] = HexTo7Seg[0x15] | DecimalPoint; + break; + + case 'j': + case 'J': + DigitDataHEX[i] = HexTo7Seg[0x16] | DecimalPoint; + break; + + case 'l': + DigitDataHEX[i] = HexTo7Seg[0x17] | DecimalPoint; + break; + + case 'L': + DigitDataHEX[i] = HexTo7Seg[0x18] | DecimalPoint; + break; + + case 'n': + DigitDataHEX[i] = HexTo7Seg[0x19] | DecimalPoint; + break; + + case 'N': + DigitDataHEX[i] = HexTo7Seg[0x1A] | DecimalPoint; + break; + + case 'o': + DigitDataHEX[i] = HexTo7Seg[0x1B] | DecimalPoint; + break; + + case 'O': + DigitDataHEX[i] = HexTo7Seg[0x1C] | DecimalPoint; + break; + + case 'p': + case 'P': + DigitDataHEX[i] = HexTo7Seg[0x1D] | DecimalPoint; + break; + + case 'q': + case 'Q': + DigitDataHEX[i] = HexTo7Seg[0x1E] | DecimalPoint; + break; + + case 'r': + case 'R': + DigitDataHEX[i] = HexTo7Seg[0x1F] | DecimalPoint; + break; + + case 's': + case 'S': + DigitDataHEX[i] = HexTo7Seg[0x20] | DecimalPoint; + break; + + case 't': + case 'T': + DigitDataHEX[i] = HexTo7Seg[0x21] | DecimalPoint; + break; + + case 'u': + DigitDataHEX[i] = HexTo7Seg[0x22] | DecimalPoint; + break; + + case 'U': + DigitDataHEX[i] = HexTo7Seg[0x23] | DecimalPoint; + break; + + case 'y': + case 'Y': + DigitDataHEX[i] = HexTo7Seg[0x24] | DecimalPoint; + break; + + case '_': + DigitDataHEX[i] = HexTo7Seg[0x25] | DecimalPoint; + break; + + case '-': + DigitDataHEX[i] = HexTo7Seg[0x26] | DecimalPoint; + break; + + case '~': + DigitDataHEX[i] = HexTo7Seg[0x27] | DecimalPoint; + break; + + + + default: + DigitDataHEX[i] = 0; + break; + } + } + } + + return TM1638_SetMultipleDigit(Handler, + (const uint8_t *)DigitDataHEX, StartAddr, Count); +} /** ================================================================================== diff --git a/TM1638.h b/TM1638.h index a1c0eaa..ab47362 100644 --- a/TM1638.h +++ b/TM1638.h @@ -262,7 +262,26 @@ TM1638_Result_t TM1638_SetMultipleDigit_HEX(TM1638_Handler_t *Handler, const uint8_t *DigitData, uint8_t StartAddr, uint8_t Count); - +/** + * @brief Set data to multiple digits in char format + * @param Handler: Pointer to handler + * @param DigitData: Array to Digits data. + * (0, 1, ... , 15, a, A, b, B, ...) + * + * @param StartAddr: First digit position + * - 0: Seg1 + * - 1: Seg2 + * - . + * - . + * - . + * + * @param Count: Number of segments to write data + * @retval TM1638_Result_t + * - TM1638_OK: Operation was successful + */ +TM1638_Result_t +TM1638_SetMultipleDigit_CHAR(TM1638_Handler_t *Handler, const uint8_t *DigitData, + uint8_t StartAddr, uint8_t Count); /** ================================================================================== From 75f9d1004933e316e6d36104e7733e0e6c77354b Mon Sep 17 00:00:00 2001 From: Vinzenz82 Date: Sat, 23 Sep 2023 12:50:36 +0200 Subject: [PATCH 3/7] made LL defs nicer --- TM1638_platform.c | 60 ++++++++++++++++++++++++++++------------------- TM1638_platform.h | 15 +++++++++++- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/TM1638_platform.c b/TM1638_platform.c index a958fd0..0a1cc84 100644 --- a/TM1638_platform.c +++ b/TM1638_platform.c @@ -37,6 +37,8 @@ #include #elif defined(TM1638_PLATFORM_STM32) #include "main.h" +#elif defined(TM1638_PLATFORM_STM32_LL) +#include "main.h" #elif defined(TM1638_PLATFORM_ESP32_IDF) #include "freertos/FreeRTOS.h" #include "driver/gpio.h" @@ -54,13 +56,26 @@ #if defined(TM1638_PLATFORM_STM32) void TM1638_SetGPIO_OUT(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) { - // GPIO_InitTypeDef GPIO_InitStruct = {0}; - // GPIO_InitStruct.Pin = GPIO_Pin; - // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - // GPIO_InitStruct.Pull = GPIO_NOPULL; - // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - // HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); - + GPIO_InitTypeDef GPIO_InitStruct = {0}; + GPIO_InitStruct.Pin = GPIO_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); +} + +void TM1638_SetGPIO_IN_PU(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + GPIO_InitStruct.Pin = GPIO_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); +} +#elif defined(TM1638_PLATFORM_STM32_LL) +void TM1638_SetGPIO_OUT(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) +{ LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = GPIO_Pin; @@ -73,13 +88,6 @@ void TM1638_SetGPIO_OUT(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) void TM1638_SetGPIO_IN_PU(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) { - // GPIO_InitTypeDef GPIO_InitStruct = {0}; - // GPIO_InitStruct.Pin = GPIO_Pin; - // GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - // GPIO_InitStruct.Pull = GPIO_PULLUP; - // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - // HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = GPIO_Pin; @@ -110,7 +118,7 @@ TM1638_PlatformInit(void) TM1638_CLK_DDR |= (1< Date: Sat, 23 Sep 2023 20:18:23 +0200 Subject: [PATCH 4/7] made the code nicer --- TM1638.c | 24 ++++++++++++++++++++---- TM1638.h | 4 +++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/TM1638.c b/TM1638.c index 71a7897..ec46805 100644 --- a/TM1638.c +++ b/TM1638.c @@ -64,7 +64,7 @@ /** * @brief Convert HEX number to Seven-Segment code */ -const uint8_t HexTo7Seg[16+24] = +const uint8_t HexTo7Seg[40] = { 0x3F, // 0 0x06, // 1 @@ -106,7 +106,6 @@ const uint8_t HexTo7Seg[16+24] = 0x08, // _ 0x40, // - 0x01 // high bar - }; @@ -548,6 +547,25 @@ TM1638_SetMultipleDigit_HEX(TM1638_Handler_t *Handler, const uint8_t *DigitData, (const uint8_t *)DigitDataHEX, StartAddr, Count); } +/** + * @brief Set data to multiple digits in char format + * @param Handler: Pointer to handler + * @param DigitData: Array to Digits data. + * Supported chars 0,1,2,3,4,5,6,7,8,9 + * A,b,C,d,E,F,g,G,h,H,i,I,j,l,L,n,N,o,O,P,q,r,S,t,u,U,y + * _,-,high bar (use ~ to set) + * + * @param StartAddr: First digit position + * - 0: Seg1 + * - 1: Seg2 + * - . + * - . + * - . + * + * @param Count: Number of segments to write data + * @retval TM1638_Result_t + * - TM1638_OK: Operation was successful + */ TM1638_Result_t TM1638_SetMultipleDigit_CHAR(TM1638_Handler_t *Handler, const uint8_t *DigitData, uint8_t StartAddr, uint8_t Count) @@ -701,8 +719,6 @@ TM1638_SetMultipleDigit_CHAR(TM1638_Handler_t *Handler, const uint8_t *DigitData DigitDataHEX[i] = HexTo7Seg[0x27] | DecimalPoint; break; - - default: DigitDataHEX[i] = 0; break; diff --git a/TM1638.h b/TM1638.h index ab47362..624220c 100644 --- a/TM1638.h +++ b/TM1638.h @@ -266,7 +266,9 @@ TM1638_SetMultipleDigit_HEX(TM1638_Handler_t *Handler, const uint8_t *DigitData, * @brief Set data to multiple digits in char format * @param Handler: Pointer to handler * @param DigitData: Array to Digits data. - * (0, 1, ... , 15, a, A, b, B, ...) + * Supported chars 0,1,2,3,4,5,6,7,8,9 + * A,b,C,d,E,F,g,G,h,H,i,I,j,l,L,n,N,o,O,P,q,r,S,t,u,U,y + * _,-,high bar (use ~ to set) * * @param StartAddr: First digit position * - 0: Seg1 From 05e3ed6399eb8813ea31ee140cf9311faa802269 Mon Sep 17 00:00:00 2001 From: Vinzenz82 Date: Sat, 23 Sep 2023 20:41:02 +0200 Subject: [PATCH 5/7] small fixes --- TM1638.c | 2 +- TM1638.h | 2 +- TM1638_platform.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TM1638.c b/TM1638.c index ec46805..52f72d9 100644 --- a/TM1638.c +++ b/TM1638.c @@ -105,7 +105,7 @@ const uint8_t HexTo7Seg[40] = 0x66, // y 0x08, // _ 0x40, // - - 0x01 // high bar + 0x01 // Overscore }; diff --git a/TM1638.h b/TM1638.h index 624220c..dad4749 100644 --- a/TM1638.h +++ b/TM1638.h @@ -268,7 +268,7 @@ TM1638_SetMultipleDigit_HEX(TM1638_Handler_t *Handler, const uint8_t *DigitData, * @param DigitData: Array to Digits data. * Supported chars 0,1,2,3,4,5,6,7,8,9 * A,b,C,d,E,F,g,G,h,H,i,I,j,l,L,n,N,o,O,P,q,r,S,t,u,U,y - * _,-,high bar (use ~ to set) + * _,-,Overscore (use ~ to set) * * @param StartAddr: First digit position * - 0: Seg1 diff --git a/TM1638_platform.h b/TM1638_platform.h index 05eb81d..42dfd2d 100644 --- a/TM1638_platform.h +++ b/TM1638_platform.h @@ -78,7 +78,7 @@ extern "C" { #define TM1638_DIO_GPIO GPIOA #define TM1638_DIO_PIN GPIO_PIN_1 #define TM1638_STB_GPIO GPIOA -#define TM1638_STB_PIN GPIO_PIN_3 +#define TM1638_STB_PIN GPIO_PIN_2 #elif defined(TM1638_PLATFORM_STM32_LL) /** @@ -87,9 +87,9 @@ extern "C" { #define TM1638_CLK_GPIO GPIOA #define TM1638_CLK_PIN LL_GPIO_PIN_1 #define TM1638_DIO_GPIO GPIOA -#define TM1638_DIO_PIN LL_GPIO_PIN_4 +#define TM1638_DIO_PIN LL_GPIO_PIN_2 #define TM1638_STB_GPIO GPIOA -#define TM1638_STB_PIN LL_GPIO_PIN_0 +#define TM1638_STB_PIN LL_GPIO_PIN_3 #elif defined(TM1638_PLATFORM_ESP32_IDF) From afe5af54bf2bb1ee089d975d7b91f3dcc06ea9cb Mon Sep 17 00:00:00 2001 From: Vinzenz82 Date: Sun, 24 Sep 2023 19:16:54 +0200 Subject: [PATCH 6/7] removed test code --- TM1638.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/TM1638.c b/TM1638.c index 52f72d9..75f0a1a 100644 --- a/TM1638.c +++ b/TM1638.c @@ -531,11 +531,6 @@ TM1638_SetMultipleDigit_HEX(TM1638_Handler_t *Handler, const uint8_t *DigitData, DigitDataHEX[i] = HexTo7Seg[0x0F] | DecimalPoint; break; - case 0x40: - DigitDataHEX[i] = HexTo7Seg[0x10] | DecimalPoint; - break; - - default: DigitDataHEX[i] = 0; break; From 0f8905d5fbf3dc96b539b9f2f87104979daec33b Mon Sep 17 00:00:00 2001 From: Vinzenz82 Date: Sun, 24 Sep 2023 19:19:55 +0200 Subject: [PATCH 7/7] changed comment --- TM1638.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TM1638.c b/TM1638.c index 75f0a1a..93595f1 100644 --- a/TM1638.c +++ b/TM1638.c @@ -548,7 +548,7 @@ TM1638_SetMultipleDigit_HEX(TM1638_Handler_t *Handler, const uint8_t *DigitData, * @param DigitData: Array to Digits data. * Supported chars 0,1,2,3,4,5,6,7,8,9 * A,b,C,d,E,F,g,G,h,H,i,I,j,l,L,n,N,o,O,P,q,r,S,t,u,U,y - * _,-,high bar (use ~ to set) + * _,-,Overscore (use ~ to set) * * @param StartAddr: First digit position * - 0: Seg1