Refactoring menu code to be non-blocking
Added macros for GPIO read/write
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="com.crt.advproject.GCCBuildCommandParser" keep-relative-paths="false" name="MCU GCC Build Output Parser" parameter="(arm-none-eabi-gcc)|(arm-none-eabi-[gc]\+\+)|(gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
|
||||
<provider class="com.crt.advproject.specs.MCUGCCBuiltinSpecsDetector" console="false" env-hash="5279856300461763" id="com.crt.advproject.GCCBuildSpecCompilerParser" keep-relative-paths="false" name="MCU GCC Built-in Compiler Parser" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.crt.advproject.specs.MCUGCCBuiltinSpecsDetector" console="false" env-hash="1306207612663373935" id="com.crt.advproject.GCCBuildSpecCompilerParser" keep-relative-paths="false" name="MCU GCC Built-in Compiler Parser" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
@@ -14,8 +14,8 @@
|
||||
<configuration id="com.crt.advproject.config.exe.release.2108029807" name="Release">
|
||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="com.crt.advproject.GCCBuildCommandParser" keep-relative-paths="false" name="MCU GCC Build Output Parser" parameter="(arm-none-eabi-gcc)|(arm-none-eabi-[gc]\+\+)|(gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
|
||||
<provider class="com.crt.advproject.specs.MCUGCCBuiltinSpecsDetector" console="false" env-hash="-22250574711266011" id="com.crt.advproject.GCCBuildSpecCompilerParser" keep-relative-paths="false" name="MCU GCC Built-in Compiler Parser" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider copy-of="extension" id="com.crt.advproject.GCCBuildCommandParser"/>
|
||||
<provider class="com.crt.advproject.specs.MCUGCCBuiltinSpecsDetector" console="false" env-hash="1278677181651646161" id="com.crt.advproject.GCCBuildSpecCompilerParser" keep-relative-paths="false" name="MCU GCC Built-in Compiler Parser" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -8,6 +8,8 @@
|
||||
"clock_config.h": "c",
|
||||
"utils.h": "c",
|
||||
"ports.h": "c",
|
||||
"mode.h": "c"
|
||||
"mode.h": "c",
|
||||
"arm_math.h": "c",
|
||||
"io.h": "c"
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,11 @@
|
||||
|
||||
#define SYS_INFO_LENGTH 24 //max string length for setup parameters (model, mfg, etc.)
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GUI_MODE_NORMAL = 0,
|
||||
GUI_MODE_MENU
|
||||
} GuiMode_t;
|
||||
|
||||
|
||||
//System data
|
||||
@@ -30,6 +34,10 @@ typedef struct
|
||||
|
||||
uint32_t language; //system language
|
||||
|
||||
uint32_t systemTime; // system time in milliseconds since boot
|
||||
|
||||
GuiMode_t guiMode;
|
||||
|
||||
} SYSTEM_DATA_t;
|
||||
|
||||
|
||||
|
||||
0
source/controller.c
Normal file
0
source/controller.c
Normal file
7
source/controller.h
Normal file
7
source/controller.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _CONTROLLER_H
|
||||
#define _CONTROLLER_H
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -247,6 +247,7 @@ void ClearFreqArray(void)
|
||||
}
|
||||
}
|
||||
|
||||
#define PIN_OUTPUT()
|
||||
void FREQ_Init(void)
|
||||
{
|
||||
uint32_t tmp;
|
||||
|
||||
30
source/io.h
Normal file
30
source/io.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef IO_H_
|
||||
#define IO_H_
|
||||
|
||||
#include "fsl_gpio.h"
|
||||
|
||||
#define LOW 0
|
||||
#define HIGH 1
|
||||
|
||||
#define PORT0 0
|
||||
#define PORT1 1
|
||||
|
||||
#define PIN_VBUS (PORT1, 6)
|
||||
#define PIN_POT_CS (PORT1, 7)
|
||||
#define PIN_SIG_CS (PORT1, 9)
|
||||
#define PIN_SD_CS (PORT1, 10)
|
||||
#define PIN_RAMP_CS (PORT1, 11)
|
||||
#define PIN_SIG_RESET (PORT1, 12)
|
||||
#define PIN_SD_RESET (PORT1, 13)
|
||||
#define PIN_RAMP_RST (PORT1, 14)
|
||||
#define PIN_POWER_CTL (PORT1, 16)
|
||||
#define PIN_ESTOP (PORT1, 17)
|
||||
|
||||
#define _P1(p1, p2) p1
|
||||
#define _P2(p1, p2) p2
|
||||
|
||||
#define GPIO_WRITE(port_pin, value) GPIO_PinWrite(GPIO, _P1 port_pin, _P2 port_pin, value )
|
||||
#define GPIO_READ(port_pin) GPIO_PinRead (GPIO, _P1 port_pin, _P2 port_pin)
|
||||
|
||||
|
||||
#endif
|
||||
@@ -49,6 +49,9 @@
|
||||
//temp
|
||||
#include "fsl_sctimer.h"
|
||||
|
||||
#include "System/system.h"
|
||||
#include "io.h"
|
||||
|
||||
extern volatile uint8_t BC_Duty_Cycle;
|
||||
|
||||
uint8_t Task,Tx_Time_Out_Flag,i,Test_Mode;
|
||||
@@ -68,6 +71,7 @@ extern uint8_t frq_update_flag,Ports_Cleared_Flag;
|
||||
extern HARDWARE_FIX_t hwf;
|
||||
extern uint8_t tempString[40]; // Todo move
|
||||
|
||||
extern SYSTEM_DATA_t sys;
|
||||
#define BYPASS_USB_SAFETY 0 //Use for debugging
|
||||
#define DDS_PLL_TEST 0
|
||||
|
||||
@@ -203,6 +207,10 @@ int main(void)
|
||||
|
||||
USB_Init();
|
||||
|
||||
Menu_init();
|
||||
|
||||
sys.guiMode = GUI_MODE_NORMAL;
|
||||
|
||||
|
||||
#if DDS_PLL_TEST
|
||||
//# Insert special test code here.
|
||||
@@ -215,24 +223,6 @@ uint32_t tmp;
|
||||
//# End Test code
|
||||
#endif
|
||||
|
||||
//#########################
|
||||
// if(Read_Model_type() == LEICA) // Read Model Patches erroneous boards sent to Leica 8/2/24
|
||||
// {
|
||||
// sprintf(tempString, "%d", hwf.mainPcbaPN);
|
||||
|
||||
// if(strncmp(tempString,"208021",6) == 0) // check for HW rev.
|
||||
// {
|
||||
// hwf.mainPcbaPN = 208025;
|
||||
// EE_WriteUINT32(EE_HWFIX_MAIN_PCBA_PN, hwf.mainPcbaPN);// Change to 208025 Assembly
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
// Leica_Patch(); // Patches erroneous boards sent to Leica 8/2/24
|
||||
|
||||
// Umag_Patch();
|
||||
//########################
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
@@ -243,7 +233,7 @@ uint32_t tmp;
|
||||
#if !BYPASS_USB_SAFETY
|
||||
//#####################
|
||||
Check_For_Usb();
|
||||
if(GPIO_PinRead(GPIO,1,6))
|
||||
if(GPIO_READ(PIN_VBUS))
|
||||
{
|
||||
Task = USB_SAFE_TASK; // process primary keys as safety menu
|
||||
safe_key(); // process primary keys as safety menu
|
||||
@@ -253,7 +243,7 @@ uint32_t tmp;
|
||||
|
||||
}
|
||||
else
|
||||
if(!GPIO_PinRead(GPIO,1,6) && Ports_Cleared_Flag)
|
||||
if(!GPIO_READ(PIN_VBUS) && Ports_Cleared_Flag)
|
||||
{
|
||||
Normal_Init(); // USB is unplugged so reinitialize
|
||||
}
|
||||
@@ -263,9 +253,32 @@ uint32_t tmp;
|
||||
|
||||
Delay_Ticks(1); //10mS delay
|
||||
|
||||
KEY_Update();
|
||||
|
||||
|
||||
|
||||
if (sys.guiMode == GUI_MODE_MENU)
|
||||
{
|
||||
Menu_service();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(KEY_GetPressed())
|
||||
{
|
||||
case MENU_KEY:
|
||||
{
|
||||
|
||||
Menu_mainMenu();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
Display_Update();
|
||||
}
|
||||
|
||||
|
||||
#if !BYPASS_USB_SAFETY
|
||||
if((tickCount++ % 10 == 0) && !GPIO_PinRead(GPIO,1,6)) //every 10 ticks = 100mS AND !USB
|
||||
if((tickCount++ % 10 == 0) && !GPIO_READ(PIN_VBUS)) //every 10 ticks = 100mS AND !USB
|
||||
#else
|
||||
if(tickCount++ % 10 == 0) //every 10 ticks = 100mS
|
||||
#endif
|
||||
@@ -287,7 +300,7 @@ uint32_t tmp;
|
||||
break;
|
||||
|
||||
case PRIMARY_TASK:
|
||||
pro_key(); // process primary keys front 6 first menu
|
||||
//pro_key(); // process primary keys front 6 first menu
|
||||
break;
|
||||
|
||||
case MENU_TASK: // Allows user to select options
|
||||
@@ -378,7 +391,7 @@ uint32_t tmp;
|
||||
if (Taps_adjust_timer == 0)
|
||||
Check_Taps(); // Check for optimum Taps
|
||||
#endif
|
||||
Display_Update();
|
||||
// Display_Update();
|
||||
|
||||
}
|
||||
|
||||
|
||||
201
source/menu.c
201
source/menu.c
@@ -40,6 +40,45 @@
|
||||
|
||||
#define MENU_TIMER_PERIOD_MS (100) //100mS for 10Hz update
|
||||
|
||||
#define MENU_STACK_SIZE 4
|
||||
#define MENU_ITEM_SIZE 10
|
||||
|
||||
typedef struct Menu_s Menu_t;
|
||||
|
||||
typedef int (*MenuHandler_t)(Menu_t *menu);
|
||||
|
||||
|
||||
struct Menu_s
|
||||
{
|
||||
MenuHandler_t handler;
|
||||
bool init;
|
||||
bool draw;
|
||||
int selected;
|
||||
MENU_ITEM_t items[MENU_ITEM_SIZE];
|
||||
int itemCount;
|
||||
int displayIndex;
|
||||
|
||||
};
|
||||
|
||||
typedef struct MenuData_s
|
||||
{
|
||||
int stackCount;
|
||||
Menu_t menuStack[MENU_STACK_SIZE];
|
||||
Menu_t *currentMenu;
|
||||
|
||||
} MenuData_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
bool exitToMainScreen;
|
||||
} MENU_t;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,6 +86,8 @@
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
static MenuData_t _menuData;
|
||||
|
||||
MENU_t menu;
|
||||
|
||||
MENU_ITEM_t mainMenu[MAIN_MENU_NUM_TX10];
|
||||
@@ -69,6 +110,9 @@ extern uint8_t Port_State[];
|
||||
|
||||
extern HARDWARE_FIX_t hwf;
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Static Function Declarations
|
||||
******************************************************************************/
|
||||
@@ -92,10 +136,126 @@ static void DisplayLanguageMenu(uint32_t selected);
|
||||
static void DisplayRegulatoryInfo(void);
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Static Functions
|
||||
******************************************************************************/
|
||||
|
||||
static int handleMainMenu(Menu_t *menu)
|
||||
{
|
||||
if (menu->init)
|
||||
{
|
||||
int itemCount = 0;
|
||||
|
||||
menu->items[itemCount].pMonoIcon = menuMore;
|
||||
menu->items[itemCount].id = MENU_ID_SYSINFO;
|
||||
strcpy(menu->items[itemCount].text, "System Information"); //System info screen
|
||||
itemCount++;
|
||||
|
||||
menu->items[itemCount].pMonoIcon = menuMore;
|
||||
menu->items[itemCount].id = MENU_ID_FREQUENCIES;
|
||||
strcpy(menu->items[itemCount].text, "Frequencies"); //Frequency Selection Menu
|
||||
itemCount++;
|
||||
|
||||
menu->items[itemCount].pMonoIcon = 0;
|
||||
menu->items[itemCount].id = MENU_ID_AUTOSHUTDOWN;
|
||||
strcpy(menu->items[itemCount].text, "Auto Shutdown"); //Auto Shutdown selection
|
||||
itemCount++;
|
||||
|
||||
menu->items[itemCount].pMonoIcon = menuMore;
|
||||
menu->items[itemCount].id = MENU_ID_LANGUAGE;
|
||||
strcpy(menu->items[itemCount].text, "Language"); //Language Selection Menu
|
||||
itemCount++;
|
||||
|
||||
menu->itemCount = itemCount;
|
||||
menu->init = false;
|
||||
|
||||
menu->draw = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
switch(KEY_GetPressed())
|
||||
{
|
||||
case KEY_UP:
|
||||
{
|
||||
if(--menu->selected < 0)
|
||||
{
|
||||
menu->selected = 0;
|
||||
}
|
||||
menu->draw = true;
|
||||
break;
|
||||
}
|
||||
case KEY_DOWN:
|
||||
{
|
||||
if(++menu->selected >= menu->itemCount)
|
||||
{
|
||||
menu->selected = menu->itemCount - 1;
|
||||
}
|
||||
menu->draw = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (menu->draw)
|
||||
{
|
||||
|
||||
LCD_Clear();
|
||||
|
||||
if(menu->selected >= (menu->displayIndex + MENU_MAX_LINES_DISPLAYED))
|
||||
{
|
||||
menu->displayIndex++;
|
||||
}
|
||||
else if(menu->selected < menu->displayIndex)
|
||||
{
|
||||
menu->displayIndex--;
|
||||
}
|
||||
|
||||
|
||||
// Draw menu items
|
||||
MENU_ITEM_t *item;
|
||||
|
||||
for(uint32_t i = menu->displayIndex; i < menu->displayIndex + menu->itemCount; i++) //this can draw extra lines off the screen but we don't care
|
||||
{
|
||||
item = &menu->items[i];
|
||||
|
||||
//Menu strings
|
||||
FL_DrawTranslatedString(item->text, MENU_MAIN_TEXT_X, MENU_MAIN_TEXT_Y_START + (i-menu->displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
|
||||
|
||||
|
||||
// Draw item status
|
||||
if (item->pMonoIcon != NULL)
|
||||
{
|
||||
GL_DrawMonoBitmap(item->pMonoIcon, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START + (i-menu->displayIndex)*MENU_LINE_HEIGHT + MENU_MAIN_STATUS_Y_OFF, LCD_DRAW_SET);
|
||||
}
|
||||
|
||||
if (item->id == MENU_ID_AUTOSHUTDOWN)
|
||||
{
|
||||
FL_DrawTranslatedString(tmr_GetAutoSDTimerString(), MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START + (i - menu->displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Draw selection bar
|
||||
uint32_t selRectY0 = MENU_MAIN_TEXT_Y_START + (menu->selected - menu->displayIndex)*MENU_LINE_HEIGHT;
|
||||
GL_DrawFilledRectangle(MENU_SEL_RECT_X0, selRectY0, MENU_SEL_RECT_X1, selRectY0 + MENU_LINE_HEIGHT, LCD_DRAW_XOR);
|
||||
|
||||
//Draw menu icons
|
||||
//Use DrawMenuBitmap(mainMenu[i], x, y)
|
||||
|
||||
//DrawMenuScrollBar(displayIndex, menuNum);
|
||||
|
||||
LCD_Update();
|
||||
|
||||
menu->draw = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -865,6 +1025,11 @@ void MENU_Init(void)
|
||||
ClearMenuItems(mainMenu, MAIN_MENU_NUM_TX10);
|
||||
ClearMenuItems(langMenu, LANG_MENU_NUM);
|
||||
|
||||
for (int i=0; i < MENU_STACK_SIZE; ++i)
|
||||
{
|
||||
_menuData.menuStack[i].selected = 0;
|
||||
_menuData.menuStack[i].handler = NULL;
|
||||
}
|
||||
|
||||
//main menu
|
||||
uint32_t i = 0;
|
||||
@@ -1093,6 +1258,42 @@ void MENU_DisplayMain(uint32_t selected)
|
||||
|
||||
|
||||
|
||||
void Menu_init(void)
|
||||
{
|
||||
_menuData.currentMenu = NULL;
|
||||
_menuData.stackCount = 0;
|
||||
|
||||
for (int i=0; i<MENU_STACK_SIZE; ++i)
|
||||
{
|
||||
_menuData.menuStack[i].displayIndex = 0;
|
||||
|
||||
for (int j=0; j<MENU_ITEM_SIZE; ++j)
|
||||
{
|
||||
_menuData.menuStack[i].items[j].id = MENU_ID_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Menu_mainMenu(void)
|
||||
{
|
||||
sys.guiMode = GUI_MODE_MENU;
|
||||
|
||||
Menu_t *menu = &_menuData.menuStack[0];
|
||||
|
||||
menu->handler = handleMainMenu;
|
||||
menu->selected = 0;
|
||||
menu->init = true;
|
||||
|
||||
_menuData.currentMenu = menu;
|
||||
}
|
||||
|
||||
void Menu_service(void)
|
||||
{
|
||||
// run the menu state machine and prevent blocking
|
||||
if (_menuData.currentMenu != NULL)
|
||||
{
|
||||
_menuData.currentMenu->handler(_menuData.currentMenu);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -60,21 +60,29 @@
|
||||
|
||||
#define MENU_SEL_RECT_RADIUS 5
|
||||
|
||||
typedef struct {
|
||||
bool exitToMainScreen;
|
||||
}MENU_t;
|
||||
typedef enum
|
||||
{
|
||||
MENU_ID_NONE = 0,
|
||||
MENU_ID_AUTOSHUTDOWN,
|
||||
MENU_ID_FREQUENCIES,
|
||||
MENU_ID_SYSINFO,
|
||||
MENU_ID_LANGUAGE,
|
||||
|
||||
} MenuItemId_t;
|
||||
|
||||
//Menu Item Struct
|
||||
//contains pointers to both mono and color bitmaps. mono bitmap requires a color.
|
||||
//each item may have a mono bitmap, a color bitmap, or no bitmap.
|
||||
typedef struct {
|
||||
|
||||
uint16_t * pMonoIcon; // bitmap
|
||||
typedef struct MENU_ITEM_s
|
||||
{
|
||||
uint32_t * pMonoIcon; // bitmap
|
||||
char text[MENU_MAX_STRING_LENGTH];
|
||||
MenuItemId_t id;
|
||||
|
||||
} MENU_ITEM_t;
|
||||
|
||||
|
||||
void Menu_init(void);
|
||||
void Menu_mainMenu(void);
|
||||
void Menu_service(void);
|
||||
|
||||
void MENU_Init(void);
|
||||
void MENU_Main(void);
|
||||
void MENU_DisplayMain(uint32_t selected);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <stdio.h>
|
||||
#include "hwFixes.h"
|
||||
#include "System\system.h"
|
||||
#include "io.h"
|
||||
|
||||
|
||||
//#define ON 1
|
||||
@@ -130,9 +131,13 @@ void Select_Bypass(RELAY_SELECT_t Bypass) // Bypass allows transmitting w/o full
|
||||
void Select_Estop(RELAY_SELECT_t E_stop)
|
||||
{
|
||||
if (E_stop)
|
||||
GPIO_PinWrite(GPIO, 1, ESTOP, 0); // Isolated
|
||||
{
|
||||
GPIO_WRITE(PIN_ESTOP, LOW);
|
||||
//GPIO_PinWrite(GPIO, 1, ESTOP, 0); // Isolated
|
||||
}
|
||||
else
|
||||
GPIO_PinWrite(GPIO, 1, ESTOP, 1); // Not Isolated
|
||||
//GPIO_PinWrite(GPIO, 1, ESTOP, 1); // Not Isolated
|
||||
GPIO_WRITE(PIN_ESTOP, HIGH);
|
||||
|
||||
}
|
||||
void Select_Transformer()
|
||||
|
||||
Reference in New Issue
Block a user