Skip to content

Commit 2f98d3d

Browse files
committed
fix baudrate for displays at 1.5/1.6 revisions
1 parent 7335b66 commit 2f98d3d

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/lcd.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#define pm_wait_ms(t) cpu_stall_wakeup_by_timer0(t*CLOCK_16M_SYS_TIMER_CLK_1MS);
1111

12+
#define LCD_UART_BAUD 38400
13+
1214
/*
1315
* LYWSD03MMC LCD buffer: byte.bit
1416
@@ -53,6 +55,7 @@ void init_lcd(bool clear){
5355
i2c_address_lcd = 0x7C;
5456
g_zcl_basicAttrs.hwVersion = 19;
5557
}else{// B1.6 uses UART and is not testable this way
58+
// UART 38400 BAUD
5659
lcd_version = 1;
5760
g_zcl_basicAttrs.hwVersion = 16;
5861
}
@@ -93,9 +96,9 @@ void init_lcd_deepsleep(){
9396
if(lcd_version != 1)
9497
return;
9598

96-
uart_gpio_set(UART_TX_PD7, UART_RX_PB0);
99+
drv_uart_pin_set(UART_TX_PD7, UART_RX_PB0);
97100
uart_reset();
98-
uart_init(61, 9, PARITY_NONE, STOP_BIT_ONE);
101+
uart_init_baudrate(LCD_UART_BAUD, UART_CLOCK_SOURCE, PARITY_NONE, STOP_BIT_ONE);
99102
uart_dma_enable(0, 0);
100103
dma_chn_irq_enable(0, 0);
101104
uart_irq_enable(0,0);
@@ -121,28 +124,27 @@ u8 reverse(u8 revByte) {
121124
}
122125

123126
void send_to_lcd_long(u8 byte1, u8 byte2, u8 byte3, u8 byte4, u8 byte5, u8 byte6){
124-
125-
if(lcd_version == 0){// B1.4 Hardware
126-
u8 lcd_set_segments[] = {0x80,0x40,0xC0,byte1,0xC0,byte2,0xC0,byte3,0xC0,byte4,0xC0,byte5,0xC0,byte6,0xC0,0x00,0xC0,0x00};
127-
send_i2c(i2c_address_lcd,lcd_set_segments, sizeof(lcd_set_segments));
128-
}else if(lcd_version == 1){// B1.6 Hardware
129-
uart_send_lcd(byte1,byte2,byte3,byte4,byte5,byte6);
130-
}else if(lcd_version == 2){// B1.9 Hardware
131-
u8 lcd_set_segments[] = {0x04,reverse(byte1),reverse(byte2),0x00,0x00,reverse(byte3),reverse(byte4),0x00,0x00,reverse(byte5),reverse(byte6)};
132-
send_i2c(i2c_address_lcd,lcd_set_segments, sizeof(lcd_set_segments));
133-
}
127+
if(lcd_version == 0){// B1.4 Hardware
128+
u8 lcd_set_segments[] = {0x80,0x40,0xC0,byte1,0xC0,byte2,0xC0,byte3,0xC0,byte4,0xC0,byte5,0xC0,byte6,0xC0,0x00,0xC0,0x00};
129+
send_i2c(i2c_address_lcd,lcd_set_segments, sizeof(lcd_set_segments));
130+
}else if(lcd_version == 1){// B1.6 Hardware
131+
uart_send_lcd(byte1,byte2,byte3,byte4,byte5,byte6);
132+
}else if(lcd_version == 2){// B1.9 Hardware
133+
u8 lcd_set_segments[] = {0x04,reverse(byte1),reverse(byte2),0x00,0x00,reverse(byte3),reverse(byte4),0x00,0x00,reverse(byte5),reverse(byte6)};
134+
send_i2c(i2c_address_lcd,lcd_set_segments, sizeof(lcd_set_segments));
135+
}
134136
}
135137

136138
void send_to_lcd(u8 byte1, u8 byte2, u8 byte3, u8 byte4, u8 byte5, u8 byte6){
137-
if(lcd_version == 0){// B1.4 Hardware
138-
u8 lcd_set_segments[] = {0x80,0x40,0xC0,byte1,0xC0,byte2,0xC0,byte3,0xC0,byte4,0xC0,byte5,0xC0,byte6};
139-
send_i2c(i2c_address_lcd,lcd_set_segments, sizeof(lcd_set_segments));
140-
}else if(lcd_version == 1){// B1.6 Hardware
141-
uart_send_lcd(byte1,byte2,byte3,byte4,byte5,byte6);
142-
}else if(lcd_version == 2){// B1.9 Hardware
143-
u8 lcd_set_segments[] = {0x04,reverse(byte1),reverse(byte2),0x00,0x00,reverse(byte3),reverse(byte4),0x00,0x00,reverse(byte5),reverse(byte6)};
144-
send_i2c(i2c_address_lcd,lcd_set_segments, sizeof(lcd_set_segments));
145-
}
139+
if(lcd_version == 0){// B1.4 Hardware
140+
u8 lcd_set_segments[] = {0x80,0x40,0xC0,byte1,0xC0,byte2,0xC0,byte3,0xC0,byte4,0xC0,byte5,0xC0,byte6};
141+
send_i2c(i2c_address_lcd,lcd_set_segments, sizeof(lcd_set_segments));
142+
}else if(lcd_version == 1){// B1.6 Hardware
143+
uart_send_lcd(byte1,byte2,byte3,byte4,byte5,byte6);
144+
}else if(lcd_version == 2){// B1.9 Hardware
145+
u8 lcd_set_segments[] = {0x04,reverse(byte1),reverse(byte2),0x00,0x00,reverse(byte3),reverse(byte4),0x00,0x00,reverse(byte5),reverse(byte6)};
146+
send_i2c(i2c_address_lcd,lcd_set_segments, sizeof(lcd_set_segments));
147+
}
146148
}
147149

148150
void update_lcd(){

0 commit comments

Comments
 (0)