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/Makefile | 38 +++++++---- app/display.c | 150 +++++++++++++++++++++++++++++++++++++++++++ app/gps.c | 6 +- app/main.c | 4 +- app/max7219.c | 190 ++++++++----------------------------------------------- app/prototypes.h | 15 +++-- 6 files changed, 219 insertions(+), 184 deletions(-) create mode 100644 app/display.c diff --git a/app/Makefile b/app/Makefile index 4b7d33a..9c7656e 100644 --- a/app/Makefile +++ b/app/Makefile @@ -26,7 +26,11 @@ LDSCRIPT = ${PROG}.ld V=1 default: ${PROG}.elf -CSRCS=led.c ticker.c ring.c usart.c stdio.c lwip_glue.c steth.c msf.c abs.c pll.c main.c time_fn.c ntp.c dcf77.c util.c stats.c gps.c hexdump.c bits.c max7219.c report.c sysclk.c cdcacm.c usb.c dfu.c adc.c dummy_kb.c ref.c ptp.c +CSRCS=led.c ticker.c ring.c usart.c stdio.c lwip_glue.c steth.c msf.c abs.c \ + pll.c main.c time_fn.c ntp.c dcf77.c util.c stats.c gps.c hexdump.c bits.c \ + max7219.c report.c sysclk.c cdcacm.c usb.c dfu.c adc.c dummy_kb.c ref.c \ + ptp.c display.c + HSRCS= events.h gps.h project.h ring.h steth.h time_fn.h ubx.h @@ -38,15 +42,24 @@ LWIP_PATH=.. VPATH=${LWIP_PATH} -LWIP_API=#${LWIP}/src/api/err.c ${LWIP}/src/api/netdb.c ${LWIP}/src/api/api_msg.c ${LWIP}/src/api/tcpip.c ${LWIP}/src/api/sockets.c ${LWIP}/src/api/api_lib.c ${LWIP}/src/api/netbuf.c ${LWIP}/src/api/netifapi.c -LWIP_CORE=${LWIP}/src/core/memp.c ${LWIP}/src/core/sys.c ${LWIP}/src/core/init.c ${LWIP}/src/core/pbuf.c ${LWIP}/src/core/dhcp.c ${LWIP}/src/core/ipv4/ip_addr.c ${LWIP}/src/core/ipv4/ip.c ${LWIP}/src/core/ipv4/ip_frag.c ${LWIP}/src/core/ipv4/inet.c ${LWIP}/src/core/ipv4/autoip.c ${LWIP}/src/core/ipv4/icmp.c ${LWIP}/src/core/ipv4/inet_chksum.c ${LWIP}/src/core/timers.c ${LWIP}/src/core/def.c ${LWIP}/src/core/netif.c ${LWIP}/src/netif/etharp.c ${LWIP}/src/core/raw.c ${LWIP}/src/core/mem.c ${LWIP}/src/core/udp.c - -DEFINES=# -#${LWIP}/src/core/tcp.c ${LWIP}/src/core/tcp_out.c #${LWIP}/src/core/tcp_in.c - -# ${LWIP}/src/core/snmp/asn1_enc.c ${LWIP}/src/core/snmp/msg_in.c ${LWIP}/src/core/snmp/mib_structs.c ${LWIP}/src/core/snmp/mib2.c ${LWIP}/src/core/snmp/asn1_dec.c ${LWIP}/src/core/snmp/msg_out.c ${LWIP}/src/core/ipv6/icmp6.c ${LWIP}/src/core/ipv6/ip6.c ${LWIP}/src/core/ipv6/ip6_addr.c ${LWIP}/src/core/ipv6/inet6.c -# ${LWIP}/src/core/dns.c ${LWIP}/src/core/stats.c ${LWIP}/src/core/ipv4/igmp.c - +LWIP_API= +# ${LWIP}/src/api/err.c ${LWIP}/src/api/netdb.c ${LWIP}/src/api/api_msg.c \ + ${LWIP}/src/api/tcpip.c ${LWIP}/src/api/sockets.c ${LWIP}/src/api/api_lib.c \ + ${LWIP}/src/api/netbuf.c ${LWIP}/src/api/netifapi.c + +LWIP_CORE= \ + ${LWIP}/src/core/memp.c ${LWIP}/src/core/sys.c \ + ${LWIP}/src/core/init.c ${LWIP}/src/core/pbuf.c \ + ${LWIP}/src/core/dhcp.c ${LWIP}/src/core/ipv4/ip_addr.c \ + ${LWIP}/src/core/ipv4/ip.c ${LWIP}/src/core/ipv4/ip_frag.c \ + ${LWIP}/src/core/ipv4/inet.c ${LWIP}/src/core/ipv4/autoip.c \ + ${LWIP}/src/core/ipv4/icmp.c ${LWIP}/src/core/ipv4/inet_chksum.c \ + ${LWIP}/src/core/timers.c ${LWIP}/src/core/def.c \ + ${LWIP}/src/core/netif.c ${LWIP}/src/netif/etharp.c \ + ${LWIP}/src/core/raw.c ${LWIP}/src/core/mem.c \ + ${LWIP}/src/core/udp.c + +DEFINES= LWIP_INC=${LWIP_PATH}/${LWIP} LWIP_LOCAL=${LWIP_PATH}/lwip/lwip-local @@ -70,7 +83,10 @@ OBJS=${MYOBJS} ${LWIP_OBJS} include ../Makefile.include CFLAGS+=-Wno-redundant-decls -Wno-unused-parameter -CPPFLAGS += -I.. -I. -I../libopencm3-local -Ilwip -I${LWIP_PATH}/${LWIP}/src/include -I${LWIP_PATH}/${LWIP}/src/include/ipv4 -I${LWIP_LOCAL}/port/stm32f4x7 +CPPFLAGS+= -I.. -I. -I../libopencm3-local -Ilwip \ + -I${LWIP_PATH}/${LWIP}/src/include \ + -I${LWIP_PATH}/${LWIP}/src/include/ipv4 \ + -I${LWIP_LOCAL}/port/stm32f4x7 LDLIBS+= -lm diff --git a/app/display.c b/app/display.c new file mode 100644 index 0000000..ad24962 --- /dev/null +++ b/app/display.c @@ -0,0 +1,150 @@ +#include "project.h" + +static int have_lock, have_dgps, have_time_lock, time_lock_enabled; + +void display_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 display_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 display_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; + + max7219_cls(); + + if (gps_initting) + max7219_write_string ("gps init", 0, 0); + + else if (!ref_valid) { + max7219_write_string ("gps acq.", 0, 0); + max7219_write_dd (gps_sats_searching, 0, 1); + max7219_write_dp (1, 1); + max7219_write_dd (gps_sats_inop, 2, 1); + max7219_write_dp (3, 1); + max7219_write_dd (gps_sats_locked, 4, 1); + max7219_write_dp (5, 1); + max7219_write_dd (gps_sats_with_e, 6, 1); + } else { + e = ref_decompose (abs); + u = time_epoch_to_utc (e); + + max7219_write_dd (u.hour, 0, 0); + max7219_write_dp (1, 0); + max7219_write_dd (u.minute, 2, 0); + max7219_write_dp (3, 0); + max7219_write_dd (u.second, 4, 0); + max7219_write_dp (5, 0); + max7219_write_dd (u.nanosecond / 10000000, 6, 0); + + + l = time_utc_to_lst (u, gps_lon); + + max7219_write_dd (l.hour, 0, 1); + max7219_write_dp (1, 1); + max7219_write_dd (l.minute, 2, 1); + max7219_write_dp (3, 1); + max7219_write_dd (l.second, 4, 1); + max7219_write_dp (5, 1); + max7219_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; + + + max7219_write_string (day_name[wday], 0, 2); + max7219_write_dp (1, 2); + max7219_write_dd (gu.hour, 2, 2); + max7219_write_dp (3, 2); + max7219_write_dd (gu.minute, 4, 2); + max7219_write_dp (5, 2); + max7219_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; + max7219_write_string (buf, 0, 2); + break; + + case 2: + if (!have_lock) break; + + snprintf (buf, sizeof (buf), "%.8f", gps_lon); + buf[sizeof (buf) - 1] = 0; + max7219_write_string (buf, 0, 2); + break; + + case 3: + + for (i = 0; i < 8; i += 2) + max7219_write_hh ((if0.ip_addr.addr >> (i << 2)) & 0xff, i, 2); + + break; + } + } + + if (time_lock_enabled) max7219_write_dp (7, 0); + + if (have_time_lock) max7219_write_dp (7, 1); + + if (have_dgps) max7219_write_dp (7, 2); + + + max7219_refresh(); +} + + diff --git a/app/gps.c b/app/gps.c index 4ddbcab..7ccefd7 100644 --- a/app/gps.c +++ b/app/gps.c @@ -214,7 +214,7 @@ ubx_recv_nav_status (uint8_t *ptr, unsigned len) fix2 = '?'; } - max7219_report_fix (fix, fix2); + display_report_fix (fix, fix2); // printf ("fix: %c%c happy %d Fix %02x flags %02x fix_stat %02x flags2 %02x \r\n",fix,fix2,gps_happy, gps_fix, flags,fix_stat,flags2); @@ -232,7 +232,7 @@ ubx_recv_nav_status (uint8_t *ptr, unsigned len) if (!kick_off_survey_mode) { printf ("GPS no time fix - kicking off survey mode\n"); ubx_cfg_tmode (1, 0, 0, 0, 0, 3600, 3600); // 1 hour and 6cm - } + } } return 0; @@ -513,7 +513,7 @@ static int ubx_recv_tim_svin (uint8_t *ptr, unsigned len) printf ("TIM-SVIN dur %u var %u obs %u valid %02x active %02x\r\n", (unsigned) dur, (unsigned) var, (unsigned) obs, valid, active); - max7219_report_svin (valid, active); + display_report_svin (valid, active); return 0; } diff --git a/app/main.c b/app/main.c index 18baed1..e874aac 100644 --- a/app/main.c +++ b/app/main.c @@ -316,7 +316,7 @@ system_init (void) ptp_clock_start(); max7219_init (1); - max7219_dispatch(); + display_dispatch(); gps_init(); ntp_init(); @@ -371,7 +371,7 @@ main (void) cmd_dispatch(); dispatch_lwip(); - max7219_dispatch(); + display_dispatch(); adc_dispatch(); pll_check(); 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(); -} - - diff --git a/app/prototypes.h b/app/prototypes.h index d6ce3ad..b96a453 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -115,10 +115,14 @@ extern void hexdump(void *_d, int len); /* bits.c */ extern void dump_bits(char *wot, uint8_t *bits); /* max7219.c */ +extern void max7219_cls(void); +extern void max7219_refresh(void); +extern uint8_t max7219_char_to_bits(unsigned v); +extern void max7219_write_dd(int u, unsigned x, unsigned y); +extern void max7219_write_string(const char *s, unsigned x, unsigned y); +extern void max7219_write_dp(unsigned x, unsigned y); +extern void max7219_write_hh(int v, unsigned x, unsigned y); extern void max7219_init(int on); -extern void max7219_report_fix(char fix, char fix2); -extern void max7219_report_svin(int valid, int active); -extern void max7219_dispatch(void); /* report.c */ extern void report_time(const char *src, EPOCH e, uint64_t abs, const char *info); /* sysclk.c */ @@ -140,7 +144,6 @@ extern void cdcacm_rings_init(void); extern uint8_t usbd_control_buffer[128]; extern usbd_device *usb_device; extern void otg_fs_isr(void); -extern enum usbd_request_return_codes usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete); extern void usb_init(void); /* dfu.c */ extern const struct usb_dfu_descriptor dfu_function; @@ -177,3 +180,7 @@ extern void ptp_set_offset(EPOCH epoch, uint64_t abs); extern EPOCH ptp_decompose_diff(int64_t diff); extern EPOCH ptp_decompose(uint64_t abs); extern void ptp_slow_tick(void); +/* display.c */ +extern void display_report_fix(char fix, char fix2); +extern void display_report_svin(int valid, int active); +extern void display_dispatch(void); -- cgit v1.2.3