CLI: Parse USB device version BCD (#14580)

* CLI: Parse USB device version BCD

* Apply suggestions
This commit is contained in:
Ryan 2022-01-17 08:44:34 +11:00 committed by GitHub
parent 557fbbd6af
commit c72ed7c024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 88 additions and 52 deletions

View File

@ -15,6 +15,8 @@
"COMBO_TERM": {"info_key": "combo.term", "value_type": "int"}, "COMBO_TERM": {"info_key": "combo.term", "value_type": "int"},
"DEBOUNCE": {"info_key": "debounce", "value_type": "int"}, "DEBOUNCE": {"info_key": "debounce", "value_type": "int"},
"DEVICE_VER": {"info_key": "usb.device_ver", "value_type": "hex"}, "DEVICE_VER": {"info_key": "usb.device_ver", "value_type": "hex"},
# TODO: Replace ^^^ with vvv
#"DEVICE_VER": {"info_key": "usb.device_version", "value_type": "bcd_version"},
"DESCRIPTION": {"info_key": "keyboard_folder", "to_json": false}, "DESCRIPTION": {"info_key": "keyboard_folder", "to_json": false},
"DIODE_DIRECTION": {"info_key": "diode_direction"}, "DIODE_DIRECTION": {"info_key": "diode_direction"},
"FORCE_NKRO": {"info_key": "usb.force_nkro", "value_type": "bool"}, "FORCE_NKRO": {"info_key": "usb.force_nkro", "value_type": "bool"},

View File

@ -20,6 +20,10 @@
"type": "string", "type": "string",
"pattern": "^0x[0-9A-F]{4}$" "pattern": "^0x[0-9A-F]{4}$"
}, },
"bcd_version": {
"type": "string",
"pattern": "^[0-9]{1,2}\\.[0-9]\\.[0-9]$"
},
"text_identifier": { "text_identifier": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
@ -70,13 +74,13 @@
"signed_int": { "signed_int": {
"type": "number", "type": "number",
"multipleOf": 1 "multipleOf": 1
} },
"signed_int_8": { "signed_int_8": {
"type": "number", "type": "number",
"min": -127, "min": -127,
"max": 127, "max": 127,
"multipleOf": 1 "multipleOf": 1
} },
"string_array": { "string_array": {
"type": "array", "type": "array",
"items": { "items": {
@ -97,7 +101,7 @@
"type": "number", "type": "number",
"min": 0, "min": 0,
"multipleOf": 1 "multipleOf": 1
} },
"unsigned_int_8": { "unsigned_int_8": {
"type": "number", "type": "number",
"min": 0, "min": 0,

View File

@ -320,7 +320,8 @@
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"device_ver": {"$ref": "qmk.definitions.v1#/hex_number_4d"}, "device_ver": {"$ref": "qmk.definitions.v1#/hex_number_4d"}, # Deprecated
"device_version": {"$ref": "qmk.definitions.v1#/bcd_version"},
"force_nkro": {"type": "boolean"}, "force_nkro": {"type": "boolean"},
"pid": {"$ref": "qmk.definitions.v1#/hex_number_4d"}, "pid": {"$ref": "qmk.definitions.v1#/hex_number_4d"},
"vid": {"$ref": "qmk.definitions.v1#/hex_number_4d"}, "vid": {"$ref": "qmk.definitions.v1#/hex_number_4d"},

View File

@ -172,7 +172,7 @@ The following animations can be enabled:
### USB ### USB
Every USB keyboard needs to have its USB parmaters defined. At a minimum you need to set vid, pid, and device version. Every USB keyboard needs to have its USB parameters defined. At a minimum you need to set the Vendor ID, Product ID, and device version.
Example: Example:
@ -181,7 +181,9 @@ Example:
"usb": { "usb": {
"vid": "0xC1ED", "vid": "0xC1ED",
"pid": "0x23B0", "pid": "0x23B0",
"device_ver": "0x0001" "device_version": "1.0.0"
} }
} }
``` ```
The device version is a BCD (binary coded decimal) value, in the format `MMmr`, so the below value would look like `0x0100` in the generated code. This also means the maximum valid values for each part are `99.9.9`, despite it being a hexadecimal value under the hood.

View File

@ -19,9 +19,9 @@
#include "config_common.h" #include "config_common.h"
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0x4025 #define VENDOR_ID 0x4025 // 40%
#define PRODUCT_ID 0x0A0C #define PRODUCT_ID 0x0F25
#define DEVICE_VER 0x0F25 #define DEVICE_VER 0x0100
#define MANUFACTURER di0ib #define MANUFACTURER di0ib
#define PRODUCT The 5x5 Keyboard #define PRODUCT The 5x5 Keyboard

View File

@ -5,9 +5,9 @@
#include "config_common.h" #include "config_common.h"
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0x4025 #define VENDOR_ID 0x4025 // 40%
#define PRODUCT_ID 0x0A0C #define PRODUCT_ID 0x05B5
#define DEVICE_VER 0x05B5 #define DEVICE_VER 0x0100
#define MANUFACTURER di0ib #define MANUFACTURER di0ib
#define PRODUCT The 5x5 Keyboard #define PRODUCT The 5x5 Keyboard

View File

@ -19,9 +19,9 @@
#include "config_common.h" #include "config_common.h"
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0x4025 #define VENDOR_ID 0x4025 // 40%
#define PRODUCT_ID 0x0A0C #define PRODUCT_ID 0x0F61
#define DEVICE_VER 0x0F61 #define DEVICE_VER 0x0100
#define MANUFACTURER di0ib #define MANUFACTURER di0ib
#define PRODUCT The 6lit Macropad #define PRODUCT The 6lit Macropad

View File

@ -19,9 +19,9 @@
#include "config_common.h" #include "config_common.h"
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0x4025 #define VENDOR_ID 0x4025 // 40%
#define PRODUCT_ID 0x0A0C #define PRODUCT_ID 0x0F00
#define DEVICE_VER 0x0F00 #define DEVICE_VER 0x0100
#define MANUFACTURER di0ib #define MANUFACTURER di0ib
#define PRODUCT The foobar Keyboard #define PRODUCT The foobar Keyboard

View File

@ -20,9 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config_common.h" #include "config_common.h"
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0x4025 #define VENDOR_ID 0x4025 // 40%
#define PRODUCT_ID 0x0A0C #define PRODUCT_ID 0x4A1F
#define DEVICE_VER 0x4A1F #define DEVICE_VER 0x0100
#define MANUFACTURER di0ib #define MANUFACTURER di0ib
#define PRODUCT half_n_half #define PRODUCT half_n_half

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define DEVICE_VER 0x07E3 #define DEVICE_VER 0x2019
#undef MATRIX_ROWS #undef MATRIX_ROWS
#undef MATRIX_COLS #undef MATRIX_COLS

View File

@ -37,7 +37,7 @@
}, },
"url": "https://caps-unlocked.com/cu80-round-2/", "url": "https://caps-unlocked.com/cu80-round-2/",
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x0081", "pid": "0x0081",
"vid": "0x4355" "vid": "0x4355"
}, },

View File

@ -37,7 +37,7 @@
}, },
"url": "https://caps-unlocked.com/cu80-round-2/", "url": "https://caps-unlocked.com/cu80-round-2/",
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x0080", "pid": "0x0080",
"vid": "0x4355" "vid": "0x4355"
}, },

View File

@ -32,7 +32,7 @@
}, },
"url": "", "url": "",
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2312", "pid": "0x2312",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -24,7 +24,7 @@
"rows": ["C0", "C1", "C2", "C3", "C7", "F7", "B1", "F2", "F3", "F4", "F5", "F6", "C6"] "rows": ["C0", "C1", "C2", "C3", "C7", "F7", "B1", "F2", "F3", "F4", "F5", "F6", "C6"]
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x23A0", "pid": "0x23A0",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -25,7 +25,7 @@
"rows": ["B0", "B1", "B2", "A15", "A10"] "rows": ["B0", "B1", "B2", "A15", "A10"]
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2350", "pid": "0x2350",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -37,7 +37,7 @@
"saturation_steps": 17 "saturation_steps": 17
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2301", "pid": "0x2301",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -37,7 +37,7 @@
"saturation_steps": 17 "saturation_steps": 17
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2320", "pid": "0x2320",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -37,7 +37,7 @@
"saturation_steps": 17 "saturation_steps": 17
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2370", "pid": "0x2370",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -36,7 +36,7 @@
"saturation_steps": 17 "saturation_steps": 17
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2390", "pid": "0x2390",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -25,7 +25,7 @@
"rows": ["B11", "A6", "A3", "A2", "A1", "B5", "B6", "C15", "C14", "C13"] "rows": ["B11", "A6", "A3", "A2", "A1", "B5", "B6", "C15", "C14", "C13"]
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2391", "pid": "0x2391",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -37,7 +37,7 @@
"saturation_steps": 17 "saturation_steps": 17
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2390", "pid": "0x2390",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -32,7 +32,7 @@
"saturation_steps": 17 "saturation_steps": 17
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2330", "pid": "0x2330",
"vid": "0xC1ED" "vid": "0xC1ED"
}, },

View File

@ -2,7 +2,7 @@
"manufacturer": "Clueboard", "manufacturer": "Clueboard",
"maintainer": "skullydazed", "maintainer": "skullydazed",
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"vid": "0xC1ED" "vid": "0xC1ED"
} }
} }

View File

@ -5,7 +5,7 @@
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED #define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x0C61 #define PRODUCT_ID 0x0C61
#define DEVICE_VER 0x00C6 #define DEVICE_VER 0x0100
#define MANUFACTURER PeiorisBoards #define MANUFACTURER PeiorisBoards
#define PRODUCT Ixora Rev1 #define PRODUCT Ixora Rev1

View File

@ -5,7 +5,7 @@
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED #define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x0C61 #define PRODUCT_ID 0x0C61
#define DEVICE_VER 0x00C6 #define DEVICE_VER 0x0100
#define MANUFACTURER PeiorisBoards #define MANUFACTURER PeiorisBoards
#define PRODUCT Vinta R1 #define PRODUCT Vinta R1

View File

@ -5,7 +5,7 @@
"usb": { "usb": {
"vid": "0x1209", "vid": "0x1209",
"pid": "0x69A1", "pid": "0x69A1",
"device_ver": "0x0001" "device_version": "0.0.1",
}, },
"diode_direction": "COL2ROW", "diode_direction": "COL2ROW",
"layouts": { "layouts": {

View File

@ -20,7 +20,7 @@
"usb": { "usb": {
"vid": "0xD772", "vid": "0xD772",
"pid": "0x000A", "pid": "0x000A",
"device_ver": "0x0001" "device_version": "0.0.1"
}, },
"layouts": { "layouts": {
"LAYOUT_all": { "LAYOUT_all": {

View File

@ -26,7 +26,7 @@
}, },
"processor": "atmega32u4", "processor": "atmega32u4",
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2320", "pid": "0x2320",
"vid": "0xFEED" "vid": "0xFEED"
}, },

View File

@ -32,7 +32,7 @@
] ]
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2321", "pid": "0x2321",
"vid": "0xFEED" "vid": "0xFEED"
}, },

View File

@ -28,7 +28,7 @@
] ]
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2322", "pid": "0x2322",
"vid": "0xFEED" "vid": "0xFEED"
}, },

View File

@ -35,7 +35,7 @@
] ]
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2323", "pid": "0x2323",
"vid": "0xFEED" "vid": "0xFEED"
}, },

View File

@ -27,7 +27,7 @@
] ]
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2324", "pid": "0x2324",
"vid": "0xFEED" "vid": "0xFEED"
}, },

View File

@ -27,7 +27,7 @@
] ]
}, },
"usb": { "usb": {
"device_ver": "0x0001", "device_version": "0.0.1",
"pid": "0x2325", "pid": "0x2325",
"vid": "0xFEED" "vid": "0xFEED"
}, },

View File

@ -12,7 +12,7 @@
"usb": { "usb": {
"vid": "0x4E53", "vid": "0x4E53",
"pid": "0x0F65", "pid": "0x0F65",
"device_ver": "0x0001" "device_version": "0.0.1"
}, },
"features": { "features": {
"bootmagic": true, "bootmagic": true,

View File

@ -37,6 +37,6 @@
"usb": { "usb": {
"vid": "0x4642", "vid": "0x4642",
"pid": "0x6F21", "pid": "0x6F21",
"device_ver": "0x0001" "device_version": "0.0.1"
} }
} }

View File

@ -5,7 +5,7 @@
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED #define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x0C60 #define PRODUCT_ID 0x0C60
#define DEVICE_VER 0x00C6 #define DEVICE_VER 0x0100
#define MANUFACTURER PeiorisBoards #define MANUFACTURER PeiorisBoards
#define PRODUCT QC60 #define PRODUCT QC60

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED #define VENDOR_ID 0xFEED
#define PRODUCT_ID 0xE401 #define PRODUCT_ID 0xE401
#define DEVICE_VER 0x0E41 #define DEVICE_VER 0x0100
#define MANUFACTURER That-Canadian #define MANUFACTURER That-Canadian
#define PRODUCT Lets Split Eh? #define PRODUCT Lets Split Eh?

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0xB16B #define VENDOR_ID 0xB16B
#define PRODUCT_ID 0x00B1 #define PRODUCT_ID 0x00B1
#define DEVICE_VER 0xE500 #define DEVICE_VER 0x0100
#define MANUFACTURER Ramon Imbao #define MANUFACTURER Ramon Imbao
#define PRODUCT SquishyTKL #define PRODUCT SquishyTKL

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED #define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x0A0C #define PRODUCT_ID 0x0A0C
#define DEVICE_VER 0x4A1F #define DEVICE_VER 0x0100
#define MANUFACTURER Kyle Terry #define MANUFACTURER Kyle Terry
#define PRODUCT spacetime #define PRODUCT spacetime

View File

@ -10,7 +10,7 @@
"usb":{ "usb":{
"vid":"0x7474", "vid":"0x7474",
"pid":"0x6270", "pid":"0x6270",
"device_ver":"0x0001" "device_version":"0.0.1"
}, },
"layouts": { "layouts": {
"LAYOUT": { "LAYOUT": {

View File

@ -108,6 +108,12 @@ def generate_config_items(kb_info_json, config_h_lines):
config_h_lines.append(f'#ifndef {key}') config_h_lines.append(f'#ifndef {key}')
config_h_lines.append(f'# define {key} {value}') config_h_lines.append(f'# define {key} {value}')
config_h_lines.append(f'#endif // {key}') config_h_lines.append(f'#endif // {key}')
elif key_type == 'bcd_version':
(major, minor, revision) = config_value.split('.')
config_h_lines.append('')
config_h_lines.append(f'#ifndef {config_key}')
config_h_lines.append(f'# define {config_key} 0x{major.zfill(2)}{minor}{revision}')
config_h_lines.append(f'#endif // {config_key}')
else: else:
config_h_lines.append('') config_h_lines.append('')
config_h_lines.append(f'#ifndef {config_key}') config_h_lines.append(f'#ifndef {config_key}')

View File

@ -387,6 +387,19 @@ def _extract_matrix_info(info_data, config_c):
return info_data return info_data
# TODO: kill off usb.device_ver in favor of usb.device_version
def _extract_device_version(info_data):
if info_data.get('usb'):
if info_data['usb'].get('device_version') and not info_data['usb'].get('device_ver'):
(major, minor, revision) = info_data['usb']['device_version'].split('.', 3)
info_data['usb']['device_ver'] = f'0x{major.zfill(2)}{minor}{revision}'
if not info_data['usb'].get('device_version') and info_data['usb'].get('device_ver'):
major = int(info_data['usb']['device_ver'][2:4])
minor = int(info_data['usb']['device_ver'][4])
revision = int(info_data['usb']['device_ver'][5])
info_data['usb']['device_version'] = f'{major}.{minor}.{revision}'
def _extract_config_h(info_data): def _extract_config_h(info_data):
"""Pull some keyboard information from existing config.h files """Pull some keyboard information from existing config.h files
""" """
@ -430,6 +443,13 @@ def _extract_config_h(info_data):
elif key_type == 'int': elif key_type == 'int':
dotty_info[info_key] = int(config_c[config_key]) dotty_info[info_key] = int(config_c[config_key])
elif key_type == 'bcd_version':
major = int(config_c[config_key][2:4])
minor = int(config_c[config_key][4])
revision = int(config_c[config_key][5])
dotty_info[info_key] = f'{major}.{minor}.{revision}'
else: else:
dotty_info[info_key] = config_c[config_key] dotty_info[info_key] = config_c[config_key]
@ -444,6 +464,7 @@ def _extract_config_h(info_data):
_extract_split_main(info_data, config_c) _extract_split_main(info_data, config_c)
_extract_split_transport(info_data, config_c) _extract_split_transport(info_data, config_c)
_extract_split_right_pins(info_data, config_c) _extract_split_right_pins(info_data, config_c)
_extract_device_version(info_data)
return info_data return info_data