Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more flexible ADC inputs #3870

Merged
merged 35 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c9fb1f3
feat: flex ADC input
raphaelcoeffic Jul 28, 2023
1dbb438
feat: add some checks around flex swicthes for colorlcd
3djc Aug 5, 2023
4f2b6de
flex switches: some color UI improvements
3djc Aug 5, 2023
89eeec6
feat: add BW UI
3djc Aug 5, 2023
d77c734
Cleanup
raphaelcoeffic Aug 5, 2023
b669aae
fix: flex switch channel offset
raphaelcoeffic Aug 6, 2023
f018585
Draft UI for POT inversion (NOT working, need YAML fixed)
3djc Aug 7, 2023
2a608bf
FIx
3djc Aug 7, 2023
6dd1ecc
Tweak color UI
raphaelcoeffic Aug 8, 2023
c49df8d
Persist pot inversion storage
raphaelcoeffic Aug 8, 2023
f9b2080
Diag analogs: display all flex inputs
raphaelcoeffic Aug 8, 2023
c2226fc
Apply ADC filter setting only on main controls
raphaelcoeffic Aug 8, 2023
9ad1e07
Implement configurable inversion on flex inputs
raphaelcoeffic Aug 8, 2023
c4dcf4e
fix: do not display FLEX switch on mainView until switchGetDisplayPos…
3djc Aug 8, 2023
e5b59c4
fix: diag keys screen layout
3djc Aug 8, 2023
1906cc5
refactor: apply ADC calibration before everything else
raphaelcoeffic Aug 8, 2023
9f76992
fix: value scoping while applying calibration
raphaelcoeffic Aug 8, 2023
a25f62d
fix: NV14 diag keys
raphaelcoeffic Aug 8, 2023
b3f0a18
Add default calibration
raphaelcoeffic Aug 9, 2023
d6b09ab
Fix inversion and some cleanup
raphaelcoeffic Aug 9, 2023
8b9989a
fix: compute mid value for all inputs without a defined center
raphaelcoeffic Aug 9, 2023
7e5f9f0
fix: use default calibration on brand new config as well
raphaelcoeffic Aug 9, 2023
9b11070
fix: flex switch unit tests
raphaelcoeffic Aug 9, 2023
050a72d
fix: legacy import
3djc Aug 9, 2023
8fe6a0e
fix: typo (thx @elecpower)
3djc Aug 10, 2023
b43a880
Fix POCKET pot definition
raphaelcoeffic Sep 3, 2023
e156748
Fix model data size checks
raphaelcoeffic Sep 29, 2023
cd05596
Fix NV14 / EL18
raphaelcoeffic Sep 29, 2023
e48a9a9
fix: Think should now be `ADC_INPUT_FLEX`
pfeerick Oct 27, 2023
a51f183
Fix portrait layout.
Oct 30, 2023
74708fd
fix: Audio MULTIPOS test
pfeerick Oct 30, 2023
740ee00
fix: Seems like wrong header name
pfeerick Oct 30, 2023
3eef459
fix: portrait still had a couple pixels of scroll
pfeerick Oct 30, 2023
5dab732
fix: alignment issue (thanks @raphaelcoeffic)
pfeerick Nov 1, 2023
bf394f3
chore: Formatting
pfeerick Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 14 additions & 59 deletions radio/src/boards/generic_stm32/switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,80 +32,35 @@

#include <stdlib.h>

void switchInit()
void boardInitSwitches()
{
_init_switches();
}

swconfig_t switchGetDefaultConfig()
SwitchHwPos boardSwitchGetPosition(uint8_t cat, uint8_t idx)
{
return _switch_default_config;
return stm32_switch_get_position(&_switch_offsets[cat][idx]);
}

switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
{
if (idx >= DIM(_switch_display))
return {0, 0};

return _switch_display[idx];
}

uint8_t switchGetMaxSwitches()
{
return n_switches;
}

uint8_t getSwitchCount()
{
int count = 0;
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
if (SWITCH_EXISTS(i)) {
++count;
}
}
return count;
}

uint8_t switchGetMaxRow(uint8_t col)
const char* boardSwitchGetName(uint8_t cat, uint8_t idx)
{
uint8_t lastrow = 0;
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
if (SWITCH_EXISTS(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (switch_display.col == col)
lastrow = switch_display.row > lastrow ? switch_display.row : lastrow;
}
}
return lastrow;
return _switch_offsets[cat][idx].name;
}

uint8_t switchGetMaxFctSwitches()
SwitchHwType boardSwitchGetType(uint8_t cat, uint8_t idx)
{
return n_fct_switches;
return _switch_offsets[cat][idx].type;
}

// returns state (0 / 1) of a specific switch position
uint32_t switchState(uint8_t pos_idx)
{
auto d = div(pos_idx, 3);
if (d.quot >= n_total_switches) return 0;
return stm32_switch_get_state(&_switch_defs[d.quot], (SwitchHwPos)d.rem);
}
uint8_t boardGetMaxSwitches() { return n_switches; }
uint8_t boardGetMaxFctSwitches() { return n_fct_switches; }

SwitchHwPos switchGetPosition(uint8_t idx)
{
if (idx >= n_total_switches) return SWITCH_HW_UP;
return stm32_switch_get_position(&_switch_defs[idx]);
}
swconfig_t boardSwitchGetDefaultConfig() { return _switch_default_config; }

const char* switchGetName(uint8_t idx)
switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
{
if (idx >= n_total_switches) return "";
return _switch_defs[idx].name;
}
// TODO: find a solution for FLEX switches so they can be displayed on main view
if (idx >= DIM(_switch_display)) return {0, 0};

SwitchHwType switchGetHwType(uint8_t idx)
{
if (idx >= n_total_switches) return SWITCH_HW_2POS;
return _switch_defs[idx].type;
return _switch_display[idx];
}
16 changes: 7 additions & 9 deletions radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,22 @@ enum PotsWarnMode {

#if defined(COLORLCD)
#define MAX_POTS 16
#define MAX_AXIS 2
#else
#define MAX_POTS 8
#define MAX_AXIS 0
#endif

#define MAX_VBAT 1
#define MAX_RTC_BAT 1

#define MAX_ANALOG_INPUTS (MAX_STICKS + MAX_POTS + MAX_AXIS + MAX_VBAT + MAX_RTC_BAT)
#define MAX_CALIB_ANALOG_INPUTS (MAX_STICKS + MAX_POTS + MAX_AXIS)
#define MAX_ANALOG_INPUTS (MAX_STICKS + MAX_POTS + MAX_VBAT + MAX_RTC_BAT)
#define MAX_CALIB_ANALOG_INPUTS (MAX_STICKS + MAX_POTS)

#define MAX_SWITCHES 20

#if !defined(MAX_FLEX_SWITCHES)
#define MAX_FLEX_SWITCHES 0
#endif

#if defined(RADIO_T20)
#define MAX_TRIMS 8
#else
Expand Down Expand Up @@ -482,11 +485,6 @@ enum MixSources {
MIXSRC_FIRST_POT SKIP,
MIXSRC_LAST_POT SKIP = MIXSRC_FIRST_POT + MAX_POTS - 1,

#if MAX_AXIS > 0
MIXSRC_FIRST_AXIS SKIP,
MIXSRC_LAST_AXIS SKIP = MIXSRC_FIRST_AXIS + MAX_AXIS - 1,
#endif

#if defined(IMU)
MIXSRC_TILT_X,
MIXSRC_TILT_Y,
Expand Down
6 changes: 3 additions & 3 deletions radio/src/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ static inline void check_struct()
CHKSIZE(ModelData, 6706);
#elif defined(PCBHORUS)
#if defined(PCBX10)
CHKSIZE(RadioData, 848);
CHKSIZE(RadioData, 836);
CHKSIZE(ModelData, 15607);
#else
CHKSIZE(RadioData, 848);
CHKSIZE(RadioData, 836);
CHKSIZE(ModelData, 15607);
#endif
#elif defined(PCBNV14)
CHKSIZE(RadioData, 848);
CHKSIZE(RadioData, 836);
CHKSIZE(ModelData, 15463);
#endif

Expand Down
1 change: 1 addition & 0 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ PACK(struct RadioData {
CUST_ARRAY(slidersConfig, struct_sliderConfig, MAX_POTS, nullptr);
potconfig_t potsConfig ARRAY(4,struct_potConfig,nullptr);
swconfig_t switchConfig ARRAY(2,struct_switchConfig,nullptr);
CUST_ARRAY(flexSwitches, struct_flexSwitch, MAX_FLEX_SWITCHES, flex_sw_valid);

EXTRA_GENERAL_FIELDS

Expand Down
12 changes: 6 additions & 6 deletions radio/src/gui/128x64/model_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ inline uint8_t TIMER_ROW(uint8_t timer, uint8_t value)
return HIDDEN_ROW;
}

#define POT_WARN_ROWS PREFLIGHT_ROW(((g_model.potsWarnMode) ? adcGetMaxInputs(ADC_INPUT_POT) : (uint8_t)0))
#define POT_WARN_ROWS PREFLIGHT_ROW(((g_model.potsWarnMode) ? adcGetMaxInputs(ADC_INPUT_FLEX) : (uint8_t)0))

#define TIMER_ROWS(x) \
1, TIMER_ROW(x,0), \
Expand Down Expand Up @@ -592,7 +592,7 @@ void menuModelSetup(event_t event)
PREFLIGHT_ROW(0), // Custom position for throttle warning value
WARN_ROWS

uint8_t(NAVIGATION_LINE_BY_LINE | (adcGetInputOffset(ADC_INPUT_POT + 1) - 1)), // Center beeps
uint8_t(NAVIGATION_LINE_BY_LINE | (adcGetInputOffset(ADC_INPUT_FLEX + 1) - 1)), // Center beeps

0, // ADC Jitter filter

Expand Down Expand Up @@ -899,7 +899,7 @@ void menuModelSetup(event_t event)
if (attr)
CHECK_INCDEC_MODELVAR_ZERO_CHECK(
event, g_model.thrTraceSrc,
adcGetMaxInputs(ADC_INPUT_POT) + MAX_OUTPUT_CHANNELS,
adcGetMaxInputs(ADC_INPUT_FLEX) + MAX_OUTPUT_CHANNELS,
isThrottleSourceAvailable);

uint8_t idx = throttleSource2Source(g_model.thrTraceSrc);
Expand Down Expand Up @@ -1078,7 +1078,7 @@ void menuModelSetup(event_t event)
}
if (g_model.potsWarnMode) {
coord_t x = MODEL_SETUP_2ND_COLUMN+28;
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
for (int i = 0; i < max_pots; ++i) {

if (!IS_POT_SLIDER_AVAILABLE(i)) {
Expand All @@ -1092,7 +1092,7 @@ void menuModelSetup(event_t event)
flags |= INVERS;
}
if (max_pots > 3) {
lcdDrawText(x, y, getAnalogShortLabel(adcGetInputOffset(ADC_INPUT_POT) + i), flags);
lcdDrawText(x, y, getAnalogShortLabel(adcGetInputOffset(ADC_INPUT_FLEX) + i), flags);
x = lcdNextPos + 1;
}
else {
Expand All @@ -1106,7 +1106,7 @@ void menuModelSetup(event_t event)

case ITEM_MODEL_SETUP_BEEP_CENTER: {
lcdDrawTextAlignedLeft(y, STR_BEEPCTR);
uint8_t input_max = adcGetMaxInputs(ADC_INPUT_MAIN) + adcGetMaxInputs(ADC_INPUT_POT);
uint8_t input_max = adcGetMaxInputs(ADC_INPUT_MAIN) + adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < input_max; i++) {
coord_t x = MODEL_SETUP_2ND_COLUMN + i*FW;
LcdFlags flags = 0;
Expand Down
10 changes: 5 additions & 5 deletions radio/src/gui/128x64/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void drawExternalAntennaAndRSSI()

void drawPotsBars()
{
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t offset = adcGetInputOffset(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
uint8_t offset = adcGetInputOffset(ADC_INPUT_FLEX);
uint8_t configured_pots = 0;

for (uint8_t i = 0; i < max_pots; i++) {
Expand Down Expand Up @@ -567,14 +567,14 @@ void menuMainView(event_t event)
uint8_t configured_switches = 0;

for (uint8_t i = 0; i < switches; i++) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
configured_switches ++;
}
}

if (configured_switches < 9) {
for (int i = 0; i < switches; ++i) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (switch_display.row >= 3) {
drawSmallSwitch(switch_display.col == 0 ? 28 : 16 * FW + 1,
Expand All @@ -594,7 +594,7 @@ void menuMainView(event_t event)
}
else {
for (int i = 0; i < switches; ++i) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
auto switch_display = switchGetDisplayPosition(i);
coord_t x = (switch_display.col == 0 ? 8 : 96) + switch_display.row * 5;
drawSmallSwitch(x, 5 * FH + 1, 4, i);
Expand Down
10 changes: 5 additions & 5 deletions radio/src/gui/212x64/model_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void menuModelSetup(event_t event)
SW_WARN_ROWS, // ITEM_MODEL_SETUP_SWITCHES_WARNING1
POT_WARN_ROWS, // ITEM_MODEL_SETUP_POTS_WARNING

uint8_t(NAVIGATION_LINE_BY_LINE | (adcGetInputOffset(ADC_INPUT_POT + 1) - 1)), // ITEM_MODEL_SETUP_BEEP_CENTER
uint8_t(NAVIGATION_LINE_BY_LINE | (adcGetInputOffset(ADC_INPUT_FLEX + 1) - 1)), // ITEM_MODEL_SETUP_BEEP_CENTER

0, // ITEM_MODEL_SETUP_USE_JITTER_FILTER

Expand Down Expand Up @@ -977,7 +977,7 @@ void menuModelSetup(event_t event)
}
if (g_model.potsWarnMode) {
coord_t x = MODEL_SETUP_2ND_COLUMN+28;
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
for (int i = 0; i < max_pots; ++i) {

if (!IS_POT_SLIDER_AVAILABLE(i)) {
Expand Down Expand Up @@ -1011,8 +1011,8 @@ void menuModelSetup(event_t event)

case ITEM_MODEL_SETUP_BEEP_CENTER: {
lcdDrawTextAlignedLeft(y, STR_BEEPCTR);
uint8_t pot_offset = adcGetInputOffset(ADC_INPUT_POT);
uint8_t max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN) + adcGetMaxInputs(ADC_INPUT_POT);
uint8_t pot_offset = adcGetInputOffset(ADC_INPUT_FLEX);
uint8_t max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN) + adcGetMaxInputs(ADC_INPUT_FLEX);
coord_t x = MODEL_SETUP_2ND_COLUMN;
for (uint8_t i = 0; i < max_inputs; i++) {
if ( i >= pot_offset && IS_POT_MULTIPOS(i - pot_offset) ) {
Expand All @@ -1024,7 +1024,7 @@ void menuModelSetup(event_t event)
flags = BLINK | INVERS;
else if (ANALOG_CENTER_BEEP(i) || (attr && CURSOR_ON_LINE()))
flags = INVERS;
if (adcGetMaxInputs(ADC_INPUT_POT) > 4 || i < pot_offset) {
if (adcGetMaxInputs(ADC_INPUT_FLEX) > 4 || i < pot_offset) {
lcdDrawText(x, y, getAnalogShortLabel(i), flags);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/212x64/radio_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
void drawPotsBars()
{
// Optimization by Mike Blandford
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t offset = adcGetInputOffset(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
uint8_t offset = adcGetInputOffset(ADC_INPUT_FLEX);

for (uint8_t x = LCD_W / 2 - max_pots / 2 * BAR_SPACING + BAR_SPACING / 2,
i = 0;
Expand Down
8 changes: 4 additions & 4 deletions radio/src/gui/212x64/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ static const coord_t _pot_slots[] = {
void drawSliders()
{
uint8_t slot_idx = 0;
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t offset = adcGetInputOffset(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
uint8_t offset = adcGetInputOffset(ADC_INPUT_FLEX);

for (uint8_t i = 0; i < max_pots; i++) {

Expand Down Expand Up @@ -534,7 +534,7 @@ void menuMainView(event_t event)
uint8_t switches = switchGetMaxSwitches();
if (getSwitchCount() > 16) { // beware, there is a desired col/row swap in this special mode
for (int i = 0; i < switches; ++i) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (g_model.view == VIEW_INPUTS) {
coord_t x = 50 + (switch_display.row % 5) * 4 +
Expand All @@ -552,7 +552,7 @@ void menuMainView(event_t event)
else {
coord_t shiftright = switchGetMaxRow(1) < 4 ? 20 : 0;
for (int i = 0; i < switches; ++i) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (g_model.view == VIEW_INPUTS) {
coord_t x = (switch_display.col == 0 ? 50 : 125) +
Expand Down
Loading