From aaa6dd8a94a0a9c7686e7299960088ed53018acb Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 13 Jul 2023 16:30:22 +0200 Subject: [PATCH] =?utf8?q?test-sinclair:=20Dek=C3=B3dov=C3=A1n=C3=AD=20?= =?utf8?q?=C4=8D=C3=ADslic?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- test-sinclair/main.c | 90 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/test-sinclair/main.c b/test-sinclair/main.c index 07c0d7d..753bcfd 100644 --- a/test-sinclair/main.c +++ b/test-sinclair/main.c @@ -150,18 +150,70 @@ static void tm_init(void) nvic_enable_irq(NVIC_TIM3_IRQ); } +/* + * Data memory of TM1618: + * + * [0] . . . - - - - - + * [1] . . - - HEAT . . . + * [2] . . . DRY - SLP MED LOW + * [3] . . HIGH AUTO COOL . . . + * [4] . . . B2 - G2 D2 C2 + * [5] . . E2 F2 A2 . . . + * [6] . . . B1 - G1 D1 C1 + * [7] . . E1 F1 A1 . . . + * + * "." is an always-zero bit not defined by TM1618, "-" is defined, but not used by AC. + */ static volatile byte tm_data[8]; -static volatile byte tm_overrun; +static volatile uint tm_overruns; static volatile byte tm_buffer[256]; static volatile uint tm_len; +/* + * + * Display segments: + * + * +--A--+ + * | | + * F B + * | | + * +--G--+ + * | | + * E C + * | | + * +--D--+ + */ + +enum tm_seg { + SEGa = 0x0800, + SEGb = 0x0010, + SEGc = 0x0001, + SEGd = 0x0002, + SEGe = 0x2000, + SEGf = 0x1000, + SEGg = 0x0004, +}; + +static const u16 tm_digits[10] = { + [0] = SEGa | SEGb | SEGc | SEGd | SEGe | SEGf, + [1] = SEGb | SEGc, + [2] = SEGa | SEGb | SEGd | SEGe | SEGg, + [3] = SEGa | SEGb | SEGc | SEGd | SEGg, + [4] = SEGb | SEGc | SEGf | SEGg, + [5] = SEGa | SEGc | SEGd | SEGf | SEGg, + [6] = SEGa | SEGc | SEGd | SEGe | SEGf | SEGg, + [7] = SEGa | SEGb | SEGc, + [8] = SEGa | SEGb | SEGc | SEGd | SEGe | SEGf | SEGg, + [9] = SEGa | SEGb | SEGc | SEGd | SEGf | SEGg, +}; + static volatile uint tm_timeouts; void spi2_isr(void) { if (SPI_SR(SPI2) & SPI_SR_OVR) - tm_overrun = 1; + tm_overruns++; if (SPI_SR(SPI2) & SPI_SR_RXNE) { byte x = SPI_DR(SPI2) ^ 0xff; #if 0 @@ -196,8 +248,38 @@ static void tm_show(void) debug_printf("TM:"); for (uint i=0; i<8; i++) debug_printf(" %02x", tm_data[i]); - debug_printf(" o=%d t=%d", tm_overrun, tm_timeouts); - tm_overrun = 0; + debug_printf(" o=%d t=%d", tm_overruns, tm_timeouts); + + debug_printf(" =>"); + if (tm_data[1] & 0x08) + debug_printf(" HEAT"); + if (tm_data[2] & 0x10) + debug_printf(" DRY"); + if (tm_data[2] & 0x04) + debug_printf(" SLEEP"); + if (tm_data[2] & 0x02) + debug_printf(" MED"); + if (tm_data[2] & 0x01) + debug_printf(" LOW"); + if (tm_data[3] & 0x20) + debug_printf(" HIGH"); + if (tm_data[3] & 0x10) + debug_printf(" AUTO"); + if (tm_data[3] & 0x08) + debug_printf(" COOL"); + + debug_putc(' '); + for (int i=0; i<2; i++) { + uint x = (tm_data[7-2*i] << 8) | tm_data[6-2*i]; + uint j = 0; + while (j < 10 && tm_digits[j] != x) + j++; + if (j == 10) + debug_putc('?'); + else + debug_putc('0' + j); + } + debug_putc('\n'); #if 0 -- 2.39.2