diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index d8be59c27..b8ef493b4 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -750,6 +750,7 @@ PACK(struct TrainerData { #define EXTRA_GENERAL_FIELDS \ NOBACKUP(uint8_t auxSerialMode:4); \ NOBACKUP(uint8_t aux2SerialMode:4); \ + CUST_ARRAY(sticksConfig, struct_sticksConfig, stick_name_valid); \ swconfig_t switchConfig ARRAY(2,struct_switchConfig,nullptr); \ uint16_t potsConfig ARRAY(2,struct_potConfig,nullptr); /* two bits per pot */ \ uint8_t slidersConfig ARRAY(1,struct_sliderConfig,nullptr); /* 1 bit per slider */ \ @@ -773,6 +774,7 @@ PACK(struct TrainerData { uint8_t potsConfig ARRAY(2,struct_potConfig,nullptr); /* two bits per pot */\ uint8_t backlightColor; \ swarnstate_t switchUnlockStates; \ + CUST_ARRAY(sticksConfig, struct_sticksConfig, stick_name_valid); \ swconfig_t switchConfig ARRAY(2,struct_switchConfig,nullptr); \ char switchNames[STORAGE_NUM_SWITCHES][LEN_SWITCH_NAME] SKIP; \ char anaNames[NUM_STICKS+STORAGE_NUM_POTS+STORAGE_NUM_SLIDERS][LEN_ANA_NAME] SKIP; \ @@ -798,6 +800,8 @@ PACK(struct TrainerData { #endif PACK(struct RadioData { + + // Real attributes NOBACKUP(uint8_t version); NOBACKUP(uint16_t variant SKIP); CalibData calib[NUM_STICKS + STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS + STORAGE_NUM_MOUSE_ANALOGS]; diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index ee519d667..1d1ffec75 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -218,6 +218,36 @@ static bool sw_write(uint32_t idx, yaml_writer_func wf, void* opaque) return str ? wf(opaque, str, strlen(str)) : true; } +static void r_stick_name(const YamlNode* node, uint8_t* data, + uint32_t bitoffs, uint16_t idx, + const char* val, uint8_t val_len) +{ + data -= offsetof(RadioData, switchConfig); + RadioData* rd = reinterpret_cast(data); + strncpy(rd->anaNames[idx], val, std::min(val_len, LEN_ANA_NAME)); +} + +static bool w_stick_name(const YamlNode* node, uint8_t* data, + uint32_t bitoffs, uint16_t idx, + yaml_writer_func wf, void* opaque) +{ + data -= offsetof(RadioData, switchConfig); + RadioData* rd = reinterpret_cast(data); + return wf(opaque, rd->anaNames[idx], strnlen(rd->anaNames[idx], LEN_ANA_NAME)); +} + +static bool stick_name_valid(uint8_t* data, uint32_t bitoffs, uint16_t idx) +{ + RadioData* rd = reinterpret_cast(data); + return rd->anaNames[idx][0] != '\0'; +} + +static const struct YamlNode struct_sticksConfig[] = { + YAML_IDX, + YAML_CUSTOM( "name", r_stick_name, w_stick_name), + YAML_END +}; + static void sw_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs, uint16_t idx, const char* val, uint8_t val_len) { @@ -464,19 +494,19 @@ static bool w_swtchSrc(const YamlNode* node, uint32_t val, yaml_writer_func wf, return wf(opaque, str, strlen(str)); } -static bool cfn_is_active(uint8_t* data, uint32_t bitoffs) +static bool cfn_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx) { data += bitoffs >> 3UL; return ((CustomFunctionData*)data)->swtch; } -static bool gvar_is_active(uint8_t* data, uint32_t bitoffs) +static bool gvar_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx) { gvar_t* gvar = (gvar_t*)(data + (bitoffs>>3UL)); return *gvar != GVAR_MAX+1; } -static bool fmd_is_active(uint8_t* data, uint32_t bitoffs) +static bool fmd_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx) { uint32_t data_ofs = bitoffs >> 3UL; if (data_ofs == offsetof(ModelData, flightModeData)) { diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index 65f9ac6c2..e7681804b 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -368,6 +368,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active), YAML_UNSIGNED( "auxSerialMode", 4 ), YAML_UNSIGNED( "aux2SerialMode", 4 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr), YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr), YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr), diff --git a/radio/src/storage/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/yaml/yaml_datastructs_t12.cpp index 61595d01f..6d1a376cc 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t12.cpp @@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 192 ), YAML_PADDING( 144 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/yaml/yaml_datastructs_t8.cpp index 61595d01f..6d1a376cc 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t8.cpp @@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 192 ), YAML_PADDING( 144 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp index 61595d01f..6d1a376cc 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp @@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 192 ), YAML_PADDING( 144 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp index ce6681667..198068835 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp @@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 192 ), YAML_PADDING( 144 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index a000d62c4..f4943e675 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -385,6 +385,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active), YAML_UNSIGNED( "auxSerialMode", 4 ), YAML_UNSIGNED( "aux2SerialMode", 4 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr), YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr), YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr), diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 9c8838449..9b0c07a6f 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -385,6 +385,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active), YAML_UNSIGNED( "auxSerialMode", 4 ), YAML_UNSIGNED( "aux2SerialMode", 4 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr), YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr), YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr), diff --git a/radio/src/storage/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/yaml/yaml_datastructs_x7.cpp index 61595d01f..6d1a376cc 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x7.cpp @@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 192 ), YAML_PADDING( 144 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index 03ca4ed08..4a44167c8 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -352,6 +352,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 32 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr), YAML_PADDING( 216 ), YAML_PADDING( 216 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index d136d89e7..76ca804e0 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -391,6 +391,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 64 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 32, struct_switchConfig, nullptr), YAML_PADDING( 432 ), YAML_PADDING( 288 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index b13641645..b5f062019 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -332,6 +332,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 120 ), YAML_PADDING( 120 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp index 717db955e..af38095d0 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp @@ -340,6 +340,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 168 ), YAML_PADDING( 120 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp index 28ea3132b..5acfa240d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp @@ -337,6 +337,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 144 ), YAML_PADDING( 144 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index 707f14360..3837ff5d4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -339,6 +339,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr), YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), + YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), YAML_PADDING( 144 ), YAML_PADDING( 144 ), diff --git a/radio/src/storage/yaml/yaml_defs.h b/radio/src/storage/yaml/yaml_defs.h index bb658e882..45d5d4258 100644 --- a/radio/src/storage/yaml/yaml_defs.h +++ b/radio/src/storage/yaml/yaml_defs.h @@ -30,18 +30,26 @@ /* public definitions */ #define ENUM(label) _yaml_attribute("enum:" _yaml_note(label)) -#define SKIP _yaml_attribute("skip:true") -#define USE_IDX _yaml_attribute("idx:true") -#define FUNC(name) _yaml_attribute("func:" _yaml_note(name)) +#define SKIP _yaml_attribute("skip:true") +#define USE_IDX _yaml_attribute("idx:true") +#define FUNC(name) _yaml_attribute("func:" _yaml_note(name)) #define NAME(label) _yaml_attribute("name:" _yaml_note(label)) -#define CUST(read,write) \ - _yaml_attribute("read:" _yaml_note(read)) \ - _yaml_attribute("write:" _yaml_note(write)) +#define CUST(read, write) \ + _yaml_attribute("read:" _yaml_note(read)) \ + _yaml_attribute("write:" _yaml_note(write)) -#define ARRAY(elmt_size,elmt_type,fcn) \ - _yaml_attribute("array:" _yaml_note(elmt_size) "|" \ - _yaml_note(elmt_type) "|" _yaml_note(fcn)) +#define ARRAY(elmt_size, elmt_type, fcn) \ + _yaml_attribute("array:" _yaml_note(elmt_size) "|" _yaml_note( \ + elmt_type) "|" _yaml_note(fcn)) + +#define CUST_ATTR(tag, read, write) \ + int _dummy_##tag[0] _yaml_attribute("raw:YAML_CUSTOM(" _yaml_note( \ + #tag) "," _yaml_note(read) "," _yaml_note(write) ")") + +#define CUST_ARRAY(tag, elmt_type, fcn) \ + int _dummy_##tag[0] _yaml_attribute("raw:YAML_ARRAY(" _yaml_note( \ + #tag) ", 0, 4, " _yaml_note(elmt_type) ", " _yaml_note(fcn) ")") #else @@ -50,8 +58,10 @@ #define USE_IDX #define FUNC(name) #define NAME(label) -#define CUST(read,write) -#define ARRAY(elmt_size,elmt_type,fcn) +#define CUST(read, write) +#define ARRAY(elmt_size, elmt_type, fcn) +#define CUST_ATTR(tag, read, write) +#define CUST_ARRAY(tag, elmt_type, fcn) #endif diff --git a/radio/src/storage/yaml/yaml_node.h b/radio/src/storage/yaml/yaml_node.h index 9584a1a91..42a515b0a 100644 --- a/radio/src/storage/yaml/yaml_node.h +++ b/radio/src/storage/yaml/yaml_node.h @@ -53,7 +53,7 @@ typedef bool (*yaml_writer_func)(void* opaque, const char* str, size_t len); struct YamlNode { - typedef bool (*is_active_func)(uint8_t* data, uint32_t bitoffs); + typedef bool (*is_active_func)(uint8_t* data, uint32_t bitoffs, uint16_t idx); typedef uint32_t (*cust_to_uint_func)(const YamlNode* node, const char* val, uint8_t val_len); diff --git a/radio/src/storage/yaml/yaml_tree_walker.cpp b/radio/src/storage/yaml/yaml_tree_walker.cpp index 0edd4ea61..d5cfee6e2 100644 --- a/radio/src/storage/yaml/yaml_tree_walker.cpp +++ b/radio/src/storage/yaml/yaml_tree_walker.cpp @@ -369,7 +369,7 @@ bool YamlTreeWalker::isElmtEmpty(uint8_t* data) // assume structs aligned on 8bit boundaries if (node->u._array.u._a.is_active) - return !node->u._array.u._a.is_active(data, bit_ofs); + return !node->u._array.u._a.is_active(data, bit_ofs, getElmts()); return yaml_is_zero(data, bit_ofs, node->size); } diff --git a/radio/util/generate_yaml.py b/radio/util/generate_yaml.py index e9dc1b937..cf522e995 100644 --- a/radio/util/generate_yaml.py +++ b/radio/util/generate_yaml.py @@ -342,6 +342,8 @@ def parse_field_array(f, node): for a in ann: if a['type'] == 'idx': use_idx = True + elif a['type'] == 'raw': + f.raw = a['val'] # let's see first if it's some kind of struct/union/enum elmt_st = parse_node(RootAST, elmt_decl) diff --git a/radio/util/yaml_parser.tmpl b/radio/util/yaml_parser.tmpl index b6b84a905..52216301b 100644 --- a/radio/util/yaml_parser.tmpl +++ b/radio/util/yaml_parser.tmpl @@ -45,8 +45,10 @@ static const struct YamlNode {{ struct.name }}[] = { YAML_UNION("{{ max_len(elmt.name) }}", {{elmt.bits}}, {{elmt.var_type}}_elmts, {{ elmt.func}}), {% elif elmt.type == 'array' %} YAML_ARRAY("{{ max_len(elmt.name) }}", {{elmt.bits // elmt.length}}, {{elmt.length}}, {{elmt.var_type}}, {{ elmt.func }}), + {% elif elmt.raw %} + {{ elmt.raw }}, {% else %} - // name='{{elmt.name}}', type='{{elmt.type}}', bits='{{elmt.bits}}', is_array='{{elmt.is_array}}', var_type='{{elmt.var_type}}', kind='{{elmt.cursor.kind}}' , type.kind='{{elmt.cursor.type.kind}}' + // name='{{elmt.name}}', type='{{elmt.type}}', bits='{{elmt.bits}}', is_array='{{elmt.is_array}}', var_type='{{elmt.var_type}}', kind='{{elmt.cursor.kind}}' , type.kind='{{elmt.cursor.type.kind}}', raw='{{elmt.raw}}' {% endif %} {% endfor %} YAML_END