Implement state machine controlled async LCD writing

This commit is contained in:
Mario Hüttel 2020-05-04 21:21:49 +02:00
parent df82f14206
commit e2c2be6e30
2 changed files with 31 additions and 3 deletions

View File

@ -24,6 +24,7 @@
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* #include <arm_math.h> */
#include <stm32/stm32f4xx.h>
@ -33,6 +34,7 @@
#include <reflow-controller/adc-meas.h>
#include <reflow-controller/shell.h>
#include <reflow-controller/pid-controller.h>
#include <reflow-controller/ui/lcd.h>
#include <reflow-controller/digio.h>
#include "fatfs/shimatta_sdio_driver/shimatta_sdio.h"
#include <reflow-controller/temp-converter.h>
@ -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 *)&current_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();
}
}

View File

@ -18,6 +18,11 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
/* Thanks to
* https://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/LCD-Ansteuerung
* for the basic code construct
*/
#include <stm32/stm32f4xx.h>
#include <reflow-controller/ui/lcd.h>
#include <reflow-controller/systick.h>