From 90812662220bc234f9478e439161ef68cdb51471 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 14 May 2023 01:19:42 +0200 Subject: [PATCH] test-display2: Clean up display handling --- test-display2/main.c | 83 +++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 52 deletions(-) diff --git a/test-display2/main.c b/test-display2/main.c index 57c52d6..d8e9cdf 100644 --- a/test-display2/main.c +++ b/test-display2/main.c @@ -122,9 +122,29 @@ static void delay_ms(uint ms) static byte disp[4]; static byte ctrl = 0x56; +static const byte disp_font[] = { + [0] = 0xee, + [1] = 0x82, + [2] = 0xdc, + [3] = 0xd6, + [4] = 0xb2, + [5] = 0x76, + [6] = 0x7e, + [7] = 0xc2, + [8] = 0xfe, + [9] = 0xf6, + [10] = 0xea, + [11] = 0x3e, + [12] = 0x6c, + [13] = 0x9e, + [14] = 0x7c, + [15] = 0x78, +}; + static void display_update(void) { // debug_puts("Display update\n"); + byte cmds[4]; cmds[0] = 0; cmds[1] = ctrl; @@ -153,50 +173,6 @@ static void display_init(void) display_update(); } -static void display_test(void) -{ - static byte mode; - - disp[0] ^= 0x01; - display_update(); - -#if 0 - byte cmds[] = { 0x00, mode ? 0x77 : 0x77 }; - i2c_transfer7(I2C1, 0x70/2, (byte *) cmds, sizeof(cmds), NULL, 0); -#endif - -#if 0 - byte disp[] = { 0xff, 0xff, mode ? 0xff : 0x00, mode ? 0xff : 0xff }; - byte cmds[] = { 0x00, 0x77, 0, 0, 0, 0 }; - cmds[2] = (disp[0] & 0xf0) | (disp[2] >> 4); - cmds[3] = (disp[1] & 0xf0) | (disp[3] >> 4); - cmds[4] = (disp[2] & 0x0f) | (disp[0] << 4); - cmds[5] = (disp[3] & 0x0f) | (disp[1] << 4); - i2c_transfer7(I2C1, 0x70/2, (byte *) cmds, sizeof(cmds), NULL, 0); -#endif - - mode = !mode; -} - -static const byte lcd_font[] = { - [0] = 0xee, - [1] = 0x82, - [2] = 0xdc, - [3] = 0xd6, - [4] = 0xb2, - [5] = 0x76, - [6] = 0x7e, - [7] = 0xc2, - [8] = 0xfe, - [9] = 0xf6, - [10] = 0xea, - [11] = 0x3e, - [12] = 0x6c, - [13] = 0x9e, - [14] = 0x7c, - [15] = 0x78, -}; - /*** Infrared Remote Control ***/ static void ir_init(void) @@ -322,7 +298,7 @@ static void ir_decode(void) static u32 ir_code; #define IR_ERR 0xff - debug_printf("IR(%d): %d %d\n", ir_bits, mark, space); + // debug_printf("IR(%d): %d %d\n", ir_bits, mark, space); if (space == IR_INF) { ir_bits = 0; @@ -335,7 +311,7 @@ static void ir_decode(void) ir_bits = 1; ir_code = 0; } else if (between(space, 2000, 2300)) { - debug_printf("==> REP\n"); + debug_printf("IR ==> REP\n"); ir_bits = IR_ERR; } } @@ -351,7 +327,9 @@ static void ir_decode(void) ir_bits = IR_ERR; } if (ir_bits == 33) { - debug_printf("==> %08x\n", (uint)ir_code); + debug_printf("IR ==> %08x\n", (uint)ir_code); + disp[3] ^= 0x01; + display_update(); ir_bits = IR_ERR; } } else { @@ -494,13 +472,13 @@ static void ep01_cb(usbd_device *dev, uint8_t ep UNUSED) debug_printf("USB: Host sent %u bytes\n", len); if (len >= 5) { for (uint i=0; i<4; i++) { + disp[i] &= 0x01; if (buf[i] < 16) - disp[i] = lcd_font[buf[i]]; - else - disp[i] = 0; + disp[i] |= disp_font[buf[i]]; } + disp[1] &= 0xfe; if (buf[4]) - disp[1] |= 1; + disp[1] |= 0x01; display_update(); } } @@ -582,7 +560,8 @@ int main(void) if (ms_ticks - last_blink >= 500) { debug_led_toggle(); last_blink = ms_ticks; - display_test(); + disp[0] ^= 0x01; + display_update(); } ir_decode(); -- 2.39.2