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>
84 lines
2.3 KiB
Django/Jinja
84 lines
2.3 KiB
Django/Jinja
//
|
|
// WARNING: DO NOT EDIT THIS FILE
|
|
// This file has been generated from the target's JSON hardware description
|
|
//
|
|
|
|
{% set regular_switches = switches | selectattr('type','!=','FSWITCH') | list %}
|
|
{% set function_switches = switches | selectattr('type','==','FSWITCH') | list %}
|
|
|
|
static const stm32_switch_t _switch_defs[] = {
|
|
{% for switch in regular_switches %}
|
|
{% if switch.type == '2POS' %}
|
|
{
|
|
"{{ switch.name }}",
|
|
{{ switch.gpio }}, {{ switch.pin }},
|
|
nullptr, 0,
|
|
SWITCH_HW_2POS, {{ 'SWITCH_HW_INVERTED' if switch.inverted else 0 }}
|
|
},
|
|
{% elif switch.type == '3POS' %}
|
|
{
|
|
"{{ switch.name }}",
|
|
{{ switch.gpio_high }}, {{ switch.pin_high }},
|
|
{{ switch.gpio_low }}, {{ switch.pin_low }},
|
|
SWITCH_HW_3POS, {{ 'SWITCH_HW_INVERTED' if switch.inverted else 0 }}
|
|
},
|
|
{% elif switch.type == 'ADC' %}
|
|
{
|
|
"{{ switch.name }}",
|
|
nullptr, {{ adc_index[switch.adc_input] }},
|
|
nullptr, 0,
|
|
SWITCH_HW_ADC, {{ 'SWITCH_HW_INVERTED' if switch.inverted else 0 }}
|
|
},
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% for switch in function_switches %}
|
|
{
|
|
"{{ switch.name }}",
|
|
{{ switch.gpio }}, {{ switch.pin }},
|
|
nullptr, 0,
|
|
SWITCH_HW_2POS, {{ 'SWITCH_HW_INVERTED' if switch.inverted else 0 }}
|
|
},
|
|
{% endfor %}
|
|
};
|
|
|
|
static const stm32_switch_t* const _switch_offsets[] = {
|
|
_switch_defs,
|
|
{% if function_switches %}
|
|
_switch_defs + {{ regular_switches | count }},
|
|
{% endif %}
|
|
};
|
|
|
|
static inline void _init_switches()
|
|
{
|
|
LL_GPIO_InitTypeDef pinInit;
|
|
LL_GPIO_StructInit(&pinInit);
|
|
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
|
pinInit.Pull = LL_GPIO_PULL_UP;
|
|
{% for sw_gpio, pins in switch_gpios.items() | sort %}
|
|
stm32_gpio_enable_clock({{ sw_gpio }});
|
|
pinInit.Pin = {{ pins | join('|') }};
|
|
LL_GPIO_Init({{ sw_gpio }}, &pinInit);
|
|
{% endfor %}
|
|
}
|
|
|
|
constexpr uint8_t n_switches = {{ regular_switches | count }};
|
|
constexpr uint8_t n_fct_switches = {{ function_switches | count }};
|
|
|
|
constexpr swconfig_t _switch_default_config = (swconfig_t)0
|
|
{% for sw in regular_switches %}
|
|
{% if sw.default %}
|
|
| ((swconfig_t)SWITCH_{{ sw.default }} << ({{ loop.index0 }} * SW_CFG_BITS))
|
|
{% endif %}
|
|
{% endfor %}
|
|
;
|
|
|
|
const switch_display_pos_t _switch_display[] = {
|
|
{% for sw in regular_switches %}
|
|
{% if sw.display %}
|
|
{ {{ sw.display[0] }}, {{ sw.display[1] }} },
|
|
{% else %}
|
|
{ 0, 0 },
|
|
{% endif %}
|
|
{% endfor %}
|
|
};
|