refact: ADC, switches and keys

Add "hardware_defs" target to dump hardware defines from hal.h per target

Fixed hal.h definitions for switches & ADC inputs

Tools to generate hardware definitions from current hal.h

generator: add support for EXTx and analog switches

WiP

Add generated header to hardware_defs target

Add support for ADC input direction and index per GPIO port

Incredible: it compiles

Removed StdPeriph ADC driver

Works on QX7

Works on TX16S (VBat missing)

Switch driver using generated switches for stm32 targets

Switch driver with generated switches for simu

Use switch names from switch driver

Fixed single conversion handling

Fixed horus VBat reading

Added switch name

Fix warnings about bitfield offsets and GCC 4.4

This is caused by bitfields that cross type boundaries. In this particular case, it happens as the bitfield is not defined the same in `rtc_backup.cpp`.

Switches has already been moved to generic driver

Jitter measurement for each sample, not just for oversampled values

Moved periph clock init to the ADC driver

ADC & GPIOs.

Add switchInit() to init pins

Fix NV14 CMake

Fix taranis target

Fix NV14 (again)

Model audio files: use new interface for switch index

Fix X9-lite

Fix simu headers

Fix getSwitchName()

Add support for ADC switches

Fix switch warning YAML

Test only switches which are defined

Conversions tests for QX7 only on QX7

Fix X12S

Fix function switch names

Enable ADC periph clock before initialising channels

NV14: offset inputs for the sticks & fix switches

WiP: get rid of VSRCRAW and some more

Simu shall use normal ADC driver

fix x7

fix nv14

Fix 9x nav

fix 212x64

fix xlite

fix x9e

fix simu lib

fix unit tests

fix x7 tests

PWM stick values should be written directly into adcValues

... just like FlySky sticks.

fix x12s

fix nv14

Add some support for SPI ADC (only unit tests)

Remove `jq` usage

fix generate_yaml.py for newer libclang

fix pot config

fix stick names

Some YAML generator improvements

Max 16 Pots on COLORLCD

Fix some source names

Use 10 bits for switches to prevent overflow

Removed horus constants for switches & ADC inputs

Fix unit tests

Fix curve edit

Fix libsimulator

Fix function switches (tpro)

Refine ADC & analog API

Moved hardware definitions scripts and templates into own dir

cleanup API refine

Fix unit tests

Mixer: apply calibration only on required inputs

Place ADC switches after all other ADC inputs

Fix X12S

Remove useless TR_POTS_VSRCRAW, TR_SW_VSRCRAW, and TR_VSRCRAW

Cleanup redundant generated YAML parsers

Fixes Boxer rebase

Add boxer to generate-hw-defs.sh

Obsolete LUA exports

Add boxer ADC_DIRECTION

Split generate_hw_defs.py into multiple files

Some cleanup (+ LUA switches)

Fix AXIS definitions

Fixed translation strings declarations

Some rebase fixes

Remove some useless StdPeriph drivers

fix: set pin mode to reset state on usart deinit

fix: use canonical names for calibration data

fix: ADC driver does not care about unconfigured inputs

fix X12S ADC

Add support for ADC conversion chaining

Better X12S ADC implem

Moved X12S ADC driver to HAL/LL

Improve ADC driver separation

Fixed taranis & nv14

Moved PWM gimbals to HAL/LL

Removed useless TR_EXTRA_VSRCRAW

Fixed include guards

Small fixes

Renamed control inputs

Moved internal and external module pulse driver def to boards

Move more things to the generic_stm32 board

Remove STR_VMIXTRIMS

Added analog labels

Generate main control names

Misuse labels / short labels for main controls

Backward compatibility: sliders and legacy names

New keys driver

Let's get rid of StdPeriph headers in simu

Add jinja2 to CI workflows

Use `grep` instead of `sed`

chore: add python jinja2 oto msys setup script

Removed more static definitions and use dynamic ones instead

Fixes X9E

Fix x7 nav too

212 switch display

Fix default sliders

Removed NUM_STICKS

212 switch display working nicely

Surface radio 'stick' replacements

fix: switch, trim & rotary pin init

Remove old key drivers

Removed VKEYS

Removed ETX_FOURCC

Fixed SURFACE_NAME

Removed TR_VSWITCHES & TR_TRIMS_SWITCHES

Fix xpot switches

Store calibrated analogs in physical order

Use getSourceString in drawSource

Implement missing YAML read/write

Fix isSourceAvailableInInputs()

Fix isSourceAvailable()

Some surface fixes

Fix CLI debug

Ported colour UI of analog diagnostics to new ADC API

Small fixes

Better input mapping

Minor tpro fixes

Fix trims available

Remove TX mode choice on surface radio

Rename surface controls

Channel order alignement

Fix throttle warning

Fix checkTrims()

Fix pot config casting issue

Fix IS_SWITCH_FS()

Fixed input mapping

Fix fswitch auto-switch

Fixed storing / reading function switches in YAML

Fix enableVBatBridge() / disableVBatBridge()

Fix interesting mode conversion

Fix sources issues

Fix special funnction list

Proper function switch handling

128 GUI improvements

Fix compilation

Boxer cosmetics

128 hardware screen cosmetic

Fix TX12 switches

More switches fixes

Simplify CPU type handling

Fix flash size

Fixed page-up / page-down in libopenui
This commit is contained in:
Raphael Coeffic
2023-06-25 14:32:39 +02:00
committed by Malte Langermann
parent b6dd3a0ef8
commit 2b100e0eb5
323 changed files with 12812 additions and 22301 deletions
+28
View File
@@ -0,0 +1,28 @@
#from os import path
import argparse
from hal_json import parse_defines
from generator import generate_from_template
# def eprint(*args, **kwargs):
# print(*args, file=sys.stderr, **kwargs)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process hardware definitions')
parser.add_argument('filename', metavar='filename', nargs='+')
parser.add_argument('-i', metavar='input', choices=['json','defines'], default='json')
parser.add_argument('-t', metavar='template')
parser.add_argument('-T', metavar='target')
args = parser.parse_args()
if args.i == 'defines':
for filename in args.filename:
parse_defines(filename, args.T)
elif args.i == 'json':
for filename in args.filename:
generate_from_template(filename, args.t, args.T)
+84
View File
@@ -0,0 +1,84 @@
import json
import jinja2
import legacy_names
import json_index
MAIN_CONTROL_LUT = {
# 2 Gimbal radios
"LH": { "str": "Rud", "local": "STR_STICK_NAMES[0]" },
"LV": { "str": "Ele", "local": "STR_STICK_NAMES[1]" },
"RV": { "str": "Thr", "local": "STR_STICK_NAMES[2]" },
"RH": { "str": "Ail", "local": "STR_STICK_NAMES[3]" },
# Surface radios
"ST": { "str": "ST", "local": "STR_SURFACE_NAMES[0]" },
"TH": { "str": "TH", "local": "STR_SURFACE_NAMES[1]" },
}
# MUST be the same order as 'EnumKeys'
KEYS_LUT = [
"KEY_MENU",
"KEY_EXIT",
"KEY_ENTER",
"KEY_PAGE",
"KEY_PAGEUP",
"KEY_PAGEDN",
"KEY_UP",
"KEY_DOWN",
"KEY_LEFT",
"KEY_RIGHT",
"KEY_PLUS",
"KEY_MINUS",
"KEY_MODEL",
"KEY_TELE",
"KEY_SYS",
"KEY_SHIFT",
"KEY_BIND",
]
def generate_from_template(json_filename, template_filename, target):
with open(json_filename) as json_file:
with open(template_filename) as template_file:
root_obj = json.load(json_file)
adc_inputs = root_obj.get('adc_inputs')
adc_index = json_index.build_adc_index(adc_inputs)
adc_gpios = json_index.build_adc_gpio_port_index(adc_inputs)
switches = root_obj.get('switches')
switch_gpios = json_index.build_switch_gpio_port_index(switches)
keys = root_obj.get('keys')
key_gpios = json_index.build_key_gpio_port_index(keys)
trims = root_obj.get('trims')
trim_gpios = json_index.build_trim_gpio_port_index(trims)
legacy_inputs = legacy_names.inputs_by_target(target)
env = jinja2.Environment(
lstrip_blocks=True,
trim_blocks=True
)
template_str = template_file.read()
template = env.from_string(template_str)
print(template.render(root_obj,
adc_index=adc_index,
adc_gpios=adc_gpios,
switch_gpios=switch_gpios,
key_gpios=key_gpios,
trim_gpios=trim_gpios,
legacy_inputs=legacy_inputs,
main_labels=MAIN_CONTROL_LUT,
key_index=KEYS_LUT))
+273
View File
@@ -0,0 +1,273 @@
from pot_config import pot_cfg_by_target
MAX_POTS = 4
MAX_SLIDERS = 4
MAX_EXTS = 4
def eprint(*args, **kwargs):
from sys import stderr
print(*args, file=stderr, **kwargs)
class ADCInput:
TYPE_STICK = 'STICK'
TYPE_POT = 'POT'
TYPE_SWITCH = 'SWITCH'
# TYPE_BATT = 'BATT'
def __init__(self, name, adc_input_type, adc, gpio, pin, channel):
self.name = name
self.type = adc_input_type
self.adc = adc
self.gpio = gpio
self.pin = pin
self.channel = channel
class SPI_ADCInput:
def __init__(self, name, adc_input_type, channel):
self.name = name
self.type = adc_input_type
self.adc = 'SPI'
self.channel = channel
class ADC:
def __init__(self, name, adc):
self.name = name
self.adc = adc
class MouseName:
AXIS = ['x','y']
def format(self, idx):
axis = self.AXIS[idx - 1]
return f'JS{axis}'
def AZ_seq():
return [chr(i) for i in range(ord('A'), ord('Z') + 1)]
class ADCInputParser:
ADC_MAIN = 'MAIN'
ADC_EXT = 'EXT'
ADC_INPUTS = [
{
'range': ['LH','LV','RV','RH','ST','TH'],
'type': ADCInput.TYPE_STICK,
'suffix': 'STICK_{}',
'name': '{}',
},
{
'range': range(1, MAX_POTS + 1),
'type': ADCInput.TYPE_POT,
'suffix': 'POT{}',
'name': 'P{}',
},
{
'range': range(1, MAX_SLIDERS + 1),
'type': ADCInput.TYPE_POT,
'suffix': 'SLIDER{}',
'name': 'SL{}',
},
{
'range': range(1, MAX_EXTS + 1),
'type': ADCInput.TYPE_POT,
'suffix': 'EXT{}',
'name': 'EXT{}',
},
{
'range': range(1, 2 + 1),
'type': 'AXIS',
'suffix': 'MOUSE{}',
'name': MouseName(),
},
{
'type': 'VBAT',
'name': 'VBAT',
'suffix': 'BATT',
},
{
'type': 'RTC_BAT',
'name': 'RTC_BAT',
'suffix': 'RTC_BAT',
},
{
'range': AZ_seq(),
'type': ADCInput.TYPE_SWITCH,
'suffix': 'SW{}',
'name': 'SW{}',
},
]
def __init__(self, target, hw_defs, labels):
self.target = target
self.hw_defs = hw_defs
self.labels = labels
self.regs = self._parse_regs()
self.dirs = self._parse_dirs()
self.adcs = []
def _parse_regs(self):
regs = {}
for reg in AZ_seq():
reg = f'GPIO{reg}'
pins_def = f'ADC_{reg}_PINS'
if pins_def in self.hw_defs:
regs[reg] = self.hw_defs[pins_def]
return regs
def _parse_dirs(self):
ret = []
dirs = self.hw_defs['ADC_DIRECTION'].strip('{} ').split(',')
#eprint(dirs)
for i in dirs:
ret.append(int(i))
return ret
def _find_adc(self, channel_def):
if (self.ext_list is None) or (channel_def not in self.ext_list):
return self.ADC_MAIN
else:
return self.ADC_EXT
def _find_gpio(self, pin):
gpio = None
for reg, pins_def in self.regs.items():
if pins_def and (pin in pins_def):
gpio = reg
return gpio
def _parse_adc(self, name, periph, prefix):
adc_periph = self.hw_defs.get(periph)
if not adc_periph:
return None
adc = ADC(name, adc_periph)
adc.dma = self.hw_defs.get(f'{prefix}_DMA')
if adc.dma:
adc.dma_channel = self.hw_defs[f'{prefix}_DMA_CHANNEL']
adc.dma_stream = self.hw_defs[f'{prefix}_DMA_STREAM']
adc.dma_stream_irq = self.hw_defs[f'{prefix}_DMA_STREAM_IRQ']
adc.dma_stream_irq_handler = self.hw_defs[f'{prefix}_DMA_STREAM_IRQHandler']
adc.sample_time = self.hw_defs[f'{prefix}_SAMPTIME']
return adc
def _parse_adcs(self):
adcs = []
adc_spi = self.hw_defs.get('ADC_SPI')
if adc_spi:
#eprint('## Found SPI ADC')
adc = ADC('SPI', adc_spi)
adc.gpio = self.hw_defs['ADC_SPI_GPIO']
adc.gpio_pin_miso = self.hw_defs['ADC_SPI_GPIO_PIN_MISO']
adc.gpio_pin_mosi = self.hw_defs['ADC_SPI_GPIO_PIN_MOSI']
adc.gpio_pin_sck = self.hw_defs['ADC_SPI_GPIO_PIN_SCK']
adc.gpio_pin_cs = self.hw_defs['ADC_SPI_GPIO_PIN_CS']
adc.gpio_af = self.hw_defs['ADC_SPI_GPIO_AF']
adcs.append(adc)
adc_main = self._parse_adc('MAIN', 'ADC_MAIN', 'ADC')
if adc_main:
adcs.append(adc_main)
self.ext_list = None
adc_ext = self._parse_adc('EXT', 'ADC_EXT', 'ADC_EXT')
if adc_ext:
self.ext_list = self.hw_defs['ADC_EXT_CHANNELS']
adcs.append(adc_ext)
return adcs
def _parse_input_type(self, input_type, name, suffix):
gpio = None
pin = None
d = 1 # non-inverted
# search for SPI input first
spi_def = f'ADC_SPI_{suffix}'
if spi_def in self.hw_defs:
#eprint('## Found SPI ADC Input:', spi_def)
channel = self.hw_defs[spi_def]
return SPI_ADCInput(name, input_type, channel)
if name != 'RTC_BAT':
pin_def = f'ADC_GPIO_PIN_{suffix}'
pin = self.hw_defs[pin_def]
gpio = self._find_gpio(pin_def)
# check if 'pin' is maybe an alias
alias = self.hw_defs.get(pin)
if alias is not None:
alias_gpio = self._find_gpio(pin)
gpio = alias_gpio if alias_gpio else gpio
pin = alias
channel_def = f'ADC_CHANNEL_{suffix}'
channel = self.hw_defs[channel_def]
adc = self._find_adc(channel_def)
return ADCInput(name, input_type, adc, gpio, pin, channel)
def _add_input(self, adc_input):
if adc_input is not None:
if adc_input.type != 'VBAT' and adc_input.type != 'RTC_BAT':
d = self.dirs[len(self.inputs)]
if d < 0:
adc_input.inverted = True
if adc_input.type == 'POT':
input_labels = self.labels[adc_input.name]
adc_input.label = input_labels['label']
adc_input.short_label = input_labels['short_label']
cfg = pot_cfg_by_target(self.target,adc_input.name)
if cfg:
adc_input.default = cfg.get('default')
self.inputs.append(adc_input)
def parse_inputs(self):
self.adcs = self._parse_adcs()
self.inputs = []
for adc_input in self.ADC_INPUTS:
input_type = adc_input['type']
input_range = adc_input.get('range')
if input_range is not None:
for i in input_range:
name = adc_input['name'].format(i)
suffix = adc_input['suffix'].format(i)
try:
self._add_input(self._parse_input_type(input_type, name, suffix))
except KeyError:
pass
else:
# type, name, suffix
name = adc_input['name']
suffix = adc_input['suffix']
try:
self._add_input(self._parse_input_type(input_type, name, suffix))
except KeyError:
pass
return { 'adcs': self.adcs, 'inputs': self.inputs }
def find_input(self, name):
for adc_input in self.inputs:
if adc_input.name == name:
return adc_input
return None
+67
View File
@@ -0,0 +1,67 @@
//
// WARNING: DO NOT EDIT THIS FILE
// This file has been generated from the target's JSON hardware description
//
{% set main_inputs = adc_inputs.inputs | selectattr('type', '==', 'STICK') | list %}
{% set n_mains = main_inputs | count %}
static const etx_hal_adc_input_t _main_inputs[] = {
{% for input in main_inputs %}
{% set label = main_labels[input.name] %}
{ "{{ input.name }}", "{{ label.str }}", {{ label.local }} },
{% endfor %}
};
{% set pot_offset = n_mains %}
{% set pot_inputs = adc_inputs.inputs | selectattr('type', '==', 'POT') | list %}
{% set n_pots = pot_inputs | count %}
static etx_hal_adc_input_t _pot_inputs[] = {
{% for input in pot_inputs %}
{ "{{ input.name }}", "{{ input.label }}", "{{ input.short_label }}" },
{% endfor %}
};
{% set axis_offset = pot_offset + n_pots %}
{% set axis_inputs = adc_inputs.inputs | selectattr('type', '==', 'AXIS') | list %}
{% set n_axis = axis_inputs | count %}
static etx_hal_adc_input_t _axis_inputs[] = {
{% for input in axis_inputs %}
{ "{{ input.name }}", "{{ input.label }}", nullptr },
{% endfor %}
};
{% set vbat_offset = axis_offset + n_axis %}
{% set vbat_inputs = adc_inputs.inputs | selectattr('type', '==', 'VBAT') | list %}
{% set n_vbat = vbat_inputs | count %}
static etx_hal_adc_input_t _vbat_inputs[] = {
{% for input in vbat_inputs %}
{ "{{ input.name }}", nullptr, nullptr },
{% endfor %}
};
{% set rtc_bat_offset = vbat_offset + n_vbat %}
{% set rtc_bat_inputs = adc_inputs.inputs | selectattr('type', '==', 'RTC_BAT') | list %}
{% set n_rtc_bat = rtc_bat_inputs | count %}
static etx_hal_adc_input_t _rtc_bat_inputs[] = {
{% for input in rtc_bat_inputs %}
{ "{{ input.name }}", nullptr, nullptr },
{% endfor %}
};
{% set n_inputs = rtc_bat_offset + n_rtc_bat %}
static const etx_hal_adc_inputs_t _hal_inputs[] = {
{ {{ n_mains }}, 0, _main_inputs },
{ {{ n_pots }}, {{ pot_offset }}, _pot_inputs },
{ {{ n_axis }}, {{ axis_offset }}, _axis_inputs },
{ {{ n_vbat }}, {{ vbat_offset }}, _vbat_inputs },
{ {{ n_rtc_bat }}, {{ rtc_bat_offset }}, _rtc_bat_inputs },
{ {{ n_inputs }}, 0, nullptr },
};
constexpr potconfig_t _pot_default_config = (0)
{% for pot in pot_inputs %}
{% if pot.default %}
| (POT_{{ pot.default }} << ({{ loop.index0 }} * POT_CFG_BITS))
{% endif %}
{% endfor %}
;
+93
View File
@@ -0,0 +1,93 @@
import re
import sys
import json
from hal_switches import Switch, parse_switches
from hal_adc import ADCInput, SPI_ADCInput, ADC, ADCInputParser
from hal_keys import Key, Trim, parse_trims, parse_keys
import legacy_names
#
# Return a file handle or STDIN
#
def open_file(filename):
if filename and not filename == '-':
return open(filename)
else:
return sys.stdin
#
# Read lines of defines into a dictionary
#
def parse_hw_defs(filename):
hw_defs = {}
with open_file(filename) as file:
for line in file.readlines():
m = re.match(r'#define ([^\s]*)\s*(.*)', line.rstrip())
name = m.group(1)
value = m.group(2)
if value.isnumeric():
value = int(value)
elif not value:
value = None
hw_defs[name] = value
return hw_defs
def prune_dict(d):
# ret = {}
# for k, v in d.items():
# if v is not None:
# ret[k] = v
# return ret
return d
class DictEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Switch):
return prune_dict(obj.__dict__)
if isinstance(obj, ADCInput):
return prune_dict(obj.__dict__)
if isinstance(obj, SPI_ADCInput):
return prune_dict(obj.__dict__)
if isinstance(obj, ADC):
return prune_dict(obj.__dict__)
if isinstance(obj, Trim):
return prune_dict(obj.__dict__)
if isinstance(obj, Key):
return prune_dict(obj.__dict__)
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
#
# Parse HAL defines into JSON
#
def parse_defines(filename, target):
hw_defs = parse_hw_defs(filename)
out_defs = {}
# parse ADC first, we might have switches using ADC
legacy_inputs = legacy_names.inputs_by_target(target)
adc_parser = ADCInputParser(target,hw_defs,legacy_inputs)
adc_inputs = adc_parser.parse_inputs()
out_defs["adc_inputs"] = adc_inputs
switches = parse_switches(target, hw_defs, adc_parser)
out_defs["switches"] = switches
keys = parse_keys(hw_defs)
out_defs["keys"] = keys
trims = parse_trims(hw_defs)
out_defs["trims"] = trims
print(json.dumps(out_defs, cls=DictEncoder, indent=2))
+32
View File
@@ -0,0 +1,32 @@
//
// WARNING: DO NOT EDIT THIS FILE
// This file has been generated from the target's JSON hardware description
//
const char* const _key_labels[] = {
{% for k in key_index %}
{% set key = keys | selectattr("key","==",k) | first %}
{% if key %}
"{{ key.label }}",
{% else %}
nullptr,
{% endif %}
{% endfor %}
};
constexpr uint32_t _defined_keys =
{% for key in keys %}
{% if loop.last %}
(1 << {{ key.key }});
{% else %}
(1 << {{ key.key }}) |
{% endif %}
{% endfor %}
constexpr uint8_t _n_keys = {{ keys | length }};
constexpr uint8_t _n_trims = {{ trims | length }};
static_assert(DIM(_key_labels) == MAX_KEYS, "wrong size _key_labels[]");
static_assert(_n_keys <= MAX_KEYS, "too many keys defined");
static_assert(_n_trims <= MAX_TRIMS, "too many trims defined");
+113
View File
@@ -0,0 +1,113 @@
# Trims:
# TRIMS_GPIO_REG_[trim]
# TRIMS_GPIO_PIN_[trim]
#
# where 'trim' is one of:
#
# (-) (+)
# 'LHL', 'LHR',
# 'LVD', 'LVU',
# 'RVD', 'RVU',
# 'RHL', 'RHR',
# 'LSD', 'LSU', T4
# 'RSD', 'RSU', T5
TRIMS = [
# Air
{ "name": "T1", "dec": "LHL", "inc": "LHR", "input": "LH" },
{ "name": "T2", "dec": "LVD", "inc": "LVU", "input": "LV" },
{ "name": "T3", "dec": "RVD", "inc": "RVU", "input": "RV" },
{ "name": "T4", "dec": "RHL", "inc": "RHR", "input": "RH" },
{ "name": "T5", "dec": "LSD", "inc": "LSU" },
{ "name": "T6", "dec": "RSD", "inc": "RSU" },
# Surface
{ "name": "T1", "dec": "T1L", "inc": "T1R", "input": "ST" },
{ "name": "T2", "dec": "T2L", "inc": "T2R", "input": "TH" },
{ "name": "T3", "dec": "T3L", "inc": "T3R"},
{ "name": "T4", "dec": "T4L", "inc": "T4R"},
{ "name": "T5", "dec": "T5L", "inc": "T5R" },
{ "name": "T6", "dec": "T6L", "inc": "T6R" },
]
KEYS = [
{ "name": "MENU", "key": "KEY_MENU", "label": "Menu" },
{ "name": "EXIT", "key": "KEY_EXIT", "label": "Exit" },
{ "name": "ENTER", "key": "KEY_ENTER", "label": "Enter" },
{ "name": "PAGE", "key": "KEY_PAGE", "label": "Page" },
{ "name": "PAGEUP", "key": "KEY_PAGEUP", "label": "PgUp" },
{ "name": "PAGEDN", "key": "KEY_PAGEDN", "label": "PgDn" },
{ "name": "UP", "key": "KEY_UP", "label": "Up" },
{ "name": "DOWN", "key": "KEY_DOWN", "label": "Down" },
{ "name": "LEFT", "key": "KEY_LEFT", "label": "Left" },
{ "name": "RIGHT", "key": "KEY_RIGHT", "label": "Right" },
{ "name": "PLUS", "key": "KEY_PLUS", "label": "Plus" },
{ "name": "MINUS", "key": "KEY_MINUS", "label": "Minus" },
{ "name": "MDL", "key": "KEY_MODEL", "label": "MDL" },
{ "name": "TELE", "key": "KEY_TELE", "label": "TELE" },
{ "name": "SYS", "key": "KEY_SYS", "label": "SYS" },
{ "name": "SHIFT", "key": "KEY_SHIFT", "label": "Shift" },
]
class Key:
def __init__(self, gpio, pin):
self.gpio = gpio
self.pin = pin
class Trim:
def __init__(self, name, dec, inc):
self.name = name
self.dec = dec
self.inc = inc
def get_trim_switch(hw_defs, tag):
gpio = f'TRIMS_GPIO_REG_{tag}'
pin = f'TRIMS_GPIO_PIN_{tag}'
if (gpio in hw_defs) and (pin in hw_defs):
return Key(hw_defs[gpio], hw_defs[pin])
return None
def parse_trims(hw_defs):
trims = []
for t in TRIMS:
name = t['name']
dec = get_trim_switch(hw_defs, t['dec'])
inc = get_trim_switch(hw_defs, t['inc'])
if dec and inc:
trims.append(Trim(name, dec, inc))
return trims
def parse_keys(hw_defs):
keys = []
for k in KEYS:
name = k['name']
gpio = f'KEYS_GPIO_REG_{name}'
pin = f'KEYS_GPIO_PIN_{name}'
if (gpio in hw_defs) and (pin in hw_defs):
key = Key(hw_defs[gpio], hw_defs[pin])
key.key = k['key']
key.name = name
key.label = k['label']
keys.append(key)
return keys
+106
View File
@@ -0,0 +1,106 @@
from switch_config import switch_cfg_by_target
class Switch:
TYPE_2POS = '2POS'
TYPE_3POS = '3POS'
TYPE_ADC = 'ADC'
def __init__(self, name, sw_type, flags):
self.name = name
self.type = sw_type
self.flags = flags
class Switch2POS(Switch):
def __init__(self, name, gpio, pin, flags=0):
super(Switch2POS, self).__init__(name, Switch.TYPE_2POS, flags)
self.gpio = gpio
self.pin = pin
class Switch3POS(Switch):
def __init__(self, name, gpio_high, pin_high, gpio_low, pin_low, flags=0):
super(Switch3POS, self).__init__(name, Switch.TYPE_3POS, flags)
self.gpio_high = gpio_high
self.pin_high = pin_high
self.gpio_low = gpio_low
self.pin_low = pin_low
class SwitchADC(Switch):
def __init__(self, name, adc_input, flags=0):
super(SwitchADC, self).__init__(name, Switch.TYPE_ADC, flags)
self.adc_input = adc_input
def AZ_seq():
return [chr(i) for i in range(ord('A'), ord('Z') + 1)]
def eprint(*args, **kwargs):
from sys import stderr
print(*args, file=stderr, **kwargs)
# switches from A to Z
def parse_switches(target, hw_defs, adc_parser):
switches = []
def find_switch(name):
for sw in switches:
if name == sw.name:
return sw
return None
for s in AZ_seq():
name = f'S{s}'
reg = f'SWITCHES_GPIO_REG_{s}'
reg_high = f'{reg}_H'
reg_low = f'{reg}_L'
pin = f'SWITCHES_GPIO_PIN_{s}'
pin_high = f'{pin}_H'
pin_low = f'{pin}_L'
inverted = f'SWITCHES_{s}_INVERTED'
adc_input_name = f'SW{s}'
switch = None
if reg in hw_defs:
# 2POS switch
reg = hw_defs[reg]
pin = hw_defs[pin]
switch = Switch2POS(name, reg, pin)
elif (reg_high in hw_defs) and (reg_low in hw_defs):
# 3POS switch
reg_high = hw_defs[reg_high]
pin_high = hw_defs[pin_high]
reg_low = hw_defs[reg_low]
pin_low = hw_defs[pin_low]
switch = Switch3POS(name, reg_high, pin_high, reg_low, pin_low)
else:
# ADC switch
if adc_parser.find_input(adc_input_name):
switch = SwitchADC(name, adc_input_name)
if switch:
if inverted in hw_defs:
switch.inverted = True
cfg = switch_cfg_by_target(target, name)
if cfg:
switch.default = cfg.get('default')
switch.display = cfg.get('display')
#eprint(switch.default)
switches.append(switch)
for i in range(1, 6 + 1):
f_sw_marker = f'FUNCTION_SWITCH_{i}'
if f_sw_marker in hw_defs:
switch = find_switch(hw_defs[f_sw_marker])
if switch:
switch.type = 'FSWITCH'
switch.name = f'SW{i}'
return switches
+86
View File
@@ -0,0 +1,86 @@
#
# These methods are used to build helper indexes on JSON structures
#
def build_adc_index(adc_inputs):
i = 0
index = {}
for adc_input in adc_inputs['inputs']:
name = adc_input['name']
index[name] = i
i = i + 1
return index
def append_to_index(d, key, val):
if key not in d:
d[key] = []
d[key].append(val)
def build_adc_gpio_port_index(adc_inputs):
i = 0
gpios = {}
for adc_input in adc_inputs['inputs']:
if adc_input['adc'] == 'SPI':
continue
gpio = adc_input['gpio']
if gpio is None:
i = i + 1
continue
if gpio not in gpios:
gpios[gpio] = []
pin = {
'pin': adc_input['pin'],
'idx': i
}
gpios[gpio].append(pin)
i = i + 1
return gpios
def build_switch_gpio_port_index(switches):
i = 0
gpios = {}
for switch in switches:
sw_type = switch['type']
if sw_type == '2POS' or sw_type == 'FSWITCH':
append_to_index(gpios, switch['gpio'], switch['pin'])
elif sw_type == '3POS':
append_to_index(gpios, switch['gpio_high'], switch['pin_high'])
append_to_index(gpios, switch['gpio_low'], switch['pin_low'])
return gpios
def build_trim_gpio_port_index(trims):
def index_contact(gpios, contact):
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'])
return gpios
def build_key_gpio_port_index(keys):
i = 0
gpios = {}
for key in keys:
append_to_index(gpios, key['gpio'], key['pin'])
return gpios
+394
View File
@@ -0,0 +1,394 @@
LEGACY_NAMES = [
{
"targets": {"x10","x10express","t16","tx16s","t18"},
"inputs": {
"LH": {
"yaml": "Rud"
},
"LV": {
"yaml": "Ele"
},
"RV": {
"yaml": "Thr"
},
"RH": {
"yaml": "Ail"
},
"P1": {
"yaml": "S1",
"lua": "s1",
"label": "S1",
"short_label": "1",
"description": "Potentiometer S1"
},
"P2": {
"yaml": "6POS",
"lua": "6pos",
"label": "6POS",
"short_label": "3",
"description": "Multipos Switch"
},
"P3": {
"yaml": "S2",
"lua": "s2",
"label": "S2",
"short_label": "2",
"description": "Potentiometer S2"
},
"SL1": {
"yaml": "LS",
"lua": "ls",
"label": "LS",
"short_label": "L",
"description": "Left slider"
},
"SL2": {
"yaml": "RS",
"lua": "rs",
"label": "RS",
"short_label": "R",
"description": "Right slider"
},
"EXT1": {
"yaml": "EXT1",
"lua": "ext1",
"label": "EXT1",
"short_label": "E1",
"description": "Ext 1"
},
"EXT2": {
"yaml": "EXT2",
"lua": "ext2",
"label": "EXT2",
"short_label": "E2",
"description": "Ext 2"
},
"EXT3": {
"yaml": "EXT3",
"lua": "ext3",
"label": "EXT3",
"short_label": "E3",
"description": "Ext 3"
},
"EXT4": {
"yaml": "EXT4",
"lua": "ext4",
"label": "EXT4",
"short_label": "E4",
"description": "Ext 4"
}
}
},
{
"targets": {"x12s"},
"inputs": {
"LH": {
"yaml": "Rud"
},
"LV": {
"yaml": "Ele"
},
"RV": {
"yaml": "Thr"
},
"RH": {
"yaml": "Ail"
},
"P1": {
"yaml": "S1",
"lua": "s1",
"label": "S1",
"short_label": "1",
"description": "Potentiometer S1"
},
"P2": {
"yaml": "6POS",
"lua": "6pos",
"label": "6POS",
"short_label": "3",
"description": "Multipos Switch"
},
"P3": {
"yaml": "S2",
"lua": "s2",
"label": "S2",
"short_label": "2",
"description": "Potentiometer S2"
},
"SL1": {
"yaml": "LS",
"lua": "ls",
"label": "LS",
"short_label": "L",
"description": "Left slider"
},
"SL2": {
"yaml": "RS",
"lua": "rs",
"label": "RS",
"short_label": "R",
"description": "Right slider"
},
"SL3": {
"yaml": "S3",
"lua": "s3",
"label": "L1",
"short_label": "1",
"description": "Slider S3"
},
"SL4": {
"yaml": "S4",
"lua": "s4",
"label": "L2",
"short_label": "2",
"description": "Slider S4"
},
"JSx": {
"yaml": "MOUSE1",
"lua": "jsx",
"description": "Joystick X"
},
"JSy": {
"yaml": "MOUSE2",
"lua": "jsy",
"description": "Joystick Y"
}
}
},
{
"targets": {"x9e"},
"inputs": {
"LH": {
"yaml": "Rud"
},
"LV": {
"yaml": "Ele"
},
"RV": {
"yaml": "Thr"
},
"RH": {
"yaml": "Ail"
},
"P1": {
"yaml": "POT1",
"lua": "s1",
"label": "F1",
"short_label": "1",
"description": "Potentiometer 1"
},
"P2": {
"yaml": "POT2",
"lua": "s2",
"label": "F2",
"short_label": "2",
"description": "Potentiometer 2"
},
"P3": {
"yaml": "POT3",
"lua": "s3",
"label": "EXT3",
"short_label": "3",
"description": "Potentiometer 3"
},
"P4": {
"yaml": "POT4",
"lua": "s4",
"label": "EXT4",
"short_label": "4",
"description": "Potentiometer 4"
},
"SL1": {
"yaml": "SLIDER1",
"lua": "ls",
"label": "LS",
"short_label": "L",
"description": "Left slider"
},
"SL2": {
"yaml": "SLIDER2",
"lua": "rs",
"label": "RS",
"short_label": "R",
"description": "Right slider"
},
"SL3": {
"yaml": "SLIDER3",
"lua": "lcs",
"label": "S1",
"short_label": "1",
"description": "Left center slider (X9E only)"
},
"SL4": {
"yaml": "SLIDER4",
"lua": "rcs",
"label": "S2",
"short_label": "2",
"description": "Right center slider (X9E only)"
}
}
},
{
"targets": {"boxer"},
"inputs": {
"LH": {
"yaml": "Rud"
},
"LV": {
"yaml": "Ele"
},
"RV": {
"yaml": "Thr"
},
"RH": {
"yaml": "Ail"
},
"P1": {
"yaml": "POT1",
"lua": "s1",
"label": "S1",
"short_label": "1",
"description": "Potentiometer 1"
},
"P2": {
"yaml": "POT2",
"lua": "s2",
"label": "S2",
"short_label": "2",
"description": "Potentiometer 2"
},
"P3": {
"yaml": "POT3",
"lua": "s3",
"label": "S3",
"short_label": "3",
"description": "6 pos"
}
}
},
{
"targets": {
"commando8",
"lr3pro",
"nv14",
"t8", "t12",
"tlite", "tpro",
"tx12", "tx12mk2",
"x7", "x7access",
"xlite", "xlites",
"zorro"
},
"inputs": {
"LH": {
"yaml": "Rud"
},
"LV": {
"yaml": "Ele"
},
"RV": {
"yaml": "Thr"
},
"RH": {
"yaml": "Ail"
},
"P1": {
"yaml": "POT1",
"lua": "s1",
"label": "S1",
"short_label": "1",
"description": "Potentiometer 1"
},
"P2": {
"yaml": "POT2",
"lua": "s2",
"label": "S2",
"short_label": "2",
"description": "Potentiometer 2"
}
}
},
{
"targets": {"x9lite","x9lites"},
"inputs": {
"LH": {
"yaml": "Rud"
},
"LV": {
"yaml": "Ele"
},
"RV": {
"yaml": "Thr"
},
"RH": {
"yaml": "Ail"
},
"P1": {
"yaml": "POT1",
"lua": "s1",
"label": "S1",
"short_label": "1",
"description": "Potentiometer 1"
}
}
},
{
"targets": {"x9d","x9d+","x9d+2019"},
"inputs": {
"LH": {
"yaml": "Rud"
},
"LV": {
"yaml": "Ele"
},
"RV": {
"yaml": "Thr"
},
"RH": {
"yaml": "Ail"
},
"P1": {
"yaml": "POT1",
"lua": "s1",
"label": "S1",
"short_label": "1",
"description": "Potentiometer 1"
},
"P2": {
"yaml": "POT2",
"lua": "s2",
"label": "S2",
"short_label": "2",
"description": "Potentiometer 2"
},
"P3": {
"yaml": "POT3",
"lua": "s3",
"label": "S3",
"short_label": "3",
"description": "Potentiometer 3"
},
"SL1": {
"yaml": "SLIDER1",
"lua": "ls",
"label": "LS",
"short_label": "L",
"description": "Left slider"
},
"SL2": {
"yaml": "SLIDER2",
"lua": "rs",
"label": "RS",
"short_label": "R",
"description": "Right slider"
}
}
}
]
def inputs_by_target(target):
for d in LEGACY_NAMES:
if target in d['targets']:
return d['inputs']
return None
+14
View File
@@ -0,0 +1,14 @@
//
// WARNING: DO NOT EDIT THIS FILE
// This file has been generated from the target's JSON hardware description
//
{% set pot_inputs = adc_inputs.inputs | selectattr('type', '==', 'POT') | list %}
{% set axis_inputs = adc_inputs.inputs | selectattr('type', '==', 'AXIS') | list %}
static const LuaSingleField _lua_inputs[] = {
{% for input in (pot_inputs + axis_inputs) %}
{% set li = legacy_inputs[input.name] %}
{ MIXSRC_FIRST_POT + {{ loop.index0 }}, "{{ li.lua }}", "{{ li.description }}" },
{% endfor %}
};
+128
View File
@@ -0,0 +1,128 @@
POT_CONFIG = {
"boxer": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "WITH_DETENT" },
"P3": { "default": "MULTIPOS_SWITCH" }
},
"tpro": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "WITH_DETENT" }
},
"t12": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "WITHOUT_DETENT" }
},
"tx12": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "WITH_DETENT" }
},
"tx12mk2": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "WITH_DETENT" }
},
"t16": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "MULTIPOS_SWITCH" },
"P3": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" }
},
"t18": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "MULTIPOS_SWITCH" },
"P3": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" }
},
"tx16s": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "MULTIPOS_SWITCH" },
"P3": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" }
},
"x7": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "WITH_DETENT" }
},
"x7access": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "WITH_DETENT" }
},
"x9d": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" }
},
"x9dp": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" }
},
"x9dp2019": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" }
},
"x9e": {
"P1": { "default": "WITH_DETENT" },
"P2": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" },
"SL3": { "default": "SLIDER_WITH_DETENT" },
"SL4": { "default": "SLIDER_WITH_DETENT" }
},
"x10": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "MULTIPOS_SWITCH" },
"P3": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" }
},
"x10express": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "MULTIPOS_SWITCH" },
"P3": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" }
},
"x12s": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "MULTIPOS_SWITCH" },
"P3": { "default": "WITH_DETENT" },
"SL1": { "default": "SLIDER_WITH_DETENT" },
"SL2": { "default": "SLIDER_WITH_DETENT" },
"SL3": { "default": "SLIDER_WITH_DETENT" },
"SL4": { "default": "SLIDER_WITH_DETENT" }
},
"xlite": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "WITHOUT_DETENT" }
},
"xlites": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "WITHOUT_DETENT" }
},
"x9lite": {
"P1": { "default": "WITH_DETENT" },
},
"x9lites": {
"P1": { "default": "WITH_DETENT" },
},
"zorro": {
"P1": { "default": "WITHOUT_DETENT" },
"P2": { "default": "WITHOUT_DETENT" }
},
}
def pot_cfg_by_target(target, name):
sw = POT_CONFIG.get(target)
if sw:
return sw.get(name)
return None
+11
View File
@@ -0,0 +1,11 @@
const hw_key_def _hw_key_defs[] = {
{% for key in keys %}
{ "{{ key.name }}", {{ key.key }} },
{% endfor %}
};
const char* const _hw_trim_defs[] = {
{% for trim in trims %}
"{{ trim.name }}",
{% endfor %}
};
+33
View File
@@ -0,0 +1,33 @@
{% set regular_switches = switches | selectattr('type','!=','FSWITCH') | list %}
{% set function_switches = switches | selectattr('type','==','FSWITCH') | list %}
const hw_switch_def _hw_switch_defs[] = {
{% for switch in regular_switches %}
{ "{{ switch.name }}", SWITCH_HW_{{ switch.type }} },
{% endfor %}
{% for switch in function_switches %}
{ "{{ switch.name }}", SWITCH_HW_2POS },
{% endfor %}
};
constexpr uint8_t n_switches = {{ regular_switches | count }};
constexpr uint8_t n_fct_switches = {{ function_switches | count }};
constexpr uint8_t n_total_switches = {{ 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 %}
};
+92
View File
@@ -0,0 +1,92 @@
//
// WARNING: DO NOT EDIT THIS FILE
// This file has been generated from the target's JSON hardware description
//
static const stm32_adc_input_t _ADC_inputs[] = {
{% for input in adc_inputs.inputs %}
{
"{{ input.name }}",
// ADC_INPUT_{{ input.type }},
{{ input.gpio if input.gpio else 'nullptr' }},
{{ input.pin if input.gpio else '0' }},
{{ input.channel if input.channel else '0' }},
{{ '1 // inverted' if input.inverted else '0 // normal' }}
},
{% endfor %}
};
{% for adc in adc_inputs.adcs %}
{% set inputs = adc_inputs.inputs | selectattr('adc', '==', adc.name) | selectattr('channel','defined') %}
static const uint8_t _ADC_{{ adc.name }}_channels[] = {
{% for input in inputs %}
{{ adc_index[input.name] }}, // {{ input.name }}
{% endfor %}
};
{% endfor %}
{% set offset = namespace(value=0) %}
static const stm32_adc_t _ADC_adc[] = {
{% for adc in adc_inputs.adcs | selectattr('name', '!=', 'SPI') %}
{% set inputs = adc_inputs.inputs | selectattr('adc', '==', adc.name) | selectattr('channel','defined') %}
{% set input_count = inputs | list | count %}
{
{{ adc.adc }},
{{ adc.dma if adc.dma else 'nullptr' }},
{{ adc.dma_channel if adc.dma else '0' }},
{{ adc.dma_stream if adc.dma else '0' }},
{{ adc.dma_stream_irq if adc.dma else '(IRQn_Type)-1' }},
_ADC_{{ adc.name }}_channels,
{{ offset.value }},
{{ input_count }},
{{ adc.sample_time if adc.sample_time else '0' }}
},
{% set offset.value = offset.value + input_count %}
{% endfor %}
};
static const stm32_spi_adc_t _ADC_spi[] = {
{% for adc in adc_inputs.adcs | selectattr('name', '==', 'SPI') %}
{% set inputs = adc_inputs.inputs | selectattr('adc', '==', adc.name) | selectattr('channel','defined') %}
{% set input_count = inputs | list | count %}
{
{{ adc.adc }},
{{ adc.gpio }},
{{ adc.gpio_pin_miso }} | {{ adc.gpio_pin_mosi }} | {{ adc.gpio_pin_sck }},
{{ adc.gpio_af }},
{{ adc.gpio_pin_cs }},
_ADC_{{ adc.name }}_channels,
{{ input_count }}
},
{% endfor %}
};
{% for adc in adc_inputs.adcs | selectattr('name', '!=', 'SPI') %}
{% if adc.dma %}
extern "C" void {{ adc.dma_stream_irq_handler }} (void)
{
stm32_hal_adc_dma_isr(&_ADC_adc[{{ loop.index0 }}]);
}
{% endif %}
{% endfor %}
extern "C" void ADC_IRQHandler()
{
{% for adc in adc_inputs.adcs | selectattr('name', '!=', 'SPI') %}
stm32_hal_adc_isr(&_ADC_adc[{{ loop.index0 }}]);
{% endfor %}
}
{% for adc_gpio, adc_inputs in adc_gpios.items() | sort %}
static const uint32_t _ADC_{{ adc_gpio }}_pins[] = {
{% for input in adc_inputs %}
{{ input.pin }},
{% endfor %}
};
{% endfor %}
static const stm32_adc_gpio_t _ADC_GPIOs[] = {
{% for adc_gpio, adc_inputs in adc_gpios.items() | sort %}
{ {{ adc_gpio }}, _ADC_{{ adc_gpio }}_pins, {{ adc_inputs|count }} },
{% endfor %}
};
+52
View File
@@ -0,0 +1,52 @@
//
// WARNING: DO NOT EDIT THIS FILE
// This file has been generated from the target's JSON hardware description
//
static inline void _init_keys()
{
LL_GPIO_InitTypeDef pinInit;
LL_GPIO_StructInit(&pinInit);
pinInit.Mode = LL_GPIO_MODE_INPUT;
pinInit.Pull = LL_GPIO_PULL_UP;
{% for key_gpio, pins in key_gpios.items() | sort %}
stm32_gpio_enable_clock({{ key_gpio }});
pinInit.Pin = {{ pins | join('|') }};
LL_GPIO_Init({{ key_gpio }}, &pinInit);
{% endfor %}
}
static inline uint32_t _read_keys()
{
uint32_t keys = 0;
{% for key in keys %}
if (!LL_GPIO_IsInputPinSet({{ key.gpio }}, {{ key.pin }}))
keys |= (1 << {{ key.key }});
{% endfor %}
return keys;
}
static inline void _init_trims()
{
LL_GPIO_InitTypeDef pinInit;
LL_GPIO_StructInit(&pinInit);
pinInit.Mode = LL_GPIO_MODE_INPUT;
pinInit.Pull = LL_GPIO_PULL_UP;
{% for trim_gpio, pins in trim_gpios.items() | sort %}
stm32_gpio_enable_clock({{ trim_gpio }});
pinInit.Pin = {{ pins | join('|') }};
LL_GPIO_Init({{ trim_gpio }}, &pinInit);
{% endfor %}
}
static inline uint32_t _read_trims()
{
uint32_t trims = 0;
{% for trim in trims %}
if (!LL_GPIO_IsInputPinSet({{ trim.dec.gpio }}, {{ trim.dec.pin }}))
trims |= (1 << {{ loop.index0 * 2 }});
if (!LL_GPIO_IsInputPinSet({{ trim.inc.gpio }}, {{ trim.inc.pin }}))
trims |= (1 << {{ loop.index0 * 2 + 1 }});
{% endfor %}
return trims;
}
+77
View File
@@ -0,0 +1,77 @@
//
// 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 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 uint8_t n_total_switches = {{ 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 %}
};
+274
View File
@@ -0,0 +1,274 @@
SWITCH_CONFIG = {
"boxer": {
# left side
"SA": { "default": "2POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display":[ 0, 1 ] },
"SE": { "default": "2POS", "display": [ 0, 2 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "2POS", "display": [ 1, 1 ] },
"SF": { "default": "TOGGLE", "display": [ 1, 2 ] },
},
"commando8": {
# left side
"SA": { "default": "2POS", "display": [ 0, 0 ] },
"SC": { "default": "3POS", "display": [ 0, 1 ] },
# right side
"SB": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "2POS", "display": [ 1, 1 ] }
},
"lr3pro": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SC": { "default": "3POS", "display": [ 0, 1 ] },
# right side
"SB": { "default": "2POS", "display": [ 1, 0 ] },
"SD": { "default": "2POS", "display": [ 1, 1 ] }
},
"t8": {
# left side
"SA": { "default": "2POS", "display": [ 0, 0 ] },
"SC": { "default": "3POS", "display": [ 0, 1 ] },
# right side
"SB": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "2POS", "display": [ 1, 1 ] }
},
"t12": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SG": { "default": "2POS", "display": [ 0, 2 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "3POS", "display": [ 1, 1 ] },
"SH": { "default": "2POS", "display": [ 1, 3 ] }
},
"t16": {
"SA": { "default": "3POS" },
"SB": { "default": "3POS" },
"SC": { "default": "3POS" },
"SD": { "default": "3POS" },
"SE": { "default": "3POS" },
"SF": { "default": "2POS" },
"SG": { "default": "3POS" },
"SH": { "default": "TOGGLE" }
},
"t18": {
"SA": { "default": "3POS" },
"SB": { "default": "3POS" },
"SC": { "default": "3POS" },
"SD": { "default": "3POS" },
"SE": { "default": "3POS" },
"SF": { "default": "2POS" },
"SG": { "default": "3POS" },
"SH": { "default": "TOGGLE" }
},
"tlite": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SC": { "default": "3POS", "display": [ 0, 1 ] },
# right side
"SB": { "default": "2POS", "display": [ 1, 0 ] },
"SD": { "default": "2POS", "display": [ 1, 1 ] }
},
"tpro": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SC": { "default": "TOGGLE", "display": [ 0, 1 ] },
# right side
"SB": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "TOGGLE", "display": [ 1, 1 ] }
},
"tx12": {
# left side
"SA": { "default": "TOGGLE", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SE": { "default": "3POS", "display": [ 0, 2 ] },
"SG": { "default": "NONE", "display": [ 0, 3 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "TOGGLE", "display": [ 1, 1 ] },
"SF": { "default": "3POS", "display": [ 1, 2 ] },
"SH": { "default": "NONE", "display": [ 1, 3 ] }
},
"tx16s": {
"SA": { "default": "3POS" },
"SB": { "default": "3POS" },
"SC": { "default": "3POS" },
"SD": { "default": "3POS" },
"SE": { "default": "3POS" },
"SF": { "default": "2POS" },
"SG": { "default": "3POS" },
"SH": { "default": "TOGGLE" }
},
"tx12mk2": {
# left side
"SA": { "default": "TOGGLE", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SE": { "default": "3POS", "display": [ 0, 2 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "TOGGLE", "display": [ 1, 1 ] },
"SF": { "default": "3POS", "display": [ 1, 2 ] },
},
"x7": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SF": { "default": "2POS", "display": [ 0, 2 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "3POS", "display": [ 1, 1 ] },
"SH": { "default": "TOGGLE", "display": [ 1, 2 ] }
},
"x7access": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SF": { "default": "2POS", "display": [ 0, 2 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "3POS", "display": [ 1, 1 ] },
"SH": { "default": "TOGGLE", "display": [ 1, 2 ] }
},
"x9d": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SE": { "default": "3POS", "display": [ 0, 2 ] },
"SF": { "default": "2POS", "display": [ 0, 3 ] },
# right side
"SC": { "default": "3POS", "display": [ 2, 0 ] },
"SD": { "default": "3POS", "display": [ 2, 1 ] },
"SG": { "default": "3POS", "display": [ 2, 2 ] },
"SH": { "default": "TOGGLE", "display": [ 2, 3 ] }
},
"x9dp": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SE": { "default": "3POS", "display": [ 0, 2 ] },
"SF": { "default": "2POS", "display": [ 0, 3 ] },
# right side
"SC": { "default": "3POS", "display": [ 2, 0 ] },
"SD": { "default": "3POS", "display": [ 2, 1 ] },
"SG": { "default": "3POS", "display": [ 2, 2 ] },
"SH": { "default": "TOGGLE", "display": [ 2, 3 ] }
},
"x9dp2019": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SE": { "default": "3POS", "display": [ 0, 2 ] },
"SF": { "default": "2POS", "display": [ 0, 3 ] },
"SI": { "default": "TOGGLE", "display": [ 0, 4 ] },
# right side
"SC": { "default": "3POS", "display": [ 2, 0 ] },
"SD": { "default": "3POS", "display": [ 2, 1 ] },
"SG": { "default": "3POS", "display": [ 2, 2 ] },
"SH": { "default": "TOGGLE", "display": [ 2, 3 ] }
},
"x9e": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SE": { "default": "3POS", "display": [ 0, 2 ] },
"SF": { "default": "2POS", "display": [ 0, 3 ] },
# extra
"SI": { "default": "NONE", "display": [ 0, 4 ] },
"SK": { "default": "NONE", "display": [ 0, 5 ] },
"SM": { "default": "NONE", "display": [ 0, 6 ] },
"SO": { "default": "NONE", "display": [ 0, 7 ] },
"SQ": { "default": "NONE", "display": [ 0, 8 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "3POS", "display": [ 1, 1 ] },
"SH": { "default": "3POS", "display": [ 1, 2 ] },
"SG": { "default": "TOGGLE", "display": [ 1, 3 ] },
# extra
"SJ": { "default": "NONE", "display": [ 1, 4 ] },
"SL": { "default": "NONE", "display": [ 1, 5 ] },
"SN": { "default": "NONE", "display": [ 1, 6 ] },
"SP": { "default": "NONE", "display": [ 1, 7 ] },
"SR": { "default": "NONE", "display": [ 1, 8 ] }
},
"xlite": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SC": { "default": "3POS", "display": [ 0, 1 ] },
# right side
"SB": { "default": "2POS", "display": [ 1, 0 ] },
"SD": { "default": "2POS", "display": [ 1, 1 ] }
},
"xlites": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SC": { "default": "3POS", "display": [ 0, 1 ] },
"SE": { "default": "TOGGLE", "display": [ 0, 2 ] },
# right side
"SB": { "default": "2POS", "display": [ 1, 0 ] },
"SD": { "default": "2POS", "display": [ 1, 1 ] },
"SE": { "default": "TOGGLE", "display": [ 1, 2 ] }
},
"x9lite": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SD": { "default": "2POS", "display": [ 0, 2 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SE": { "default": "TOGGLE", "display": [ 1, 1 ] }
},
"x9lites": {
# left side
"SA": { "default": "3POS", "display": [ 0, 0 ] },
"SB": { "default": "3POS", "display": [ 0, 1 ] },
"SD": { "default": "2POS", "display": [ 0, 2 ] },
"SF": { "default": "TOGGLE", "display": [ 0, 3 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 1 ] },
"SE": { "default": "TOGGLE", "display": [ 1, 2 ] },
"SG": { "default": "TOGGLE", "display": [ 1, 3 ] }
},
"x10": {
"SA": { "default": "3POS" },
"SB": { "default": "3POS" },
"SC": { "default": "3POS" },
"SD": { "default": "3POS" },
"SE": { "default": "3POS" },
"SF": { "default": "2POS" },
"SG": { "default": "3POS" },
"SH": { "default": "TOGGLE" }
},
"x10express": {
"SA": { "default": "3POS" },
"SB": { "default": "3POS" },
"SC": { "default": "3POS" },
"SD": { "default": "3POS" },
"SE": { "default": "3POS" },
"SF": { "default": "2POS" },
"SG": { "default": "3POS" },
"SH": { "default": "TOGGLE" }
},
"zorro": {
# left side
"SB": { "default": "3POS", "display": [ 0, 0 ] },
"SA": { "default": "TOGGLE", "display": [ 0, 1 ] },
"SE": { "default": "2POS", "display": [ 0, 2 ] },
"SG": { "default": "TOGGLE", "display": [ 0, 3 ] },
# right side
"SC": { "default": "3POS", "display": [ 1, 0 ] },
"SD": { "default": "TOGGLE", "display": [ 1, 1 ] },
"SF": { "default": "2POS", "display": [ 1, 2 ] },
"SH": { "default": "TOGGLE", "display": [ 1, 3 ] },
},
}
def switch_cfg_by_target(target, name):
sw = SWITCH_CONFIG.get(target)
if sw:
return sw.get(name)
return None
+28
View File
@@ -0,0 +1,28 @@
//
// WARNING: DO NOT EDIT THIS FILE
// This file has been generated from the target's JSON hardware description
//
{% set main_inputs = adc_inputs.inputs | selectattr('type', '==', 'STICK') | list %}
{% set pot_inputs = adc_inputs.inputs | selectattr('type', '==', 'POT') | list %}
{% set axis_inputs = adc_inputs.inputs | selectattr('type', '==', 'AXIS') | list %}
struct legacy_input_t {
const char* legacy;
uint16_t src_raw;
};
static const legacy_input_t _legacy_inputs[] = {
{% for input in main_inputs %}
{% set li = legacy_inputs[input.name] %}
{ "{{ li.yaml }}", MIXSRC_FIRST_STICK + {{ loop.index0 }} },
{% endfor %}
{% for input in pot_inputs %}
{% set li = legacy_inputs[input.name] %}
{ "{{ li.yaml }}", MIXSRC_FIRST_POT + {{ loop.index0 }} },
{% endfor %}
{% for input in axis_inputs %}
{% set li = legacy_inputs[input.name] %}
{ "{{ li.yaml }}", MIXSRC_FIRST_AXIS + {{ loop.index0 }} },
{% endfor %}
};
-174
View File
@@ -1,174 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
import traceback
import time
import re
PREC1 = 10
PREC2 = 100
CONSTANT_VALUE = ""
dups_cnst = []
dups_name = []
exports = []
exports_multiple = []
exports_script_outputs = []
warning = None
error = None
def checkName(name):
global warning
if name in dups_name:
print("WARNING: Duplicate name %s found for constant %s" % (name, CONSTANT_VALUE))
warning = True
dups_name.append(name)
if name != name.lower():
print("WARNING: Name not in lower case %s found for constant %s" % (name, CONSTANT_VALUE))
warning = True
def LEXP(name, description):
# print "LEXP %s, %s" % (name, description)
checkName(name)
exports.append((CONSTANT_VALUE, name, description))
def LEXP_MULTIPLE(nameFormat, descriptionFormat, valuesCount):
# print "LEXP_MULTIPLE %s, %s, %s" % (nameFormat, descriptionFormat, valuesCount)
for v in range(valuesCount):
name = nameFormat + str(v)
# print name
checkName(name)
exports_multiple.append((CONSTANT_VALUE, nameFormat, descriptionFormat, valuesCount))
if len(sys.argv) < 3:
print("Error: not enough arguments!")
print("Usage:")
print(" luaexport.py <version> <input txt> <output cpp> [<doc output>]")
version = sys.argv[1]
inputFile = sys.argv[2]
outputFile = sys.argv[3]
docFile = None
if len(sys.argv) >= 4:
docFile = sys.argv[4]
print("Version %s" % version)
print("Input file %s" % inputFile)
print("Output file %s" % outputFile)
if docFile:
print("Documentation file %s" % docFile)
with open(inputFile, "r") as inp:
while True:
line = inp.readline()
if len(line) == 0:
break
line = line.strip('\r\n')
line = line.strip()
# print "line: %s" % line
if line.find('LEXP') < 0:
continue
parts = line.split('LEXP')
# print parts
if len(parts) != 2:
print("Wrong line: %s" % line)
continue
cmd = 'LEXP' + parts[1]
cnst = parts[0].rstrip(', ')
if cnst.find('=') != -1:
# constant contains =
cnst = cnst.split('=')[0].strip()
# print "Found constant %s with command: %s" % (cnst, cmd)
try:
CONSTANT_VALUE = cnst
# if CONSTANT_VALUE in dups_cnst:
# print "WARNING: Duplicate CONSTANT_VALUE found: %s" % CONSTANT_VALUE
# warning = True
# continue
# dups_cnst.append(CONSTANT_VALUE)
# print cmd
eval(cmd)
except:
print("ERROR: problem with the definition: %s" % line)
traceback.print_exc()
error = True
with open(outputFile, "w") as out:
out.write("//This file was generated by luaexport.py script on %s for EdgeTX version %s\n\n\n"
% (time.asctime(), version))
header = """
struct LuaSingleField {
uint16_t id;
const char * name;
const char * desc;
};
struct LuaMultipleField {
uint16_t id;
const char * name;
const char * desc;
uint8_t count;
};
"""
out.write(header)
out.write("""
// The list of Lua fields
// this aray is alphabetically sorted by the second field (name)
const LuaSingleField luaSingleFields[] = {
""")
exports.sort(key=lambda x: x[1]) # sort by name
data = [" {%s, \"%s\", \"%s\"}" % export for export in exports]
out.write(",\n".join(data))
out.write("\n};\n\n")
print("Generated %d items in luaFields[]" % len(exports))
out.write("""
// The list of Lua fields that have a range of values
const LuaMultipleField luaMultipleFields[] = {
""")
data = [" {%s, \"%s\", \"%s\", %d}" % export for export in exports_multiple]
out.write(",\n".join(data))
out.write("\n};\n\n")
print("Generated %d items in luaMultipleFields[]" % len(exports_multiple))
if docFile:
# prepare fields
all_exports = [(name, desc) for (id, name, desc) in exports]
for (id, nameFormat, descriptionFormat, valuesCount) in exports_multiple:
for v in range(1, valuesCount + 1):
name = nameFormat + str(v)
desc = descriptionFormat % v
all_exports.append((name, desc))
# natural sort by field name
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key[0])]
all_exports.sort(key=alphanum_key)
with open(docFile, "w") as out:
out.write("Alphabetical list of Lua fields for EdgeTX version %s\n\n\n" % version)
FIELD_NAME_WIDTH = 25
out.write("Field name%sField description\n" % (' ' * (FIELD_NAME_WIDTH - len('Field name'))))
out.write("----------------------------------------------\n")
data = ["%s%s%s" % (name_, ' ' * (FIELD_NAME_WIDTH - len(name_)), desc_) for (name_, desc_) in all_exports]
out.write("\n".join(data))
out.write("\n")
if warning:
sys.exit(1)
elif error:
os.remove(outputFile)
sys.exit(2)
sys.exit(0)