V1
Diff: ihm_L476.cpp
- Revision:
- 0:d67999aa55a3
diff -r 000000000000 -r d67999aa55a3 ihm_L476.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ihm_L476.cpp Fri Dec 21 10:21:16 2018 +0000 @@ -0,0 +1,466 @@ +#include "ihm_L476.h" + +/** @defgroup STM32L476G_DISCOVERY_GLASS_LCD_Private_Constants Private Constants + * @{ + */ +#define ASCII_CHAR_0 0x30 /* 0 */ +#define ASCII_CHAR_AT_SYMBOL 0x40 /* @ */ +#define ASCII_CHAR_LEFT_OPEN_BRACKET 0x5B /* [ */ +#define ASCII_CHAR_APOSTROPHE 0x60 /* ` */ +#define ASCII_CHAR_LEFT_OPEN_BRACE 0x7B /* ( */ + +Ticker ticker_scrool; + +static void Convert(uint8_t *Char, Point_Typedef Point, DoublePoint_Typedef Colon); +static void WriteChar(uint8_t *ch, Point_Typedef Point, DoublePoint_Typedef Colon, unsigned char Position); + +uint8_t Global_Bar_Value=0; + + +void BSP_LCD_GLASS_CLEAR_WITHOUT_BAR(void) +{ + BSP_LCD_GLASS_Clear(); + BSP_LCD_GLASS_SetBar(Global_Bar_Value); +} + +void BSP_LCD_GLASS_SetBar(uint8_t Value) +{ + Global_Bar_Value=Value&0xFF; + uint32_t valBAR0=0,valBAR1=0,valBAR2=0,valBAR3=0; + + if((Value&0x01)==0x01) + valBAR0=LCD_BAR0_SEG; + else + valBAR0=0; + if((Value&0x02)==0x02) + valBAR1=LCD_BAR1_SEG; + else + valBAR1=0; + if((Value&0x04)==0x04) + valBAR2=LCD_BAR2_SEG; + else + valBAR2=0; + if((Value&0x08)==0x08) + valBAR3=LCD_BAR3_SEG; + else + valBAR3=0; + + HAL_LCD_Write(&LCDHandle, LCD_BAR0_2_COM, ~(LCD_BAR0_SEG | LCD_BAR2_SEG), ( valBAR0|valBAR2 )); + HAL_LCD_Write(&LCDHandle, LCD_BAR1_3_COM, ~(LCD_BAR1_SEG | LCD_BAR3_SEG), ( valBAR1|valBAR3)); + HAL_LCD_UpdateDisplayRequest(&LCDHandle); +} + +static void Convert(uint8_t *Char, Point_Typedef Point, DoublePoint_Typedef Colon) +{ + uint16_t ch = 0 ; + uint8_t loop = 0, index = 0; + + switch (*Char) + { + case ' ' : + ch = 0x00; + break; + + case 0x27 : //' + ch= 0x0040; + break; + + case 0x5C : // / + ch=0x0009; + break; + + case '[' : + ch = 0x1D00; + break; + + case ']' : + ch = 0x4700; + break; + + case '*': + ch = C_STAR; + break; + + case '(' : + ch = C_OPENPARMAP; + break; + + case ')' : + ch = C_CLOSEPARMAP; + break; + + case 'd' : + ch = C_DMAP; + break; + + case 'm' : + ch = C_MMAP; + break; + + case 'n' : + ch = C_NMAP; + break; + + case 230 : + ch = C_UMAP; + break; + + case '-' : + ch = C_MINUS; + break; + + case '+' : + ch = C_PLUS; + break; + + case '/' : + ch = C_SLATCH; + break; + + case 248 : + ch = C_PERCENT_1; + break; + + case '%' : + ch = C_PERCENT_2; + break; + + case 255 : + ch = C_FULL; + break ; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + ch = NumberMap[*Char - ASCII_CHAR_0]; + break; + + default: + /* The character Char is one letter in upper case*/ + if ((*Char < ASCII_CHAR_LEFT_OPEN_BRACKET) && (*Char > ASCII_CHAR_AT_SYMBOL)) + { + ch = CapLetterMap[*Char - 'A']; + } + /* The character Char is one letter in lower case*/ + if ((*Char < ASCII_CHAR_LEFT_OPEN_BRACE) && (*Char > ASCII_CHAR_APOSTROPHE)) + { + ch = CapLetterMap[*Char - 'a']; + } + break; + } + + /* Set the digital point can be displayed if the point is on */ + if (Point == POINT_ON) + { + ch |= 0x0002; + } + + /* Set the "COL" segment in the character that can be displayed if the colon is on */ + if (Colon == DOUBLEPOINT_ON) + { + ch |= 0x0020; + } + + for (loop = 12, index = 0 ; index < 4; loop -= 4, index++) + { + Digit[index] = (ch >> loop) & 0x0f; /*To isolate the less significant digit */ + } +} + + +static void WriteChar(uint8_t *ch, Point_Typedef Point, DoublePoint_Typedef Colon, unsigned char Position) +{ + uint32_t data = 0x00; + /* To convert displayed character in segment in array digit */ + Convert(ch, (Point_Typedef)Point, (DoublePoint_Typedef)Colon); + + switch (Position) + { + /* Position 1 on LCD (Digit1)*/ + case LCD_DIGIT_POSITION_1: + data = ((Digit[0] & 0x1) << LCD_SEG0_SHIFT) | (((Digit[0] & 0x2) >> 1) << LCD_SEG1_SHIFT) + | (((Digit[0] & 0x4) >> 2) << LCD_SEG22_SHIFT) | (((Digit[0] & 0x8) >> 3) << LCD_SEG23_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT1_COM0, LCD_DIGIT1_COM0_SEG_MASK, data); /* 1G 1B 1M 1E */ + + data = ((Digit[1] & 0x1) << LCD_SEG0_SHIFT) | (((Digit[1] & 0x2) >> 1) << LCD_SEG1_SHIFT) + | (((Digit[1] & 0x4) >> 2) << LCD_SEG22_SHIFT) | (((Digit[1] & 0x8) >> 3) << LCD_SEG23_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT1_COM1, LCD_DIGIT1_COM1_SEG_MASK, data) ; /* 1F 1A 1C 1D */ + + data = ((Digit[2] & 0x1) << LCD_SEG0_SHIFT) | (((Digit[2] & 0x2) >> 1) << LCD_SEG1_SHIFT) + | (((Digit[2] & 0x4) >> 2) << LCD_SEG22_SHIFT) | (((Digit[2] & 0x8) >> 3) << LCD_SEG23_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT1_COM2, LCD_DIGIT1_COM2_SEG_MASK, data) ; /* 1Q 1K 1Col 1P */ + + data = ((Digit[3] & 0x1) << LCD_SEG0_SHIFT) | (((Digit[3] & 0x2) >> 1) << LCD_SEG1_SHIFT) + | (((Digit[3] & 0x4) >> 2) << LCD_SEG22_SHIFT) | (((Digit[3] & 0x8) >> 3) << LCD_SEG23_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT1_COM3, LCD_DIGIT1_COM3_SEG_MASK, data) ; /* 1H 1J 1DP 1N */ + break; + + /* Position 2 on LCD (Digit2)*/ + case LCD_DIGIT_POSITION_2: + data = ((Digit[0] & 0x1) << LCD_SEG2_SHIFT) | (((Digit[0] & 0x2) >> 1) << LCD_SEG3_SHIFT) + | (((Digit[0] & 0x4) >> 2) << LCD_SEG20_SHIFT) | (((Digit[0] & 0x8) >> 3) << LCD_SEG21_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT2_COM0, LCD_DIGIT2_COM0_SEG_MASK, data); /* 1G 1B 1M 1E */ + + data = ((Digit[1] & 0x1) << LCD_SEG2_SHIFT) | (((Digit[1] & 0x2) >> 1) << LCD_SEG3_SHIFT) + | (((Digit[1] & 0x4) >> 2) << LCD_SEG20_SHIFT) | (((Digit[1] & 0x8) >> 3) << LCD_SEG21_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT2_COM1, LCD_DIGIT2_COM1_SEG_MASK, data) ; /* 1F 1A 1C 1D */ + + data = ((Digit[2] & 0x1) << LCD_SEG2_SHIFT) | (((Digit[2] & 0x2) >> 1) << LCD_SEG3_SHIFT) + | (((Digit[2] & 0x4) >> 2) << LCD_SEG20_SHIFT) | (((Digit[2] & 0x8) >> 3) << LCD_SEG21_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT2_COM2, LCD_DIGIT2_COM2_SEG_MASK, data) ; /* 1Q 1K 1Col 1P */ + + data = ((Digit[3] & 0x1) << LCD_SEG2_SHIFT) | (((Digit[3] & 0x2) >> 1) << LCD_SEG3_SHIFT) + | (((Digit[3] & 0x4) >> 2) << LCD_SEG20_SHIFT) | (((Digit[3] & 0x8) >> 3) << LCD_SEG21_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT2_COM3, LCD_DIGIT2_COM3_SEG_MASK, data) ; /* 1H 1J 1DP 1N */ + break; + + /* Position 3 on LCD (Digit3)*/ + case LCD_DIGIT_POSITION_3: + data = ((Digit[0] & 0x1) << LCD_SEG4_SHIFT) | (((Digit[0] & 0x2) >> 1) << LCD_SEG5_SHIFT) + | (((Digit[0] & 0x4) >> 2) << LCD_SEG18_SHIFT) | (((Digit[0] & 0x8) >> 3) << LCD_SEG19_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT3_COM0, LCD_DIGIT3_COM0_SEG_MASK, data); /* 1G 1B 1M 1E */ + + data = ((Digit[1] & 0x1) << LCD_SEG4_SHIFT) | (((Digit[1] & 0x2) >> 1) << LCD_SEG5_SHIFT) + | (((Digit[1] & 0x4) >> 2) << LCD_SEG18_SHIFT) | (((Digit[1] & 0x8) >> 3) << LCD_SEG19_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT3_COM1, LCD_DIGIT3_COM1_SEG_MASK, data) ; /* 1F 1A 1C 1D */ + + data = ((Digit[2] & 0x1) << LCD_SEG4_SHIFT) | (((Digit[2] & 0x2) >> 1) << LCD_SEG5_SHIFT) + | (((Digit[2] & 0x4) >> 2) << LCD_SEG18_SHIFT) | (((Digit[2] & 0x8) >> 3) << LCD_SEG19_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT3_COM2, LCD_DIGIT3_COM2_SEG_MASK, data) ; /* 1Q 1K 1Col 1P */ + + data = ((Digit[3] & 0x1) << LCD_SEG4_SHIFT) | (((Digit[3] & 0x2) >> 1) << LCD_SEG5_SHIFT) + | (((Digit[3] & 0x4) >> 2) << LCD_SEG18_SHIFT) | (((Digit[3] & 0x8) >> 3) << LCD_SEG19_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT3_COM3, LCD_DIGIT3_COM3_SEG_MASK, data) ; /* 1H 1J 1DP 1N */ + break; + + /* Position 4 on LCD (Digit4)*/ + case LCD_DIGIT_POSITION_4: + data = ((Digit[0] & 0x1) << LCD_SEG6_SHIFT) | (((Digit[0] & 0x8) >> 3) << LCD_SEG17_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT4_COM0, LCD_DIGIT4_COM0_SEG_MASK, data); /* 1G 1B 1M 1E */ + + data = (((Digit[0] & 0x2) >> 1) << LCD_SEG7_SHIFT) | (((Digit[0] & 0x4) >> 2) << LCD_SEG16_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT4_COM0_1, LCD_DIGIT4_COM0_1_SEG_MASK, data); /* 1G 1B 1M 1E */ + + data = ((Digit[1] & 0x1) << LCD_SEG6_SHIFT) | (((Digit[1] & 0x8) >> 3) << LCD_SEG17_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT4_COM1, LCD_DIGIT4_COM1_SEG_MASK, data) ; /* 1F 1A 1C 1D */ + + data = (((Digit[1] & 0x2) >> 1) << LCD_SEG7_SHIFT) | (((Digit[1] & 0x4) >> 2) << LCD_SEG16_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT4_COM1_1, LCD_DIGIT4_COM1_1_SEG_MASK, data) ; /* 1F 1A 1C 1D */ + + data = ((Digit[2] & 0x1) << LCD_SEG6_SHIFT) | (((Digit[2] & 0x8) >> 3) << LCD_SEG17_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT4_COM2, LCD_DIGIT4_COM2_SEG_MASK, data) ; /* 1Q 1K 1Col 1P */ + + data = (((Digit[2] & 0x2) >> 1) << LCD_SEG7_SHIFT) | (((Digit[2] & 0x4) >> 2) << LCD_SEG16_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT4_COM2_1, LCD_DIGIT4_COM2_1_SEG_MASK, data) ; /* 1Q 1K 1Col 1P */ + + data = ((Digit[3] & 0x1) << LCD_SEG6_SHIFT) | (((Digit[3] & 0x8) >> 3) << LCD_SEG17_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT4_COM3, LCD_DIGIT4_COM3_SEG_MASK, data) ; /* 1H 1J 1DP 1N */ + + data = (((Digit[3] & 0x2) >> 1) << LCD_SEG7_SHIFT) | (((Digit[3] & 0x4) >> 2) << LCD_SEG16_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT4_COM3_1, LCD_DIGIT4_COM3_1_SEG_MASK, data) ; /* 1H 1J 1DP 1N */ + break; + + /* Position 5 on LCD (Digit5)*/ + case LCD_DIGIT_POSITION_5: + data = (((Digit[0] & 0x2) >> 1) << LCD_SEG9_SHIFT) | (((Digit[0] & 0x4) >> 2) << LCD_SEG14_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT5_COM0, LCD_DIGIT5_COM0_SEG_MASK, data); /* 1G 1B 1M 1E */ + + data = ((Digit[0] & 0x1) << LCD_SEG8_SHIFT) | (((Digit[0] & 0x8) >> 3) << LCD_SEG15_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT5_COM0_1, LCD_DIGIT5_COM0_1_SEG_MASK, data); /* 1G 1B 1M 1E */ + + data = (((Digit[1] & 0x2) >> 1) << LCD_SEG9_SHIFT) | (((Digit[1] & 0x4) >> 2) << LCD_SEG14_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT5_COM1, LCD_DIGIT5_COM1_SEG_MASK, data) ; /* 1F 1A 1C 1D */ + + data = ((Digit[1] & 0x1) << LCD_SEG8_SHIFT) | (((Digit[1] & 0x8) >> 3) << LCD_SEG15_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT5_COM1_1, LCD_DIGIT5_COM1_1_SEG_MASK, data) ; /* 1F 1A 1C 1D */ + + data = (((Digit[2] & 0x2) >> 1) << LCD_SEG9_SHIFT) | (((Digit[2] & 0x4) >> 2) << LCD_SEG14_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT5_COM2, LCD_DIGIT5_COM2_SEG_MASK, data) ; /* 1Q 1K 1Col 1P */ + + data = ((Digit[2] & 0x1) << LCD_SEG8_SHIFT) | (((Digit[2] & 0x8) >> 3) << LCD_SEG15_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT5_COM2_1, LCD_DIGIT5_COM2_1_SEG_MASK, data) ; /* 1Q 1K 1Col 1P */ + + data = (((Digit[3] & 0x2) >> 1) << LCD_SEG9_SHIFT) | (((Digit[3] & 0x4) >> 2) << LCD_SEG14_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT5_COM3, LCD_DIGIT5_COM3_SEG_MASK, data) ; /* 1H 1J 1DP 1N */ + + data = ((Digit[3] & 0x1) << LCD_SEG8_SHIFT) | (((Digit[3] & 0x8) >> 3) << LCD_SEG15_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT5_COM3_1, LCD_DIGIT5_COM3_1_SEG_MASK, data) ; /* 1H 1J 1DP 1N */ + break; + + /* Position 6 on LCD (Digit6)*/ + case LCD_DIGIT_POSITION_6: + data = ((Digit[0] & 0x1) << LCD_SEG10_SHIFT) | (((Digit[0] & 0x2) >> 1) << LCD_SEG11_SHIFT) + | (((Digit[0] & 0x4) >> 2) << LCD_SEG12_SHIFT) | (((Digit[0] & 0x8) >> 3) << LCD_SEG13_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT6_COM0, LCD_DIGIT6_COM0_SEG_MASK, data); /* 1G 1B 1M 1E */ + + data = ((Digit[1] & 0x1) << LCD_SEG10_SHIFT) | (((Digit[1] & 0x2) >> 1) << LCD_SEG11_SHIFT) + | (((Digit[1] & 0x4) >> 2) << LCD_SEG12_SHIFT) | (((Digit[1] & 0x8) >> 3) << LCD_SEG13_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT6_COM1, LCD_DIGIT6_COM1_SEG_MASK, data) ; /* 1F 1A 1C 1D */ + + data = ((Digit[2] & 0x1) << LCD_SEG10_SHIFT) | (((Digit[2] & 0x2) >> 1) << LCD_SEG11_SHIFT) + | (((Digit[2] & 0x4) >> 2) << LCD_SEG12_SHIFT) | (((Digit[2] & 0x8) >> 3) << LCD_SEG13_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT6_COM2, LCD_DIGIT6_COM2_SEG_MASK, data) ; /* 1Q 1K 1Col 1P */ + + data = ((Digit[3] & 0x1) << LCD_SEG10_SHIFT) | (((Digit[3] & 0x2) >> 1) << LCD_SEG11_SHIFT) + | (((Digit[3] & 0x4) >> 2) << LCD_SEG12_SHIFT) | (((Digit[3] & 0x8) >> 3) << LCD_SEG13_SHIFT); + HAL_LCD_Write(&LCDHandle, LCD_DIGIT6_COM3, LCD_DIGIT6_COM3_SEG_MASK, data) ; /* 1H 1J 1DP 1N */ + break; + + default: + break; + } +} + + +void BSP_LCD_GLASS_DisplayString_iut_cachan(uint8_t *ptr) +{ + unsigned char position = 0; + + /* Send the string character by character on lCD */ + while ((*ptr != 0) & (position <= LCD_DIGIT_POSITION_6)) + { + /* Write one character on LCD */ + if(*(ptr+1)=='.') + { + if(*(ptr+2)==':') + { + WriteChar(ptr, POINT_ON, DOUBLEPOINT_ON, position); + ptr=ptr+3; + } + else + { + WriteChar(ptr, POINT_ON, DOUBLEPOINT_OFF, position); + ptr=ptr+2; + } + } + else if(*(ptr+1)==':') + { + if(*(ptr+2)=='.') + { + WriteChar(ptr, POINT_ON, DOUBLEPOINT_ON, position); + ptr=ptr+3; + } + else + { + WriteChar(ptr, POINT_OFF, DOUBLEPOINT_ON, position); + ptr=ptr+2; + } + } + else + { + WriteChar(ptr, POINT_OFF, DOUBLEPOINT_OFF, position); + /* Point on the next character */ + ptr++; + } + /* Increment the character counter */ + position++; + } + /* Update the LCD display */ + BSP_LCD_GLASS_SetBar(Global_Bar_Value); + HAL_LCD_UpdateDisplayRequest(&LCDHandle); + +} + +// Constructor +IHM_L476::IHM_L476() +{ + BSP_LCD_GLASS_Init(); +} + +// Destructor +IHM_L476::~IHM_L476() +{ + BSP_LCD_GLASS_DeInit(); +} + +char stemp[64]; + +void IHM_L476::LCD_printf(const char* format, ...) +{ + uint8_t i=0,real_length=0; + va_list arg; + va_start(arg,format); + vsprintf(stemp,format,arg); + va_end(arg); + while(stemp[i]!='\0') + { + if(((stemp[i]!='.')&&(stemp[i]!=':'))) + real_length++; + i++; + } + if(real_length<7) + { + ticker_scrool.detach(); + BSP_LCD_GLASS_CLEAR_WITHOUT_BAR(); + BSP_LCD_GLASS_DisplayString_iut_cachan((uint8_t*)stemp); + } + else + { + stemp[i]=255; + stemp[i+1]='\0'; + real_length++; + BSP_LCD_GLASS_ScrollSentence_iut_cachan((uint8_t*)stemp, real_length, 1, 200); + + } +} + +uint8_t* ptr1; +uint8_t str[6] = ""; +uint8_t sizestr = 0; + +void Decalage_sentence(void) +{ + static uint8_t nbrchar=0; + + *(str) =* (ptr1+((nbrchar+1)%sizestr)); + *(str+1) =* (ptr1+((nbrchar+2)%sizestr)); + *(str+2) =* (ptr1+((nbrchar+3)%sizestr)); + *(str+3) =* (ptr1+((nbrchar+4)%sizestr)); + *(str+4) =* (ptr1+((nbrchar+5)%sizestr)); + *(str+5) =* (ptr1+((nbrchar+6)%sizestr)); + nbrchar++; + BSP_LCD_GLASS_CLEAR_WITHOUT_BAR(); + BSP_LCD_GLASS_DisplayString_iut_cachan(str); + +} + +void BSP_LCD_GLASS_ScrollSentence_iut_cachan(uint8_t* ptr, uint8_t size, uint16_t nScroll, uint16_t ScrollSpeed) +{ + ptr1 = ptr; + + *(str) =* (ptr1); + *(str+1) =* (ptr1+1); + *(str+2) =* (ptr1+2); + *(str+3) =* (ptr1+3); + *(str+4) =* (ptr1+4); + *(str+5) =* (ptr1+5); + /* To calculate end of string */ + sizestr = size; + + +/* BSP_LCD_GLASS_DisplayString(str); + wait_ms(ScrollSpeed);*/ + + /* To shift the string for scrolling display*/ + BSP_LCD_GLASS_DisplayString_iut_cachan(str); + + ticker_scrool.attach(&Decalage_sentence, (double)ScrollSpeed/1000.); + +} + +void IHM_L476::LCD_clear(void) +{ + BSP_LCD_GLASS_CLEAR_WITHOUT_BAR(); +} + +void IHM_L476::BAR_set(unsigned char valeur) +{ + BSP_LCD_GLASS_SetBar(valeur); +} \ No newline at end of file