diff --git a/freertos/FreeRTOSConfig.h b/freertos/FreeRTOSConfig.h index eb7f425..45f189d 100644 --- a/freertos/FreeRTOSConfig.h +++ b/freertos/FreeRTOSConfig.h @@ -10,7 +10,7 @@ #define configTICK_RATE_HZ ( 1000 ) #define configMAX_PRIORITIES ( 5 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 64 ) -#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 72 * 1024 ) ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 48 * 1024 ) ) #define configMAX_TASK_NAME_LEN ( 10 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 diff --git a/hardware/gpio.c b/hardware/gpio.c index e70280d..d55af25 100644 --- a/hardware/gpio.c +++ b/hardware/gpio.c @@ -7,6 +7,43 @@ unsigned char gpio_use_lcd(void) { return 1; } +void digital_tube_key_config(void) { + +} + +void lcd_key_config(void) { + GPIO_InitTypeDef GPIO_Structure; + GPIO_Structure.Pin = UP_KEY_PIN; + GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_Structure.Mode = GPIO_MODE_INPUT; + GPIO_Structure.Pull = GPIO_PULLUP; + HAL_GPIO_Init(UP_KEY_PORT, &GPIO_Structure); + + GPIO_Structure.Pin = DOWN_KEY_PIN; + GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_Structure.Mode = GPIO_MODE_INPUT; + GPIO_Structure.Pull = GPIO_PULLUP; + HAL_GPIO_Init(DOWN_KEY_PORT, &GPIO_Structure); + + GPIO_Structure.Pin = LEFT_KEY_PIN; + GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_Structure.Mode = GPIO_MODE_INPUT; + GPIO_Structure.Pull = GPIO_PULLUP; + HAL_GPIO_Init(LEFT_KEY_PORT, &GPIO_Structure); + + GPIO_Structure.Pin = RIGHT_KEY_PIN; + GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_Structure.Mode = GPIO_MODE_INPUT; + GPIO_Structure.Pull = GPIO_PULLUP; + HAL_GPIO_Init(RIGHT_KEY_PORT, &GPIO_Structure); + + GPIO_Structure.Pin = CENTER_KEY_PIN; + GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_Structure.Mode = GPIO_MODE_INPUT; + GPIO_Structure.Pull = GPIO_PULLUP; + HAL_GPIO_Init(CENTER_KEY_PORT, &GPIO_Structure); +} + void gpio_config(void) { GPIO_InitTypeDef GPIO_Structure; @@ -49,35 +86,7 @@ void gpio_config(void) { GPIO_Structure.Pull = GPIO_PULLUP; HAL_GPIO_Init(LCD_A0_Port, &GPIO_Structure); - GPIO_Structure.Pin = UP_KEY_PIN; - GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_Structure.Mode = GPIO_MODE_INPUT; - GPIO_Structure.Pull = GPIO_PULLUP; - HAL_GPIO_Init(UP_KEY_PORT, &GPIO_Structure); - - GPIO_Structure.Pin = DOWN_KEY_PIN; - GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_Structure.Mode = GPIO_MODE_INPUT; - GPIO_Structure.Pull = GPIO_PULLUP; - HAL_GPIO_Init(DOWN_KEY_PORT, &GPIO_Structure); - - GPIO_Structure.Pin = LEFT_KEY_PIN; - GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_Structure.Mode = GPIO_MODE_INPUT; - GPIO_Structure.Pull = GPIO_PULLUP; - HAL_GPIO_Init(LEFT_KEY_PORT, &GPIO_Structure); - - GPIO_Structure.Pin = RIGHT_KEY_PIN; - GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_Structure.Mode = GPIO_MODE_INPUT; - GPIO_Structure.Pull = GPIO_PULLUP; - HAL_GPIO_Init(RIGHT_KEY_PORT, &GPIO_Structure); - - GPIO_Structure.Pin = CENTER_KEY_PIN; - GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_Structure.Mode = GPIO_MODE_INPUT; - GPIO_Structure.Pull = GPIO_PULLUP; - HAL_GPIO_Init(CENTER_KEY_PORT, &GPIO_Structure); + lcd_key_config(); GPIO_Structure.Pin = CHG_EN_Pin; GPIO_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; diff --git a/hardware/gpio.h b/hardware/gpio.h index a49134c..2f60956 100644 --- a/hardware/gpio.h +++ b/hardware/gpio.h @@ -50,6 +50,8 @@ #define SPI_FLASH_CS_Port GPIOB unsigned char gpio_use_lcd(void); +void lcd_key_config(void); +void digital_tube_key_config(void); void gpio_config(void); #endif /* POWER_MANAGER_HARDWARE_GPIO_H_ */ diff --git a/rmfs/filesystem.c b/rmfs/filesystem.c index e2c38a6..b7196ea 100644 --- a/rmfs/filesystem.c +++ b/rmfs/filesystem.c @@ -8,12 +8,18 @@ static unsigned short used_sector = 0; static unsigned char filesystem_status = 0; +static struct log_table_element { + unsigned int started_page; + unsigned int page_length; +} *log_table; + void filesystem_config(void) { unsigned char flash_sector_table[2]; unsigned short total_sector = w25qxx_get_total_sector(); if (total_sector < 128) filesystem_status = 1; else { + total_sector = total_sector - 4; w25qxx_read(flash_sector_table, 0x000000UL, 2); used_sector = ((flash_sector_table[0] << 8) | flash_sector_table[1]); if (used_sector > total_sector) @@ -23,7 +29,7 @@ void filesystem_config(void) { unsigned short get_rmfs_remain(void) { if (filesystem_status == 0) - return (w25qxx_get_total_sector() - used_sector); + return (w25qxx_get_total_sector() - used_sector - 4); return 0; } @@ -36,3 +42,9 @@ void make_rmfs_table(void) { w25qxx_erase_chip(); w25qxx_write(flash_sector_table, 0x000000UL, 2); } + +void get_rmfs_log_page(unsigned short index) { + if (index <= used_sector) { + + } +} diff --git a/tasks/digital_tube.c b/tasks/digital_tube.c index d2ae234..0b82a22 100644 --- a/tasks/digital_tube.c +++ b/tasks/digital_tube.c @@ -4,23 +4,30 @@ #include "main.h" +extern unsigned char lcd_digital_tube_check(unsigned int delay_xms); + _Noreturn void digital_tube_task(void *parameters) { (void) parameters; static unsigned int running_timer_counter = 0; static unsigned char digital_tube_display_buffer[4] = {0}; static mode_target_e last_mode = refresh_mode; + static typology_e last_typo = refresh_typology; iic_config(); + digital_tube_key_config(); tm1650_config(); while (1) { running_timer_counter++; mode_target_e current_mode = fsm_get_mode(); - if (last_mode != current_mode || running_timer_counter % 5 == 0) { + typology_e current_typo = fsm_get_typology(); + if (last_mode != current_mode || last_typo != current_typo || running_timer_counter % 5 == 0) { + unsigned char current_status = (current_mode & 0x03) | ((current_typo & 0x03) << 2); digital_tube_display_buffer[0] = 0; - digital_tube_display_buffer[1] = current_mode + (16 * (running_timer_counter % 10 == 0)); + digital_tube_display_buffer[1] = current_status + (16 * (running_timer_counter % 10 == 0)); tm1650_write_data(1, digital_tube_display_buffer); } + last_typo = current_typo; last_mode = current_mode; - HAL_IWDG_Refresh(&hiwdg1); - delayms(100); + if (lcd_digital_tube_check(100) == 1) + vTaskDelete(NULL); } } diff --git a/tasks/gui.c b/tasks/gui.c index d6f681d..e9e5bdc 100644 --- a/tasks/gui.c +++ b/tasks/gui.c @@ -6,8 +6,10 @@ #include "gui.h" extern volatile unsigned char lcd_frame_buffer[128 * 160 * 2]; +extern unsigned char lcd_digital_tube_check(unsigned int delay_xms); static void form_config(void) { + lcd_key_config(); gui_clear_screen(C_WHITE); gui_printf(22, 74, C_DARK_GREEN, C_WHITE, "Calibrating..."); HAL_IWDG_Refresh(&hiwdg1); @@ -41,6 +43,7 @@ _Noreturn void gui_task(void *parameters) { Form_UpdateEvent(); if (lcd_off_flag != 1) lcd_refresh_once(lcd_frame_buffer); - delayms(100); + if (lcd_digital_tube_check(100) == 0) + vTaskDelete(NULL); } } diff --git a/user/main.c b/user/main.c index 7199a11..89c053c 100644 --- a/user/main.c +++ b/user/main.c @@ -1,25 +1,10 @@ #include "main.h" -void initialize_task(void *parameters) { - (void) parameters; +unsigned char lcd_digital_tube_check(unsigned int delay_xms) { BaseType_t xReturned; - rtc_config(); - filter_config(); - dma_config(); - ramecc_config(); - usart1_config(); - usart2_config(); - error_check(); - adc_config(); - dac_config(); - spi1_config(); - spi3_config(); - w25qxx_config(); - filesystem_config(); - calibrate_params_config(); - iwdg_config(); - - if (gpio_use_lcd() == 1) { + unsigned char using_lcd_flag = gpio_use_lcd(); + HAL_IWDG_Refresh(&hiwdg1); + if (using_lcd_flag == 1) { xReturned = xTaskCreate((TaskFunction_t) gui_task, (const char *) "GUITask", (configSTACK_DEPTH_TYPE) 2048, @@ -38,6 +23,30 @@ void initialize_task(void *parameters) { if (xReturned != pdPASS) error_handler(__FILE__, __LINE__); } + delayms(delay_xms); + return using_lcd_flag; +} + +void initialize_task(void *parameters) { + (void) parameters; + BaseType_t xReturned; + rtc_config(); + filter_config(); + dma_config(); + ramecc_config(); + usart1_config(); + usart2_config(); + error_check(); + adc_config(); + dac_config(); + spi1_config(); + spi3_config(); + w25qxx_config(); + filesystem_config(); + calibrate_params_config(); + iwdg_config(); + + lcd_digital_tube_check(1); xReturned = xTaskCreate((TaskFunction_t) fsm_task, (const char *) "FSMTask",