diff options
Diffstat (limited to 'app/max7219.c')
-rw-r--r-- | app/max7219.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/app/max7219.c b/app/max7219.c index 8c1c859..85e66a7 100644 --- a/app/max7219.c +++ b/app/max7219.c @@ -115,10 +115,10 @@ write_regs (uint8_t reg, uint8_t data1, uint8_t data2, uint8_t data3) unlock(); } -static void write_pair (uint8_t reg, int d1, int d2, int d3) +static void write_triad (uint8_t reg, int d1, int d2, int d3, unsigned dm) { - write_regs (reg, d1 / 10, d2 / 10, d3 / 10); - write_regs (reg - 1, (d1 % 10) | 0x80, (d2 % 10) | 0x80, (d3 % 10) | 0x80); + write_regs (reg++, (d1 % 10) | ((dm & 0x1) ? 0x80 : 0), (d2 % 10) | ((dm & 0x4) ? 0x80 : 0), (d3 % 10) | ((dm & 0x10) ? 0x80 : 0)); + write_regs (reg, (d1 / 10) | ((dm & 0x2) ? 0x80 : 0), (d2 / 10) | ((dm & 0x8) ? 0x80 : 0), (d3 / 10) | ((dm & 0x20) ? 0x80 : 0)); } @@ -153,6 +153,29 @@ static void st_test (void) #endif +unsigned fix_dots, fix_dots_even; + +void max7219_report_fix (char fix, char fix2) +{ + fix_dots = 0; + + + if (fix == 'L') + fix_dots |= 0x1; + + if (fix2 == 'D') fix_dots |= 0x4; + + if (fix == 'T') fix_dots |= 0x11; +} + +void max7219_report_svin (int valid, int active) +{ + fix_dots_even = 0; + + if (active || valid) fix_dots_even |= 0x10; +} + + void max7219_dispatch (void) { uint32_t now = HW_CLOCK_REG; @@ -162,6 +185,8 @@ void max7219_dispatch (void) UTC u; UTC gu; ST l; + unsigned last_dots; + e = pll_decompose (abs); @@ -171,10 +196,15 @@ void max7219_dispatch (void) e.s += gps_utc_diff; gu = time_epoch_to_utc (e); - write_pair (8, u.hour, l.hour, gps_wday); - write_pair (6, u.minute, l.minute, gu.hour); - write_pair (4, u.second, l.second, gu.minute); - write_pair (2, u.nanosecond / 10000000, l.nanosecond / 10000000, gu.second); + last_dots = fix_dots; + + if (u.nanosecond < 500000000) last_dots |= fix_dots_even; + + + write_triad (1, u.nanosecond / 10000000, l.nanosecond / 10000000, gu.second, last_dots); + write_triad (3, u.second, l.second, gu.minute, 0x15); + write_triad (5, u.minute, l.minute, gu.hour, 0x15); + write_triad (7, u.hour, l.hour, gps_wday, 0x15); if (u.minute == m) return; |