Cleanup main function

This commit is contained in:
Mario Hüttel 2020-05-11 21:51:32 +02:00
parent 8d6c81441d
commit 13bdd6b8eb
1 changed files with 31 additions and 16 deletions

View File

@ -73,6 +73,11 @@ FATFS *fs_ptr = &fs;
static inline void uart_gpio_config()
{
/*
* In case the application is build in debug mode, use the TX/RX Pins on the debug header
* else the Pins on the DIGIO header are configured in the digio module
*/
#ifdef DEBUGBUILD
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(SHELL_UART_PORT_RCC_MASK));
SHELL_UART_PORT->MODER &= MODER_DELETE(SHELL_UART_TX_PIN) & MODER_DELETE(SHELL_UART_RX_PIN);
@ -151,7 +156,15 @@ static inline int32_t handle_pid_controller(struct pid_controller *pid, float ta
return pid_out;
}
const char *oven_controller_hello_world = "Hello world :)\n";
static void setup_unused_pins()
{
int i;
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(RCC_AHB1ENR_GPIOEEN));
GPIOE->MODER = 0UL;
for (i = 0; i < 16; i++)
GPIOE->PUPDR |= PULLDOWN(i);
}
static inline void setup_system()
{
@ -169,16 +182,26 @@ static inline void setup_system()
uart_gpio_config();
setup_sell_uart(&shell_uart);
setup_unused_pins();
}
static void handle_shell_uart_input(shellmatta_handle_t shell_handle)
{
int uart_receive_status;
const char *uart_input;
size_t uart_input_len;
/* Handle uart input for shell */
uart_receive_status = uart_receive_data_with_dma(&shell_uart, &uart_input, &uart_input_len);
if (uart_receive_status >= 0)
shell_handle_input(shell_handle, uart_input, uart_input_len);
}
int main()
{
bool sd_card_mounted = false;
FIL test_file;
const char *uart_input;
size_t uart_input_len;
shellmatta_handle_t shell_handle;
int uart_receive_status;
uint64_t pid_timestamp = 0ULL;
bool pid_controller_active = false;
@ -194,13 +217,6 @@ int main()
shell_handle = shell_init(write_shell_callback);
shell_print_motd(shell_handle);
if (f_mount(fs_ptr, "0:/", 1) == FR_OK) {
sd_card_mounted = true;
f_open(&test_file, "hello-world.txt", FA_OPEN_APPEND | FA_WRITE);
f_write(&test_file, oven_controller_hello_world, strlen(oven_controller_hello_world), NULL);
f_close(&test_file);
}
pid_init(&pid, 0.1, 0.1, 4.0, 0.0, 100.0, 40.0);
pid_zero(&pid);
@ -219,6 +235,8 @@ int main()
/* Blink red led in case of temp error */
if (pt1000_value_status < 0)
led_set(0, !led_get(0));
else
led_set(0, 0);
}
/* Handle error in case PID controller should be active, but temperature measurement failed */
@ -243,10 +261,7 @@ int main()
snprintf(&disp[1][0], 17, "Rotary: %u", (unsigned int)rot);
snprintf(&disp[2][0], 17, "Button: %s", (button == BUTTON_SHORT ? "SHORT" : (button == BUTTON_LONG ? "LONG" : "")));
/* Handle uart input for shell */
uart_receive_status = uart_receive_data_with_dma(&shell_uart, &uart_input, &uart_input_len);
if (uart_receive_status >= 0)
shell_handle_input(shell_handle, uart_input, uart_input_len);
handle_shell_uart_input(shell_handle);
if (systick_ticks_have_passed(display_timestamp, 2) || lcd_ret == LCD_FSM_CALL_AGAIN) {
lcd_ret = lcd_fsm_write_buffer(disp);