Merge a81f7efe3d5b9662cf9ca0e6ca2a01dd22769021 into 57f89e5388f0f79e27d0e634c9d4621e5a9c214f

This commit is contained in:
Matthew J Wolf
2025-01-01 13:07:11 -05:00
committed by GitHub
15 changed files with 2167 additions and 0 deletions

View File

@ -0,0 +1,6 @@
{
"manufacturer": "Model F Labs",
"keyboard_name": "Reproduction IBM F62 Keyboard",
"maintainer": "Purdea Andrei",
"url": "https://www.modelfkeyboards.com/"
}

View File

@ -0,0 +1,87 @@
/* Copyright 2022 Matthew J Wolf
*
* 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/>.
*
* -----
* Based on F62_-_HHKB_-_Split_Backspace.json from Joe of Model F Labs
*/
/* all
* - Base
*
* Esc 1 2 3 4 5 6 7 8 9 0 - + \ `
*
* Tab Q W E R T Y U I O P [ ] Bspc
*
* Lctl A S D F G H J K L ; ' # Ent
*
* Lsft \ Z X C V B N M , . / Rsft Fn1
*
* Caps GUILalt Space Ratl NlkRctl
*
* - FN1
*
* ` F1 F2 F3 F4 F5 F6 F7 F8 F9 F10F11F12InsDel
*
* PscSklPauUp Del
*
* Vo-Vo+MutEjc Kp*Kp/HomPGuLefRgh
*
* Kp+Kp-EndPGdDow
*
* Fn2
*
* - FN2
*
* Dl-Dl+
*
* EprResHPt
*
* Deb
*
*
*
*
*
*/
#include QMK_KEYBOARD_H
enum layer_names {
_BASE,
_FN1,
_FN2
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_BASE] = LAYOUT_all(
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_GRV,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC,
KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT,
KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, MO(_FN1),
KC_CAPS, KC_LGUI, KC_LALT, KC_SPC, _______, KC_RALT, KC_NUM, KC_RCTL
),
[_FN1] = LAYOUT_all(
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL,
_______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_SCRL, KC_PAUS, KC_UP, _______, KC_DEL,
_______, KC_VOLD, KC_VOLU, KC_MUTE, KC_EJCT, _______, KC_PAST, KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, _______, _______,
_______, _______, _______, _______, _______, _______, _______, KC_PPLS, KC_PMNS, KC_END, KC_PGDN, KC_DOWN, _______, _______,
_______, _______, _______, MO(_FN2), _______, _______, _______, _______
),
[_FN2] = LAYOUT_all(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, HF_DWLD,HF_DWLU, _______, _______,
_______, _______, _______, EE_CLR, QK_BOOT, HF_TOGG, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, DB_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______
)
};

View File

@ -0,0 +1,3 @@
# A keymap for model_f_labs/f62/$(CONTROLLER)
Keymap for the HHKB Split Shift and Split Backspace.

View File

@ -0,0 +1,35 @@
# model_f_labs/f62
![model_f_labs/f62](https://images2.imgbox.com/e5/97/1hPUzXct_o.jpg)
A short description of the keyboard/project
* Keyboard Maintainer: [Purdea Andrei](https://github.com/purdeaandrei)
* Build Maintainer: Matthew J Wolf
* Hardware Supported: Supports the brand new Model F reproductions from https://www.modelfkeyboards.com/, using the smaller xwhatsit controller developed by wcass.
* Hardware Availability: https://www.modelfkeyboards.com/
Make example for this keyboard (after setting up your build environment):
make model_f_labs/f62:default
See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
## How do you enter the boot loader?
There are three ways to enter the boot loader.
* **Command**: At the same time hold down both shift key and the B key.
Left Shift + Right Shift + B
* **Keycode in Layout**: Press the key mapped to `QK_BOOT`.
The default location is the R key on the second layer.
FN + Spacebar + R
* **Physical Reset PCB Pad**: Short pads of the PCB.
The description and image below are from the
Model F Labs manual web page.
At the very worst you have to open up the keyboard to short PROG on the actual xwhatsit controller (unscrew the 2 controller screws to see the components side of the board, make a connection with a conductive metal object like an uncoated metal paper clip, then connect the USB cable to the controller and within a split second remove the paper clip). Per pandrew: “You might think that a screwdriver is gonna be enough, but due to surface oxidation it is likely not gonna be good enough. I like to use sharp metal tweezers, because they can dig into the pad a little bit, breaking up the surface oxidation, and I can actually be sure its shorting. Apply constant strong pressure on the pads while plugging in the keyboard to make sure theyre perfectly shorted. If you hear the windows USB plug-in sound (assuming the sound effect is enabled), then you know you have succeeded. Ive even seen people tell me they tried everything to short the pads with, and then I asked them to solder the pads together and it suddenly works. Theres something about the size of those pads, or about the fact that they need to be shorted in the perfect moment when the chip leaves reset, that make people think they are perfectly shorted and yet they arent. This affects me too, sometimes it takes me up to 3 tries to get it into bootloader mode. Another thing to double check that you are indeed shorting the PROG pad and not the reset pad. I believe in some versions of the wcass controller there is a reset pad on the opposite side of the board. So dont be like I see some pads, those must be it, make sure to be shorting the correct ones.” [1]
![PCB PADS](https://images2.imgbox.com/ef/20/C9zUfX1h_o.jpg)
1. “Brand New Model F and Beam Spring keyboards manual,” Brand New Model F Keyboards, https://www.modelfkeyboards.com/manual/ (accessed Mar. 16, 2024).

View File

@ -0,0 +1,2 @@
DEFAULT_FOLDER = model_f_labs/f62/wcass
# Brand new model f keyboards by default come with the wcass controller.

View File

@ -0,0 +1,117 @@
/*
Copyright 2020 Purdea Andrei
Copyright 2021-2023 Matthew J Wolf
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/>.
*/
#pragma once
/* key matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 9
// Note: physical column are 16, but only 11 are ever used. Column 0..9 match the physical column. Column 10 is physical column 15.
/*
* Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk, and define SOFT_SERIAL_PIN.
*/
/* 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
/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/
#define HOLD_ON_OTHER_KEY_PRESS
/* XWHATSIT CONTROLLER TYPE */
#define CONTROLLER_IS_XWHATSIT_MODEL_F_OR_WCASS_MODEL_F
#define CAPSENSE_KEYBOARD_SETTLE_TIME_US 8
#define CAPSENSE_DAC_SETTLE_TIME_US 8
#define CAPSENSE_HARDCODED_SAMPLE_TIME 4
#define CAPSENSE_CAL_ENABLED 1
#define CAPSENSE_CAL_DEBUG 0
#define CAPSENSE_CAL_INIT_REPS 16
#define CAPSENSE_CAL_EACHKEY_REPS 16
#define CAPSENSE_CAL_BINS 5
#define CAPSENSE_CAL_THRESHOLD_OFFSET 24
#if !CAPSENSE_CAL_ENABLED
#define CAPSENSE_HARDCODED_THRESHOLD 142
#endif
#define CAPSENSE_KEYMAP_COL_TO_PHYSICAL_COL(col) (((col) == 8)?15:(col))
// By default we set up for support of xwhatsit's solenoid driver board.
// Comment out HAPTIC_ENABLE_PIN if you don't have an enable pin:
#define HAPTIC_ENABLE_PIN B7
// We disable haptic feedbeck during USB low power conditions:
#define HAPTIC_OFF_IN_LOW_POWER 1
// Change this if you are using a different pin for the solenoid:
#define SOLENOID_PIN B6
// If you are not using a solenoid then comment out the above, and also in rules.mk, remove "HAPTIC_ENABLE += SOLENOID"
// You can also tune the following for your solenoid:
#define SOLENOID_DEFAULT_DWELL 4
#define SOLENOID_MIN_DWELL 4
#define NO_HAPTIC_MOD
// ----- xwhatsit hardware configuration (type_f) -----
#define CAPSENSE_DAC_SCLK B1
#define CAPSENSE_DAC_DIN B2
#define CAPSENSE_DAC_SYNC_N B0
#define CAPSENSE_DAC_MAX 1023
#define CAPSENSE_SHIFT_DIN D4
#define CAPSENSE_SHIFT_OE D5
#define CAPSENSE_SHIFT_SHCP D7
#define CAPSENSE_SHIFT_STCP D6
#define CAPSENSE_SHIFT_STCP_IO _SFR_IO_ADDR(PORTD)
#define CAPSENSE_SHIFT_STCP_BIT 6
#define SETUP_ROW_GPIOS() \
do { \
PORTC |= 0xF0; \
PORTD |= 0x0F; \
} while (0)
#define SETUP_UNUSED_PINS() do {} while (0)
#define CAPSENSE_READ_ROWS_NUMBER_OF_BYTES_PER_SAMPLE 2
#define CAPSENSE_READ_ROWS_PIN_1 _SFR_IO_ADDR(PINC)
#define CAPSENSE_READ_ROWS_PIN_2 _SFR_IO_ADDR(PIND)
#define CAPSENSE_READ_ROWS_ASM_INSTRUCTIONS "in %[dest_row_1], %[ioreg_row_1]\n\tin %[dest_row_2], %[ioreg_row_2]"
#define CAPSENSE_READ_ROWS_STORE_TO_ARRAY_INSTRUCTIONS \
"st %a[arr]+, %[dest_row_1]" "\n\t" \
"st %a[arr]+, %[dest_row_2]"
#define CAPSENSE_READ_ROWS_STORE_TO_ARRAY_INSTRUCTIONS_FAKE \
"st %a[arr], %[dest_row_1]" "\n\t" \
"st %a[arr], %[dest_row_2]"
#define CAPSENSE_READ_ROWS_OUTPUT_CONSTRAINTS [dest_row_1] "=&r" (dest_row_1), [dest_row_2] "=&r" (dest_row_2)
#define CAPSENSE_READ_ROWS_INPUT_CONSTRAINTS [ioreg_row_1] "I" (CAPSENSE_READ_ROWS_PIN_1), [ioreg_row_2] "I" (CAPSENSE_READ_ROWS_PIN_2)
#define CAPSENSE_READ_ROWS_LOCAL_VARS uint8_t dest_row_1, dest_row_2
#define CAPSENSE_READ_ROWS_EXTRACT_FROM_ARRAY do { dest_row_1 = array[p0++]; dest_row_2 = array[p0++]; } while (0)
#if (!defined(CAPSENSE_CONDUCTIVE_PLASTIC_IS_PUSHED_DOWN_ON_KEYPRESS)) && (!defined(CAPSENSE_CONDUCTIVE_PLASTIC_IS_PULLED_UP_ON_KEYPRESS))
#define CAPSENSE_CONDUCTIVE_PLASTIC_IS_PUSHED_DOWN_ON_KEYPRESS
#endif
#define CAPSENSE_KEYMAP_ROW_TO_PHYSICAL_ROW(row) (7-(row))
#define CAPSENSE_PHYSICAL_ROW_TO_KEYMAP_ROW(row) (7-(row))
#define CAPSENSE_READ_ROWS_VALUE ((dest_row_1 >> 4) | (dest_row_2 << 4))

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
# model_f_labs/f62/wcass
![model_f_labs/f62/wcass](https://images2.imgbox.com/e5/97/1hPUzXct_o.jpg)
A short description of the keyboard/project
* Keyboard Maintainer: [Purdea Andrei](https://github.com/purdeaandrei)
* Hardware Supported: Supports the brand new Model F reproductions from https://www.modelfkeyboards.com/, using the smaller xwhatsit controller developed by wcass.
* Hardware Availability: https://www.modelfkeyboards.com/
Make example for this keyboard (after setting up your build environment):
make model_f_labs/f62/wcass:default
See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
## How do you enter the boot loader?
There are three ways to enter the boot loader.
* **Command**: At the same time hold down both shift key and the B key.
Left Shift + Right Shift + B
* **Keycode in Layout**: Press the key mapped to `QK_BOOT`.
The default location is the R key on the second layer.
FN + Spacebar + R
* **Physical Reset PCB Pad**: Short pads of the PCB.
The description and image below are from the
Model F Labs manual web page.
At the very worst you have to open up the keyboard to short PROG on the actual xwhatsit controller (unscrew the 2 controller screws to see the components side of the board, make a connection with a conductive metal object like an uncoated metal paper clip, then connect the USB cable to the controller and within a split second remove the paper clip). Per pandrew: “You might think that a screwdriver is gonna be enough, but due to surface oxidation it is likely not gonna be good enough. I like to use sharp metal tweezers, because they can dig into the pad a little bit, breaking up the surface oxidation, and I can actually be sure its shorting. Apply constant strong pressure on the pads while plugging in the keyboard to make sure theyre perfectly shorted. If you hear the windows USB plug-in sound (assuming the sound effect is enabled), then you know you have succeeded. Ive even seen people tell me they tried everything to short the pads with, and then I asked them to solder the pads together and it suddenly works. Theres something about the size of those pads, or about the fact that they need to be shorted in the perfect moment when the chip leaves reset, that make people think they are perfectly shorted and yet they arent. This affects me too, sometimes it takes me up to 3 tries to get it into bootloader mode. Another thing to double check that you are indeed shorting the PROG pad and not the reset pad. I believe in some versions of the wcass controller there is a reset pad on the opposite side of the board. So dont be like I see some pads, those must be it, make sure to be shorting the correct ones.” [1]
![PCB PADS](https://images2.imgbox.com/ef/20/C9zUfX1h_o.jpg)
1. “Brand New Model F and Beam Spring keyboards manual,” Brand New Model F Keyboards, https://www.modelfkeyboards.com/manual/ (accessed Mar. 16, 2024).

View File

@ -0,0 +1,7 @@
# Build Options
# change yes to no to disable
#
#HAPTIC_ENABLE = yes
HAPTIC_DRIVER = solenoid
CUSTOM_MATRIX=lite
SRC += xwhatsit_capsense_matrix.c xwhatsit_util_comm.c

View File

@ -0,0 +1,18 @@
/* Copyright 2020 Purdea Andrei
*
* 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/>.
*/
const char *KEYBOARD_FILENAME = __FILE__; // used by util_comm

View File

@ -0,0 +1,63 @@
/* Copyright 2020 Purdea Andrei
* Copyright 2021 Matthew J Wolf
*
* 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/>.
*/
// This file should be included at the end of each keyboard-specific config.h
#pragma once
#ifndef MATRIX_CAPSENSE_ROWS
# ifdef MATRIX_EXTRA_DIRECT_ROWS
# define MATRIX_CAPSENSE_ROWS (MATRIX_ROWS - MATRIX_EXTRA_DIRECT_ROWS)
# ifndef MATRIX_EXTRA_DIRECT_COLS
# define MATRIX_EXTRA_DIRECT_COLS MATRIX_COLS
# endif
# else
# define MATRIX_CAPSENSE_ROWS MATRIX_ROWS
# endif
#endif
#ifndef CAPSENSE_CAL_INIT_REPS
# define CAPSENSE_CAL_INIT_REPS 16
#endif
#ifndef CAPSENSE_CAL_EACHKEY_REPS
# define CAPSENSE_CAL_EACHKEY_REPS 16
#endif
// Testing Options
#ifndef CAPSENSE_KEYBOARD_SETTLE_TIME_US
# error "Please define CAPSENSE_KEYBOARD_SETTLE_TIME_US in config.h"
#endif
#ifndef CAPSENSE_DAC_SETTLE_TIME_US
# error "Please define CAPSENSE_DAC_SETTLE_TIME_US in config.h"
#endif
#ifndef CAPSENSE_HARDCODED_SAMPLE_TIME
# error "Please define CAPSENSE_HARDCODED_SAMPLE_TIME in config.h"
#endif
#ifndef CAPSENSE_CAL_ENABLED
# error "Please define CAPSENSE_CAL_ENABLED as 1/0 in config.h"
#endif
#ifndef CAPSENSE_CAL_DEBUG
# error "Please define CAPSENSE_CAL_DEBUG as 1/0 in config.h"
#endif
#ifndef CAPSENSE_CAL_BINS
# error "Please define CAPSENSE_CAL_BINS in config.h"
#endif
#ifndef CAPSENSE_CAL_THRESHOLD_OFFSET
# error "Please define CAPSENSE_CAL_THRESHOLD_OFFSET in config.h"
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,69 @@
/* Copyright 2020 Purdea Andrei
* Copyright 2021 Matthew J Wolf
*
* 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/>.
*/
#pragma once
#define nSHDN_BIT 12
#define MCP_DAC_GAIN_2X 0
#define MCP_DAC_GAIN_1X 1
#define nGA_BIT 13
#define BUF_BIT 14
#define TRACKING_TEST_TIME 4
// Key 1 is the always non-pressed key under the space bar to the right.
#define TRACKING_KEY_1_COL 6
#define TRACKING_KEY_1_ROW 4
// Key 2 is the always-pressed calibration pad to the far right-bottom of the keyboard. (both on F62 and F77)
#define TRACKING_KEY_2_COL 15
#define TRACKING_KEY_2_ROW 6
// Key 3 is the F key
#define TRACKING_KEY_3_COL 2
#define TRACKING_KEY_3_ROW 5
// Key 4 is the half of the split backspace that is unused if the user has a normal backspace.
#define TRACKING_KEY_4_COL 7
#define TRACKING_KEY_4_ROW 3
// Key 5 is hidden key next to the left shift, which is only used in ISO layouts.
#define TRACKING_KEY_5_COL 0
#define TRACKING_KEY_5_ROW 7
#define TRACKING_REPS 16
#ifndef NO_PRINT
# define NRTIMES 64
# define TESTATONCE 8
# define REPS_V2 15
#endif
#ifndef MATRIX_MANIPULATE_H
# define MATRIX_MANIPULATE_H
# include "quantum.h"
// Contains stuff used to manipulate the matrix using the util.
// These are defined in capsense_matrix.c. This file is not called matrix.h to avoid conflict with qmk-native matrix.h
extern bool keyboard_scan_enabled;
void matrix_scan_raw(matrix_row_t current_matrix[]);
extern uint16_t cal_thresholds[CAPSENSE_CAL_BINS];
extern matrix_row_t assigned_to_threshold[CAPSENSE_CAL_BINS][MATRIX_CAPSENSE_ROWS];
uint16_t measure_middle_keymap_coords(uint8_t col, uint8_t row, uint8_t time, uint8_t reps);
void shift_data(uint32_t data, int data_idle, int shcp_idle, int stcp_idle);
void dac_write_threshold(uint16_t value);
uint8_t test_single(uint8_t col, uint16_t time, uint8_t *interference_ptr);
void shift_select_col_no_strobe(uint8_t col);
void shift_select_nothing(void);
#endif

View File

@ -0,0 +1,210 @@
/* Copyright 2020 Purdea Andrei
* Copyright 2021-2022 Matthew J Wolf
*
* 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 "quantum.h"
#include "raw_hid.h"
#include "xwhatsit_util_comm.h"
#include "xwhatsit_capsense_matrix.h"
#include <string.h>
#include <platforms/eeprom.h>
extern const char *KEYBOARD_FILENAME; // This must be defined in keyboard_name.c to equal the filename. This is sent back to the PC-side software for it to determine which keyboard we are using.
static const uint8_t magic[] = UTIL_COMM_MAGIC;
// Has well know issues.
//#define min(x, y) (((x) < (y))?(x):(y))
inline int min(int x, int y) {
if (x > y) {
return y;
}
return x;
}
void raw_hid_receive(uint8_t *data, uint8_t length) {
if (0 != memcmp(data, magic, sizeof(magic))) {
return;
}
uint8_t response[RAW_EPSIZE];
memcpy(response, magic, sizeof(magic));
response[2] = UTIL_COMM_RESPONSE_ERROR;
switch (data[2]) {
case UTIL_COMM_GET_VERSION:
response[2] = UTIL_COMM_RESPONSE_OK;
response[3] = UTIL_COMM_VERSION_MAJOR;
response[4] = UTIL_COMM_VERSION_MID;
response[5] = (UTIL_COMM_VERSION_MINOR >> 8) & 0xff;
response[6] = (UTIL_COMM_VERSION_MINOR >> 0) & 0xff;
break;
case UTIL_COMM_DISABLE_KEYBOARD:
response[2] = UTIL_COMM_RESPONSE_OK;
response[3] = (uint8_t)keyboard_scan_enabled;
keyboard_scan_enabled = 0;
break;
case UTIL_COMM_ENABLE_KEYBOARD:
response[2] = UTIL_COMM_RESPONSE_OK;
response[3] = (uint8_t)keyboard_scan_enabled;
keyboard_scan_enabled = 1;
break;
case UTIL_COMM_ENTER_BOOTLOADER:
keyboard_scan_enabled = 0;
wait_ms(10);
bootloader_jump();
// we should not be reaching the following:
wait_ms(10);
response[2] = UTIL_COMM_RESPONSE_OK;
break;
case UTIL_COMM_GET_KEYSTATE:
response[2] = UTIL_COMM_RESPONSE_OK;
{
matrix_row_t current_matrix[MATRIX_ROWS];
matrix_scan_raw(current_matrix);
char *current_matrix_ptr = (char *)current_matrix;
int offset = 0;
if (sizeof(current_matrix) > 32 - 3) {
offset = data[3];
current_matrix_ptr += offset;
}
memcpy(&response[3], current_matrix_ptr, min(32 - 3, sizeof(current_matrix) - offset));
}
break;
case UTIL_COMM_GET_THRESHOLDS:
response[2] = UTIL_COMM_RESPONSE_OK;
#if CAPSENSE_CAL_ENABLED
response[3] = CAPSENSE_CAL_BINS;
{
const uint8_t cal_bin = data[3];
response[4] = cal_thresholds[cal_bin] & 0xff;
response[5] = (cal_thresholds[cal_bin] >> 8) & 0xff;
char *assigned_to_threshold_ptr = (char *)assigned_to_threshold[cal_bin];
int offset = 0;
if (sizeof(assigned_to_threshold[cal_bin]) > 32 - 6) {
offset = data[4];
assigned_to_threshold_ptr += offset;
}
memcpy(&response[6], assigned_to_threshold_ptr, min(32 - 6, sizeof(assigned_to_threshold[cal_bin]) - offset));
}
#else
response[3] = 0;
response[4] = (CAPSENSE_HARDCODED_THRESHOLD)&0xff;
response[5] = ((CAPSENSE_HARDCODED_THRESHOLD) >> 8) & 0xff;
#endif
break;
case UTIL_COMM_GET_KEYBOARD_FILENAME: {
response[2] = UTIL_COMM_RESPONSE_OK;
if (data[3] >= strlen(KEYBOARD_FILENAME) + 1) {
response[3] = 0;
} else {
const char *substring = KEYBOARD_FILENAME + data[3];
size_t substring_length = strlen(substring) + 1;
if (substring_length > RAW_EPSIZE - 3) substring_length = RAW_EPSIZE - 3;
memcpy(&response[3], substring, substring_length);
}
break;
}
case UTIL_COMM_ERASE_EEPROM: {
response[2] = UTIL_COMM_RESPONSE_OK;
uint16_t addr;
for (addr = 0; addr < E2END; addr += 1) {
eeprom_update_byte((uint8_t *)addr, 0xff);
}
break;
}
case UTIL_COMM_GET_SIGNAL_VALUE: {
response[2] = UTIL_COMM_RESPONSE_OK;
uint8_t col = data[3];
uint8_t row = data[4];
uint8_t count = data[5];
int i;
for (i = 0; i < count; i++) {
uint16_t value = measure_middle_keymap_coords(col, row, CAPSENSE_HARDCODED_SAMPLE_TIME, 8);
response[3 + i * 2] = value & 0xff;
response[3 + i * 2 + 1] = (value >> 8) & 0xff;
col += 1;
if (col >= MATRIX_COLS) {
col -= MATRIX_COLS;
row += 1;
}
if (row >= MATRIX_CAPSENSE_ROWS) {
break;
}
}
break;
}
case UTIL_COMM_GET_KEYBOARD_DETAILS: {
response[2] = UTIL_COMM_RESPONSE_OK;
response[3] = MATRIX_COLS;
response[4] = MATRIX_ROWS;
response[5] = GET_KEYBOARD_DETAILS_5;
#if defined(CONTROLLER_IS_XWHATSIT_BEAMSPRING_REV_4)
response[5] = 1;
#elif defined(CONTROLLER_IS_XWHATSIT_MODEL_F_OR_WCASS_MODEL_F)
response[5] = 2;
#elif defined(CONTROLLER_IS_THROUGH_HOLE_BEAMSPRING)
response[5] = 3;
#elif defined(CONTROLLER_IS_THROUGH_HOLE_MODEL_F)
response[5] = 4;
#else
response[5] = 0;
#endif
response[6] = CAPSENSE_KEYBOARD_SETTLE_TIME_US;
response[7] = CAPSENSE_DAC_SETTLE_TIME_US;
response[8] = CAPSENSE_HARDCODED_SAMPLE_TIME;
response[9] = CAPSENSE_CAL_ENABLED;
response[10] = CAPSENSE_DAC_MAX & 0xFF;
response[11] = (CAPSENSE_DAC_MAX >> 8) & 0xFF;
response[12] = MATRIX_CAPSENSE_ROWS;
response[13] = 0; // reserved for future
response[14] = 0; // reserved for future
response[15] = 0; // reserved for future
break;
}
case UTIL_COMM_SHIFT_DATA:
case UTIL_COMM_SHIFT_DATA_EXT: {
response[2] = UTIL_COMM_RESPONSE_OK;
uint32_t shdata = (((uint32_t)(data[3])) << 0) | (((uint32_t)(data[4])) << 8) | (((uint32_t)(data[5])) << 16) | (((uint32_t)(data[6])) << 24);
int data_idle = 0;
int shcp_idle = 0;
int stcp_idle = 0;
if (data[2] == UTIL_COMM_SHIFT_DATA_EXT) {
data_idle = data[7];
shcp_idle = data[8];
stcp_idle = data[9];
}
shift_data(shdata, data_idle, shcp_idle, stcp_idle);
response[3] = readPin(CAPSENSE_SHIFT_DIN);
response[4] = readPin(CAPSENSE_SHIFT_SHCP);
response[5] = readPin(CAPSENSE_SHIFT_STCP);
break;
}
case UTIL_COMM_SET_DAC_VALUE: {
response[2] = UTIL_COMM_RESPONSE_OK;
uint16_t value = data[3] | (((uint16_t)data[4]) << 8);
dac_write_threshold(value);
break;
}
case UTIL_COMM_GET_ROW_STATE: {
response[2] = UTIL_COMM_RESPONSE_OK;
response[3] = test_single(255, 0, NULL);
break;
}
default:
break;
}
raw_hid_send(response, sizeof(response));
}

View File

@ -0,0 +1,59 @@
/* Copyright 2020 Purdea Andrei
* Copyright 2021 Matthew J Wolf
*
* 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/>.
*/
#pragma once
#ifndef RAW_EPSIZE
# define RAW_EPSIZE 32
#endif
# define UTIL_COMM_VERSION_MAJOR 2
# define UTIL_COMM_VERSION_MID 0
# define UTIL_COMM_VERSION_MINOR 5
# define UTIL_COMM_MAGIC \
{ 0x55, 0xAA }
enum command {
UTIL_COMM_GET_VERSION = 0x11,
UTIL_COMM_ENTER_BOOTLOADER,
UTIL_COMM_DISABLE_KEYBOARD,
UTIL_COMM_ENABLE_KEYBOARD,
UTIL_COMM_GET_KEYSTATE,
UTIL_COMM_GET_THRESHOLDS,
UTIL_COMM_GET_KEYBOARD_FILENAME,
UTIL_COMM_ERASE_EEPROM,
UTIL_COMM_GET_SIGNAL_VALUE,
UTIL_COMM_GET_KEYBOARD_DETAILS,
UTIL_COMM_SHIFT_DATA,
UTIL_COMM_SET_DAC_VALUE,
UTIL_COMM_GET_ROW_STATE,
UTIL_COMM_SHIFT_DATA_EXT,
};
enum response { UTIL_COMM_RESPONSE_OK = 0x22, UTIL_COMM_RESPONSE_ERROR };
#if defined(CONTROLLER_IS_XWHATSIT_BEAMSPRING_REV_4)
# define GET_KEYBOARD_DETAILS_5 1
#elif defined(CONTROLLER_IS_XWHATSIT_MODEL_F_OR_WCASS_MODEL_F)
# define GET_KEYBOARD_DETAILS_5 2
#elif defined(CONTROLLER_IS_THROUGH_HOLE_BEAMSPRING)
# define GET_KEYBOARD_DETAILS_5 3
#elif defined(CONTROLLER_IS_THROUGH_HOLE_MODEL_F)
# define GET_KEYBOARD_DETAILS_5 4
#else
# define GET_KEYBOARD_DETAILS_5 0
#endif