Update usb_usb to current tmk_kbd/core code.

master
flabbergast 6 years ago
parent 5735053085
commit ac35130dc6
  1. 47
      usb_usb/Makefile
  2. 31
      usb_usb/keymap_common.c
  3. 2
      usb_usb/keymap_common.h
  4. 12
      usb_usb/keymap_js.c
  5. 36
      usb_usb/main.cpp
  6. 2
      usb_usb/matrix.c
  7. 233
      usb_usb/usb_usb.cpp

@ -39,15 +39,15 @@
#----------------------------------------------------------------------------
# Target file name (without extension).
TARGET = usb_usb
TARGET ?= usb_usb
TMK_DIR = ../../tmk_core
TMK_DIR ?= ../../tmk_keyboard/tmk_core
# Directory keyboard dependent files exist
TARGET_DIR = .
TARGET_DIR ?= .
# MCU name
MCU = atmega32u4
MCU ?= atmega32u4
# Processor frequency.
@ -61,7 +61,7 @@ MCU = atmega32u4
# does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate
# software delays.
F_CPU = 16000000
F_CPU ?= 16000000
@ -69,7 +69,7 @@ F_CPU = 16000000
# LUFA specific
#
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
ARCH ?= AVR8
# Input clock frequency.
# This will define a symbol, F_USB, in all source code files equal to the
# input clock frequency (before any prescaling is performed) in Hz. This value may
@ -81,20 +81,21 @@ ARCH = AVR8
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_USB = $(F_CPU)
F_USB ?= $(F_CPU)
# Interrupt driven control endpoint task
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
# Build Options
# comment out to disable the options.
# comment out to disable the options.
#
MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Media control and System control
CONSOLE_ENABLE = yes # Console for debug
#COMMAND_ENABLE = yes # Commands for debug and configuration
#NKRO_ENABLE = yes # USB Nkey Rollover
MOUSEKEY_ENABLE ?= yes # Mouse keys
EXTRAKEY_ENABLE ?= yes # Media control and System control
CONSOLE_ENABLE ?= yes # Console for debug
#COMMAND_ENABLE ?= yes # Commands for debug and configuration
#NKRO_ENABLE ?= yes # USB Nkey Rollover
# Boot Section Size in bytes
# Teensy halfKay 512
@ -108,18 +109,28 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096
#OPT_DEFS += -DNO_ACTION_LAYER
#OPT_DEFS += -DNO_ACTION_MACRO
SRC = \
keymap_common.c \
matrix.c \
SRC ?= usb_usb.cpp \
main.cpp
#
# Keymap file
#
ifeq (yes,$(strip $(UNIMAP_ENABLE)))
KEYMAP_FILE = unimap
else
ifeq (yes,$(strip $(ACTIONMAP_ENABLE)))
KEYMAP_FILE = actionmap
else
KEYMAP_FILE = keymap
endif
endif
ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC)
SRC := $(KEYMAP_FILE)_$(KEYMAP).c $(SRC)
else
SRC := keymap_js.c $(SRC)
endif
CONFIG_H = config.h
CONFIG_H ?= config.h

@ -1,31 +0,0 @@
/*
Copyright 2014 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "keymap_common.h"
#include "progmem.h"
/* translates key to keycode */
uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
{
return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
}
/* translates Fn keycode to action */
action_t keymap_fn_to_action(uint8_t keycode)
{
return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
}

@ -29,7 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
extern const uint16_t fn_actions[];
extern const action_t fn_actions[];
/* ,---------------. ,---------------. ,---------------.

@ -8,9 +8,9 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
* |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |FN1|FN1|Pau| |VDn|VUp|Mut|Pwr| | Help |
* `---' `---------------' `---------------' `---------------' `-----------' `---------------' `-------'
* ,-----------------------------------------------------------. ,-----------. ,---------------. ,-------.
* | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|JPY| \ | |Ins|Hom|PgU| |NmL| /| *| -| |Stp|Agn|
* | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|JPY|Bsp| |Ins|Hom|PgU| |NmL| /| *| -| |Stp|Agn|
* |-----------------------------------------------------------| |-----------| |---------------| |-------|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| Bsp | |Del|End|PgD| | 7| 8| 9| +| |Mnu|Und|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | |Del|End|PgD| | 7| 8| 9| +| |Mnu|Und|
* |-----------------------------------------------------------| `-----------' |---------------| |-------|
* |CapsL | A| S| D| F| G| H| J| K| L| ;| :| #|Retn| | 4| 5| 6|KP,| |Sel|Cpy|
* |-----------------------------------------------------------| ,---. |---------------| |-------|
@ -22,8 +22,8 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
KEYMAP_ALL(
F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24,
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, FN1, FN1, PAUS, VOLD,VOLU,MUTE,PWR, HELP,
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, JYEN,BSLS, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, STOP,AGIN,
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSPC, DEL, END, PGDN, P7, P8, P9, PPLS, MENU,UNDO,
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, JYEN,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, STOP,AGIN,
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSLS, DEL, END, PGDN, P7, P8, P9, PPLS, MENU,UNDO,
CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, NUHS,ENT, P4, P5, P6, PCMM, SLCT,COPY,
LSFT,NUBS,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RO, RSFT, UP, P1, P2, P3, PEQL, EXEC,PSTE,
LCTL,LALT,LGUI,MHEN,HANJ, SPC, HAEN,HENK,KANA,RGUI,RALT,RCTL,FN0, LEFT,DOWN,RGHT, P0, PDOT,PENT, FIND,CUT
@ -95,7 +95,7 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24,
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS,TRNS,BRK, VOLD,VOLU,MUTE,PWR, HELP,
GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS,DEL, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, STOP,AGIN,
TAB, WH_L,WH_D,MS_U,WH_U,WH_R,NO, PGUP,UP, PGDN,NO, NO, NO, BSPC, DEL, END, PGDN, P7, P8, P9, PPLS, MENU,UNDO,
TAB, WH_L,WH_D,MS_U,WH_U,WH_R,NO, PGUP,UP, PGDN,NO, NO, NO, NO, DEL, END, PGDN, P7, P8, P9, PPLS, MENU,UNDO,
LCTL,BTN3,MS_L,MS_D,MS_R,NO, NO, LEFT,DOWN,RGHT,FN2, NO, NO, ENT, P4, P5, P6, PCMM, SLCT,COPY,
LSFT,BTN3,BTN2,BTN1,BTN4,BTN5,NO, NO, FN3, FN4, NO, NO, RO, RSFT, UP, P1, P2, P3, PEQL, EXEC,PSTE,
LCTL,LGUI,LALT,TRNS,TRNS, BTN1, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, LEFT,DOWN,RGHT, P0, PDOT,PENT, FIND,CUT
@ -138,7 +138,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
/*
* Fn action definition
*/
const uint16_t fn_actions[] PROGMEM = {
const action_t fn_actions[] PROGMEM = {
[0] = ACTION_LAYER_MOMENTARY(2),
[1] = ACTION_LAYER_TOGGLE(1),
[2] = ACTION_LAYER_TAP_KEY(3, KC_SCLN),

@ -3,17 +3,9 @@
#include <avr/power.h>
#include <util/delay.h>
// USB HID host
#include "Usb.h"
#include "usbhub.h"
#include "hid.h"
#include "hidboot.h"
#include "parser.h"
// LUFA
#include "lufa.h"
#include "timer.h"
#include "sendchar.h"
#include "debug.h"
#include "keyboard.h"
@ -64,22 +56,6 @@ static void LUFA_setup(void)
/*
* USB Host Shield HID keyboard
*/
USB usb_host;
USBHub hub1(&usb_host);
HIDBoot<HID_PROTOCOL_KEYBOARD> kbd(&usb_host);
KBDReportParser kbd_parser;
void led_set(uint8_t usb_led)
{
kbd.SetReport(0, 0, 2, 0, 1, &usb_led);
}
int main(void)
{
// LED for debug
@ -94,10 +70,6 @@ int main(void)
LUFA_setup();
// USB Host Shield setup
usb_host.Init();
kbd.SetReportParser(0, (HIDReportParser*)&kbd_parser);
/* NOTE: Don't insert time consuming job here.
* It'll cause unclear initialization failure when DFU reset(worm start).
*/
@ -111,17 +83,9 @@ int main(void)
debug("init: done\n");
uint16_t timer;
for (;;) {
keyboard_task();
timer = timer_read();
usb_host.Task();
timer = timer_elapsed(timer);
if (timer > 100) {
debug("host.Task: "); debug_hex16(timer); debug("\n");
}
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
// LUFA Task for control request
USB_USBTask();

@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <stdbool.h>
#include "usb_hid.h"
#include "keycode.h"
#include "util.h"
#include "print.h"
#include "debug.h"
#include "matrix.h"
#include "usb_hid.h"
/* KEY CODE to Matrix
*

@ -0,0 +1,233 @@
/*
Copyright 2016 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdbool.h>
// USB HID host
#include "Usb.h"
#include "usbhub.h"
#include "hid.h"
#include "hidboot.h"
#include "parser.h"
#include "keycode.h"
#include "util.h"
#include "print.h"
#include "debug.h"
#include "timer.h"
#include "matrix.h"
#include "led.h"
#include "host.h"
#include "keyboard.h"
/* KEY CODE to Matrix
*
* HID keycode(1 byte):
* Higher 5 bits indicates ROW and lower 3 bits COL.
*
* 7 6 5 4 3 2 1 0
* +---------------+
* | ROW | COL |
* +---------------+
*
* Matrix space(16 * 16):
* r\c0123456789ABCDEF
* 0 +----------------+
* : | |
* : | |
* 16 +----------------+
*/
#define ROW_MASK 0xF0
#define COL_MASK 0x0F
#define CODE(row, col) (((row) << 4) | (col))
#define ROW(code) (((code) & ROW_MASK) >> 4)
#define COL(code) ((code) & COL_MASK)
#define ROW_BITS(code) (1 << COL(code))
// Integrated key state of all keyboards
static report_keyboard_t keyboard_report;
static bool matrix_is_mod =false;
/*
* USB Host Shield HID keyboards
* This supports two cascaded hubs and four keyboards
*/
USB usb_host;
USBHub hub1(&usb_host);
USBHub hub2(&usb_host);
HIDBoot<HID_PROTOCOL_KEYBOARD> kbd1(&usb_host);
HIDBoot<HID_PROTOCOL_KEYBOARD> kbd2(&usb_host);
HIDBoot<HID_PROTOCOL_KEYBOARD> kbd3(&usb_host);
HIDBoot<HID_PROTOCOL_KEYBOARD> kbd4(&usb_host);
KBDReportParser kbd_parser1;
KBDReportParser kbd_parser2;
KBDReportParser kbd_parser3;
KBDReportParser kbd_parser4;
uint8_t matrix_rows(void) { return MATRIX_ROWS; }
uint8_t matrix_cols(void) { return MATRIX_COLS; }
bool matrix_has_ghost(void) { return false; }
void matrix_init(void) {
// USB Host Shield setup
usb_host.Init();
kbd1.SetReportParser(0, (HIDReportParser*)&kbd_parser1);
kbd2.SetReportParser(0, (HIDReportParser*)&kbd_parser2);
kbd3.SetReportParser(0, (HIDReportParser*)&kbd_parser3);
kbd4.SetReportParser(0, (HIDReportParser*)&kbd_parser4);
}
static void or_report(report_keyboard_t report) {
// integrate reports into keyboard_report
keyboard_report.mods |= report.mods;
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
if (IS_ANY(report.keys[i])) {
for (uint8_t j = 0; j < KEYBOARD_REPORT_KEYS; j++) {
if (! keyboard_report.keys[j]) {
keyboard_report.keys[j] = report.keys[i];
break;
}
}
}
}
}
uint8_t matrix_scan(void) {
static uint16_t last_time_stamp1 = 0;
static uint16_t last_time_stamp2 = 0;
static uint16_t last_time_stamp3 = 0;
static uint16_t last_time_stamp4 = 0;
// check report came from keyboards
if (kbd_parser1.time_stamp != last_time_stamp1 ||
kbd_parser2.time_stamp != last_time_stamp2 ||
kbd_parser3.time_stamp != last_time_stamp3 ||
kbd_parser4.time_stamp != last_time_stamp4) {
last_time_stamp1 = kbd_parser1.time_stamp;
last_time_stamp2 = kbd_parser2.time_stamp;
last_time_stamp3 = kbd_parser3.time_stamp;
last_time_stamp4 = kbd_parser4.time_stamp;
// clear and integrate all reports
keyboard_report = {};
or_report(kbd_parser1.report);
or_report(kbd_parser2.report);
or_report(kbd_parser3.report);
or_report(kbd_parser4.report);
matrix_is_mod = true;
dprintf("state: %02X %02X", keyboard_report.mods, keyboard_report.reserved);
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
dprintf(" %02X", keyboard_report.keys[i]);
}
dprint("\r\n");
} else {
matrix_is_mod = false;
}
uint16_t timer;
timer = timer_read();
usb_host.Task();
timer = timer_elapsed(timer);
if (timer > 100) {
dprintf("host.Task: %d\n", timer);
}
static uint8_t usb_state = 0;
if (usb_state != usb_host.getUsbTaskState()) {
usb_state = usb_host.getUsbTaskState();
dprintf("usb_state: %02X\n", usb_state);
// restore LED state when keyboard comes up
if (usb_state == USB_STATE_RUNNING) {
keyboard_set_leds(host_keyboard_leds());
}
}
return 1;
}
bool matrix_is_modified(void) {
return matrix_is_mod;
}
bool matrix_is_on(uint8_t row, uint8_t col) {
uint8_t code = CODE(row, col);
if (IS_MOD(code)) {
if (keyboard_report.mods & ROW_BITS(code)) {
return true;
}
}
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
if (keyboard_report.keys[i] == code) {
return true;
}
}
return false;
}
matrix_row_t matrix_get_row(uint8_t row) {
uint16_t row_bits = 0;
if (IS_MOD(CODE(row, 0)) && keyboard_report.mods) {
row_bits |= keyboard_report.mods;
}
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
if (IS_ANY(keyboard_report.keys[i])) {
if (row == ROW(keyboard_report.keys[i])) {
row_bits |= ROW_BITS(keyboard_report.keys[i]);
}
}
}
return row_bits;
}
uint8_t matrix_key_count(void) {
uint8_t count = 0;
count += bitpop(keyboard_report.mods);
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
if (IS_ANY(keyboard_report.keys[i])) {
count++;
}
}
return count;
}
void matrix_print(void) {
print("\nr/c 0123456789ABCDEF\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
xprintf("%02d: ", row);
print_bin_reverse16(matrix_get_row(row));
print("\n");
}
}
void led_set(uint8_t usb_led)
{
kbd1.SetReport(0, 0, 2, 0, 1, &usb_led);
kbd2.SetReport(0, 0, 2, 0, 1, &usb_led);
kbd3.SetReport(0, 0, 2, 0, 1, &usb_led);
kbd4.SetReport(0, 0, 2, 0, 1, &usb_led);
}
Loading…
Cancel
Save