diff --git a/TM1638.c b/TM1638.c index 0fc1dea..93595f1 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[40] = { 0x3F, // 0 0x06, // 1 @@ -81,7 +81,31 @@ 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 // Overscore }; @@ -518,6 +542,188 @@ 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 + * _,-,Overscore (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) +{ + 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..dad4749 100644 --- a/TM1638.h +++ b/TM1638.h @@ -262,7 +262,28 @@ 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. + * 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 + * _,-,Overscore (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); /** ================================================================================== diff --git a/TM1638_platform.c b/TM1638_platform.c index 5212a20..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" @@ -71,6 +73,29 @@ void TM1638_SetGPIO_IN_PU(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) 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; + 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) +{ + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + GPIO_InitStruct.Pin = GPIO_Pin; + 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) { @@ -93,7 +118,7 @@ TM1638_PlatformInit(void) TM1638_CLK_DDR |= (1<