Changes for menu

* Make Systick a 100us Timer. Millisecond ticks are still untouched.
* LCD now has a 100us resolution tick
* LCD uses 500us delay for waitstate
* Make 'About' menu verbose:
	* Add 3 page menu
	* 1st page: Generic info
	* 2nd page: Version info
	* 3rd page: Uptime in seconds
This commit is contained in:
Mario Hüttel 2020-06-14 13:25:47 +02:00
parent d178910594
commit 43b4fd1e77
6 changed files with 115 additions and 26 deletions

View File

@ -32,9 +32,9 @@
* @brief Reload value for the systick timer. * @brief Reload value for the systick timer.
* *
* This value has to be configured to set the systick to a one milliscond tick interval * This value has to be configured to set the systick to a one milliscond tick interval
* The default value is 168000, which results in a 1ms tick for 168 MHz CPU speed * The default value is 16800, which results in a 100us tick for 168 MHz CPU speed
*/ */
#define SYSTICK_RELOAD (168000UL) #define SYSTICK_RELOAD (16800UL)
/** /**
* @brief Variable used by the systick_wait_ms function * @brief Variable used by the systick_wait_ms function
@ -52,7 +52,7 @@ extern volatile uint64_t global_tick_ms;
/** /**
* @brief Wait counter for the display. This must not be used anywhere else * @brief Wait counter for the display. This must not be used anywhere else
*/ */
extern volatile uint32_t lcd_tick_ms; extern volatile uint32_t lcd_tick_100us;
/** /**
* @brief Setup the Systick timer to generate a 1 ms tick * @brief Setup the Systick timer to generate a 1 ms tick

View File

@ -66,10 +66,14 @@ void menu_entry_dropback(struct lcd_menu *menu, menu_func_t parent_func);
void menu_entry_enter(struct lcd_menu *menu, menu_func_t entry, bool handle_immediately); void menu_entry_enter(struct lcd_menu *menu, menu_func_t entry, bool handle_immediately);
void menu_override_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text); void menu_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text);
void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom_row); void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom_row);
int16_t menu_get_rotary_delta(const struct lcd_menu *menu);
enum button_state menu_get_button_state(const struct lcd_menu *menu);
void menu_list_compute_count(struct menu_list *list); void menu_list_compute_count(struct menu_list *list);
void menu_list_scroll_down(struct menu_list *list); void menu_list_scroll_down(struct menu_list *list);

View File

@ -31,6 +31,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
static char __attribute__((section(".ccmram"))) display_buffer[4][21] = {0}; static char __attribute__((section(".ccmram"))) display_buffer[4][21] = {0};
static struct lcd_menu reflow_menu; static struct lcd_menu reflow_menu;
@ -106,14 +107,21 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry
{ {
static void *my_parent; static void *my_parent;
static bool button_ready; static bool button_ready;
static int page = 0;
static uint64_t uptime_secs;
uint64_t new_uptime_secs;
int16_t rot_delta;
enum button_state push_button;
char buff[20]; char buff[20];
if (entry_type == MENU_ENTRY_FIRST_ENTER) { if (entry_type == MENU_ENTRY_FIRST_ENTER) {
uptime_secs = 0ULL;
page = 0;
my_parent = parent; my_parent = parent;
button_ready = false; button_ready = false;
menu_display_clear(menu); menu_display_clear(menu);
menu_ack_rotary_delta(menu);
menu->update_display(0, LCD_SHIMATTA_STRING " Reflow"); /* menu->update_display(0, LCD_SHIMATTA_STRING " Reflow");
snprintf(buff, sizeof(buff), "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER)); snprintf(buff, sizeof(buff), "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER));
menu->update_display(1, buff); menu->update_display(1, buff);
if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) { if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) {
@ -122,13 +130,63 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry
} }
menu->update_display(3, __DATE__); menu->update_display(3, __DATE__);
*/ }
switch (page) {
case 0:
menu_lcd_output(menu, 0, LCD_SHIMATTA_STRING " Shimatta");
menu_lcd_output(menu, 1, "Oven Controller");
menu_lcd_output(menu, 2, "(c) Mario H\xF5ttel");
menu_lcd_output(menu, 3, " Version->");
break;
case 1:
menu_lcd_output(menu, 0, "Version Number:");
snprintf(buff, sizeof(buff), "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER));
menu_lcd_output(menu, 1, buff);
if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) {
snprintf(buff, sizeof(buff), "%s", &xstr(GIT_VER)[LCD_CHAR_WIDTH]);
menu_lcd_output(menu, 2, buff);
}
menu_lcd_output(menu, 3, "<-About Uptime->");
break;
case 2:
new_uptime_secs = (uint64_t)(systick_get_global_tick() / 1000);
if (new_uptime_secs != uptime_secs) {
uptime_secs = new_uptime_secs;
menu_lcd_output(menu, 0, "Uptime:");
snprintf(buff, sizeof(buff), "%u s", (unsigned int)uptime_secs);
menu_lcd_output(menu, 1, buff);
menu_lcd_output(menu, 3, "<-Version");
}
break;
default:
page = 0;
break;
} }
if (menu->inputs.push_button == BUTTON_IDLE) rot_delta = menu_get_rotary_delta(menu);
if (rot_delta >= 4) {
menu_ack_rotary_delta(menu);
if (page < 2) {
page++;
menu_display_clear(menu);
}
} else if (rot_delta <= -4) {
menu_ack_rotary_delta(menu);
if (page > 0) {
page--;
menu_display_clear(menu);
}
}
push_button = menu_get_button_state(menu);
if (push_button == BUTTON_IDLE)
button_ready = true; button_ready = true;
if (button_ready && if (button_ready &&
(menu->inputs.push_button == BUTTON_SHORT_RELEASED || menu->inputs.push_button == BUTTON_LONG)) { (push_button == BUTTON_SHORT_RELEASED || push_button == BUTTON_LONG)) {
menu_entry_dropback(menu, my_parent); menu_entry_dropback(menu, my_parent);
} }
} }
@ -143,11 +201,12 @@ static void reflow_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_e
"Monitoring", "Monitoring",
NULL NULL
}; };
static const menu_func_t root_entry_funcs[] = { static const menu_func_t root_entry_funcs[] = {
reflow_menu_about, reflow_menu_about,
reflow_menu_monitor reflow_menu_monitor
}; };
enum button_state push_button;
int16_t rot_delta;
if (entry_type != MENU_ENTRY_CONTINUE) { if (entry_type != MENU_ENTRY_CONTINUE) {
menu_display_clear(menu); menu_display_clear(menu);
@ -163,19 +222,20 @@ static void reflow_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_e
} }
} }
if (menu->inputs.push_button == BUTTON_IDLE) { push_button = menu_get_button_state(menu);
rot_delta = menu_get_rotary_delta(menu);
if (push_button == BUTTON_IDLE) {
button_valid = true; button_valid = true;
} else if (button_valid && menu->inputs.push_button == BUTTON_SHORT_RELEASED) { } else if (button_valid && push_button == BUTTON_SHORT_RELEASED) {
/* Enter currently selected menu_entry */ /* Enter currently selected menu_entry */
menu_list_enter_selected_entry(&list, menu); menu_list_enter_selected_entry(&list, menu);
} }
if (rot_delta >= 4) {
if (menu->inputs.rotary_encoder_delta >= 4) {
menu_list_scroll_down(&list); menu_list_scroll_down(&list);
menu_ack_rotary_delta(menu); menu_ack_rotary_delta(menu);
} else if (menu->inputs.rotary_encoder_delta <= -4) { } else if (rot_delta <= -4) {
menu_list_scroll_up(&list); menu_list_scroll_up(&list);
menu_ack_rotary_delta(menu); menu_ack_rotary_delta(menu);
} }
@ -183,7 +243,6 @@ static void reflow_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_e
menu_list_display(&list, 1, 3); menu_list_display(&list, 1, 3);
} }
int reflow_menu_handle() int reflow_menu_handle()
{ {
int32_t rot_delta; int32_t rot_delta;
@ -195,9 +254,9 @@ int reflow_menu_handle()
menu_handle(reflow_menu_ptr, (int16_t)rot_delta, button); menu_handle(reflow_menu_ptr, (int16_t)rot_delta, button);
if (lcd_ret != LCD_FSM_WAIT_CALL || lcd_tick_ms >= 1) { if (lcd_ret != LCD_FSM_WAIT_CALL || lcd_tick_100us >= 5) {
lcd_ret = lcd_fsm_write_buffer(display_buffer); lcd_ret = lcd_fsm_write_buffer(display_buffer);
lcd_tick_ms = 0UL; lcd_tick_100us = 0UL;
} }
if (lcd_ret == LCD_FSM_CALL_AGAIN) if (lcd_ret == LCD_FSM_CALL_AGAIN)

View File

@ -28,11 +28,11 @@
volatile uint32_t wait_tick_ms = 0UL; volatile uint32_t wait_tick_ms = 0UL;
volatile uint64_t global_tick_ms = 0ULL; volatile uint64_t global_tick_ms = 0ULL;
volatile uint32_t lcd_tick_ms = 0UL; volatile uint32_t lcd_tick_100us = 0UL;
void systick_setup(void) void systick_setup(void)
{ {
/* Setup Systick for 1ms tick @ 168 MHz Clock Speed */ /* Setup Systick for 100us tick @ 168 MHz Clock Speed */
SysTick_Config(SYSTICK_RELOAD); SysTick_Config(SYSTICK_RELOAD);
} }
@ -82,8 +82,14 @@ bool __attribute__((optimize("O3"))) systick_ticks_have_passed(uint64_t start_ti
*/ */
void __attribute__((optimize("O3"))) SysTick_Handler() void __attribute__((optimize("O3"))) SysTick_Handler()
{ {
/* Increase tick counters */ static uint32_t pre_tick = 0UL;
wait_tick_ms++;
global_tick_ms++; pre_tick++;
lcd_tick_ms++; if (pre_tick == 10) {
pre_tick = 0;
/* Increase tick counters */
wait_tick_ms++;
global_tick_ms++;
}
lcd_tick_100us++;
} }

View File

@ -403,7 +403,7 @@ enum lcd_fsm_ret lcd_fsm_write_buffer(const char (*display_buffer)[21])
state_cnt++; state_cnt++;
break; break;
case 4: case 4:
if (!systick_ticks_have_passed(timestamp, 5)) { if (!systick_ticks_have_passed(timestamp, 4)) {
ret = LCD_FSM_WAIT_CALL; ret = LCD_FSM_WAIT_CALL;
} else { } else {
ret = LCD_FSM_CALL_AGAIN; ret = LCD_FSM_CALL_AGAIN;

View File

@ -88,7 +88,7 @@ void menu_entry_enter(struct lcd_menu *menu, menu_func_t entry, bool handle_imme
menu_handle(menu, menu->inputs.rotary_encoder_delta, menu->inputs.push_button); menu_handle(menu, menu->inputs.rotary_encoder_delta, menu->inputs.push_button);
} }
void menu_override_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text) void menu_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text)
{ {
if (!menu || !menu->update_display) if (!menu || !menu->update_display)
return; return;
@ -209,6 +209,26 @@ void menu_ack_rotary_delta(struct lcd_menu *menu)
menu->inputs.rotary_encoder_delta = 0; menu->inputs.rotary_encoder_delta = 0;
} }
int16_t menu_get_rotary_delta(const struct lcd_menu *menu)
{
int16_t ret = 0;
if (menu)
ret = menu->inputs.rotary_encoder_delta;
return ret;
}
enum button_state menu_get_button_state(const struct lcd_menu *menu)
{
enum button_state ret = BUTTON_IDLE;
if (menu)
ret = menu->inputs.push_button;
return ret;
}
void menu_display_clear(struct lcd_menu *menu) void menu_display_clear(struct lcd_menu *menu)
{ {
uint8_t i; uint8_t i;