fix: Use keysGetMaxTrims() instead of MAX_TRIMS (#3860)
* fix: use keysGetMaxTrims() instead of MAX_TRIMS * feat: add support for virtual trims This is necessary for radios like X-lite where half of the trims are simulated
This commit is contained in:
@@ -68,9 +68,10 @@ class Trim:
|
||||
|
||||
def __init__(self, name, dec, inc):
|
||||
self.name = name
|
||||
self.dec = dec
|
||||
self.inc = inc
|
||||
self.active_low = True
|
||||
if dec and dec.gpio and inc and inc.gpio:
|
||||
self.dec = dec
|
||||
self.inc = inc
|
||||
self.active_low = True
|
||||
|
||||
def get_trim_switch(hw_defs, tag):
|
||||
|
||||
@@ -98,6 +99,11 @@ def parse_trims(hw_defs):
|
||||
if dec and inc:
|
||||
trims.append(Trim(name, dec, inc))
|
||||
|
||||
elif t.get('input'):
|
||||
input = t['input']
|
||||
if f'TRIMS_VIRTUAL_{input}' in hw_defs:
|
||||
trims.append(Trim(name, None, None))
|
||||
|
||||
return trims
|
||||
|
||||
|
||||
|
||||
@@ -66,13 +66,19 @@ def build_switch_gpio_port_index(switches):
|
||||
def build_trim_gpio_port_index(trims):
|
||||
|
||||
def index_contact(gpios, contact):
|
||||
append_to_index(gpios, contact['gpio'], contact['pin'])
|
||||
gpio = contact['gpio']
|
||||
pin = contact['pin']
|
||||
if gpio and pin:
|
||||
append_to_index(gpios, contact['gpio'], contact['pin'])
|
||||
|
||||
i = 0
|
||||
gpios = {}
|
||||
for trim in trims:
|
||||
index_contact(gpios, trim['dec'])
|
||||
index_contact(gpios, trim['inc'])
|
||||
dec = trim.get('dec')
|
||||
inc = trim.get('inc')
|
||||
if dec and inc:
|
||||
index_contact(gpios, dec)
|
||||
index_contact(gpios, inc)
|
||||
|
||||
return gpios
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ static inline uint32_t _read_keys()
|
||||
return keys;
|
||||
}
|
||||
|
||||
{% set hw_trims = trims | selectattr('dec', 'defined') | selectattr('inc', 'defined') | list %}
|
||||
static inline void _init_trims()
|
||||
{
|
||||
{% for trim_gpio, pins in trim_gpios | dictsort %}
|
||||
@@ -36,7 +37,7 @@ static inline void _init_trims()
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
{% for trim in trims %}
|
||||
{% for trim in hw_trims %}
|
||||
pinInit.Pin = {{ trim.dec.pin }};
|
||||
pinInit.Pull = {{ 'LL_GPIO_PULL_UP' if trim.dec.active_low else 'LL_GPIO_PULL_DOWN' }};
|
||||
LL_GPIO_Init({{ trim.dec.gpio }}, &pinInit);
|
||||
@@ -49,7 +50,7 @@ static inline void _init_trims()
|
||||
static inline uint32_t _read_trims()
|
||||
{
|
||||
uint32_t trims = 0;
|
||||
{% for trim in trims %}
|
||||
{% for trim in hw_trims %}
|
||||
if ({{'!' if trim.dec.active_low }}LL_GPIO_IsInputPinSet({{ trim.dec.gpio }}, {{ trim.dec.pin }}))
|
||||
trims |= (1 << {{ loop.index0 * 2 }});
|
||||
if ({{'!' if trim.inc.active_low }}LL_GPIO_IsInputPinSet({{ trim.inc.gpio }}, {{ trim.inc.pin }}))
|
||||
|
||||
Reference in New Issue
Block a user