From debd902a3d5788beab8580a26c84d7db2365a638 Mon Sep 17 00:00:00 2001 From: marksard <38324387+marksard@users.noreply.github.com> Date: Thu, 4 Apr 2019 14:56:22 +0900 Subject: [Keyboard] add treeadstone48 (#5405) * Keyboard: add treeadstone48 * rename layout defines * Use of pragma once * move common include code * fixed info.json * change keymap layout from kc to normal * fix alpha revision keymap * fixed info.json * remove USE_Link_Time_Optimization --- keyboards/treadstone48/rev1/config.h | 133 ++++++++ keyboards/treadstone48/rev1/info.json | 261 +++++++++++++++ keyboards/treadstone48/rev1/matrix.c | 357 +++++++++++++++++++++ keyboards/treadstone48/rev1/rev1.c | 15 + keyboards/treadstone48/rev1/rev1.h | 202 ++++++++++++ keyboards/treadstone48/rev1/rules.mk | 3 + keyboards/treadstone48/rev1/serial_config.h | 8 + .../treadstone48/rev1/serial_config_simpleapi.h | 8 + keyboards/treadstone48/rev1/split_scomm.c | 92 ++++++ keyboards/treadstone48/rev1/split_scomm.h | 21 ++ keyboards/treadstone48/rev1/split_util.c | 70 ++++ keyboards/treadstone48/rev1/split_util.h | 16 + 12 files changed, 1186 insertions(+) create mode 100644 keyboards/treadstone48/rev1/config.h create mode 100644 keyboards/treadstone48/rev1/info.json create mode 100644 keyboards/treadstone48/rev1/matrix.c create mode 100644 keyboards/treadstone48/rev1/rev1.c create mode 100644 keyboards/treadstone48/rev1/rev1.h create mode 100644 keyboards/treadstone48/rev1/rules.mk create mode 100644 keyboards/treadstone48/rev1/serial_config.h create mode 100644 keyboards/treadstone48/rev1/serial_config_simpleapi.h create mode 100644 keyboards/treadstone48/rev1/split_scomm.c create mode 100644 keyboards/treadstone48/rev1/split_scomm.h create mode 100644 keyboards/treadstone48/rev1/split_util.c create mode 100644 keyboards/treadstone48/rev1/split_util.h (limited to 'keyboards/treadstone48/rev1') diff --git a/keyboards/treadstone48/rev1/config.h b/keyboards/treadstone48/rev1/config.h new file mode 100644 index 0000000000..aa6dd9e634 --- /dev/null +++ b/keyboards/treadstone48/rev1/config.h @@ -0,0 +1,133 @@ +/* +Copyright 2012 Jun Wako +Copyright 2015 Jack Humbert + +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 . +*/ + +#ifndef REV1_CONFIG_H +#define REV1_CONFIG_H + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0xDFA3 +#define DEVICE_VER 0x0010 +#define MANUFACTURER marksard +#define PRODUCT treadstone48 +#define DESCRIPTION Symmetrical staggered 47+1 Keys Keyboard + +#define PREVENT_STUCK_MODIFIERS +#define TAPPING_FORCE_HOLD +#define TAPPING_TERM 150 + +/* Use I2C or Serial */ +#define USE_I2C +#define USE_SERIAL +//#define USE_MATRIX_I2C + +/* Select hand configuration */ +#define MASTER_LEFT +// #define MASTER_RIGHT +// #define EE_HANDS + +// OLED support +// see ./rules.mk: OLED_ENABLE=yes or no +#ifdef OLED_ENABLE + #define SSD1306OLED +#endif + +/* key matrix size */ +// Rows are doubled-up +#define MATRIX_ROWS 16 +#define MATRIX_ROW_PINS { F4, F5, F6, F7, B1, B3, B2, B6 } + +// wiring of each half +#define MATRIX_COLS 6 +#define MATRIX_COL_PINS { D4, C6, D7, E6, B4, B5 } + +/* define if matrix has ghost */ +//#define MATRIX_HAS_GHOST + +/* number of backlight levels */ +// #define BACKLIGHT_LEVELS 3 + +/* Set 0 if debouncing isn't needed */ +#define DEBOUNCING_DELAY 5 + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +//#define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +//#define LOCKING_RESYNC_ENABLE + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +/* ws2812 RGB LED */ +#define RGB_DI_PIN D3 +#define RGBLIGHT_TIMER +//#define RGBLED_NUM 12 // Number of LEDs. see ./keymaps/default/config.h +#define ws2812_PORTREG PORTD +#define ws2812_DDRREG DDRD + +// treadstone48 keyboard RGB LED support +//#define RGBLIGHT_ANIMATIONS : see ./rules.mk: LED_ANIMATIONS = yes or no +// see ./rules.mk: LED_BACK_ENABLE or LED_UNDERGLOW_ENABLE set yes +#define RGBLED_NUM 12 + +#ifndef IOS_DEVICE_ENABLE + #define RGBLIGHT_LIMIT_VAL 180 + #define RGBLIGHT_VAL_STEP 17 +#else + #define RGBLIGHT_LIMIT_VAL 50 + #define RGBLIGHT_VAL_STEP 4 +#endif +#define RGBLIGHT_HUE_STEP 10 +#define RGBLIGHT_SAT_STEP 17 + +#if defined(RGBLIGHT_ENABLE) && !defined(IOS_DEVICE_ENABLE) +// USB_MAX_POWER_CONSUMPTION value for treadstone48 keyboard +// 120 RGBoff, OLEDoff +// 120 OLED +// 330 RGB 6 +// 300 RGB 32 +// 310 OLED & RGB 32 + #define USB_MAX_POWER_CONSUMPTION 400 +#else + // fix iPhone and iPad power adapter issue + // iOS device need lessthan 100 + #define USB_MAX_POWER_CONSUMPTION 100 +#endif + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +// #define NO_DEBUG + +/* disable print */ +// #define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT +//#define NO_ACTION_MACRO +//#define NO_ACTION_FUNCTION + + +#endif diff --git a/keyboards/treadstone48/rev1/info.json b/keyboards/treadstone48/rev1/info.json new file mode 100644 index 0000000000..df9e7591b5 --- /dev/null +++ b/keyboards/treadstone48/rev1/info.json @@ -0,0 +1,261 @@ +{ + "keyboard_name": "Treadstone48", + "url": "https://github.com/marksard/Keyboards", + "maintainer": "marksard", + "width": 14.75, + "height": 4, + "layouts": { + "LAYOUT_base": { + "layout": [ + { + "label": "Esc", + "x": 1, + "y": 0 + }, + { + "label": "Q", + "x": 2.25, + "y": 0 + }, + { + "label": "W", + "x": 3.25, + "y": 0 + }, + { + "label": "E", + "x": 4.25, + "y": 0 + }, + { + "label": "R", + "x": 5.25, + "y": 0 + }, + { + "label": "T", + "x": 6.25, + "y": 0 + }, + { + "label": "Y", + "x": 7.75, + "y": 0 + }, + { + "label": "U", + "x": 8.75, + "y": 0 + }, + { + "label": "I", + "x": 9.75, + "y": 0 + }, + { + "label": "O", + "x": 10.75, + "y": 0 + }, + { + "label": "P", + "x": 11.75, + "y": 0 + }, + { + "label": "-", + "x": 13.75, + "y": 0 + }, + { + "label": "Tab", + "x": 1, + "y": 1, + "w": 1.5 + }, + { + "label": "A", + "x": 2.5, + "y": 1 + }, + { + "label": "S", + "x": 3.5, + "y": 1 + }, + { + "label": "D", + "x": 4.5, + "y": 1 + }, + { + "label": "F", + "x": 5.5, + "y": 1 + }, + { + "label": "G", + "x": 6.5, + "y": 1 + }, + { + "label": "H", + "x": 7.5, + "y": 1 + }, + { + "label": "J", + "x": 8.5, + "y": 1 + }, + { + "label": "K", + "x": 9.5, + "y": 1 + }, + { + "label": "L", + "x": 10.5, + "y": 1 + }, + { + "label": ":", + "x": 11.5, + "y": 1 + }, + { + "label": "Enter", + "x": 12.5, + "y": 1, + "w": 2.25 + }, + { + "label": "Shift", + "x": 0, + "y": 2, + "w": 2.25 + }, + { + "label": "Z", + "x": 2.25, + "y": 2 + }, + { + "label": "X", + "x": 3.25, + "y": 2 + }, + { + "label": "C", + "x": 4.25, + "y": 2 + }, + { + "label": "V", + "x": 5.25, + "y": 2 + }, + { + "label": "B", + "x": 6.25, + "y": 2 + }, + { + "label": "N", + "x": 7.75, + "y": 2 + }, + { + "label": "M", + "x": 8.75, + "y": 2 + }, + { + "label": "<", + "x": 9.75, + "y": 2 + }, + { + "label": ">", + "x": 10.75, + "y": 2 + }, + { + "label": "?", + "x": 11.75, + "y": 2 + }, + { + "label": "\u2191", + "x": 12.75, + "y": 2 + }, + { + "label": "Ctrl", + "x": 0.75, + "y": 3, + "w": 1.25 + }, + { + "label": "Win", + "x": 2, + "y": 3, + "w": 1.25 + }, + { + "label": "Alt", + "x": 3.25, + "y": 3, + "w": 1.25 + }, + { + "label": "Lower", + "x": 4.5, + "y": 3 + }, + { + "label": "BackSpace", + "x": 5.5, + "y": 3, + "w": 2 + }, + { + "x": 7.5, + "y": 3, + "w": 2 + }, + { + "label": "Raise", + "x": 9.5, + "y": 3 + }, + { + "label": "Menu", + "x": 10.5, + "y": 3, + "w": 1.25 + }, + { + "label": "\u2190", + "x": 11.75, + "y": 3 + }, + { + "label": "\u2193", + "x": 12.75, + "y": 3 + }, + { + "label": "\u2192", + "x": 13.75, + "y": 3 + }, + { + "label": "_", + "x": 12.75, + "y": 0 + } + ] + } + } +} diff --git a/keyboards/treadstone48/rev1/matrix.c b/keyboards/treadstone48/rev1/matrix.c new file mode 100644 index 0000000000..8685a8125e --- /dev/null +++ b/keyboards/treadstone48/rev1/matrix.c @@ -0,0 +1,357 @@ +/* +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 . +*/ + +/* + * scan matrix + */ +#include +#include +#include +#include +#include +#include +#include +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" +#include "split_util.h" +#include "pro_micro.h" + +#ifdef USE_MATRIX_I2C +# include "i2c.h" +#else // USE_SERIAL +# include "split_scomm.h" +#endif + +#ifndef DEBOUNCE +# define DEBOUNCE 5 +#endif + +#define ERROR_DISCONNECT_COUNT 5 + +static uint8_t debouncing = DEBOUNCE; +static const int ROWS_PER_HAND = MATRIX_ROWS/2; +static uint8_t error_count = 0; +uint8_t is_master = 0 ; + +static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; + +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +static matrix_row_t read_cols(void); +static void init_cols(void); +static void unselect_rows(void); +static void select_row(uint8_t row); +static uint8_t matrix_master_scan(void); + + +__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 matrix_init(void) +{ + debug_enable = true; + debug_matrix = true; + debug_mouse = true; + // initialize row and col + unselect_rows(); + init_cols(); + + TX_RX_LED_INIT; + TXLED0; + RXLED0; + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + matrix_debouncing[i] = 0; + } + + is_master = has_usb(); + + matrix_init_quantum(); +} + +uint8_t _matrix_scan(void) +{ + // Right hand is stored after the left in the matirx so, we need to offset it + int offset = isLeftHand ? 0 : (ROWS_PER_HAND); + + for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { + select_row(i); + _delay_us(30); // without this wait read unstable value. + matrix_row_t cols = read_cols(); + if (matrix_debouncing[i+offset] != cols) { + matrix_debouncing[i+offset] = cols; + debouncing = DEBOUNCE; + } + unselect_rows(); + } + + if (debouncing) { + if (--debouncing) { + _delay_ms(1); + } else { + for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { + matrix[i+offset] = matrix_debouncing[i+offset]; + } + } + } + + return 1; +} + +#ifdef USE_MATRIX_I2C + +// Get rows from other half over i2c +int i2c_transaction(void) { + int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; + + int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); + if (err) goto i2c_error; + + // start of matrix stored at 0x00 + err = i2c_master_write(0x00); + if (err) goto i2c_error; + + // Start read + err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); + if (err) goto i2c_error; + + if (!err) { + int i; + for (i = 0; i < ROWS_PER_HAND-1; ++i) { + matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); + } + matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); + i2c_master_stop(); + } else { +i2c_error: // the cable is disconnceted, or something else went wrong + i2c_reset_state(); + return err; + } + + return 0; +} + +#else // USE_SERIAL + +int serial_transaction(int master_changed) { + int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; +#ifdef SERIAL_USE_MULTI_TRANSACTION + int ret=serial_update_buffers(master_changed); +#else + int ret=serial_update_buffers(); +#endif + if (ret ) { + if(ret==2) RXLED1; + return 1; + } + RXLED0; + memcpy(&matrix[slaveOffset], + (void *)serial_slave_buffer, sizeof(serial_slave_buffer)); + return 0; +} +#endif + +uint8_t matrix_scan(void) +{ + if (is_master) { + matrix_master_scan(); + }else{ + matrix_slave_scan(); + int offset = (isLeftHand) ? ROWS_PER_HAND : 0; + memcpy(&matrix[offset], + (void *)serial_master_buffer, sizeof(serial_master_buffer)); + matrix_scan_quantum(); + } + return 1; +} + + +uint8_t matrix_master_scan(void) { + + int ret = _matrix_scan(); + int mchanged = 1; + + int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; + +#ifdef USE_MATRIX_I2C +// for (int i = 0; i < ROWS_PER_HAND; ++i) { + /* i2c_slave_buffer[i] = matrix[offset+i]; */ +// i2c_slave_buffer[i] = matrix[offset+i]; +// } +#else // USE_SERIAL + #ifdef SERIAL_USE_MULTI_TRANSACTION + mchanged = memcmp((void *)serial_master_buffer, + &matrix[offset], sizeof(serial_master_buffer)); + #endif + memcpy((void *)serial_master_buffer, + &matrix[offset], sizeof(serial_master_buffer)); +#endif + +#ifdef USE_MATRIX_I2C + if( i2c_transaction() ) { +#else // USE_SERIAL + if( serial_transaction(mchanged) ) { +#endif + // turn on the indicator led when halves are disconnected + TXLED1; + + error_count++; + + if (error_count > ERROR_DISCONNECT_COUNT) { + // reset other half if disconnected + int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; + for (int i = 0; i < ROWS_PER_HAND; ++i) { + matrix[slaveOffset+i] = 0; + } + } + } else { + // turn off the indicator led on no error + TXLED0; + error_count = 0; + } + matrix_scan_quantum(); + return ret; +} + +void matrix_slave_scan(void) { + _matrix_scan(); + + int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; + +#ifdef USE_MATRIX_I2C + for (int i = 0; i < ROWS_PER_HAND; ++i) { + /* i2c_slave_buffer[i] = matrix[offset+i]; */ + i2c_slave_buffer[i] = matrix[offset+i]; + } +#else // USE_SERIAL + #ifdef SERIAL_USE_MULTI_TRANSACTION + int change = 0; + #endif + for (int i = 0; i < ROWS_PER_HAND; ++i) { + #ifdef SERIAL_USE_MULTI_TRANSACTION + if( serial_slave_buffer[i] != matrix[offset+i] ) + change = 1; + #endif + serial_slave_buffer[i] = matrix[offset+i]; + } + #ifdef SERIAL_USE_MULTI_TRANSACTION + slave_buffer_change_count += change; + #endif +#endif +} + +bool matrix_is_modified(void) +{ + if (debouncing) return false; + return true; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & ((matrix_row_t)1<> 4) + 1) &= ~_BV(col_pins[x] & 0xF); + _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF); + } +} + +static matrix_row_t read_cols(void) +{ + matrix_row_t result = 0; + for(int x = 0; x < MATRIX_COLS; x++) { + result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x); + } + return result; +} + +static void unselect_rows(void) +{ + for(int x = 0; x < ROWS_PER_HAND; x++) { + _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF); + _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF); + } +} + +static void select_row(uint8_t row) +{ + _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF); + _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF); +} diff --git a/keyboards/treadstone48/rev1/rev1.c b/keyboards/treadstone48/rev1/rev1.c new file mode 100644 index 0000000000..2637864271 --- /dev/null +++ b/keyboards/treadstone48/rev1/rev1.c @@ -0,0 +1,15 @@ +#include "treadstone48.h" + + +#ifdef SSD1306OLED +void led_set_kb(uint8_t usb_led) { + // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here + //led_set_user(usb_led); +} +#endif + +void matrix_init_kb(void) { + + matrix_init_user(); +}; + diff --git a/keyboards/treadstone48/rev1/rev1.h b/keyboards/treadstone48/rev1/rev1.h new file mode 100644 index 0000000000..c6145398dd --- /dev/null +++ b/keyboards/treadstone48/rev1/rev1.h @@ -0,0 +1,202 @@ +#ifndef REV1_H +#define REV1_CONFIG_H + +#include "../treadstone48.h" + +//void promicro_bootloader_jmp(bool program); +#include "quantum.h" + +#ifdef RGBLIGHT_ENABLE +//rgb led driver +#include "ws2812.h" +#endif + +#ifdef USE_I2C +#include +#ifdef __AVR__ + #include + #include +#endif +#endif + +// full Keymap +// (TRRS jack on the left half is to the right, TRRS jack on the right half is to the left) +#define LAYOUT_full( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, R00, R01, R02, R03, R04, R05, R40, R41, R42, R43, R44, R45, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, R10, R11, R12, R13, R14, R15, R50, R51, R52, R53, R54, R55, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, R20, R21, R22, R23, R24, R25, R60, R61, R62, R63, R64, R65, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, R30, R31, R32, R33, R34, R35, R70, R71, R72, R73, R74, R75 \ + ) \ + { \ + { L45, L44, L43, L42, L41, L40 }, \ + { L55, L54, L53, L52, L51, L50 }, \ + { L65, L64, L63, L62, L61, L60 }, \ + { L75, L74, L73, L72, L71, L70 }, \ + { L05, L04, L03, L02, L01, L00 }, \ + { L15, L14, L13, L12, L11, L10 }, \ + { L25, L24, L23, L22, L21, L20 }, \ + { L35, L34, L33, L32, L31, L30 }, \ + { R45, R44, R43, R42, R41, R40 }, \ + { R55, R54, R53, R52, R51, R50 }, \ + { R65, R64, R63, R62, R61, R60 }, \ + { R75, R74, R73, R72, R71, R70 }, \ + { R05, R04, R03, R02, R01, R00 }, \ + { R15, R14, R13, R12, R11, R10 }, \ + { R25, R24, R23, R22, R21, R20 }, \ + { R35, R34, R33, R32, R31, R30 }, \ + } + +#define K_N KC_NO + +////////////////////////////////////////////////////////////////////////////// +// When only use Treadstone48. +// L75 is ExtraKey +////////////////////////////////////////////////////////////////////////////// +#define LAYOUT_base( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75 \ + ) \ + LAYOUT_full( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N \ + ) + +// Used to create a keymap using only KC_ prefixed keys +#define LAYOUT_base_kc( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75 \ + ) \ + LAYOUT_base( \ + KC_##L00, KC_##L01, KC_##L02, KC_##L03, KC_##L04, KC_##L05, KC_##L40, KC_##L41, KC_##L42, KC_##L43, KC_##L44, KC_##L45, \ + KC_##L10, KC_##L11, KC_##L12, KC_##L13, KC_##L14, KC_##L15, KC_##L50, KC_##L51, KC_##L52, KC_##L53, KC_##L54, KC_##L55, \ + KC_##L20, KC_##L21, KC_##L22, KC_##L23, KC_##L24, KC_##L25, KC_##L60, KC_##L61, KC_##L62, KC_##L63, KC_##L64, KC_##L65, \ + KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##L70, KC_##L71, KC_##L72, KC_##L73, KC_##L74, KC_##L75 \ + ) +////////////////////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////////////////////// +// When connecting Rhymestone to Treadstone48. +// L75 is ExtraKey +////////////////////////////////////////////////////////////////////////////// +#define LAYOUT_rs( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, R40, R41, R42, R43, R44, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, R50, R51, R52, R53, R54, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, R60, R61, R62, R63, R64, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, R70, R71, R72, R73, R74, L75 \ + ) \ + LAYOUT_full( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R44, R43, R42, R41, R40, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R54, R53, R52, R51, R50, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R64, R63, R62, R61, R60, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R74, R73, R72, R71, R70 \ + ) + +// When use right hand side of the Rhymestone. +#ifdef RHYMESTONE_RIGHTHAND +#undef LAYOUT_rs +#define LAYOUT_rs( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, R40, R41, R42, R43, R44, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, R50, R51, R52, R53, R54, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, R60, R61, R62, R63, R64, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, R70, R71, R72, R73, R74, L75 \ + ) \ + LAYOUT_full( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R40, R41, R42, R43, R44, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R50, R51, R52, R53, R54, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R60, R61, R62, R63, R64, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R70, R71, R72, R73, R74 \ + ) +#endif + +// Used to create a keymap using only KC_ prefixed keys +#define LAYOUT_rs_kc( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, R40, R41, R42, R43, R44, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, R50, R51, R52, R53, R54, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, R60, R61, R62, R63, R64, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, R70, R71, R72, R73, R74 \ + ) \ + LAYOUT_rs( \ + KC_##L00, KC_##L01, KC_##L02, KC_##L03, KC_##L04, KC_##L05, KC_##L40, KC_##L41, KC_##L42, KC_##L43, KC_##L44, KC_##L45, KC_##R40, KC_##R41, KC_##R42, KC_##R43, KC_##R44, \ + KC_##L10, KC_##L11, KC_##L12, KC_##L13, KC_##L14, KC_##L15, KC_##L50, KC_##L51, KC_##L52, KC_##L53, KC_##L54, KC_##L55, KC_##R50, KC_##R51, KC_##R52, KC_##R53, KC_##R54, \ + KC_##L20, KC_##L21, KC_##L22, KC_##L23, KC_##L24, KC_##L25, KC_##L60, KC_##L61, KC_##L62, KC_##L63, KC_##L64, KC_##L65, KC_##R60, KC_##R61, KC_##R62, KC_##R63, KC_##R64, \ + KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##L70, KC_##L71, KC_##L72, KC_##L73, KC_##L74, KC_##L75, KC_##R70, KC_##R71, KC_##R72, KC_##R73, KC_##R74 \ + ) +////////////////////////////////////////////////////////////////////////////// + + + +////////////////////////////////////////////////////////////////////////////// +// Alpha version keymap. +// L30 is ExtraKey +////////////////////////////////////////////////////////////////////////////// +#ifdef ANGELINA_KEYMAP +#undef LAYOUT_base +#undef LAYOUT_base_kc +#undef LAYOUT_rs +#undef LAYOUT_rs_kc + +#define LAYOUT_base( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, \ + L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, L30 \ + ) \ + LAYOUT_full( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N, K_N \ + ) + +// Used to create a keymap using only KC_ prefixed keys +#define LAYOUT_base_kc( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75 \ + ) \ + LAYOUT_base( \ + KC_##L00, KC_##L01, KC_##L02, KC_##L03, KC_##L04, KC_##L05, KC_##L40, KC_##L41, KC_##L42, KC_##L43, KC_##L44, KC_##L45, \ + KC_##L10, KC_##L11, KC_##L12, KC_##L13, KC_##L14, KC_##L15, KC_##L50, KC_##L51, KC_##L52, KC_##L53, KC_##L54, KC_##L55, \ + KC_##L20, KC_##L21, KC_##L22, KC_##L23, KC_##L24, KC_##L25, KC_##L60, KC_##L61, KC_##L62, KC_##L63, KC_##L64, KC_##L65, \ + KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##L70, KC_##L71, KC_##L72, KC_##L73, KC_##L74, KC_##L75 \ + ) + +#define LAYOUT_rs( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, R40, R41, R42, R43, R44, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, R50, R51, R52, R53, R54, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, R60, R61, R62, R63, R64, \ + L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, R70, R71, R72, R73, R74, L30 \ + ) \ + LAYOUT_full( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R44, R43, R42, R41, R40, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R54, R53, R52, R51, R50, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R64, R63, R62, R61, R60, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, K_N, K_N, K_N, K_N, K_N, K_N, K_N, R74, R73, R72, R71, R70 \ + ) + +// Used to create a keymap using only KC_ prefixed keys +#define LAYOUT_rs_kc( \ + L00, L01, L02, L03, L04, L05, L40, L41, L42, L43, L44, L45, R40, R41, R42, R43, R44, \ + L10, L11, L12, L13, L14, L15, L50, L51, L52, L53, L54, L55, R50, R51, R52, R53, R54, \ + L20, L21, L22, L23, L24, L25, L60, L61, L62, L63, L64, L65, R60, R61, R62, R63, R64, \ + L30, L31, L32, L33, L34, L35, L70, L71, L72, L73, L74, L75, R70, R71, R72, R73, R74 \ + ) \ + LAYOUT_rs( \ + KC_##L00, KC_##L01, KC_##L02, KC_##L03, KC_##L04, KC_##L05, KC_##L40, KC_##L41, KC_##L42, KC_##L43, KC_##L44, KC_##L45, KC_##R40, KC_##R41, KC_##R42, KC_##R43, KC_##R44, \ + KC_##L10, KC_##L11, KC_##L12, KC_##L13, KC_##L14, KC_##L15, KC_##L50, KC_##L51, KC_##L52, KC_##L53, KC_##L54, KC_##L55, KC_##R50, KC_##R51, KC_##R52, KC_##R53, KC_##R54, \ + KC_##L20, KC_##L21, KC_##L22, KC_##L23, KC_##L24, KC_##L25, KC_##L60, KC_##L61, KC_##L62, KC_##L63, KC_##L64, KC_##L65, KC_##R60, KC_##R61, KC_##R62, KC_##R63, KC_##R64, \ + KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##L70, KC_##L71, KC_##L72, KC_##L73, KC_##L74, KC_##L75, KC_##R70, KC_##R71, KC_##R72, KC_##R73, KC_##R74 \ + ) + +#endif +////////////////////////////////////////////////////////////////////////////// + +#endif diff --git a/keyboards/treadstone48/rev1/rules.mk b/keyboards/treadstone48/rev1/rules.mk new file mode 100644 index 0000000000..6028b5a5b9 --- /dev/null +++ b/keyboards/treadstone48/rev1/rules.mk @@ -0,0 +1,3 @@ +SRC += rev1/matrix.c +SRC += rev1/split_util.c +SRC += rev1/split_scomm.c diff --git a/keyboards/treadstone48/rev1/serial_config.h b/keyboards/treadstone48/rev1/serial_config.h new file mode 100644 index 0000000000..37135213d5 --- /dev/null +++ b/keyboards/treadstone48/rev1/serial_config.h @@ -0,0 +1,8 @@ +//// #error rev2 serial config + +#ifndef SOFT_SERIAL_PIN +/* Soft Serial defines */ +#define SOFT_SERIAL_PIN D2 + +#define SERIAL_USE_MULTI_TRANSACTION +#endif diff --git a/keyboards/treadstone48/rev1/serial_config_simpleapi.h b/keyboards/treadstone48/rev1/serial_config_simpleapi.h new file mode 100644 index 0000000000..e2d22a41e7 --- /dev/null +++ b/keyboards/treadstone48/rev1/serial_config_simpleapi.h @@ -0,0 +1,8 @@ +#ifndef SERIAL_CONFIG_SIMPLEAPI_H +#define SERIAL_CONFIG_SIMPLEAPI_H + +#undef SERIAL_USE_MULTI_TRANSACTION +#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 +#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2 + +#endif // SERIAL_CONFIG_SIMPLEAPI_H diff --git a/keyboards/treadstone48/rev1/split_scomm.c b/keyboards/treadstone48/rev1/split_scomm.c new file mode 100644 index 0000000000..ada7867960 --- /dev/null +++ b/keyboards/treadstone48/rev1/split_scomm.c @@ -0,0 +1,92 @@ +#ifdef USE_SERIAL +#ifdef SERIAL_USE_MULTI_TRANSACTION +/* --- USE flexible API (using multi-type transaction function) --- */ + +#include +#include +#include +#include +#include "serial.h" +#ifdef CONSOLE_ENABLE + #include +#endif + +uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; +uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; +uint8_t volatile status_com = 0; +uint8_t volatile status1 = 0; +uint8_t slave_buffer_change_count = 0; +uint8_t s_change_old = 0xff; +uint8_t s_change_new = 0xff; + +SSTD_t transactions[] = { +#define GET_SLAVE_STATUS 0 + /* master buffer not changed, only recive slave_buffer_change_count */ + { (uint8_t *)&status_com, + 0, NULL, + sizeof(slave_buffer_change_count), &slave_buffer_change_count, + }, +#define PUT_MASTER_GET_SLAVE_STATUS 1 + /* master buffer changed need send, and recive slave_buffer_change_count */ + { (uint8_t *)&status_com, + sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, + sizeof(slave_buffer_change_count), &slave_buffer_change_count, + }, +#define GET_SLAVE_BUFFER 2 + /* recive serial_slave_buffer */ + { (uint8_t *)&status1, + 0, NULL, + sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer + } +}; + +void serial_master_init(void) +{ + soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); +} + +void serial_slave_init(void) +{ + soft_serial_target_init(transactions, TID_LIMIT(transactions)); +} + +// 0 => no error +// 1 => slave did not respond +// 2 => checksum error +int serial_update_buffers(int master_update) +{ + int status, smatstatus; + static int need_retry = 0; + + if( s_change_old != s_change_new ) { + smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER); + if( smatstatus == TRANSACTION_END ) { + s_change_old = s_change_new; +#ifdef CONSOLE_ENABLE + uprintf("slave matrix = %b %b %b %b %b\n", + serial_slave_buffer[0], serial_slave_buffer[1], + serial_slave_buffer[2], serial_slave_buffer[3], + serial_slave_buffer[4] ); +#endif + } + } else { + // serial_slave_buffer dosen't change + smatstatus = TRANSACTION_END; // dummy status + } + + if( !master_update && !need_retry) { + status = soft_serial_transaction(GET_SLAVE_STATUS); + } else { + status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); + } + if( status == TRANSACTION_END ) { + s_change_new = slave_buffer_change_count; + need_retry = 0; + } else { + need_retry = 1; + } + return smatstatus; +} + +#endif // SERIAL_USE_MULTI_TRANSACTION +#endif /* USE_SERIAL */ diff --git a/keyboards/treadstone48/rev1/split_scomm.h b/keyboards/treadstone48/rev1/split_scomm.h new file mode 100644 index 0000000000..16887eb74f --- /dev/null +++ b/keyboards/treadstone48/rev1/split_scomm.h @@ -0,0 +1,21 @@ +#pragma once + +#ifndef SERIAL_USE_MULTI_TRANSACTION +/* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */ +#include "serial.h" + +#else +/* --- USE flexible API (using multi-type transaction function) --- */ +// Buffers for master - slave communication +#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 +#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2 + +extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; +extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; +extern uint8_t slave_buffer_change_count; + +void serial_master_init(void); +void serial_slave_init(void); +int serial_update_buffers(int master_changed); + +#endif diff --git a/keyboards/treadstone48/rev1/split_util.c b/keyboards/treadstone48/rev1/split_util.c new file mode 100644 index 0000000000..e1ff8b4379 --- /dev/null +++ b/keyboards/treadstone48/rev1/split_util.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include "split_util.h" +#include "matrix.h" +#include "keyboard.h" + +#ifdef USE_MATRIX_I2C +# include "i2c.h" +#else +# include "split_scomm.h" +#endif + +volatile bool isLeftHand = true; + +static void setup_handedness(void) { + #ifdef EE_HANDS + isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); + #else + // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c + #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) + isLeftHand = !has_usb(); + #else + isLeftHand = has_usb(); + #endif + #endif +} + +static void keyboard_master_setup(void) { + +#ifdef USE_MATRIX_I2C + i2c_master_init(); +#else + serial_master_init(); +#endif +} + +static void keyboard_slave_setup(void) { + +#ifdef USE_MATRIX_I2C + i2c_slave_init(SLAVE_I2C_ADDRESS); +#else + serial_slave_init(); +#endif +} + +bool has_usb(void) { + USBCON |= (1 << OTGPADE); //enables VBUS pad + _delay_us(5); + return (USBSTA & (1< +#include "eeconfig.h" + +#define SLAVE_I2C_ADDRESS 0x32 + +extern volatile bool isLeftHand; + +// slave version of matix scan, defined in matrix.c +void matrix_slave_scan(void); + +void split_keyboard_setup(void); +bool has_usb(void); + +void matrix_master_OLED_init (void); -- cgit v1.2.3