From d67292fb0c6de27da56bcb0323454a1198d0c280 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 8 May 2020 22:01:28 +0200 Subject: [PATCH] Display test... --- test-display/main.c | 53 ++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/test-display/main.c b/test-display/main.c index 11b09f3..47c553f 100644 --- a/test-display/main.c +++ b/test-display/main.c @@ -113,36 +113,59 @@ static void delay_ms(uint ms) * (01) */ +static byte disp[4]; +static byte ctrl = 0x77; -static void display_init(void) +static void display_update(void) { - debug_puts("I2C init\n"); - i2c_peripheral_disable(I2C1); - i2c_set_speed(I2C1, i2c_speed_sm_100k, rcc_apb1_frequency / 1000000); - i2c_peripheral_enable(I2C1); - - debug_puts("I2C transfer\n"); - - // byte disp[] = { 0xb6, 0xb6, 0xb6, 0xb6 }; - // byte disp[] = { 0x7f, 0x12, 0xbc, 0xb6 }; - // byte disp[] = { 0xff, 0xff, 0xff, 0xff }; - byte disp[] = { 0x80, 0x80, 0x80, 0xff }; - byte cmds[] = { 0x00, 0x47, 0, 0, 0, 0 }; + byte cmds[6]; + cmds[0] = 0; + cmds[1] = ctrl; 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); + debug_puts("I2C transfer\n"); + i2c_transfer7(I2C1, 0x70/2, (byte *) cmds, sizeof(cmds), NULL, 0); debug_puts("I2C done\n"); } +static void display_init(void) +{ + debug_puts("I2C init\n"); + i2c_peripheral_disable(I2C1); + i2c_set_speed(I2C1, i2c_speed_sm_100k, rcc_apb1_frequency / 1000000); + i2c_peripheral_enable(I2C1); + + disp[0] = 0x7f; + disp[1] = 0x12; + disp[2] = 0xbc; + disp[3] = 0xb6; + 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; } @@ -354,7 +377,7 @@ int main(void) u32 last_blink = 0; for (;;) { - if (ms_ticks - last_blink >= 100) { + if (ms_ticks - last_blink >= 500) { debug_led_toggle(); last_blink = ms_ticks; display_test(); -- 2.39.2