]> git.tdb.fi Git - model-railway-devices.git/commitdiff
Fix S88 latching logic
authorMikko Rasa <tdb@tdb.fi>
Thu, 31 Oct 2013 22:14:23 +0000 (00:14 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 31 Oct 2013 22:14:23 +0000 (00:14 +0200)
s88w/s88w-r.c

index 171653299fd2568bfbe91b58aca5fc6b3dc089df..f94a1be0e0e1038f128c844d5219270d0d6694a8 100644 (file)
@@ -42,9 +42,11 @@ uint8_t rx_buf[7];
 uint8_t rx_fill = 0xFF;
 uint8_t input[128] = { 0 };
 uint8_t latch[128] = { 0 };
+uint8_t output[128] = { 0 };
 uint8_t out_offset = 0;
 uint8_t out_bits = 0;
 uint8_t out_fill = 0;
+volatile uint8_t load_pos = 0xFF;
 volatile uint8_t reset_pos = 0xFF;
 uint8_t lcd_enabled = 0;
 uint8_t log_row = 0;
@@ -70,6 +72,15 @@ int main()
 
                check_input();
 
+               i = load_pos;
+               if(i!=0xFF)
+               {
+                       output[i] = latch[i];
+                       if(++i>=sizeof(input))
+                               i = 0xFF;
+                       load_pos = i;
+               }
+
                i = reset_pos;
                if(i!=0xFF)
                {
@@ -134,7 +145,7 @@ void check_input()
                                        uint8_t shift = 4*(j&1);
                                        uint8_t bits = decode_hex(rx_buf[3+i]);
                                        input[j/2] = (input[j/2]&~(0xF<<shift)) | (bits<<shift);
-                                       latch[j/2] = input[j/2];
+                                       latch[j/2] |= input[j/2];
                                }
 
                                if(lcd_enabled)
@@ -203,6 +214,7 @@ ISR(PCINT2_vect)
                                out_offset = 0;
                                out_bits = latch[0];
                                out_fill = 8;
+                               load_pos = 0;
                        }
 
                        if(out_bits&1)
@@ -214,7 +226,7 @@ ISR(PCINT2_vect)
                        if(!--out_fill)
                        {
                                ++out_offset;
-                               out_bits = latch[out_offset];
+                               out_bits = output[out_offset];
                                out_fill = 8;
                        }