From 76ded0675164453f307ee9a26bfbfb58f9979a20 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Thu, 8 Dec 2022 21:53:45 +0100 Subject: [PATCH] Split UI sources in a default one for the radios and the Module17 one. --- meson.build | 62 ++++-- openrtx/include/core/ui.h | 199 ------------------- openrtx/include/ui/ui_default.h | 226 ++++++++++++++++++++++ openrtx/src/core/openrtx.c | 2 + openrtx/src/core/state.c | 1 + openrtx/src/core/voicePromptUtils.c | 2 +- openrtx/src/ui/{ => default}/ui.c | 2 +- openrtx/src/ui/{ => default}/ui_main.c | 4 +- openrtx/src/ui/{ => default}/ui_menu.c | 2 +- openrtx/src/ui/{ => default}/ui_strings.c | 0 10 files changed, 276 insertions(+), 224 deletions(-) create mode 100644 openrtx/include/ui/ui_default.h rename openrtx/src/ui/{ => default}/ui.c (99%) rename openrtx/src/ui/{ => default}/ui_main.c (99%) rename openrtx/src/ui/{ => default}/ui_menu.c (99%) rename openrtx/src/ui/{ => default}/ui_strings.c (100%) diff --git a/meson.build b/meson.build index 3a770e9d..9b918715 100644 --- a/meson.build +++ b/meson.build @@ -30,7 +30,7 @@ def += {'FONT_UBUNTU_REGULAR': ''} ## ## -## OpenRTX sources +## OpenRTX core sources ## openrtx_src = ['openrtx/src/core/state.c', @@ -54,10 +54,6 @@ openrtx_src = ['openrtx/src/core/state.c', 'openrtx/src/core/voicePrompts.c', 'openrtx/src/core/voicePromptUtils.c', 'openrtx/src/core/voicePromptData.S', - 'openrtx/src/ui/ui.c', - 'openrtx/src/ui/ui_strings.c', - 'openrtx/src/ui/ui_main.c', - 'openrtx/src/ui/ui_menu.c', 'openrtx/src/rtx/rtx.cpp', 'openrtx/src/rtx/OpMode_FM.cpp', 'openrtx/src/rtx/OpMode_M17.cpp', @@ -85,6 +81,21 @@ openrtx_inc = ['openrtx/include', 'platform/drivers/backlight', 'platform/drivers/chSelector'] +## +## OpenRTX UI sources +## + +openrtx_ui_default = ['openrtx/src/ui/default/ui.c', + 'openrtx/src/ui/default/ui_main.c', + 'openrtx/src/ui/default/ui_menu.c', + 'openrtx/src/ui/default/ui_strings.c'] + +openrtx_ui_module17 = [] + +## +## Selection of main entrypoint +## + main_src = [] # Add to sources either the main executable or a platform test @@ -159,6 +170,8 @@ mdx_src = ['openrtx/src/core/xmodem.c', 'platform/drivers/backlight/backlight_MDx.c', 'platform/drivers/tones/toneGenerator_MDx.cpp'] +mdx_src = mdx_src + openrtx_ui_default + ## ## GDx family: Radioddity GD-77 and Baofeng DM-1801 ## @@ -182,6 +195,8 @@ gdx_src = ['openrtx/src/core/xmodem.c', 'platform/drivers/audio/inputStream_GDx.c', 'platform/drivers/audio/outputStream_GDx.c'] +gdx_src = gdx_src + openrtx_ui_default + ## ## --------------------- MCU-dependent source files ---------------------------- ## @@ -270,11 +285,17 @@ linux_platform_src = ['platform/targets/linux/emulator/emulator.c', linux_src = src + linux_platform_src +# +# Select which UI to use +# +linux_src = linux_src + openrtx_ui_default +# linux_src = linux_src + openrtx_ui_module17 -# GDx family display emulation -#linux_def = def + {'SCREEN_WIDTH': '128', 'SCREEN_HEIGHT': '64', 'PIX_FMT_BW': ''} -# MDx family display emulation +# +# Select which screen type to emulate +# linux_def = def + {'SCREEN_WIDTH': '160', 'SCREEN_HEIGHT': '128', 'PIX_FMT_RGB565': ''} +#linux_def = def + {'SCREEN_WIDTH': '128', 'SCREEN_HEIGHT': '64', 'PIX_FMT_BW': ''} linux_def += {'VP_USE_FILESYSTEM':''} linux_inc = inc + ['platform/targets/linux', @@ -356,18 +377,19 @@ dm1801_def = def + mk22fn512_def + {'PLATFORM_DM1801': ''} ## ## Module 17 ## -mod17_src = src + stm32f405_src + ['platform/targets/Module17/platform.c', - 'platform/drivers/display/SH110x_Mod17.c', - 'platform/drivers/ADC/ADC1_Mod17.c', - 'platform/drivers/keyboard/keyboard_Mod17.c', - 'platform/drivers/NVM/nvmem_Mod17.c', - 'platform/drivers/CPS/cps_io_native_Mod17.c', - 'platform/drivers/baseband/radio_Mod17.cpp', - 'platform/drivers/audio/inputStream_Mod17.cpp', - 'platform/drivers/audio/outputStream_Mod17.cpp', - 'platform/drivers/audio/audio_Mod17.c', - 'platform/drivers/baseband/MCP4551_Mod17.cpp'] +mod17_src = ['platform/targets/Module17/platform.c', + 'platform/drivers/display/SH110x_Mod17.c', + 'platform/drivers/ADC/ADC1_Mod17.c', + 'platform/drivers/keyboard/keyboard_Mod17.c', + 'platform/drivers/NVM/nvmem_Mod17.c', + 'platform/drivers/CPS/cps_io_native_Mod17.c', + 'platform/drivers/baseband/radio_Mod17.cpp', + 'platform/drivers/audio/inputStream_Mod17.cpp', + 'platform/drivers/audio/outputStream_Mod17.cpp', + 'platform/drivers/audio/audio_Mod17.c', + 'platform/drivers/baseband/MCP4551_Mod17.cpp'] +mod17_src = src + openrtx_ui_module17 + mod17_src + stm32f405_src mod17_inc = inc + stm32f405_inc + ['platform/targets/Module17'] mod17_def = def + stm32f405_def + {'PLATFORM_MOD17': ''} @@ -625,7 +647,7 @@ foreach t : targets # Module17 also uses dfu-tool for flashing elif name == 'openrtx_mod17' - + # Wrap target for Module17 for consistency, same output as bin target custom_target(name+'_wrap', output : name+'_wrap', diff --git a/openrtx/include/core/ui.h b/openrtx/include/core/ui.h index 71276ade..5e7ba2ea 100644 --- a/openrtx/include/core/ui.h +++ b/openrtx/include/core/ui.h @@ -21,206 +21,7 @@ #define UI_H #include -#include -#include -#include #include -#include -#include - -// Maximum menu entry length -#define MAX_ENTRY_LEN 21 -// Frequency digits -#define FREQ_DIGITS 7 -// Time & Date digits -#define TIMEDATE_DIGITS 10 -// Max number of UI events -#define MAX_NUM_EVENTS 16 - -enum uiScreen -{ - MAIN_VFO = 0, - MAIN_VFO_INPUT, - MAIN_MEM, - MODE_VFO, - MODE_MEM, - MENU_TOP, - MENU_BANK, - MENU_CHANNEL, - MENU_CONTACTS, - MENU_GPS, - MENU_SETTINGS, - MENU_BACKUP_RESTORE, - MENU_BACKUP, - MENU_RESTORE, - MENU_INFO, - MENU_ABOUT, - SETTINGS_TIMEDATE, - SETTINGS_TIMEDATE_SET, - SETTINGS_DISPLAY, - SETTINGS_GPS, - SETTINGS_M17, - SETTINGS_VOICE, - SETTINGS_RESET2DEFAULTS, - LOW_BAT -}; - -enum SetRxTx -{ - SET_RX = 0, - SET_TX -}; - -// This enum is needed to have item numbers that match -// menu elements even if some elements may be missing (GPS) -enum menuItems -{ - M_BANK = 0, - M_CHANNEL, - M_CONTACTS, -#ifdef GPS_PRESENT - M_GPS, -#endif - M_SETTINGS, - M_BACKUP_RESTORE, - M_INFO, - M_ABOUT -}; - -enum settingsItems -{ - S_DISPLAY = 0 -#ifdef RTC_PRESENT - ,S_TIMEDATE -#endif -#ifdef GPS_PRESENT - ,S_GPS -#endif - ,S_M17 - ,S_VOICE - ,S_RESET2DEFAULTS -}; - -enum backupRestoreItems -{ - BR_BACKUP = 0, - BR_RESTORE -}; - -enum displayItems -{ - D_BRIGHTNESS = 0 -#ifdef SCREEN_CONTRAST - ,D_CONTRAST -#endif - ,D_TIMER -}; - -#ifdef GPS_PRESENT -enum settingsGPSItems -{ - G_ENABLED = 0, - G_SET_TIME, - G_TIMEZONE -}; -#endif -enum settingsVoicePromptItems -{ - VP_LEVEL = 0, - VP_PHONETIC, -}; - -/** - * Struct containing a set of positions and sizes that get - * calculated for the selected display size. - * Using these parameters make the UI automatically adapt - * To displays of different sizes - */ -typedef struct layout_t -{ - uint16_t hline_h; - uint16_t top_h; - uint16_t line1_h; - uint16_t line2_h; - uint16_t line3_h; - uint16_t menu_h; - uint16_t bottom_h; - uint16_t bottom_pad; - uint16_t status_v_pad; - uint16_t horizontal_pad; - uint16_t text_v_offset; - point_t top_pos; - point_t line1_pos; - point_t line2_pos; - point_t line3_pos; - point_t bottom_pos; - fontSize_t top_font; - fontSize_t line1_font; - fontSize_t line2_font; - fontSize_t line3_font; - fontSize_t bottom_font; - fontSize_t input_font; - fontSize_t menu_font; - fontSize_t mode_font_big; - fontSize_t mode_font_small; -} layout_t; - -/** - * This structs contains state variables internal to the - * UI that need to be kept between executions of the UI - * This state does not need to be saved on device poweroff - */ -typedef struct ui_state_t -{ - // Index of the currently selected menu entry - uint8_t menu_selected; - // If true we can change a menu entry value with UP/DOWN - bool edit_mode; - // Variables used for VFO input - uint8_t input_number; - uint8_t input_position; - uint8_t input_set; - long long last_keypress; - freq_t new_rx_frequency; - freq_t new_tx_frequency; - char new_rx_freq_buf[14]; - char new_tx_freq_buf[14]; -#ifdef RTC_PRESENT - // Variables used for Time & Date input - datetime_t new_timedate; - char new_date_buf[9]; - char new_time_buf[9]; -#endif - char new_callsign[10]; - // Which state to return to when we exit menu - uint8_t last_main_state; -} -ui_state_t; - -extern layout_t layout; -// Copy of the radio state -extern state_t last_state; -extern const char *menu_items[]; -extern const char *settings_items[]; -extern const char *display_items[]; -extern const char *settings_gps_items[]; -extern const char * settings_voice_items[]; - -extern const char *backup_restore_items[]; -extern const char *info_items[]; -extern const char *authors[]; -extern const uint8_t menu_num; -extern const uint8_t settings_num; -extern const uint8_t display_num; -extern const uint8_t settings_gps_num; -extern const uint8_t settings_voice_num; -extern const uint8_t backup_restore_num; -extern const uint8_t info_num; -extern const uint8_t author_num; -extern const color_t color_black; -extern const color_t color_grey; -extern const color_t color_white; -extern const color_t yellow_fab413; /** * This function initialises the User Interface, starting the diff --git a/openrtx/include/ui/ui_default.h b/openrtx/include/ui/ui_default.h new file mode 100644 index 00000000..ae04781f --- /dev/null +++ b/openrtx/include/ui/ui_default.h @@ -0,0 +1,226 @@ +/*************************************************************************** + * Copyright (C) 2022 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN, * + * Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#ifndef UI_DEFAULT_H +#define UI_DEFAULT_H + +#include +#include +#include +#include +#include +#include +#include +#include + +// Maximum menu entry length +#define MAX_ENTRY_LEN 21 +// Frequency digits +#define FREQ_DIGITS 7 +// Time & Date digits +#define TIMEDATE_DIGITS 10 +// Max number of UI events +#define MAX_NUM_EVENTS 16 + +enum uiScreen +{ + MAIN_VFO = 0, + MAIN_VFO_INPUT, + MAIN_MEM, + MODE_VFO, + MODE_MEM, + MENU_TOP, + MENU_BANK, + MENU_CHANNEL, + MENU_CONTACTS, + MENU_GPS, + MENU_SETTINGS, + MENU_BACKUP_RESTORE, + MENU_BACKUP, + MENU_RESTORE, + MENU_INFO, + MENU_ABOUT, + SETTINGS_TIMEDATE, + SETTINGS_TIMEDATE_SET, + SETTINGS_DISPLAY, + SETTINGS_GPS, + SETTINGS_M17, + SETTINGS_VOICE, + SETTINGS_RESET2DEFAULTS, + LOW_BAT +}; + +enum SetRxTx +{ + SET_RX = 0, + SET_TX +}; + +// This enum is needed to have item numbers that match +// menu elements even if some elements may be missing (GPS) +enum menuItems +{ + M_BANK = 0, + M_CHANNEL, + M_CONTACTS, +#ifdef GPS_PRESENT + M_GPS, +#endif + M_SETTINGS, + M_BACKUP_RESTORE, + M_INFO, + M_ABOUT +}; + +enum settingsItems +{ + S_DISPLAY = 0 +#ifdef RTC_PRESENT + ,S_TIMEDATE +#endif +#ifdef GPS_PRESENT + ,S_GPS +#endif + ,S_M17 + ,S_VOICE + ,S_RESET2DEFAULTS +}; + +enum backupRestoreItems +{ + BR_BACKUP = 0, + BR_RESTORE +}; + +enum displayItems +{ + D_BRIGHTNESS = 0 +#ifdef SCREEN_CONTRAST + ,D_CONTRAST +#endif + ,D_TIMER +}; + +#ifdef GPS_PRESENT +enum settingsGPSItems +{ + G_ENABLED = 0, + G_SET_TIME, + G_TIMEZONE +}; +#endif +enum settingsVoicePromptItems +{ + VP_LEVEL = 0, + VP_PHONETIC, +}; + +/** + * Struct containing a set of positions and sizes that get + * calculated for the selected display size. + * Using these parameters make the UI automatically adapt + * To displays of different sizes + */ +typedef struct layout_t +{ + uint16_t hline_h; + uint16_t top_h; + uint16_t line1_h; + uint16_t line2_h; + uint16_t line3_h; + uint16_t menu_h; + uint16_t bottom_h; + uint16_t bottom_pad; + uint16_t status_v_pad; + uint16_t horizontal_pad; + uint16_t text_v_offset; + point_t top_pos; + point_t line1_pos; + point_t line2_pos; + point_t line3_pos; + point_t bottom_pos; + fontSize_t top_font; + fontSize_t line1_font; + fontSize_t line2_font; + fontSize_t line3_font; + fontSize_t bottom_font; + fontSize_t input_font; + fontSize_t menu_font; + fontSize_t mode_font_big; + fontSize_t mode_font_small; +} layout_t; + +/** + * This structs contains state variables internal to the + * UI that need to be kept between executions of the UI + * This state does not need to be saved on device poweroff + */ +typedef struct ui_state_t +{ + // Index of the currently selected menu entry + uint8_t menu_selected; + // If true we can change a menu entry value with UP/DOWN + bool edit_mode; + // Variables used for VFO input + uint8_t input_number; + uint8_t input_position; + uint8_t input_set; + long long last_keypress; + freq_t new_rx_frequency; + freq_t new_tx_frequency; + char new_rx_freq_buf[14]; + char new_tx_freq_buf[14]; +#ifdef RTC_PRESENT + // Variables used for Time & Date input + datetime_t new_timedate; + char new_date_buf[9]; + char new_time_buf[9]; +#endif + char new_callsign[10]; + // Which state to return to when we exit menu + uint8_t last_main_state; +} +ui_state_t; + +extern layout_t layout; +// Copy of the radio state +extern state_t last_state; +extern const char *menu_items[]; +extern const char *settings_items[]; +extern const char *display_items[]; +extern const char *settings_gps_items[]; +extern const char * settings_voice_items[]; + +extern const char *backup_restore_items[]; +extern const char *info_items[]; +extern const char *authors[]; +extern const uint8_t menu_num; +extern const uint8_t settings_num; +extern const uint8_t display_num; +extern const uint8_t settings_gps_num; +extern const uint8_t settings_voice_num; +extern const uint8_t backup_restore_num; +extern const uint8_t info_num; +extern const uint8_t author_num; +extern const color_t color_black; +extern const color_t color_grey; +extern const color_t color_white; +extern const color_t yellow_fab413; + +#endif /* UI_DEFAULT_H */ diff --git a/openrtx/src/core/openrtx.c b/openrtx/src/core/openrtx.c index 7bd9da45..dd347c6a 100644 --- a/openrtx/src/core/openrtx.c +++ b/openrtx/src/core/openrtx.c @@ -19,6 +19,7 @@ ***************************************************************************/ #include +#include #include #include #include @@ -27,6 +28,7 @@ #include #include #include +#include #include #ifdef PLATFORM_LINUX #include diff --git a/openrtx/src/core/state.c b/openrtx/src/core/state.c index ddf5ca68..826f1956 100644 --- a/openrtx/src/core/state.c +++ b/openrtx/src/core/state.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/openrtx/src/core/voicePromptUtils.c b/openrtx/src/core/voicePromptUtils.c index c1feac0a..55f5398d 100644 --- a/openrtx/src/core/voicePromptUtils.c +++ b/openrtx/src/core/voicePromptUtils.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include "interfaces/cps_io.h" diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/default/ui.c similarity index 99% rename from openrtx/src/ui/ui.c rename to openrtx/src/ui/default/ui.c index b2c7fd67..399bdef7 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/default/ui.c @@ -64,7 +64,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/openrtx/src/ui/ui_main.c b/openrtx/src/ui/default/ui_main.c similarity index 99% rename from openrtx/src/ui/ui_main.c rename to openrtx/src/ui/default/ui_main.c index 9332e329..3ad16d51 100644 --- a/openrtx/src/ui/ui_main.c +++ b/openrtx/src/ui/default/ui_main.c @@ -22,9 +22,9 @@ #include #include #include -#include +#include #include -#include "ui/ui_strings.h" +#include void _ui_drawMainBackground() { diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/default/ui_menu.c similarity index 99% rename from openrtx/src/ui/ui_menu.c rename to openrtx/src/ui/default/ui_menu.c index 217df6bf..a00dd5eb 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/default/ui_menu.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/openrtx/src/ui/ui_strings.c b/openrtx/src/ui/default/ui_strings.c similarity index 100% rename from openrtx/src/ui/ui_strings.c rename to openrtx/src/ui/default/ui_strings.c