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
@@ -22,72 +22,6 @@
#include "stm32_switch_driver.h"
#include "hal/adc_driver.h"
bool stm32_switch_get_state(const stm32_switch_t* sw, SwitchHwPos pos)
{
switch (sw->type) {
case SWITCH_HW_2POS:
switch (pos) {
case SWITCH_HW_UP:
if (sw->flags & SWITCH_HW_INVERTED)
return !LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
else
return LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
case SWITCH_HW_DOWN:
if (sw->flags & SWITCH_HW_INVERTED)
return LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
else
return !LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
default:
return false;
}
break;
case SWITCH_HW_3POS: {
auto hi = LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
auto lo = LL_GPIO_IsInputPinSet(sw->GPIOx_low, sw->Pin_low);
switch (pos) {
case SWITCH_HW_UP:
if (sw->flags & SWITCH_HW_INVERTED)
return !hi && lo;
else
return hi && !lo;
case SWITCH_HW_DOWN:
if (sw->flags & SWITCH_HW_INVERTED)
return hi && !lo;
else
return !hi && lo;
case SWITCH_HW_MID:
return hi && lo;
default:
return false;
}
} break;
case SWITCH_HW_ADC: {
uint16_t value = getAnalogValue(sw->Pin_high);
switch (pos) {
case SWITCH_HW_UP:
return value < 1024;
case SWITCH_HW_DOWN:
return value > 3 * 1024;
case SWITCH_HW_MID:
return (value >= 1024) && (value <= 3 * 1024);
}
} break;
default:
break;
}
return false;
}
SwitchHwPos stm32_switch_get_position(const stm32_switch_t* sw)
{
bool inv = sw->flags & SWITCH_HW_INVERTED;