feat: More flexible ADC inputs (#3870)

Co-authored-by: 3djc <lesitewebdejc@hotmail.com>
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
This commit is contained in:
Raphael Coeffic
2023-11-02 11:07:53 +10:00
committed by GitHub
co-authored by 3djc Peter Feerick philmoz
parent f5593c44e8
commit b48e07026d
78 changed files with 1291 additions and 773 deletions
+20 -65
View File
@@ -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]);
}
const char* boardSwitchGetName(uint8_t cat, uint8_t idx)
{
return _switch_offsets[cat][idx].name;
}
SwitchHwType boardSwitchGetType(uint8_t cat, uint8_t idx)
{
return _switch_offsets[cat][idx].type;
}
uint8_t boardGetMaxSwitches() { return n_switches; }
uint8_t boardGetMaxFctSwitches() { return n_fct_switches; }
swconfig_t boardSwitchGetDefaultConfig() { return _switch_default_config; }
switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
{
if (idx >= DIM(_switch_display))
return {0, 0};
// TODO: find a solution for FLEX switches so they can be displayed on main view
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)
{
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;
}
uint8_t switchGetMaxFctSwitches()
{
return n_fct_switches;
}
// 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);
}
SwitchHwPos switchGetPosition(uint8_t idx)
{
if (idx >= n_total_switches) return SWITCH_HW_UP;
return stm32_switch_get_position(&_switch_defs[idx]);
}
const char* switchGetName(uint8_t idx)
{
if (idx >= n_total_switches) return "";
return _switch_defs[idx].name;
}
SwitchHwType switchGetHwType(uint8_t idx)
{
if (idx >= n_total_switches) return SWITCH_HW_2POS;
return _switch_defs[idx].type;
}