diff --git a/include/led7seg.h b/include/led7seg.h index 39c4bb5..a1202d3 100644 --- a/include/led7seg.h +++ b/include/led7seg.h @@ -21,7 +21,7 @@ extern struct st_7seg st_7seg; void init_7seg(void); void step_7seg(void); int bt_inputs(void); -void decimal_7seg(int module, int value, int dp); +void decimal_7seg(int module, int value, uint8_t dp); void hex_7seg(int module, uint32_t value, uint8_t dp); void blank_7seg(int module); diff --git a/include/proto.h b/include/proto.h index b7abca9..6149861 100644 --- a/include/proto.h +++ b/include/proto.h @@ -52,14 +52,15 @@ enum proto_led_format { PROTO_LED_FMT_OFF = 0x00, PROTO_LED_FMT_DEC = 0x01, PROTO_LED_FMT_HEX = 0x02, - PROTO_LED_FMT_DP_0 = 0x00, - PROTO_LED_FMT_DP_1 = 0x20, - PROTO_LED_FMT_DP_2 = 0x40, - PROTO_LED_FMT_DP_3 = 0x60, - PROTO_LED_FMT_DP_4 = 0x80, - PROTO_LED_FMT_DP_5 = 0xa0, - PROTO_LED_FMT_DP_6 = 0xc0, - PROTO_LED_FMT_DP_7 = 0xe0, + PROTO_LED_FMT_DP_OFF = 0x00, + PROTO_LED_FMT_DP_0 = 0x10, + PROTO_LED_FMT_DP_1 = 0x30, + PROTO_LED_FMT_DP_2 = 0x50, + PROTO_LED_FMT_DP_3 = 0x70, + PROTO_LED_FMT_DP_4 = 0x90, + PROTO_LED_FMT_DP_5 = 0xb0, + PROTO_LED_FMT_DP_6 = 0xd0, + PROTO_LED_FMT_DP_7 = 0xf0, }; struct __attribute__((__packed__)) pkt_update_display { diff --git a/include/serial.h b/include/serial.h index 072436d..b2c8771 100644 --- a/include/serial.h +++ b/include/serial.h @@ -19,7 +19,7 @@ struct dma_tx_buf { ssize_t packet_end[8]; /* The following may be accessed by anything */ - uint8_t data[512]; + uint8_t data[256]; }; struct uart_dma_state { @@ -36,7 +36,7 @@ struct uart_dma_state { DMA_Channel_TypeDef *tx_dma_ch; USART_TypeDef *usart; - uint8_t rx_buf[32]; + uint8_t rx_buf[256]; uint8_t addr; }; diff --git a/src/led7seg.c b/src/led7seg.c index ac86c73..273431e 100644 --- a/src/led7seg.c +++ b/src/led7seg.c @@ -45,7 +45,7 @@ void init_7seg() { } } -void decimal_7seg(int module, int value, int dp) { +void decimal_7seg(int module, int value, uint8_t dp) { if (value < -9999999 || value > 99999999) { st_7seg.data[module][0] = 0xE; st_7seg.data[module][1] = 16; /* blank */ @@ -66,7 +66,7 @@ void decimal_7seg(int module, int value, int dp) { st_7seg.data[module][digit] = r; } - st_7seg.dp[module] = dp > 0 ? (1< #include +#include #include static void tx_time_sync(void); @@ -9,6 +10,7 @@ static void proto_handle_host(bool timeout); static void proto_update_lcd_strings(void); static ErrorCode tx_update_display(void); static void tx_adc_data(void); +static void update_displays(struct pkt_update_display *pk); static void tx_button_state(void); @@ -57,6 +59,7 @@ void uart_handle_user_packet(struct ll_pkt *pkt, size_t len) { } else if (board_config == BCFG_DISPLAY) { if (pkt->type == PK_DISPLAY_UPDATE) { + update_displays((struct pkt_update_display *)pkt); tx_button_state(); } } else if (board_config == BCFG_MEAS) { @@ -110,6 +113,29 @@ void proto_handle_host(bool timeout) { } } +void update_displays(struct pkt_update_display *pk) { + const char *buf[4] = { + &pk->lcd[0], + &pk->lcd[20], + &pk->lcd[40], + &pk->lcd[60], + }; + lcd_write_dma(buf); + + for (int module=0; module<3; module++) { + int fmt = pk->led_fmt[module]; + uint8_t dp = (fmt & 0x10) ? (1<<(fmt>>5)) : 0; + + if ((fmt&3) == PROTO_LED_FMT_OFF) { + blank_7seg(module); + } else if ((fmt&3) == PROTO_LED_FMT_DEC) { + decimal_7seg(module, pk->led[module], dp); + } else if ((fmt&3) == PROTO_LED_FMT_HEX) { + hex_7seg(module, pk->led[module], dp); + } + } +} + void tx_adc_data() { struct pkt_adc_data pk = { .ll_pkt = {