From 164b7331c3b98165e49d38127bee366f9c545513 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 16 Feb 2025 21:39:29 +0000 Subject: Migrate some DEFAULT_FOLDER to keyboard_aliases.hjson (#24915) --- data/mappings/keyboard_aliases.hjson | 36 ++ keyboards/cannonkeys/db60/hotswap/rules.mk | 2 + keyboards/cannonkeys/db60/j02/rules.mk | 2 + keyboards/cannonkeys/db60/rev2/rules.mk | 2 + keyboards/cannonkeys/db60/rules.mk | 4 - keyboards/converter/palm_usb/config.h | 56 --- keyboards/converter/palm_usb/info.json | 20 -- keyboards/converter/palm_usb/matrix.c | 382 --------------------- keyboards/converter/palm_usb/readme.md | 97 ------ keyboards/converter/palm_usb/rules.mk | 7 - keyboards/converter/palm_usb/stowaway/config.h | 56 +++ .../converter/palm_usb/stowaway/keyboard.json | 18 + keyboards/converter/palm_usb/stowaway/matrix.c | 382 +++++++++++++++++++++ keyboards/converter/palm_usb/stowaway/readme.md | 97 ++++++ keyboards/converter/palm_usb/stowaway/rules.mk | 5 + .../handwired/meck_tkl/blackpill_f401/rules.mk | 2 + keyboards/handwired/meck_tkl/rules.mk | 4 - keyboards/hhkb/ansi/32u2/rules.mk | 4 + keyboards/hhkb/ansi/32u4/rules.mk | 4 + keyboards/hhkb/ansi/rules.mk | 6 - keyboards/kakunpc/angel64/alpha/rules.mk | 3 + keyboards/kakunpc/angel64/rev1/rules.mk | 3 + keyboards/kakunpc/angel64/rules.mk | 5 - keyboards/oddball/rules.mk | 3 - keyboards/oddball/v1/rules.mk | 1 + keyboards/oddball/v2/rules.mk | 1 + keyboards/oddball/v2_1/rules.mk | 1 + keyboards/teleport/native/ansi/rules.mk | 1 + keyboards/teleport/native/iso/rules.mk | 1 + keyboards/teleport/native/rules.mk | 3 - keyboards/westm/westm68/rev1/rules.mk | 2 + keyboards/westm/westm68/rev2/rules.mk | 2 + keyboards/westm/westm68/rules.mk | 4 - keyboards/westm/westm9/rev1/rules.mk | 2 + keyboards/westm/westm9/rev2/rules.mk | 2 + keyboards/westm/westm9/rules.mk | 4 - keyboards/woodkeys/meira/featherble/rules.mk | 3 + keyboards/woodkeys/meira/promicro/rules.mk | 3 + keyboards/woodkeys/meira/rules.mk | 4 - keyboards/work_louder/loop/post_rules.mk | 1 + keyboards/work_louder/loop/rules.mk | 3 - keyboards/work_louder/work_board/post_rules.mk | 1 + keyboards/work_louder/work_board/rules.mk | 3 - keyboards/zsa/planck_ez/base/rules.mk | 2 + keyboards/zsa/planck_ez/glow/rules.mk | 2 + keyboards/zsa/planck_ez/rules.mk | 4 - 46 files changed, 641 insertions(+), 609 deletions(-) create mode 100644 keyboards/cannonkeys/db60/hotswap/rules.mk create mode 100644 keyboards/cannonkeys/db60/j02/rules.mk create mode 100644 keyboards/cannonkeys/db60/rev2/rules.mk delete mode 100644 keyboards/cannonkeys/db60/rules.mk delete mode 100644 keyboards/converter/palm_usb/config.h delete mode 100644 keyboards/converter/palm_usb/info.json delete mode 100644 keyboards/converter/palm_usb/matrix.c delete mode 100644 keyboards/converter/palm_usb/readme.md delete mode 100644 keyboards/converter/palm_usb/rules.mk create mode 100644 keyboards/converter/palm_usb/stowaway/config.h create mode 100644 keyboards/converter/palm_usb/stowaway/matrix.c create mode 100644 keyboards/converter/palm_usb/stowaway/readme.md create mode 100644 keyboards/converter/palm_usb/stowaway/rules.mk create mode 100644 keyboards/handwired/meck_tkl/blackpill_f401/rules.mk delete mode 100644 keyboards/handwired/meck_tkl/rules.mk create mode 100644 keyboards/hhkb/ansi/32u2/rules.mk create mode 100644 keyboards/hhkb/ansi/32u4/rules.mk delete mode 100644 keyboards/hhkb/ansi/rules.mk create mode 100644 keyboards/kakunpc/angel64/alpha/rules.mk create mode 100644 keyboards/kakunpc/angel64/rev1/rules.mk delete mode 100644 keyboards/kakunpc/angel64/rules.mk delete mode 100644 keyboards/oddball/rules.mk create mode 100644 keyboards/oddball/v1/rules.mk create mode 100644 keyboards/oddball/v2/rules.mk create mode 100644 keyboards/oddball/v2_1/rules.mk create mode 100644 keyboards/teleport/native/ansi/rules.mk create mode 100644 keyboards/teleport/native/iso/rules.mk delete mode 100644 keyboards/teleport/native/rules.mk create mode 100644 keyboards/westm/westm68/rev1/rules.mk create mode 100644 keyboards/westm/westm68/rev2/rules.mk delete mode 100644 keyboards/westm/westm68/rules.mk create mode 100644 keyboards/westm/westm9/rev1/rules.mk create mode 100644 keyboards/westm/westm9/rev2/rules.mk delete mode 100644 keyboards/westm/westm9/rules.mk delete mode 100644 keyboards/woodkeys/meira/rules.mk create mode 100644 keyboards/work_louder/loop/post_rules.mk delete mode 100644 keyboards/work_louder/loop/rules.mk create mode 100644 keyboards/work_louder/work_board/post_rules.mk delete mode 100644 keyboards/work_louder/work_board/rules.mk create mode 100644 keyboards/zsa/planck_ez/base/rules.mk create mode 100644 keyboards/zsa/planck_ez/glow/rules.mk delete mode 100644 keyboards/zsa/planck_ez/rules.mk diff --git a/data/mappings/keyboard_aliases.hjson b/data/mappings/keyboard_aliases.hjson index d03ff33f2c..09549baf69 100644 --- a/data/mappings/keyboard_aliases.hjson +++ b/data/mappings/keyboard_aliases.hjson @@ -1626,9 +1626,15 @@ "buzzard": { "target": "buzzard/rev1" }, + "cannonkeys/db60": { + "target": "cannonkeys/db60/rev2" + }, "clickety_split/leeloo": { "target": "clickety_split/leeloo/rev3" }, + "converter/palm_usb": { + "target": "converter/palm_usb/stowaway" + }, "crkbd": { "target": "crkbd/rev1" }, @@ -1713,6 +1719,9 @@ "handwired/dactyl_manuform/6x6": { "target": "handwired/dactyl_manuform/6x6/promicro" }, + "handwired/meck_tkl": { + "target": "handwired/meck_tkl/blackpill_f401" + }, "handwired/ms_sculpt_mobile": { "target": "handwired/ms_sculpt_mobile/teensy2pp" }, @@ -1752,6 +1761,9 @@ "hillside/46": { "target": "hillside/46/0_1" }, + "hhkb/ansi": { + "target": "hhkb/ansi/32u4" + }, "hillside/48": { "target": "hillside/48/0_1" }, @@ -1797,6 +1809,9 @@ "kakunpc/angel17": { "target": "kakunpc/angel17/rev1" }, + "kakunpc/angel64": { + "target": "kakunpc/angel64/rev1" + }, "kakunpc/business_card": { "target": "kakunpc/business_card/beta" }, @@ -2148,6 +2163,9 @@ "takashiski/namecard2x4": { "target": "takashiski/namecard2x4/rev2" }, + "teleport/native": { + "target": "teleport/native/iso" + }, "themadnoodle/noodlepad": { "target": "themadnoodle/noodlepad/v1" }, @@ -2181,6 +2199,21 @@ "vitamins_included": { "target": "vitamins_included/rev2" }, + "westm/westm68": { + "target": "westm/westm68/rev2" + }, + "westm/westm9": { + "target": "westm/westm9/rev2" + }, + "woodkeys/meira": { + "target": "woodkeys/meira/promicro" + }, + "work_louder/loop": { + "target": "work_louder/loop/rev3" + }, + "work_louder/work_board": { + "target": "work_louder/work_board/rev3" + }, "yanghu/unicorne": { "target": "yanghu/unicorne/f411" }, @@ -2195,5 +2228,8 @@ }, "yynmt/acperience12": { "target": "yynmt/acperience12/rev1" + }, + "zsa/planck_ez": { + "target": "zsa/planck_ez/base" } } diff --git a/keyboards/cannonkeys/db60/hotswap/rules.mk b/keyboards/cannonkeys/db60/hotswap/rules.mk new file mode 100644 index 0000000000..0ab54aaaf7 --- /dev/null +++ b/keyboards/cannonkeys/db60/hotswap/rules.mk @@ -0,0 +1,2 @@ +# Wildcard to allow APM32 MCU +DFU_SUFFIX_ARGS = -v FFFF -p FFFF diff --git a/keyboards/cannonkeys/db60/j02/rules.mk b/keyboards/cannonkeys/db60/j02/rules.mk new file mode 100644 index 0000000000..0ab54aaaf7 --- /dev/null +++ b/keyboards/cannonkeys/db60/j02/rules.mk @@ -0,0 +1,2 @@ +# Wildcard to allow APM32 MCU +DFU_SUFFIX_ARGS = -v FFFF -p FFFF diff --git a/keyboards/cannonkeys/db60/rev2/rules.mk b/keyboards/cannonkeys/db60/rev2/rules.mk new file mode 100644 index 0000000000..0ab54aaaf7 --- /dev/null +++ b/keyboards/cannonkeys/db60/rev2/rules.mk @@ -0,0 +1,2 @@ +# Wildcard to allow APM32 MCU +DFU_SUFFIX_ARGS = -v FFFF -p FFFF diff --git a/keyboards/cannonkeys/db60/rules.mk b/keyboards/cannonkeys/db60/rules.mk deleted file mode 100644 index 60addd7fe7..0000000000 --- a/keyboards/cannonkeys/db60/rules.mk +++ /dev/null @@ -1,4 +0,0 @@ -# Wildcard to allow APM32 MCU -DFU_SUFFIX_ARGS = -v FFFF -p FFFF - -DEFAULT_FOLDER = cannonkeys/db60/rev2 diff --git a/keyboards/converter/palm_usb/config.h b/keyboards/converter/palm_usb/config.h deleted file mode 100644 index 84394b9f71..0000000000 --- a/keyboards/converter/palm_usb/config.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2012 Jun Wako - -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 . -*/ - -/* This code makes use of cy384's Arduino USB HID adapter for the Palm Portable - Keyboard, released under the BSD licence */ - - - - -#pragma once - -// IO pins to serial -// https://deskthority.net/wiki/Arduino_Pro_Micro for pin lookup -#define VCC_PIN D1 // pro micro 2 -#define RX_PIN D0 //pro micro 3 , was 8 on cy384 -#define RTS_PIN C6 // 5 //[ was D4 // 4 on the cy384 -#define DCD_PIN E6 //7 - -// if using the particular arduino pinout of CY384 -#ifdef CY384 - #define GND_PIN D7 //6 - #define PULLDOWN_PIN B1 // 15 -#endif - -#ifndef HANDSPRING -// Set to 1 for Handspring or to disable RTS/DCD based handshake. - #define HANDSPRING 0 -#endif - -#define MAXDROP 10 // check if keyboard is connected every X polling cycles -#define SLEEP_TIMEOUT 500000 // check keyboard/reset this many millis - - -#define MATRIX_ROWS 12 -#define MATRIX_COLS 8 - -/* key combination for command */ -#define IS_COMMAND() ( \ - get_mods() == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) || \ - get_mods() == (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) || \ - get_mods() == (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)) \ -) diff --git a/keyboards/converter/palm_usb/info.json b/keyboards/converter/palm_usb/info.json deleted file mode 100644 index c5b893d757..0000000000 --- a/keyboards/converter/palm_usb/info.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "keyboard_name": "Stowaway Converter", - "manufacturer": "QMK", - "url": "", - "maintainer": "qmk", - "usb": { - "vid": "0xFEED", - "pid": "0x0001", - "device_version": "1.0.0" - }, - "processor": "atmega32u4", - "bootloader": "caterina", - "features": { - "bootmagic": false, - "mousekey": false, - "extrakey": false, - "console": true, - "command": true - } -} diff --git a/keyboards/converter/palm_usb/matrix.c b/keyboards/converter/palm_usb/matrix.c deleted file mode 100644 index db3784df19..0000000000 --- a/keyboards/converter/palm_usb/matrix.c +++ /dev/null @@ -1,382 +0,0 @@ -/* -Copyright 2018 milestogo -with elements Copyright 2014 cy384 under a modified BSD license -building on qmk structure Copyright 2012 Jun Wako - -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 . -*/ - -#include "matrix.h" -#include "debug.h" -#include "wait.h" -#include "uart.h" -#include "timer.h" - - -/* - * Matrix Array usage: - * - * ROW: 12(4bits) - * COL: 8(3bits) - * - * +---------+ - * 0|00 ... 07| - * 1|00 ... 07| - * :| ... | - * :| ... | - * A| | - * B| | - * +---------+ - */ -static uint8_t matrix[MATRIX_ROWS]; - - -// we're going to need a sleep timer -static uint16_t last_activity ; -// and a byte to track duplicate up events signalling all keys up. -static uint16_t last_upKey ; -// serial device can disconnect. Check every MAXDROP characters. -static uint16_t disconnect_counter = 0; - - -// bitmath masks. -#define KEY_MASK 0b10000000 -#define COL_MASK 0b00000111 -#define ROW_MASK 0b01111000 - - -#define ROW(code) (( code & ROW_MASK ) >>3) -#define COL(code) ((code & COL_MASK) ) -#define KEYUP(code) ((code & KEY_MASK) >>7 ) - -__attribute__ ((weak)) -void matrix_init_kb(void) { - matrix_init_user(); -} - -__attribute__ ((weak)) -void matrix_scan_kb(void) { - matrix_scan_user(); -} - -__attribute__ ((weak)) -void matrix_init_user(void) { -} - -__attribute__ ((weak)) -void matrix_scan_user(void) { -} - -inline -uint8_t matrix_rows(void) -{ - return MATRIX_ROWS; -} - -inline -uint8_t matrix_cols(void) -{ - return MATRIX_COLS; -} - - -void pins_init(void) { - // set pins for pullups, Rts , power &etc. - - //print ("pins setup\n"); - gpio_set_pin_output(VCC_PIN); - gpio_write_pin_low(VCC_PIN); - -#if ( HANDSPRING == 0) - -#ifdef CY835 - gpio_set_pin_output(GND_PIN); - gpio_write_pin_low(GND_PIN); - - gpio_set_pin_output(PULLDOWN_PIN); - gpio_write_pin_low(PULLDOWN_PIN); -#endif - - gpio_set_pin_input(DCD_PIN); - gpio_set_pin_input(RTS_PIN); -#endif - -/* check that the other side isn't powered up. - test=gpio_read_pin(DCD_PIN); - xprintf("b%02X:", test); - test=gpio_read_pin(RTS_PIN); - xprintf("%02X\n", test); -*/ - -} - -uint8_t rts_reset(void) { - static uint8_t firstread ; -/* bounce RTS so device knows it is rebooted */ - -// On boot, we keep rts as input, then switch roles here -// on leaving sleep, we toggle the same way - - firstread=gpio_read_pin(RTS_PIN); - // printf("r%02X:", firstread); - - gpio_set_pin_output(RTS_PIN); - - if (firstread) { - gpio_write_pin_low(RTS_PIN); - } - wait_ms(10); - gpio_write_pin_high(RTS_PIN); - - -/* the future is Arm - if (!palReadPad(RTS_PIN_IOPRT)) - { - wait_ms(10); - palSetPadMode(RTS_PINn_IOPORT, PinDirectionOutput_PUSHPULL); - palSetPad(RTS_PORT, RTS_PIN); - } - else - { - palSetPadMode(RTS_PIN_RTS_PORT, PinDirectionOutput_PUSHPULL); - palSetPad(RTS_PORT, RTS_PIN); - palClearPad(RTS_PORT, RTS_PIN); - wait_ms(10); - palSetPad(RTS_PORT, RTS_PIN); - } -*/ - - - wait_ms(5); - //print("rts\n"); - return 1; -} - -uint8_t get_serial_byte(void) { - static uint8_t code; - while(1) { - code = uart_read(); - if (code) { - dprintf("%02X ", code); - return code; - } - } -} - -uint8_t palm_handshake(void) { - // assumes something has seen DCD go high, we've toggled RTS - // and we now need to verify handshake. - // listen for up to 4 packets before giving up. - // usually I get the sequence FF FA FD - static uint8_t codeA=0; - - for (uint8_t i=0; i < 5; i++) { - codeA=get_serial_byte(); - if ( 0xFA == codeA) { - if( 0xFD == get_serial_byte()) { - return 1; - } - } - } - return 0; -} - -uint8_t palm_reset(void) { - print("@"); - rts_reset(); // shouldn't need to power cycle. - - if ( palm_handshake() ) { - last_activity = timer_read(); - return 1; - } else { - print("failed reset"); - return 0; - } - -} - -uint8_t handspring_handshake(void) { - // should be sent 15 ms after power up. - // listen for up to 4 packets before giving up. - static uint8_t codeA=0; - - for (uint8_t i=0; i < 5; i++) { - codeA=get_serial_byte(); - if ( 0xF9 == codeA) { - if( 0xFB == get_serial_byte()) { - return 1; - } - } - } - return 0; -} - -uint8_t handspring_reset(void) { - gpio_write_pin_low(VCC_PIN); - wait_ms(5); - gpio_write_pin_high(VCC_PIN); - - if ( handspring_handshake() ) { - last_activity = timer_read(); - disconnect_counter=0; - return 1; - } else { - print("-HSreset"); - return 0; - } -} - -void matrix_init(void) -{ - debug_enable = true; - //debug_matrix =true; - - uart_init(9600); // arguments all #defined - -#if (HANDSPRING == 0) - pins_init(); // set all inputs and outputs. -#endif - - print("power up\n"); - gpio_write_pin_high(VCC_PIN); - - // wait for DCD strobe from keyboard - it will do this - // up to 3 times, then the board needs the RTS toggled to try again - -#if ( HANDSPRING == 1) - if ( handspring_handshake() ) { - last_activity = timer_read(); - } else { - print("failed handshake"); - wait_ms(1000); - //BUG /should/ power cycle or toggle RTS & reset, but this usually works. - } - -#else /// Palm / HP device with DCD - while( !gpio_read_pin(DCD_PIN) ) {;} - print("dcd\n"); - - rts_reset(); // at this point the keyboard should think all is well. - - if ( palm_handshake() ) { - last_activity = timer_read(); - } else { - print("failed handshake"); - wait_ms(1000); - //BUG /should/ power cycle or toggle RTS & reset, but this usually works. - } - -#endif - - // initialize matrix state: all keys off - for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; - - matrix_init_kb(); - return; - - -} - - -uint8_t matrix_scan(void) -{ - uint8_t code; - code = uart_read(); - if (!code) { -/* - disconnect_counter ++; - if (disconnect_counter > MAXDROP) { - // set all keys off - for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; - } -*/ - // check if the keyboard is asleep. - if (timer_elapsed(last_activity) > SLEEP_TIMEOUT) { -#if(HANDSPRING ==0 ) - palm_reset(); -#else - handspring_reset(); -#endif - return 0; - } - - } - - last_activity = timer_read(); - disconnect_counter=0; // if we are getting serial data, we're connected. - - dprintf("%02X ", code); - - switch (code) { - case 0xFD: // unexpected reset byte 2 - print("rstD "); - return 0; - case 0xFA: // unexpected reset - print("rstA "); - return 0; - } - - if (KEYUP(code)) { - if (code == last_upKey) { - // all keys are not pressed. - // Manual says to disable all modifiers left open now. - // but that could defeat sticky keys. - // BUG? dropping this byte. - last_upKey=0; - return 0; - } - // release - if (matrix_is_on(ROW(code), COL(code))) { - matrix[ROW(code)] &= ~(1< + +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 . +*/ + +/* This code makes use of cy384's Arduino USB HID adapter for the Palm Portable + Keyboard, released under the BSD licence */ + + + + +#pragma once + +// IO pins to serial +// https://deskthority.net/wiki/Arduino_Pro_Micro for pin lookup +#define VCC_PIN D1 // pro micro 2 +#define RX_PIN D0 //pro micro 3 , was 8 on cy384 +#define RTS_PIN C6 // 5 //[ was D4 // 4 on the cy384 +#define DCD_PIN E6 //7 + +// if using the particular arduino pinout of CY384 +#ifdef CY384 + #define GND_PIN D7 //6 + #define PULLDOWN_PIN B1 // 15 +#endif + +#ifndef HANDSPRING +// Set to 1 for Handspring or to disable RTS/DCD based handshake. + #define HANDSPRING 0 +#endif + +#define MAXDROP 10 // check if keyboard is connected every X polling cycles +#define SLEEP_TIMEOUT 500000 // check keyboard/reset this many millis + + +#define MATRIX_ROWS 12 +#define MATRIX_COLS 8 + +/* key combination for command */ +#define IS_COMMAND() ( \ + get_mods() == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) || \ + get_mods() == (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) || \ + get_mods() == (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)) \ +) diff --git a/keyboards/converter/palm_usb/stowaway/keyboard.json b/keyboards/converter/palm_usb/stowaway/keyboard.json index 9a263327ad..c93957b7d8 100644 --- a/keyboards/converter/palm_usb/stowaway/keyboard.json +++ b/keyboards/converter/palm_usb/stowaway/keyboard.json @@ -1,4 +1,22 @@ { + "keyboard_name": "Stowaway Converter", + "manufacturer": "QMK", + "url": "", + "maintainer": "qmk", + "usb": { + "vid": "0xFEED", + "pid": "0x0001", + "device_version": "1.0.0" + }, + "processor": "atmega32u4", + "bootloader": "caterina", + "features": { + "bootmagic": false, + "mousekey": false, + "extrakey": false, + "console": true, + "command": true + }, "layouts": { "LAYOUT": { "layout": [ diff --git a/keyboards/converter/palm_usb/stowaway/matrix.c b/keyboards/converter/palm_usb/stowaway/matrix.c new file mode 100644 index 0000000000..db3784df19 --- /dev/null +++ b/keyboards/converter/palm_usb/stowaway/matrix.c @@ -0,0 +1,382 @@ +/* +Copyright 2018 milestogo +with elements Copyright 2014 cy384 under a modified BSD license +building on qmk structure Copyright 2012 Jun Wako + +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 . +*/ + +#include "matrix.h" +#include "debug.h" +#include "wait.h" +#include "uart.h" +#include "timer.h" + + +/* + * Matrix Array usage: + * + * ROW: 12(4bits) + * COL: 8(3bits) + * + * +---------+ + * 0|00 ... 07| + * 1|00 ... 07| + * :| ... | + * :| ... | + * A| | + * B| | + * +---------+ + */ +static uint8_t matrix[MATRIX_ROWS]; + + +// we're going to need a sleep timer +static uint16_t last_activity ; +// and a byte to track duplicate up events signalling all keys up. +static uint16_t last_upKey ; +// serial device can disconnect. Check every MAXDROP characters. +static uint16_t disconnect_counter = 0; + + +// bitmath masks. +#define KEY_MASK 0b10000000 +#define COL_MASK 0b00000111 +#define ROW_MASK 0b01111000 + + +#define ROW(code) (( code & ROW_MASK ) >>3) +#define COL(code) ((code & COL_MASK) ) +#define KEYUP(code) ((code & KEY_MASK) >>7 ) + +__attribute__ ((weak)) +void matrix_init_kb(void) { + matrix_init_user(); +} + +__attribute__ ((weak)) +void matrix_scan_kb(void) { + matrix_scan_user(); +} + +__attribute__ ((weak)) +void matrix_init_user(void) { +} + +__attribute__ ((weak)) +void matrix_scan_user(void) { +} + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + + +void pins_init(void) { + // set pins for pullups, Rts , power &etc. + + //print ("pins setup\n"); + gpio_set_pin_output(VCC_PIN); + gpio_write_pin_low(VCC_PIN); + +#if ( HANDSPRING == 0) + +#ifdef CY835 + gpio_set_pin_output(GND_PIN); + gpio_write_pin_low(GND_PIN); + + gpio_set_pin_output(PULLDOWN_PIN); + gpio_write_pin_low(PULLDOWN_PIN); +#endif + + gpio_set_pin_input(DCD_PIN); + gpio_set_pin_input(RTS_PIN); +#endif + +/* check that the other side isn't powered up. + test=gpio_read_pin(DCD_PIN); + xprintf("b%02X:", test); + test=gpio_read_pin(RTS_PIN); + xprintf("%02X\n", test); +*/ + +} + +uint8_t rts_reset(void) { + static uint8_t firstread ; +/* bounce RTS so device knows it is rebooted */ + +// On boot, we keep rts as input, then switch roles here +// on leaving sleep, we toggle the same way + + firstread=gpio_read_pin(RTS_PIN); + // printf("r%02X:", firstread); + + gpio_set_pin_output(RTS_PIN); + + if (firstread) { + gpio_write_pin_low(RTS_PIN); + } + wait_ms(10); + gpio_write_pin_high(RTS_PIN); + + +/* the future is Arm + if (!palReadPad(RTS_PIN_IOPRT)) + { + wait_ms(10); + palSetPadMode(RTS_PINn_IOPORT, PinDirectionOutput_PUSHPULL); + palSetPad(RTS_PORT, RTS_PIN); + } + else + { + palSetPadMode(RTS_PIN_RTS_PORT, PinDirectionOutput_PUSHPULL); + palSetPad(RTS_PORT, RTS_PIN); + palClearPad(RTS_PORT, RTS_PIN); + wait_ms(10); + palSetPad(RTS_PORT, RTS_PIN); + } +*/ + + + wait_ms(5); + //print("rts\n"); + return 1; +} + +uint8_t get_serial_byte(void) { + static uint8_t code; + while(1) { + code = uart_read(); + if (code) { + dprintf("%02X ", code); + return code; + } + } +} + +uint8_t palm_handshake(void) { + // assumes something has seen DCD go high, we've toggled RTS + // and we now need to verify handshake. + // listen for up to 4 packets before giving up. + // usually I get the sequence FF FA FD + static uint8_t codeA=0; + + for (uint8_t i=0; i < 5; i++) { + codeA=get_serial_byte(); + if ( 0xFA == codeA) { + if( 0xFD == get_serial_byte()) { + return 1; + } + } + } + return 0; +} + +uint8_t palm_reset(void) { + print("@"); + rts_reset(); // shouldn't need to power cycle. + + if ( palm_handshake() ) { + last_activity = timer_read(); + return 1; + } else { + print("failed reset"); + return 0; + } + +} + +uint8_t handspring_handshake(void) { + // should be sent 15 ms after power up. + // listen for up to 4 packets before giving up. + static uint8_t codeA=0; + + for (uint8_t i=0; i < 5; i++) { + codeA=get_serial_byte(); + if ( 0xF9 == codeA) { + if( 0xFB == get_serial_byte()) { + return 1; + } + } + } + return 0; +} + +uint8_t handspring_reset(void) { + gpio_write_pin_low(VCC_PIN); + wait_ms(5); + gpio_write_pin_high(VCC_PIN); + + if ( handspring_handshake() ) { + last_activity = timer_read(); + disconnect_counter=0; + return 1; + } else { + print("-HSreset"); + return 0; + } +} + +void matrix_init(void) +{ + debug_enable = true; + //debug_matrix =true; + + uart_init(9600); // arguments all #defined + +#if (HANDSPRING == 0) + pins_init(); // set all inputs and outputs. +#endif + + print("power up\n"); + gpio_write_pin_high(VCC_PIN); + + // wait for DCD strobe from keyboard - it will do this + // up to 3 times, then the board needs the RTS toggled to try again + +#if ( HANDSPRING == 1) + if ( handspring_handshake() ) { + last_activity = timer_read(); + } else { + print("failed handshake"); + wait_ms(1000); + //BUG /should/ power cycle or toggle RTS & reset, but this usually works. + } + +#else /// Palm / HP device with DCD + while( !gpio_read_pin(DCD_PIN) ) {;} + print("dcd\n"); + + rts_reset(); // at this point the keyboard should think all is well. + + if ( palm_handshake() ) { + last_activity = timer_read(); + } else { + print("failed handshake"); + wait_ms(1000); + //BUG /should/ power cycle or toggle RTS & reset, but this usually works. + } + +#endif + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; + + matrix_init_kb(); + return; + + +} + + +uint8_t matrix_scan(void) +{ + uint8_t code; + code = uart_read(); + if (!code) { +/* + disconnect_counter ++; + if (disconnect_counter > MAXDROP) { + // set all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; + } +*/ + // check if the keyboard is asleep. + if (timer_elapsed(last_activity) > SLEEP_TIMEOUT) { +#if(HANDSPRING ==0 ) + palm_reset(); +#else + handspring_reset(); +#endif + return 0; + } + + } + + last_activity = timer_read(); + disconnect_counter=0; // if we are getting serial data, we're connected. + + dprintf("%02X ", code); + + switch (code) { + case 0xFD: // unexpected reset byte 2 + print("rstD "); + return 0; + case 0xFA: // unexpected reset + print("rstA "); + return 0; + } + + if (KEYUP(code)) { + if (code == last_upKey) { + // all keys are not pressed. + // Manual says to disable all modifiers left open now. + // but that could defeat sticky keys. + // BUG? dropping this byte. + last_upKey=0; + return 0; + } + // release + if (matrix_is_on(ROW(code), COL(code))) { + matrix[ROW(code)] &= ~(1<