[wip] working on display layout

This commit is contained in:
2023-04-01 22:43:36 +02:00
parent 32daa4bce9
commit 07dd185e7c
24 changed files with 901 additions and 254 deletions

View File

@@ -1,11 +1,31 @@
#include "main.h"
#include "hw_button.h"
#include "ctrl_bottom_button.h"
#include "ctrl_channel_button.h"
#include "ctrl_app.h"
#define FUN_GEN_FOCUS_MAX 6U
#define PWM_GEN_FOCUS_MAX 4U
typedef void (*btn_action_t)(void);
typedef struct
{
btn_action_t command;
BITMAP_buttonName_t bitmap_name;
} CMD_button_t;
static GEN_fg_t func_gen[3];
static GEN_pwm_t pwm_gen[3];
const static GENERATOR_t generators[CHANNEL_MAX] = {
static const CMD_button_t btn_command[BTN_STATE_MAX][DISP_BTN_MAX];
static const LAY_dispBtn_t btn_hw_to_disp[BTN_BOT_MAX] = {DISP_BTN_1, DISP_BTN_2, DISP_BTN_3, DISP_BTN_4, DISP_BTN_5};
static HW_BotBtnName_t last_key;
static APP_data_t *_app_data;
static const GENERATOR_t generators[CHANNEL_MAX] = {
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[0]},
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[1]},
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[2]},
@@ -16,4 +36,362 @@ const static GENERATOR_t generators[CHANNEL_MAX] = {
void APP_init(APP_data_t *app_data)
{
}
_app_data = app_data;
_app_data->freq_focus_digit = 0;
_app_data->ampl_focus_digit = 0;
_app_data->offs_focus_digit = 0;
_app_data->phas_focus_digit = 0;
_app_data->duty_focus_digit = 0;
_app_data->curr_gen_type = GEN_FG_TYPE;
_app_data->generator = generators[CHANNEL1].gen;
_app_data->curr_state_lay = LAY_MAIN;
_app_data->curr_state_btn = BTN_MAIN_FG;
_app_data->isChannelChange = 1;
_app_data->isGraphChange = 1;
_app_data->isValueChange = 1;
_app_data->isButtonChange = 1;
_app_data->isButtonBlink = 1;
CTRL_buttonsInit();
}
void CTRL_buttonsInit(void)
{
CTRL_bottomButtonInit();
// CTRL_channelButtonInit();
}
void CTRL_buttonsHandler(void)
{
CTRL_bottomButtonsHandler();
CTRL_channelButtonsHandler();
}
void CTRL_pushedDispBtnEvent(ButtonKey_t *key)
{
last_key = btn_hw_to_disp[key->instance];
btn_command[_app_data->curr_state_btn][last_key].command();
}
void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
{
UNUSED(key);
}
inline BITMAP_buttonName_t CTRL_getBitmapName(LAY_dispBtn_t disp_btn)
{
return btn_command[_app_data->curr_state_btn][disp_btn].bitmap_name;
}
static void _doNoting(void)
{
return;
}
static void _backToMain(void)
{
_app_data->curr_state_lay = LAY_MAIN;
switch (_app_data->curr_gen_type)
{
case GEN_FG_TYPE:
_app_data->curr_state_btn = BTN_MAIN_FG;
break;
case GEN_PWM_TYPE:
_app_data->curr_state_btn = BTN_MAIN_PWM;
break;
default:
break;
}
_app_data->isButtonChange = 1;
_app_data->isGraphChange = 1;
_app_data->isValueChange = 1;
}
static void _blockFocusAtMaxAndMin(void)
{
switch (_app_data->curr_state_btn)
{
case BTN_FREQ_MIN:
if (_app_data->freq_focus_digit > 0)
{
_app_data->curr_state_btn = BTN_FREQ;
_app_data->isButtonChange = 1;
}
break;
case BTN_FREQ_MAX:
if (_app_data->freq_focus_digit < FUN_GEN_FOCUS_MAX)
{
_app_data->curr_state_btn = BTN_FREQ;
_app_data->isButtonChange = 1;
}
break;
case BTN_FREQ:
if (_app_data->freq_focus_digit == 0)
{
_app_data->curr_state_btn = BTN_FREQ_MIN;
_app_data->isButtonChange = 1;
}
else if (_app_data->freq_focus_digit == FUN_GEN_FOCUS_MAX)
{
_app_data->curr_state_btn = BTN_FREQ_MAX;
_app_data->isButtonChange = 1;
}
break;
default:
break;
}
}
static void _enterToFreqLayout(void)
{
_app_data->curr_state_lay = LAY_FREQ;
_app_data->curr_state_btn = BTN_FREQ;
_blockFocusAtMaxAndMin();
_app_data->isButtonChange = 1;
_app_data->isGraphChange = 1;
_app_data->isValueChange = 1;
}
static void _enterToAmplLayout(void)
{
_app_data->curr_state_lay = LAY_AMPL;
_app_data->curr_state_btn = BTN_AMPL;
_app_data->isButtonChange = 1;
_app_data->isGraphChange = 1;
_app_data->isValueChange = 1;
}
static void _enterToOffslLayout(void)
{
_app_data->curr_state_lay = LAY_OFFS;
_app_data->curr_state_btn = BTN_OFFS;
_app_data->isButtonChange = 1;
_app_data->isGraphChange = 1;
_app_data->isValueChange = 1;
}
static void _enterToPhasLayout(void)
{
_app_data->curr_state_lay = LAY_PHAS;
_app_data->curr_state_btn = BTN_PHAS;
_app_data->isButtonChange = 1;
_app_data->isGraphChange = 1;
_app_data->isValueChange = 1;
}
static void _enterToDutyLayout(void)
{
_app_data->curr_state_lay = LAY_DUTY;
_app_data->curr_state_btn = BTN_DUTY;
_app_data->isButtonChange = 1;
_app_data->isGraphChange = 1;
_app_data->isValueChange = 1;
}
static void _enterToWavelLayout(void)
{
_app_data->curr_state_lay = LAY_WAVE;
_app_data->curr_state_btn = BTN_WAVE;
_app_data->isButtonChange = 1;
_app_data->isGraphChange = 1;
_app_data->isValueChange = 1;
}
static void _moveToLeftFocusFreqNumber(void)
{
_app_data->freq_focus_digit += 1;
_app_data->isValueChange = 1;
_blockFocusAtMaxAndMin();
_app_data->timer_blink[last_key] = 2;
_app_data->isButtonBlink |= (1 << last_key);
}
static void _moveToRighttFocusFreqNumber(void)
{
_app_data->freq_focus_digit -= 1;
_app_data->isValueChange = 1;
_blockFocusAtMaxAndMin();
_app_data->timer_blink[last_key] = 2;
_app_data->isButtonBlink |= (1 << last_key);
}
static void _setTo0_01xFocusNumber(void)
{
switch (_app_data->curr_state_lay)
{
case LAY_AMPL:
_app_data->ampl_focus_digit = 1;
break;
case LAY_OFFS:
_app_data->offs_focus_digit = 1;
break;
default:
break;
}
_app_data->timer_blink[last_key] = 2;
_app_data->isButtonBlink |= (1 << last_key);
}
static void _setTo0_1xFocusNumber(void)
{
switch (_app_data->curr_state_lay)
{
case LAY_AMPL:
_app_data->ampl_focus_digit = 10;
break;
case LAY_OFFS:
_app_data->offs_focus_digit = 10;
break;
default:
break;
}
_app_data->timer_blink[last_key] = 2;
_app_data->isButtonBlink |= (1 << last_key);
}
static void _setTo1xFocusNumber(void)
{
switch (_app_data->curr_state_lay)
{
case LAY_AMPL:
_app_data->ampl_focus_digit = 10;
break;
case LAY_OFFS:
_app_data->offs_focus_digit = 10;
break;
case LAY_PHAS:
_app_data->offs_focus_digit = 1;
break;
case LAY_DUTY:
_app_data->offs_focus_digit = 1;
break;
default:
break;
}
_app_data->timer_blink[last_key] = 2;
_app_data->isButtonBlink |= (1 << last_key);
}
static void _setTo10xFocusNumber(void)
{
switch (_app_data->curr_state_lay)
{
case LAY_AMPL:
_app_data->ampl_focus_digit = 100;
break;
case LAY_OFFS:
_app_data->offs_focus_digit = 100;
break;
case LAY_PHAS:
_app_data->offs_focus_digit = 10;
break;
case LAY_DUTY:
_app_data->offs_focus_digit = 10;
break;
default:
break;
}
_app_data->timer_blink[last_key] = 2;
_app_data->isButtonBlink |= (1 << last_key);
}
static const CMD_button_t btn_command[BTN_STATE_MAX][DISP_BTN_MAX] = {
{
// BTN_MAIN_FG
{_enterToFreqLayout, BITMAP_BTN_FREQ},
{_enterToAmplLayout, BITMAP_BTN_AMPL},
{_enterToOffslLayout, BITMAP_BTN_OFFS},
{_enterToPhasLayout, BITMAP_BTN_PHAS},
{_enterToWavelLayout, BITMAP_BTN_WAVE},
},
{
// BTN_MAIN_PWM
{_enterToFreqLayout, BITMAP_BTN_FREQ},
{_enterToAmplLayout, BITMAP_BTN_AMPL},
{_enterToOffslLayout, BITMAP_BTN_OFFS},
{_enterToPhasLayout, BITMAP_BTN_PHAS},
{_enterToDutyLayout, BITMAP_BTN_NONE},
},
{
// BTN_FREQ
{_moveToLeftFocusFreqNumber, BITMAP_BTN_LEFT},
{_moveToRighttFocusFreqNumber, BITMAP_BTN_RIGHT},
{_doNoting, BITMAP_BTN_NONE},
{_doNoting, BITMAP_BTN_NONE},
{_backToMain, BITMAP_BTN_BACK},
},
{
// BTN_FREQ_MIN
{_moveToLeftFocusFreqNumber, BITMAP_BTN_LEFT},
{_doNoting, BITMAP_BTN_EMPTY},
{_doNoting, BITMAP_BTN_NONE},
{_doNoting, BITMAP_BTN_NONE},
{_backToMain, BITMAP_BTN_BACK},
},
{
// BTN_FREQ_MAX
{_doNoting, BITMAP_BTN_EMPTY},
{_moveToRighttFocusFreqNumber, BITMAP_BTN_RIGHT},
{_doNoting, BITMAP_BTN_NONE},
{_doNoting, BITMAP_BTN_NONE},
{_backToMain, BITMAP_BTN_BACK},
},
{
// BTN_AMPL
{_setTo1xFocusNumber, BITMAP_BTN_X1},
{_setTo0_1xFocusNumber, BITMAP_BTN_X0_1},
{_setTo0_01xFocusNumber, BITMAP_BTN_X0_01},
{_doNoting, BITMAP_BTN_NONE},
{_backToMain, BITMAP_BTN_BACK},
},
{
// BTN_OFFS
{_setTo1xFocusNumber, BITMAP_BTN_X1},
{_setTo0_1xFocusNumber, BITMAP_BTN_X0_1},
{_setTo0_01xFocusNumber, BITMAP_BTN_X0_01},
{_doNoting, BITMAP_BTN_NONE},
{_backToMain, BITMAP_BTN_BACK},
},
{
// BTN_PHAS
{_setTo10xFocusNumber, BITMAP_BTN_X10},
{_setTo1xFocusNumber, BITMAP_BTN_X1},
{_doNoting, BITMAP_BTN_NONE},
{_doNoting, BITMAP_BTN_NONE},
{_backToMain, BITMAP_BTN_BACK},
},
{
// BTN_DUTY
{_setTo10xFocusNumber, BITMAP_BTN_X10},
{_setTo1xFocusNumber, BITMAP_BTN_X1},
{_doNoting, BITMAP_BTN_NONE},
{_doNoting, BITMAP_BTN_NONE},
{_backToMain, BITMAP_BTN_BACK},
},
{
// BTN_WAVE
{_doNoting, BITMAP_BTN_NONE},
{_doNoting, BITMAP_BTN_NONE},
{_doNoting, BITMAP_BTN_NONE},
{_doNoting, BITMAP_BTN_NONE},
{_backToMain, BITMAP_BTN_BACK},
},
};

View File

@@ -1,6 +1,7 @@
#pragma once
#include "disp_layout_types.h"
#include "hw_button.h"
#include "bitmap_disp_buttons.h"
#include "ctrl_app_types.h"
typedef struct
{
@@ -23,30 +24,12 @@ typedef struct
uint8_t connected;
} GEN_fg_t;
typedef enum
{
GEN_FG_TYPE,
GEN_PWM_TYPE,
GEN_TYPE_MAX
} GEN_type_t;
typedef struct
{
GEN_type_t gen_type;
void *gen;
void *const gen;
} GENERATOR_t;
typedef enum
{
CHANNEL1,
CHANNEL2,
CHANNEL3,
CHANNEL4,
CHANNEL5,
CHANNEL6,
CHANNEL_MAX
} GEN_channel_t;
typedef struct
{
uint8_t freq_focus_digit;
@@ -55,16 +38,25 @@ typedef struct
uint8_t phas_focus_digit;
uint8_t duty_focus_digit;
GEN_type_t gen_type;
GEN_type_t curr_gen_type;
void *generator;
GEN_channel_t curr_channel;
LAY_state_t curr_layout;
STATE_layout_t curr_state_lay;
STATE_button_t curr_state_btn;
uint8_t isChannelChange;
uint8_t isGraphChange;
uint8_t isValueChange;
uint8_t isButtonChange;
uint8_t isButtonBlink;
uint8_t timer_blink[LAY_BTN_MAX];
uint8_t timer_blink[DISP_BTN_MAX];
} APP_data_t;
void APP_init(APP_data_t *app_data);
void CTRL_buttonsInit(void);
void CTRL_buttonsHandler(void);
void CTRL_pushedDispBtnEvent(ButtonKey_t *key);
void CTRL_pushedChanBtnEvent(ButtonKey_t *key);
BITMAP_buttonName_t CTRL_getBitmapName(LAY_dispBtn_t disp_btn);

View File

@@ -0,0 +1,56 @@
#pragma once
typedef enum
{
GEN_FG_TYPE,
GEN_PWM_TYPE,
GEN_TYPE_MAX
} GEN_type_t;
typedef enum
{
CHANNEL1,
CHANNEL2,
CHANNEL3,
CHANNEL4,
CHANNEL5,
CHANNEL6,
CHANNEL_MAX
} GEN_channel_t;
typedef enum
{
LAY_MAIN,
LAY_FREQ,
LAY_AMPL,
LAY_OFFS,
LAY_PHAS,
LAY_DUTY,
LAY_WAVE,
LAY_STATE_MAX
} STATE_layout_t;
typedef enum
{
BTN_MAIN_FG,
BTN_MAIN_PWM,
BTN_FREQ,
BTN_FREQ_MIN,
BTN_FREQ_MAX,
BTN_AMPL,
BTN_OFFS,
BTN_PHAS,
BTN_DUTY,
BTN_WAVE,
BTN_STATE_MAX
} STATE_button_t;
typedef enum
{
DISP_BTN_1,
DISP_BTN_2,
DISP_BTN_3,
DISP_BTN_4,
DISP_BTN_5,
DISP_BTN_MAX,
} LAY_dispBtn_t;

View File

@@ -1,7 +1,6 @@
#include "main.h"
#include "config.h"
#include "hw_button.h"
#include "ctrl_button.h"
// #include "ctrl_app.h"
#include "ctrl_bottom_button.h"
static ButtonKey_t bottom_buttons[BTN_BOT_MAX];
@@ -53,4 +52,9 @@ void CTRL_bottomButtonsHandler(void)
{
buttonHandler(&bottom_buttons[btn_key]);
}
}
__weak void CTRL_pushedDispBtnEvent(ButtonKey_t *key)
{
UNUSED(key);
}

View File

@@ -11,4 +11,5 @@ typedef enum
} HW_BotBtnName_t;
void CTRL_bottomButtonInit(void);
void CTRL_bottomButtonsHandler(void);
void CTRL_bottomButtonsHandler(void);
void CTRL_pushedDispBtnEvent(ButtonKey_t *key);

View File

@@ -1,47 +1,49 @@
#include "main.h"
#include "config.h"
#include "hw_button.h"
#include "ctrl_button.h"
#include "ctrl_channel_button.h"
#define DUMMY_GPIO_Port GPIOA
#define DUMMY_GPIO_Pin GPIO_PIN_0
static ButtonKey_t channel_buttons[BTN_CH_MAX];
void CTRL_channelButtonInit(void)
{
channel_buttons[BTN_CH_1].instance = BTN_CH_1;
channel_buttons[BTN_CH_1].buttonPressed = CTRL_pushedChanBtnEvent;
channel_buttons[BTN_CH_1].gpio_port = BTN1_GPIO_Port;
channel_buttons[BTN_CH_1].gpio_pin = BTN1_Pin;
channel_buttons[BTN_CH_1].gpio_port = DUMMY_GPIO_Port;
channel_buttons[BTN_CH_1].gpio_pin = DUMMY_GPIO_Pin;
channel_buttons[BTN_CH_1].pushed_state = GPIO_PIN_SET;
channel_buttons[BTN_CH_2].instance = BTN_CH_2;
channel_buttons[BTN_CH_2].buttonPressed = CTRL_pushedChanBtnEvent;
channel_buttons[BTN_CH_2].gpio_port = BTN2_GPIO_Port;
channel_buttons[BTN_CH_2].gpio_pin = BTN2_Pin;
channel_buttons[BTN_CH_2].gpio_port = DUMMY_GPIO_Port;
channel_buttons[BTN_CH_2].gpio_pin = DUMMY_GPIO_Pin;
channel_buttons[BTN_CH_2].pushed_state = GPIO_PIN_SET;
channel_buttons[BTN_CH_3].instance = BTN_CH_3;
channel_buttons[BTN_CH_3].buttonPressed = CTRL_pushedChanBtnEvent;
channel_buttons[BTN_CH_3].gpio_port = BTN3_GPIO_Port;
channel_buttons[BTN_CH_3].gpio_pin = BTN3_Pin;
channel_buttons[BTN_CH_3].gpio_port = DUMMY_GPIO_Port;
channel_buttons[BTN_CH_3].gpio_pin = DUMMY_GPIO_Pin;
channel_buttons[BTN_CH_3].pushed_state = GPIO_PIN_SET;
channel_buttons[BTN_CH_4].instance = BTN_CH_4;
channel_buttons[BTN_CH_4].buttonPressed = CTRL_pushedChanBtnEvent;
channel_buttons[BTN_CH_4].gpio_port = BTN4_GPIO_Port;
channel_buttons[BTN_CH_4].gpio_pin = BTN4_Pin;
channel_buttons[BTN_CH_4].gpio_port = DUMMY_GPIO_Port;
channel_buttons[BTN_CH_4].gpio_pin = DUMMY_GPIO_Pin;
channel_buttons[BTN_CH_4].pushed_state = GPIO_PIN_SET;
channel_buttons[BTN_CH_5].instance = BTN_CH_5;
channel_buttons[BTN_CH_5].buttonPressed = CTRL_pushedChanBtnEvent;
channel_buttons[BTN_CH_5].gpio_port = BTN5_GPIO_Port;
channel_buttons[BTN_CH_5].gpio_pin = BTN5_Pin;
channel_buttons[BTN_CH_5].gpio_port = DUMMY_GPIO_Port;
channel_buttons[BTN_CH_5].gpio_pin = DUMMY_GPIO_Pin;
channel_buttons[BTN_CH_5].pushed_state = GPIO_PIN_SET;
channel_buttons[BTN_CH_6].instance = BTN_CH_6;
channel_buttons[BTN_CH_6].buttonPressed = CTRL_pushedChanBtnEvent;
channel_buttons[BTN_CH_6].gpio_port = BTN5_GPIO_Port;
channel_buttons[BTN_CH_6].gpio_pin = BTN5_Pin;
channel_buttons[BTN_CH_6].gpio_port = DUMMY_GPIO_Port;
channel_buttons[BTN_CH_6].gpio_pin = DUMMY_GPIO_Pin;
channel_buttons[BTN_CH_6].pushed_state = GPIO_PIN_SET;
for (HW_chanBtnName_t btn_key = BTN_CH_1; btn_key < BTN_CH_MAX; btn_key++)