forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got ps2avrGB to work with the V-USB protocol
- Loading branch information
1 parent
10ff962
commit f7462aa
Showing
19 changed files
with
886 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ifndef MAKEFILE_INCLUDED | ||
include ../../Makefile | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
ps2avrGB keyboard firmware | ||
========================== | ||
|
||
This is a port of the QMK firmware for boards that are based on the | ||
ps2avrGB firmware, like the [ps2avrGB | ||
keyboard](https://www.keyclack.com/product/gb-ps2avrgb/) or the ones sold | ||
by [Winkeyless](http://winkeyless.kr/product/ps2avrgb-parts/). | ||
|
||
Note that this is a complete replacement for the firmware, so you won't be | ||
using Bootmapper Client to change any keyboard settings, since not all the | ||
USB report options are supported. | ||
|
||
## Supported Boards | ||
|
||
Only the [B.mini X2](http://winkeyless.kr/product/b-mini-x2-pcb/) has been | ||
tested so far (since it's the only one I own). But other boards that use | ||
the ps2avrGB firmware should work as well. | ||
|
||
## Installing | ||
|
||
First, install the requirements. These commands are for OSX, but all you | ||
need is the AVR toolchain and `bootloadHID` for flashing: | ||
|
||
``` | ||
$ brew cask install crosspack-avr | ||
$ brew install --HEAD https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb | ||
``` | ||
|
||
In order to use the `./program` script, which can reboot the board into | ||
the bootloader, you'll need Python 2 with PyUSB installed: | ||
|
||
``` | ||
$ pip install pyusb | ||
``` | ||
|
||
Then, with the keyboard plugged in, simply run this command from the | ||
`qmk_firmware` directory: | ||
|
||
``` | ||
$ make ps2avrGB-program | ||
``` | ||
|
||
If you prefer, you can just build it and flash the firmware directly with | ||
`bootloadHID` if you boot the board while holding down `L_Ctrl` to keep it | ||
in the bootloader: | ||
|
||
``` | ||
$ make ps2avrGB | ||
$ bootloadHID -r ps2avrGB_default.hex | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
From my experience, it's really hard to brick these boards. But these | ||
tricks have been useful when it got stuck in a weird scenario. | ||
|
||
1. Try plugging the board in while pressing `L_Ctrl`. This will force it | ||
to boot only the bootloader without loading the firmware. Once this is | ||
done, just reflash the board with the original firmware. | ||
2. Sometimes USB hubs can act weird, so try connecting the board directly | ||
to your computer or plugging/unplugging the USB hub. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2017 Luiz Ribeiro <[email protected]> | ||
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/>. | ||
*/ | ||
|
||
#ifndef CONFIG_H | ||
#define CONFIG_H | ||
|
||
#include "config_common.h" | ||
|
||
#define VENDOR_ID 0x20A0 | ||
#define PRODUCT_ID 0x422D | ||
// TODO: share these strings with usbconfig.h | ||
// Edit usbconfig.h to change these. | ||
#define MANUFACTURER winkeyless.kr | ||
#define PRODUCT ps2avrGB | ||
|
||
/* matrix size */ | ||
#define MATRIX_ROWS 8 | ||
#define MATRIX_COLS 15 | ||
|
||
/* only support one hard-coded backlight color for now */ | ||
#define BACKLIGHT_LEVELS 0 | ||
#define BACKLIGHT_COLOR 0x110000 | ||
|
||
#define NO_UART 1 | ||
#define EEPROM_BOOTLOADER_START 1 | ||
|
||
/* key combination for command */ | ||
#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "ps2avrGB.h" | ||
|
||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
KEYMAP( \ | ||
ESC, NO, NO, NO, NO, NO, NO, MPRV,MPLY,MNXT,MUTE,VOLD,VOLU,PSCR,HOME,END, \ | ||
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, DEL, \ | ||
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, FN1, \ | ||
FN2, A, S, D, F, G, H, J, K, L, SCLN,QUOT,ENT, PGUP,\ | ||
LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RSFT, UP, PGDN,\ | ||
FN0, LALT,LGUI, SPC, RGUI,RALT,RCTL,LEFT,DOWN,RGHT \ | ||
), | ||
KEYMAP( \ | ||
NO, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, NO, NO, NO, \ | ||
NO, NO, NO, NO, NO, NO, NO, MPRV,MPLY,MNXT,MUTE,VOLD,VOLU,DEL, NO, \ | ||
NO, NO, NO, NO, NO, NO, NO, PGUP,NO, NO, NO, NO, NO, NO, TRNS,\ | ||
FN2, NO, NO, PGDN,NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, NO, NO, \ | ||
TRNS,NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, TRNS, NO, NO, \ | ||
TRNS,TRNS,TRNS, NO, TRNS,TRNS,TRNS,NO, NO, NO \ | ||
), | ||
KEYMAP( \ | ||
NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ | ||
NO, NO, NO, NO, END, NO, NO, NO, NO, NO, HOME,NO, NO, NO, NO, \ | ||
NO, BTN1,MS_U,BTN2,NO, NO, NO, PGUP,FN1, NO, NO, NO, NO, NO, TRNS,\ | ||
FN2, MS_L,MS_D,MS_R,NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, NO, NO, \ | ||
TRNS,NO, DEL, NO, NO, NO, NO, NO, NO, NO, NO, TRNS, NO, NO, \ | ||
TRNS,TRNS,TRNS, NO, TRNS,TRNS,TRNS,NO, NO, NO \ | ||
), | ||
}; | ||
|
||
const uint16_t PROGMEM fn_actions[] = { | ||
[0] = ACTION_LAYER_MOMENTARY(1), | ||
[1] = ACTION_LAYER_TOGGLE(2), | ||
[2] = ACTION_MODS_TAP_KEY(MOD_LCTL, KC_ESC), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
Copyright 2017 Luiz Ribeiro <[email protected]> | ||
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 <avr/io.h> | ||
#include <util/delay.h> | ||
|
||
#include "matrix.h" | ||
|
||
#ifndef DEBOUNCE | ||
# define DEBOUNCE 5 | ||
#endif | ||
|
||
static uint8_t debouncing = DEBOUNCE; | ||
|
||
static matrix_row_t matrix[MATRIX_ROWS]; | ||
static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
|
||
void matrix_init(void) { | ||
// all outputs for rows high | ||
DDRB = 0xFF; | ||
PORTB = 0xFF; | ||
// all inputs for columns | ||
DDRA = 0x00; | ||
DDRC &= ~(0x111111<<2); | ||
DDRD &= ~(1<<PIND7); | ||
// all columns are pulled-up | ||
PORTA = 0xFF; | ||
PORTC |= (0b111111<<2); | ||
PORTD |= (1<<PIND7); | ||
|
||
// initialize matrix state: all keys off | ||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
matrix[row] = 0x00; | ||
matrix_debouncing[row] = 0x00; | ||
} | ||
} | ||
|
||
void matrix_set_row_status(uint8_t row) { | ||
DDRB = (1 << row); | ||
PORTB = ~(1 << row); | ||
} | ||
|
||
uint8_t bit_reverse(uint8_t x) { | ||
x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); | ||
x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); | ||
x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); | ||
return x; | ||
} | ||
|
||
uint8_t matrix_scan(void) { | ||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
matrix_set_row_status(row); | ||
_delay_us(5); | ||
|
||
matrix_row_t cols = ( | ||
// cols 0..7, PORTA 0 -> 7 | ||
(~PINA) & 0xFF | ||
) | ( | ||
// cols 8..13, PORTC 7 -> 0 | ||
bit_reverse((~PINC) & 0xFF) << 8 | ||
) | ( | ||
// col 14, PORTD 7 | ||
((~PIND) & (1 << PIND7)) << 7 | ||
); | ||
|
||
if (matrix_debouncing[row] != cols) { | ||
matrix_debouncing[row] = cols; | ||
debouncing = DEBOUNCE; | ||
} | ||
} | ||
|
||
if (debouncing) { | ||
if (--debouncing) { | ||
_delay_ms(1); | ||
} else { | ||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
matrix[i] = matrix_debouncing[i]; | ||
} | ||
} | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
inline matrix_row_t matrix_get_row(uint8_t row) { | ||
return matrix[row]; | ||
} | ||
|
||
void matrix_print(void) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2017 Luiz Ribeiro <[email protected]> | ||
# | ||
# 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/>. | ||
|
||
from __future__ import print_function | ||
|
||
import os | ||
import sys | ||
import time | ||
import usb | ||
|
||
if len(sys.argv) < 2: | ||
print('Usage: %s <firmware.hex>' % sys.argv[0]) | ||
sys.exit(1) | ||
|
||
print('Searching for ps2avrGB... ', end='') | ||
|
||
dev = usb.core.find(idVendor=0x20A0, idProduct=0x422D) | ||
if dev is None: | ||
raise ValueError('Device not found') | ||
|
||
print('Found', end='\n\n') | ||
|
||
print('Device Information:') | ||
print(' idVendor: %d (0x%04x)' % (dev.idVendor, dev.idVendor)) | ||
print(' idProduct: %d (0x%04x)' % (dev.idProduct, dev.idProduct)) | ||
print('Manufacturer: %s' % (dev.iManufacturer)) | ||
print('Serial: %s' % (dev.iSerialNumber)) | ||
print('Product: %s' % (dev.iProduct), end='\n\n') | ||
|
||
print('Transferring control to bootloader... ', end='') | ||
|
||
dev.set_configuration() | ||
|
||
request_type = usb.util.build_request_type( | ||
usb.util.CTRL_OUT, | ||
usb.util.CTRL_TYPE_CLASS, | ||
usb.util.CTRL_RECIPIENT_DEVICE) | ||
|
||
USBRQ_HID_SET_REPORT = 0x09 | ||
HID_REPORT_OPTION = 0x0301 | ||
|
||
|
||
try: | ||
dev.ctrl_transfer( | ||
request_type, | ||
USBRQ_HID_SET_REPORT, | ||
HID_REPORT_OPTION, | ||
0, | ||
[0, 0, 0xFF] + [0] * 5 | ||
) | ||
except usb.core.USBError: | ||
# for some reason I keep getting USBError, but it works! | ||
pass | ||
|
||
# wait a bit until bootloader starts up | ||
time.sleep(2) | ||
|
||
print('OK') | ||
print('Programming...') | ||
if os.system('bootloadHID -r "%s"' % sys.argv[1]) == 0: | ||
print('\nDone!') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2017 Luiz Ribeiro <[email protected]> | ||
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/>. | ||
*/ | ||
#ifndef KEYMAP_COMMON_H | ||
#define KEYMAP_COMMON_H | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include "keycode.h" | ||
#include "action.h" | ||
#include "action_code.h" | ||
#include "action_layer.h" | ||
#include "action_macro.h" | ||
#include "action_util.h" | ||
#include "report.h" | ||
#include "host.h" | ||
#include "print.h" | ||
#include "debug.h" | ||
#include "keymap.h" | ||
|
||
|
||
#define KEYMAP( \ | ||
K05, K25, K35, K45, K55, K06, KA6, KA7, K07, KB5, KC5, KD5, KE5, KD1, KE1, KE2, \ | ||
K04, K14, K24, K34, K44, K54, K16, KB6, KB7, K17, KA4, KB4, KC4, KE4, KD0, \ | ||
K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC3, KD3, K67, \ | ||
K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KB2, KD2, KE0, \ | ||
K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KB1, K86, K77, \ | ||
K00, K10, K20, K56, K57, KB0, KC0, K66, K76, K96 \ | ||
) \ | ||
{ \ | ||
{ KC_##K00, KC_##K10, KC_##K20, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KB0, KC_##KC0, KC_##KD0, KC_##KE0 }, \ | ||
{ KC_##K01, KC_##K11, KC_##K21, KC_##K31, KC_##K41, KC_##K51, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KA1, KC_##KB1, KC_NO, KC_##KD1, KC_##KE1 }, \ | ||
{ KC_##K02, KC_##K12, KC_##K22, KC_##K32, KC_##K42, KC_##K52, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KA2, KC_##KB2, KC_NO, KC_##KD2, KC_##KE2 }, \ | ||
{ KC_##K03, KC_##K13, KC_##K23, KC_##K33, KC_##K43, KC_##K53, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KA3, KC_##KB3, KC_##KC3, KC_##KD3, KC_NO }, \ | ||
{ KC_##K04, KC_##K14, KC_##K24, KC_##K34, KC_##K44, KC_##K54, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KA4, KC_##KB4, KC_##KC4, KC_NO, KC_##KE4 }, \ | ||
{ KC_##K05, KC_NO, KC_##K25, KC_##K35, KC_##K45, KC_##K55, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KB5, KC_##KC5, KC_##KD5, KC_##KE5 }, \ | ||
{ KC_##K06, KC_##K16, KC_##K26, KC_##K36, KC_##K46, KC_##K56, KC_##K66, KC_##K76, KC_##K86, KC_##K96, KC_##KA6, KC_##KB6, KC_##KC6, KC_##KD6, KC_##KE6 }, \ | ||
{ KC_##K07, KC_##K17, KC_##K27, KC_##K37, KC_##K47, KC_##K57, KC_##K67, KC_##K77, KC_NO, KC_NO, KC_##KA7, KC_##KB7, KC_##KC7, KC_##KD7, KC_##KE7 } \ | ||
} | ||
|
||
#endif |
Oops, something went wrong.