From e2c2be6e30c923a5fe6a1559e39daa56301b0b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 4 May 2020 21:21:49 +0200 Subject: [PATCH] Implement state machine controlled async LCD writing --- stm-firmware/main.c | 29 ++++++++++++++++++++++++++--- stm-firmware/ui/lcd.c | 5 +++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/stm-firmware/main.c b/stm-firmware/main.c index 4dc7585..9fa8d3d 100644 --- a/stm-firmware/main.c +++ b/stm-firmware/main.c @@ -24,6 +24,7 @@ */ #include +#include #include /* #include */ #include @@ -33,6 +34,7 @@ #include #include #include +#include #include #include "fatfs/shimatta_sdio_driver/shimatta_sdio.h" #include @@ -135,6 +137,7 @@ static volatile enum button_state button; static volatile uint32_t main_loops_per_ms; int main() { + char disp[4][21] = {0}; bool sd_card_mounted = false; FIL test_file; const char *uart_input; @@ -146,7 +149,8 @@ int main() uint64_t ms_stamp = 0ULL; static struct pid_controller pid; - uint64_t pid_timestamp = 0; + uint64_t pid_timestamp = 0ULL; + uint64_t display_timestamp = 0ULL; setup_nvic_priorities(); systick_setup(); @@ -158,10 +162,14 @@ int main() loudspeaker_setup(); rotary_encoder_setup(); button_init(); + lcd_init(); uart_gpio_config(); setup_sell_uart(&shell_uart); + lcd_home(); + lcd_string("Reflow"); + shell_handle = shell_init(write_shell_callback); shell_print_motd(shell_handle); @@ -187,19 +195,34 @@ int main() if (pt1000_value_status >= 0) { (void)temp_converter_convert_resistance_to_temp(pt1000_value, (float *)¤t_temperature); - if ((systick_get_global_tick() - pid_timestamp) >= 250) { + if (systick_ticks_have_passed(pid_timestamp, 250)) { + pid_out = pid_sample(&pid, 100.0 - current_temperature); pid_timestamp = systick_get_global_tick(); + snprintf(&disp[2][0], 21, "Temp: %.1f C", current_temperature); + led_set(1, !led_get(1)); } } + //pid_timestamp = systick_get_global_tick(); + button = button_read_event(); - rot = rotary_encoder_get_abs_val(); + uart_receive_status = uart_receive_data_with_dma(&shell_uart, &uart_input, &uart_input_len); if (uart_receive_status >= 1) shell_handle_input(shell_handle, uart_input, uart_input_len); main_loop_cnt++; + + strcpy(&disp[0][0], "Line 1"); + strcpy(&disp[1][0], "Line 2"); + strcpy(&disp[3][0], "Shimatta Reflow"); + + if (systick_ticks_have_passed(display_timestamp, 1)) { + display_timestamp = systick_get_global_tick(); + lcd_fsm_write_buffer(disp); + } + __WFI(); } } diff --git a/stm-firmware/ui/lcd.c b/stm-firmware/ui/lcd.c index a696482..e2fda69 100644 --- a/stm-firmware/ui/lcd.c +++ b/stm-firmware/ui/lcd.c @@ -18,6 +18,11 @@ * If not, see . */ +/* Thanks to + * https://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/LCD-Ansteuerung + * for the basic code construct + */ + #include #include #include