]> mj.ucw.cz Git - home-hw.git/commitdiff
test-sinclair: Dekódování číslic
authorMartin Mares <mj@ucw.cz>
Thu, 13 Jul 2023 14:30:22 +0000 (16:30 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 13 Jul 2023 14:30:22 +0000 (16:30 +0200)
test-sinclair/main.c

index 07c0d7dcd4abcb0bb44411c53a8f8ad877f93825..753bcfd9ffe951f94b4a9b2152792ec6eb69e9dd 100644 (file)
@@ -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