chore: store more hardware settings in hwdef JSON files (#7031)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
|
||||
class CFS:
|
||||
|
||||
def __init__(self, cfs_rgb_led, cfs_groups):
|
||||
self.rgb_led = cfs_rgb_led
|
||||
self.groups = cfs_groups
|
||||
|
||||
def parse_cfs(hw_defs):
|
||||
|
||||
cfs_rgb_led = 0
|
||||
cfs_groups = 0
|
||||
|
||||
fcfs = f'FUNCTION_SWITCHES'
|
||||
frgb = f'FUNCTION_SWITCHES_RGB_LEDS'
|
||||
|
||||
if fcfs in hw_defs:
|
||||
if frgb in hw_defs:
|
||||
cfs_rgb_led = 1
|
||||
if f'RADIO_GX12' in hw_defs:
|
||||
cfs_groups = 4
|
||||
elif f'RADIO_PA01' in hw_defs:
|
||||
cfs_groups = 2
|
||||
else:
|
||||
cfs_groups = 3
|
||||
|
||||
return CFS(cfs_rgb_led, cfs_groups)
|
||||
@@ -6,6 +6,9 @@ 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
|
||||
from hal_lcd import Display, parse_lcd
|
||||
from hal_cfs import CFS, parse_cfs
|
||||
from hal_misc import Misc, parse_misc
|
||||
|
||||
import legacy_names
|
||||
|
||||
@@ -62,6 +65,12 @@ class DictEncoder(json.JSONEncoder):
|
||||
return prune_dict(obj.__dict__)
|
||||
if isinstance(obj, Key):
|
||||
return prune_dict(obj.__dict__)
|
||||
if isinstance(obj, Display):
|
||||
return prune_dict(obj.__dict__)
|
||||
if isinstance(obj, CFS):
|
||||
return prune_dict(obj.__dict__)
|
||||
if isinstance(obj, Misc):
|
||||
return prune_dict(obj.__dict__)
|
||||
|
||||
# Let the base class default method raise the TypeError
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
@@ -89,5 +98,14 @@ def parse_defines(filename, target):
|
||||
trims = parse_trims(hw_defs)
|
||||
out_defs["trims"] = trims
|
||||
|
||||
display = parse_lcd(hw_defs)
|
||||
out_defs["display"] = display
|
||||
|
||||
cfs = parse_cfs(hw_defs)
|
||||
out_defs["custom_switches"] = cfs
|
||||
|
||||
misc = parse_misc(hw_defs)
|
||||
out_defs["hardware"] = misc
|
||||
|
||||
print(json.dumps(out_defs, cls=DictEncoder, indent=2))
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
|
||||
class Display:
|
||||
|
||||
def __init__(self, w, h, phys_w, phys_h, depth, color, oled, bl_color):
|
||||
self.w = w
|
||||
self.h = h
|
||||
self.phys_w = phys_w
|
||||
self.phys_h = phys_h
|
||||
self.depth = depth
|
||||
self.color = color
|
||||
self.oled = oled
|
||||
self.backlight_color = bl_color
|
||||
|
||||
def parse_lcd(hw_defs):
|
||||
|
||||
fw = f'LCD_W'
|
||||
fh = f'LCD_H'
|
||||
fphys_w = f'LCD_PHYS_W'
|
||||
fphys_h = f'LCD_PHYS_H'
|
||||
fdepth = f'LCD_DEPTH'
|
||||
foled = f'OLED_SCREEN'
|
||||
fbl_color = f'HAS_BACKLIGHT_COLOR'
|
||||
|
||||
w = hw_defs[fw]
|
||||
h = hw_defs[fh]
|
||||
if fphys_w in hw_defs:
|
||||
phys_w = hw_defs[fphys_w]
|
||||
else:
|
||||
phys_w = w
|
||||
if fphys_h in hw_defs:
|
||||
phys_h = hw_defs[fphys_h]
|
||||
else:
|
||||
phys_h = h
|
||||
depth = hw_defs[fdepth]
|
||||
|
||||
if phys_w == fw:
|
||||
phys_w = w
|
||||
if phys_w == fh:
|
||||
phys_w = h
|
||||
if phys_h == fh:
|
||||
phys_h = h
|
||||
if phys_h == fw:
|
||||
phys_h = w
|
||||
|
||||
if foled in hw_defs:
|
||||
oled = 1
|
||||
else:
|
||||
oled = 0
|
||||
|
||||
if depth < 16:
|
||||
color = 0
|
||||
else:
|
||||
color = 1
|
||||
|
||||
if fbl_color in hw_defs:
|
||||
bl_color = 1
|
||||
else:
|
||||
bl_color = 0
|
||||
|
||||
return Display(w, h, phys_w, phys_h, depth, color, oled, bl_color)
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
class Misc:
|
||||
|
||||
def __init__(self, has_audio_mute, has_bling_leds, has_ext_module_support, has_int_module_support, sport_max_baudrate, surface):
|
||||
self.has_audio_mute = has_audio_mute
|
||||
self.has_bling_leds = has_bling_leds
|
||||
self.has_ext_module_support = has_ext_module_support
|
||||
self.has_int_module_support = has_int_module_support
|
||||
self.sport_max_baudrate = sport_max_baudrate
|
||||
self.surface = surface
|
||||
|
||||
def parse_misc(hw_defs):
|
||||
|
||||
if f'RADIO_MT12' in hw_defs:
|
||||
surface = 1
|
||||
else:
|
||||
surface = 0
|
||||
|
||||
if f'SPORT_MAX_BAUDRATE' in hw_defs:
|
||||
sport_max_baudrate = hw_defs[f'SPORT_MAX_BAUDRATE']
|
||||
else:
|
||||
sport_max_baudrate = 400000
|
||||
|
||||
if f'AUDIO_MUTE_GPIO' in hw_defs:
|
||||
has_audio_mute = 1
|
||||
else:
|
||||
has_audio_mute = 0
|
||||
|
||||
if f'BLING_LED_STRIP_LENGTH' in hw_defs:
|
||||
has_bling_leds = hw_defs[f'BLING_LED_STRIP_LENGTH']
|
||||
else:
|
||||
has_bling_leds = 0
|
||||
|
||||
if f'RADIO_T8' in hw_defs:
|
||||
has_ext_module_support = 0
|
||||
else:
|
||||
has_ext_module_support = 1
|
||||
|
||||
if f'PCBX9D' in hw_defs or f'PCBX9DP' in hw_defs or f'PCBX9E' in hw_defs:
|
||||
has_int_module_support = 0
|
||||
else:
|
||||
has_int_module_support = 1
|
||||
|
||||
return Misc(has_audio_mute, has_bling_leds, has_ext_module_support, has_int_module_support, sport_max_baudrate, surface)
|
||||
Reference in New Issue
Block a user