From 269f2a83fff7618567ebc06b89f89eb6043c8fda Mon Sep 17 00:00:00 2001 From: root Date: Mon, 8 Mar 2021 17:46:28 +0000 Subject: move display code of max7219, tidy makefile --- app/max7219.c | 190 ++++++++-------------------------------------------------- 1 file changed, 26 insertions(+), 164 deletions(-) (limited to 'app/max7219.c') diff --git a/app/max7219.c b/app/max7219.c index 2e055fb..76af7b0 100644 --- a/app/max7219.c +++ b/app/max7219.c @@ -12,7 +12,7 @@ #define N_DISPLAYS 3 #define N_DIGITS 8 -static uint8_t fb[N_DISPLAYS][N_DIGITS]; +static uint8_t max7219_fb[N_DISPLAYS][N_DIGITS]; static void @@ -95,19 +95,19 @@ write_reg (uint8_t reg, uint8_t data) unlock(); } -static void cls (void) +void max7219_cls (void) { unsigned i; for (i = 0; i < N_DISPLAYS; ++i) - memset (&fb[i], 0, N_DIGITS); + memset (&max7219_fb[i], 0, N_DIGITS); } -static void -refresh (void) +void +max7219_refresh (void) { static uint8_t last_brightness = 255; unsigned i, j; @@ -128,7 +128,7 @@ refresh (void) do { spip_send_8 (N_DIGITS - j); - spip_send_8 (fb[i][j]); + spip_send_8 (max7219_fb[i][j]); } while (i--); set (0, 0, 0); @@ -148,7 +148,7 @@ refresh (void) #define SF 0x02 #define SG 0x01 -static uint8_t hex (unsigned v) +uint8_t max7219_char_to_bits (unsigned v) { switch (v) { case 0: @@ -271,7 +271,7 @@ static uint8_t hex (unsigned v) return 0; } -static void write_dd (int u, unsigned x, unsigned y) +void max7219_write_dd (int u, unsigned x, unsigned y) { unsigned t; @@ -282,29 +282,40 @@ static void write_dd (int u, unsigned x, unsigned y) t = u / 10; u %= 10; - fb[y][x] = hex (t); - fb[y][x + 1] = hex (u); + max7219_fb[y][x] = max7219_char_to_bits (t); + max7219_fb[y][x + 1] = max7219_char_to_bits (u); } -static void write_string (const char *s, unsigned x, unsigned y) +void max7219_write_string (const char *s, unsigned x, unsigned y) { for (; (x < N_DIGITS) && *s; s++, x++) { - fb[y][x] = hex (*s); + max7219_fb[y][x] = max7219_char_to_bits (*s); if (* (s + 1) == '.') { - fb[y][x] |= SDP; + max7219_fb[y][x] |= SDP; s++; } } } -static inline void write_dp (unsigned x, unsigned y) +void max7219_write_dp (unsigned x, unsigned y) { - fb[y][x] |= SDP; + max7219_fb[y][x] |= SDP; +} + + +void max7219_write_hh (int v, unsigned x, unsigned y) +{ + if (v < 0) return; + + if (v > 0xff) return; + + max7219_fb[y][x] = max7219_char_to_bits ((v >> 4) & 0xf); + max7219_fb[y][x + 1] = max7219_char_to_bits (v & 0xf); } @@ -345,155 +356,6 @@ max7219_init (int on) -static int have_lock, have_dgps, have_time_lock, time_lock_enabled; - -void max7219_report_fix (char fix, char fix2) -{ - - have_lock = 0; - - if (fix == 'L') - have_lock = 1; - - if (fix2 == 'D') have_dgps = 1; - else have_dgps = 0; - - if (fix == 'T') { - have_lock = 1; - have_time_lock = 1; - } -} - -void max7219_report_svin (int valid, int active) -{ - time_lock_enabled = 0; - - if (active || valid) time_lock_enabled = 1; -} - - -static const char *day_name[] = {"su", "mo", "tu", "we", "th", "fr", "sa"}; - - -void max7219_dispatch (void) -{ - uint64_t abs = ref_get(); - char buf[32]; - int wday; - EPOCH e; - UTC u; - UTC gu; - ST l; - unsigned i; - - - uint64_t wot; - - cls(); - - if (gps_initting) - write_string ("gps init", 0, 0); - - else if (!ref_valid) { - write_string ("gps acq.", 0, 0); - write_dd (gps_sats_searching, 0, 1); - write_dp (1, 1); - write_dd (gps_sats_inop, 2, 1); - write_dp (3, 1); - write_dd (gps_sats_locked, 4, 1); - write_dp (5, 1); - write_dd (gps_sats_with_e, 6, 1); - } else { - e = ref_decompose (abs); - u = time_epoch_to_utc (e); - - write_dd (u.hour, 0, 0); - write_dp (1, 0); - write_dd (u.minute, 2, 0); - write_dp (3, 0); - write_dd (u.second, 4, 0); - write_dp (5, 0); - write_dd (u.nanosecond / 10000000, 6, 0); - - - l = time_utc_to_lst (u, gps_lon); - - write_dd (l.hour, 0, 1); - write_dp (1, 1); - write_dd (l.minute, 2, 1); - write_dp (3, 1); - write_dd (l.second, 4, 1); - write_dp (5, 1); - write_dd (l.nanosecond / 10000000, 6, 1); - - wot = e.s; - wot /= 7; - wot %= 4; - - switch (wot) { - case 0: - - if (!have_lock) break; - - e.s += 86400; - e.s += gps_utc_diff; - gu = time_epoch_to_utc (e); - - - wday = gps_wday; - - if (wday < 0) wday = 0; - - if (wday > 6) wday = 6; - - - write_string (day_name[wday], 0, 2); - write_dp (1, 2); - write_dd (gu.hour, 2, 2); - write_dp (3, 2); - write_dd (gu.minute, 4, 2); - write_dp (5, 2); - write_dd (gu.second, 6, 2); - - break; - - case 1: - if (!have_lock) break; - - snprintf (buf, sizeof (buf), "%.8f", gps_lat); - buf[sizeof (buf) - 1] = 0; - write_string (buf, 0, 2); - break; - - case 2: - if (!have_lock) break; - - snprintf (buf, sizeof (buf), "%.8f", gps_lon); - buf[sizeof (buf) - 1] = 0; - write_string (buf, 0, 2); - break; - - case 3: - - - for (i = 0; i < 8; ++i) - fb[2][i ^ 1] = hex ((if0.ip_addr.addr >> (i << 2)) & 0xf); - - break; - } - } - - if (time_lock_enabled) write_dp (7, 0); - - if (have_time_lock) write_dp (7, 1); - - if (have_dgps) write_dp (7, 2); - - - refresh(); -} - - -- cgit v1.2.3