Skip to content

Commit

Permalink
Add dynamic detect function to adapt to different display module.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuYanzhen1 committed Jul 12, 2023
1 parent df46a5c commit 529ae34
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 55 deletions.
2 changes: 1 addition & 1 deletion freertos/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 38 additions & 29 deletions hardware/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions hardware/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
14 changes: 13 additions & 1 deletion rmfs/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

Expand All @@ -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) {

}
}
15 changes: 11 additions & 4 deletions tasks/digital_tube.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 4 additions & 1 deletion tasks/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
47 changes: 28 additions & 19 deletions user/main.c
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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",
Expand Down

0 comments on commit 529ae34

Please sign in to comment.