Browse Source

Implement data driven joysticks

zvecr 3 months ago
parent
commit
0ed0ce46ee
9 changed files with 73 additions and 11 deletions
  1. +5
    -0
      data/mappings/info_config.hjson
  2. +2
    -0
      data/mappings/info_rules.hjson
  3. +33
    -0
      data/schemas/keyboard.jsonschema
  4. +0
    -6
      keyboards/handwired/battleship_gamepad/battleship_gamepad.c
  5. +0
    -4
      keyboards/handwired/battleship_gamepad/config.h
  6. +9
    -0
      keyboards/handwired/battleship_gamepad/info.json
  7. +0
    -1
      keyboards/handwired/battleship_gamepad/rules.mk
  8. +21
    -0
      lib/python/qmk/cli/generate/keyboard_c.py
  9. +3
    -0
      lib/python/qmk/info.py

+ 5
- 0
data/mappings/info_config.hjson View File

@ -70,6 +70,11 @@
"LED_KANA_PIN": {"info_key": "indicators.kana"},
"LED_PIN_ON_STATE": {"info_key": "indicators.on_state", "value_type": "int"},
// Joystick
"JOYSTICK_AXIS_COUNT": {"info_key": "joystick.axis_count", "value_type": "int"},
"JOYSTICK_AXIS_RESOLUTION": {"info_key": "joystick.axis_resolution", "value_type": "int"},
"JOYSTICK_BUTTON_COUNT": {"info_key": "joystick.button_count", "value_type": "int"},
// Leader Key
"LEADER_PER_KEY_TIMING": {"info_key": "leader_key.timing", "value_type": "flag"},
"LEADER_KEY_STRICT_KEY_PROCESSING": {"info_key": "leader_key.strict_processing", "value_type": "flag"},


+ 2
- 0
data/mappings/info_rules.hjson View File

@ -23,6 +23,8 @@
"ENCODER_ENABLE": {"info_key": "encoder.enabled", "value_type": "bool"},
"ENCODER_DRIVER": {"info_key": "encoder.driver"},
"FIRMWARE_FORMAT": {"info_key": "build.firmware_format"},
"JOYSTICK_DRIVER": {"info_key": "joystick.driver"},
"JOYSTICK_ENABLE": {"info_key": "joystick.enabled", "value_type": "bool"},
"KEYBOARD_SHARED_EP": {"info_key": "usb.shared_endpoint.keyboard", "value_type": "bool"},
"LAYOUTS": {"info_key": "community_layouts", "value_type": "list"},
"LED_MATRIX_DRIVER": {"info_key": "led_matrix.driver"},


+ 33
- 0
data/schemas/keyboard.jsonschema View File

@ -332,6 +332,39 @@
"on_state": {"$ref": "qmk.definitions.v1#/bit"}
}
},
"joystick": {
"type": "object",
"properties": {
"enabled": {"type": "boolean"},
"driver": {"type": "string"},
"button_count": {"$ref": "qmk.definitions.v1#/unsigned_int"},
"axis_resolution": {"$ref": "qmk.definitions.v1#/unsigned_int"},
"axes": {
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"additionalProperties": false,
"properties": {
"input_pin": {"$ref": "qmk.definitions.v1#/mcu_pin"},
"low": {"$ref": "qmk.definitions.v1#/unsigned_int"},
"rest": {"$ref": "qmk.definitions.v1#/unsigned_int"},
"high": {"$ref": "qmk.definitions.v1#/unsigned_int"}
}
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"virtual": {"type": "boolean"}
}
}
]
}
}
}
},
"keycodes": {"$ref": "qmk.definitions.v1#/keycode_decl_array"},
"layout_aliases": {
"type": "object",


+ 0
- 6
keyboards/handwired/battleship_gamepad/battleship_gamepad.c View File

@ -16,12 +16,6 @@
#include "quantum.h"
/* joystick config */
joystick_config_t joystick_axes[JOYSTICK_AXIS_COUNT] = {
[0] = JOYSTICK_AXIS_IN(F5, 1023, 512, 0),
[1] = JOYSTICK_AXIS_IN(F4, 0, 512, 1023)
};
/* joystick button code (thumbstick pressed) */
void keyboard_pre_init_kb(void) {
setPinInputHigh(F6);


+ 0
- 4
keyboards/handwired/battleship_gamepad/config.h View File

@ -16,10 +16,6 @@
#pragma once
/* joystick configuration */
#define JOYSTICK_BUTTON_COUNT 25
#define JOYSTICK_AXIS_RESOLUTION 10
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE


+ 9
- 0
keyboards/handwired/battleship_gamepad/info.json View File

@ -13,6 +13,15 @@
"rows": ["B6", "B2", "B3", "B1", "F7"]
},
"diode_direction": "COL2ROW",
"joystick": {
"button_count": 25,
"axis_resolution": 10,
"axes": [
{"input_pin": "F5", "low": 1023, "rest": 512, "high": 0},
{"input_pin": "F4", "low": 0, "rest": 512, "high": 1023},
{"virtual": true}
]
},
"processor": "atmega32u4",
"bootloader": "caterina",
"layouts": {


+ 0
- 1
keyboards/handwired/battleship_gamepad/rules.mk View File

@ -11,4 +11,3 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
AUDIO_ENABLE = no # Audio output
JOYSTICK_ENABLE = yes
JOYSTICK_DRIVER = analog

+ 21
- 0
lib/python/qmk/cli/generate/keyboard_c.py View File

@ -91,6 +91,26 @@ def _gen_matrix_mask(info_data):
return lines
def _gen_joystick_axes(info_data):
"""Convert info.json content to joystick_axes
"""
if 'axes' not in info_data.get('joystick', {}):
return []
lines = []
lines.append('#ifdef JOYSTICK_ENABLE')
lines.append('joystick_config_t joystick_axes[JOYSTICK_AXIS_COUNT] = {')
for index, axis in enumerate(info_data['joystick']['axes']):
if 'input_pin' in axis:
lines.append(f" [{index}] = JOYSTICK_AXIS_IN({axis['input_pin']}, {axis['low']}, {axis['rest']}, {axis['high']}),")
else:
lines.append(f" [{index}] = JOYSTICK_AXIS_VIRTUAL,")
lines.append('};')
lines.append('#endif')
return lines
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
@cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate keyboard.c for.')
@ -105,6 +125,7 @@ def generate_keyboard_c(cli):
keyboard_h_lines.extend(_gen_led_configs(kb_info_json))
keyboard_h_lines.extend(_gen_matrix_mask(kb_info_json))
keyboard_h_lines.extend(_gen_joystick_axes(kb_info_json))
# Show the results
dump_lines(cli.args.output, keyboard_h_lines, cli.args.quiet)

+ 3
- 0
lib/python/qmk/info.py View File

@ -215,6 +215,9 @@ def info_json(keyboard):
# Merge in data from <keyboard.c>
info_data = _extract_led_config(info_data, str(keyboard))
if 'axes' in info_data.get('joystick', {}):
info_data['joystick']['axis_count'] = len(info_data['joystick']['axes'])
# Validate
_validate(keyboard, info_data)


Loading…
Cancel
Save