def generate_dfu_header(cli): """Generates the Keyboard.h file. """ # Determine our keyboard(s) if not cli.config.generate_dfu_header.keyboard: cli.log.error('Missing parameter: --keyboard') cli.subcommands['info'].print_help() return False if not is_keyboard(cli.config.generate_dfu_header.keyboard): cli.log.error('Invalid keyboard: "%s"', cli.config.generate_dfu_header.keyboard) return False # Build the Keyboard.h file. kb_info_json = dotty(info_json(cli.config.generate_dfu_header.keyboard)) keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once'] keyboard_h_lines.append(f'#define MANUFACTURER {kb_info_json["manufacturer"]}') keyboard_h_lines.append(f'#define PRODUCT {kb_info_json["keyboard_name"]} Bootloader') # Optional if 'qmk_lufa_bootloader.esc_output' in kb_info_json: keyboard_h_lines.append(f'#define QMK_ESC_OUTPUT {kb_info_json["qmk_lufa_bootloader.esc_output"]}') if 'qmk_lufa_bootloader.esc_input' in kb_info_json: keyboard_h_lines.append(f'#define QMK_ESC_INPUT {kb_info_json["qmk_lufa_bootloader.esc_input"]}') if 'qmk_lufa_bootloader.led' in kb_info_json: keyboard_h_lines.append(f'#define QMK_LED {kb_info_json["qmk_lufa_bootloader.led"]}') if 'qmk_lufa_bootloader.speaker' in kb_info_json: keyboard_h_lines.append(f'#define QMK_SPEAKER {kb_info_json["qmk_lufa_bootloader.speaker"]}') # Show the results dump_lines(cli.args.output, keyboard_h_lines, cli.args.quiet)
def generate_version_h(cli): """Generates the version.h file. """ if cli.args.skip_all: cli.args.skip_git = True if cli.args.skip_all: current_time = "1970-01-01-00:00:00" else: current_time = strftime(TIME_FMT) if cli.args.skip_git: git_version = "NA" chibios_version = "NA" chibios_contrib_version = "NA" else: git_version = get_git_version(current_time) chibios_version = get_git_version(current_time, "chibios", "os") chibios_contrib_version = get_git_version(current_time, "chibios-contrib", "os") # Build the version.h file. version_h_lines = [ GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once' ] version_h_lines.append(f""" #define QMK_VERSION "{git_version}" #define QMK_BUILDDATE "{current_time}" #define CHIBIOS_VERSION "{chibios_version}" #define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}" """) # Show the results dump_lines(cli.args.output, version_h_lines, cli.args.quiet)
def generate_config_h(cli): """Generates the info_config.h file. """ # Determine our keyboard/keymap if cli.args.keymap: km = locate_keymap(cli.args.keyboard, cli.args.keymap) km_json = json_load(km) validate(km_json, 'qmk.keymap.v1') kb_info_json = dotty(km_json.get('config', {})) else: kb_info_json = dotty(info_json(cli.args.keyboard)) # Build the info_config.h file. config_h_lines = [ GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once' ] generate_config_items(kb_info_json, config_h_lines) generate_matrix_size(kb_info_json, config_h_lines) if 'matrix_pins' in kb_info_json: config_h_lines.append(matrix_pins(kb_info_json['matrix_pins'])) if 'split' in kb_info_json: generate_split_config(kb_info_json, config_h_lines) # Show the results dump_lines(cli.args.output, config_h_lines, cli.args.quiet)
def generate_keyboard_h(cli): """Generates the keyboard.h file. """ has_layout_h = would_populate_layout_h(cli.args.keyboard) # Build the layouts.h file. keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "quantum.h"'] if not has_layout_h: keyboard_h_lines.append('#error("<keyboard>.h is only optional for data driven keyboards - kb.h == bad times")') # Show the results dump_lines(cli.args.output, keyboard_h_lines, cli.args.quiet)
def generate_rules_mk(cli): """Generates a rules.mk file from info.json. """ # Determine our keyboard/keymap if cli.args.keymap: km = locate_keymap(cli.args.keyboard, cli.args.keymap) km_json = json_load(km) validate(km_json, 'qmk.keymap.v1') kb_info_json = dotty(km_json.get('config', {})) else: kb_info_json = dotty(info_json(cli.args.keyboard)) info_rules_map = json_load(Path('data/mappings/info_rules.json')) rules_mk_lines = [GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE] # Iterate through the info_rules map to generate basic rules for rules_key, info_dict in info_rules_map.items(): new_entry = process_mapping_rule(kb_info_json, rules_key, info_dict) if new_entry: rules_mk_lines.append(new_entry) # Iterate through features to enable/disable them if 'features' in kb_info_json: for feature, enabled in kb_info_json['features'].items(): feature = feature.upper() enabled = 'yes' if enabled else 'no' rules_mk_lines.append(f'{feature}_ENABLE ?= {enabled}') # Set SPLIT_TRANSPORT, if needed if kb_info_json.get('split', {}).get('transport', {}).get('protocol') == 'custom': rules_mk_lines.append('SPLIT_TRANSPORT ?= custom') # Set CUSTOM_MATRIX, if needed if kb_info_json.get('matrix_pins', {}).get('custom'): if kb_info_json.get('matrix_pins', {}).get('custom_lite'): rules_mk_lines.append('CUSTOM_MATRIX ?= lite') else: rules_mk_lines.append('CUSTOM_MATRIX ?= yes') # Show the results dump_lines(cli.args.output, rules_mk_lines) if cli.args.output: if cli.args.quiet: if cli.args.escape: print(cli.args.output.as_posix().replace(' ', '\\ ')) else: print(cli.args.output) else: cli.log.info('Wrote rules.mk to %s.', cli.args.output)
def generate_keyboard_c(cli): """Generates the keyboard.h file. """ kb_info_json = info_json(cli.args.keyboard) # Build the layouts.h file. keyboard_h_lines = [ GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#include QMK_KEYBOARD_H', '' ] keyboard_h_lines.extend(_gen_led_config(kb_info_json)) # Show the results dump_lines(cli.args.output, keyboard_h_lines, cli.args.quiet)
def via2json(cli): """Convert a VIA backup json to keymap.json format. This command uses the `qmk.keymap` module to generate a keymap.json from a VIA backup json. The generated keymap is written to stdout, or to a file if -o is provided. """ # Find appropriate layout macro keymap_layout = cli.args.layout if cli.args.layout else _find_via_layout_macro( cli.args.keyboard) if not keymap_layout: cli.log.error( f"Couldn't find LAYOUT macro for keyboard {cli.args.keyboard}. Please specify it with the '-l' argument." ) exit(1) # Load the VIA backup json with cli.args.filename.open('r') as fd: via_backup = json.load(fd) # Generate keyboard metadata keyboard_data = info_json(cli.args.keyboard) # Get keycode array keymap_data = _via_to_keymap(via_backup, keyboard_data, keymap_layout) # Convert macros macro_data = list() if via_backup.get('macros'): macro_data = _convert_macros(via_backup['macros']) # Replace VIA macro keys with JSON keymap ones keymap_data = _fix_macro_keys(keymap_data) # Generate the keymap.json keymap_json = generate_json(cli.args.keymap, cli.args.keyboard, keymap_layout, keymap_data, macro_data) keymap_lines = [json.dumps(keymap_json, cls=KeymapJSONEncoder)] dump_lines(cli.args.output, keymap_lines, cli.args.quiet)