htx_studio_keyboard固件源码

This commit is contained in:
htx_studio 2025-04-30 19:47:42 +08:00
parent 9f04023d35
commit 715fbf209e
30 changed files with 11178 additions and 0 deletions

View File

@ -0,0 +1,254 @@
/* Copyright 2020 Richard Sutherland <rich@brickbots.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "spi_master.h"
#include "adns.h"
#include "debug.h"
#include "wait.h"
#include "pointing_device.h"
#include "adns9800_srom_A6.h"
// registers
#define REG_Product_ID 0x00
#define REG_Revision_ID 0x01
#define REG_Motion 0x02
#define REG_Delta_X_L 0x03
#define REG_Delta_X_H 0x04
#define REG_Delta_Y_L 0x05
#define REG_Delta_Y_H 0x06
#define REG_SQUAL 0x07
#define REG_Pixel_Sum 0x08
#define REG_Maximum_Pixel 0x09
#define REG_Minimum_Pixel 0x0a
#define REG_Shutter_Lower 0x0b
#define REG_Shutter_Upper 0x0c
#define REG_Frame_Period_Lower 0x0d
#define REG_Frame_Period_Upper 0x0e
#define REG_Configuration_I 0x0f
#define REG_Configuration_II 0x10
#define REG_Frame_Capture 0x12
#define REG_SROM_Enable 0x13
#define REG_Run_Downshift 0x14
#define REG_Rest1_Rate 0x15
#define REG_Rest1_Downshift 0x16
#define REG_Rest2_Rate 0x17
#define REG_Rest2_Downshift 0x18
#define REG_Rest3_Rate 0x19
#define REG_Frame_Period_Max_Bound_Lower 0x1a
#define REG_Frame_Period_Max_Bound_Upper 0x1b
#define REG_Frame_Period_Min_Bound_Lower 0x1c
#define REG_Frame_Period_Min_Bound_Upper 0x1d
#define REG_Shutter_Max_Bound_Lower 0x1e
#define REG_Shutter_Max_Bound_Upper 0x1f
#define REG_LASER_CTRL0 0x20
#define REG_Observation 0x24
#define REG_Data_Out_Lower 0x25
#define REG_Data_Out_Upper 0x26
#define REG_SROM_ID 0x2a
#define REG_Lift_Detection_Thr 0x2e
#define REG_Configuration_V 0x2f
#define REG_Configuration_IV 0x39
#define REG_Power_Up_Reset 0x3a
#define REG_Shutdown 0x3b
#define REG_Inverse_Product_ID 0x3f
#define REG_Motion_Burst 0x50
#define REG_SROM_Load_Burst 0x62
#define REG_Pixel_Burst 0x64
// pins
#define NCS A4
extern const uint16_t firmware_length;
extern const uint8_t firmware_data[];
enum motion_burst_propertr{
motion = 0,
observation,
delta_x_l,
delta_x_h,
delta_y_l,
delta_y_h,
squal,
pixel_sum,
maximum_pixel,
minimum_pixel,
shutter_upper,
shutter_lower,
frame_period_upper,
frame_period_lower,
end_data
};
void adns_begin(void){
spi_start(NCS, false, 3, 8);
}
void adns_end(void){
spi_stop();
}
void adns_write(uint8_t reg_addr, uint8_t data){
adns_begin();
//send address of the register, with MSBit = 1 to indicate it's a write
spi_write(reg_addr | 0x80 );
spi_write(data);
// tSCLK-NCS for write operation
wait_us(20);
// tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
wait_us(100);
adns_end();
}
uint8_t adns_read(uint8_t reg_addr){
adns_begin();
// send adress of the register, with MSBit = 0 to indicate it's a read
spi_write(reg_addr & 0x7f );
uint8_t data = spi_read();
// tSCLK-NCS for read operation is 120ns
wait_us(1);
// tSRW/tSRR (=20us) minus tSCLK-NCS
wait_us(19);
adns_end();
return data;
}
void pointing_device_init(void) {
dprint("STARTING INTI\n");
spi_init();
// reset serial port
adns_begin();
adns_end();
// reboot
adns_write(REG_Power_Up_Reset, 0x5a);
wait_ms(50);
// read registers and discard
adns_read(REG_Motion);
adns_read(REG_Delta_X_L);
adns_read(REG_Delta_X_H);
adns_read(REG_Delta_Y_L);
adns_read(REG_Delta_Y_H);
// upload firmware
// set the configuration_IV register in 3k firmware mode
// bit 1 = 1 for 3k mode, other bits are reserved
adns_write(REG_Configuration_V, 0x02);
// write 0x1d in SROM_enable reg for initializing
adns_write(REG_SROM_Enable, 0x1d);
// wait for more than one frame period
// assume that the frame rate is as low as 100fps... even if it should never be that low
wait_ms(10);
// write 0x18 to SROM_enable to start SROM download
adns_write(REG_SROM_Enable, 0x18);
// write the SROM file (=firmware data)
// write burst destination adress
adns_begin();
spi_write(REG_SROM_Load_Burst | 0x80);
wait_us(15);
// send all bytes of the firmware
unsigned char c;
for(int i = 0; i < firmware_length; i++){
c = (unsigned char)pgm_read_byte(firmware_data + i);
spi_write(c);
wait_us(15);
}
adns_end();
wait_ms(10);
// enable laser(bit 0 = 0b), in normal mode (bits 3,2,1 = 000b)
// reading the actual value of the register is important because the real
// default value is different from what is said in the datasheet, and if you
// change the reserved bytes (like by writing 0x00...) it would not work.
uint8_t laser_ctrl0 = adns_read(REG_LASER_CTRL0);
adns_write(REG_LASER_CTRL0, laser_ctrl0 & 0xf0);
wait_ms(1);
// set the configuration_I register to set the CPI
// 0x01 = 50, minimum
// 0x44 = 3400, default
// 0x8e = 7100
// 0xA4 = 8200, maximum
adns_write(REG_Configuration_I, 0x1A);
wait_ms(100);
dprint("INIT ENDED\n");
}
int16_t convertDeltaToInt(uint8_t high, uint8_t low){
// join bytes into twos compliment
//int16_t twos_comp = (high << 8) | low;
//return twos_comp;
return (high << 8) | low;
}
motion_delta_t readSensor(void) {
adns_begin();
// read from Motion_Burst to enable burt mode
spi_write(REG_Motion_Burst & 0x7f);
// Wait one frame per docs, thanks u/kbjunky
wait_us(100);
uint8_t burst_data[pixel_sum];
for (int i = 0; i < pixel_sum; ++i) {
burst_data[i] = spi_read();
}
uint16_t delta_x = convertDeltaToInt(burst_data[delta_x_h], burst_data[delta_x_l]);
uint16_t delta_y = convertDeltaToInt(burst_data[delta_y_h], burst_data[delta_y_l]);
// Only consider the MSB for motion as this byte has other status bits
uint8_t motion_ind = burst_data[motion] & 0b10000000;
adns_end();
motion_delta_t delta = {delta_x, delta_y, motion_ind};
return delta;
}
bool pointing_device_task(void) {
motion_delta_t delta = readSensor();
report_mouse_t report = pointing_device_get_report();
if(delta.motion_ind) {
// clamp deltas from -127 to 127
report.x = delta.delta_x < -127 ? -127 : delta.delta_x > 127 ? 127 : delta.delta_x;
report.x = -report.x;
report.y = delta.delta_y < -127 ? -127 : delta.delta_y > 127 ? 127 : delta.delta_y;
}
pointing_device_set_report(report);
return pointing_device_send();
}

View File

@ -0,0 +1,38 @@
/* Copyright 2020 Richard Sutherland <rich@brickbots.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
void adns_begin(void);
void adns_end(void);
void adns_write(uint8_t reg_addr, uint8_t data);
uint8_t adns_read(uint8_t reg_addr);
int16_t convertDeltaToInt(uint8_t high, uint8_t low);
struct _motion_delta {
int16_t delta_x;
int16_t delta_y;
int8_t motion_ind;
};
typedef struct _motion_delta motion_delta_t;
motion_delta_t readSensor(void);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
#pragma once
#define SPI_DRIVER SPID1
#define SPI_SCK_PIN A5
#define SPI_MISO_PIN A6
#define SPI_MOSI_PIN A7
#define POINTING_DEVICE_CS_PIN A4
#define POINTING_DEVICE_MOTION_PIN A3
#define POINTING_DEVICE_TASK_THROTTLE_MS 1
#define ENCODER_RESOLUTION 2
#ifdef RGB_MATRIX_ENABLE
#define WS2812_BITBANG_NOP_FUDGE 0
#define WS2812_PWM_DRIVER PWMD3
#define WS2812_PWM_CHANNEL 1
#define WS2812_DMA_STREAM STM32_DMA1_STREAM1
#define WS2812_DMA_CHANNEL 1
#define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM3_UP
#endif

View File

@ -0,0 +1,25 @@
/* Copyright 2020 QMK
*
* 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 HAL_USE_PWM TRUE
#define HAL_USE_SPI TRUE
#define SPI_USE_WAIT TRUE
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
#include_next <halconf.h>

View File

@ -0,0 +1,231 @@
{
"keyboard_name": "One-Handed_Keyboard_ML",
"manufacturer": "HTXStudio",
"url": "https://github.com/htx-studio",
"maintainer": "HTXStudio",
"usb": {
"vid": "0x475D",
"pid": "0x03AF",
"device_version": "3.1.0"
},
"processor": "STM32G431",
"bootloader": "stm32-dfu",
"diode_direction": "ROW2COL",
"matrix": {
"rows": 6,
"cols": 14
},
"features": {
"bootmagic": true,
"extrakey": true,
"mousekey": true,
"nkro": true,
"pointing_device": true,
"encoder": true,
"rgb_matrix": true
},
"matrix_pins": {
"cols": ["A0", "A1", "A2", "C4", "B0", "B1", "B2", "B7", "B5", "B3", "B10", "C11", "C10", "A15"],
"rows": ["B12", "B15", "C6", "B13", "B14", "A8"]
},
"encoder": {
"rotary": [
{"pin_a": "A9", "pin_b": "A10"}
]
},
"ws2812": {
"pin": "B4",
"driver": "pwm"
},
"layouts": {
"LAYOUT": {
"layout": [
{"matrix": [0, 0], "w":1, "h":1, "x":0, "y":0},
{"matrix": [0, 1], "w":1, "h":1, "x":1, "y":0},
{"matrix": [0, 2], "w":1, "h":1, "x":2, "y":0},
{"matrix": [0, 3], "w":1, "h":1, "x":3, "y":0},
{"matrix": [0, 4], "w":1, "h":1, "x":4, "y":0},
{"matrix": [0, 5], "w":1, "h":1, "x":5, "y":0},
{"matrix": [0, 6], "w":1, "h":1, "x":6, "y":0},
{"matrix": [0, 7], "w":1, "h":1, "x":7, "y":0},
{"matrix": [0, 8], "w":1, "h":1, "x":8, "y":0},
{"matrix": [0, 9], "w":1, "h":1, "x":9, "y":0},
{"matrix": [0, 10], "w":1, "h":1, "x":10, "y":0},
{"matrix": [0, 11], "w":1, "h":1, "x":11, "y":0},
{"matrix": [0, 12], "w":1, "h":1, "x":12, "y":0},
{"matrix": [0, 13], "w":1, "h":1, "x":13, "y":0},
{"matrix": [1, 0], "w":1, "h":1, "x":0, "y":1},
{"matrix": [1, 1], "w":1, "h":1, "x":1, "y":1},
{"matrix": [1, 2], "w":1, "h":1, "x":2, "y":1},
{"matrix": [1, 3], "w":1, "h":1, "x":3, "y":1},
{"matrix": [1, 4], "w":1, "h":1, "x":4, "y":1},
{"matrix": [1, 5], "w":1, "h":1, "x":5, "y":1},
{"matrix": [1, 6], "w":1, "h":1, "x":6, "y":1},
{"matrix": [1, 7], "w":1, "h":1, "x":7, "y":1},
{"matrix": [1, 8], "w":1, "h":1, "x":8, "y":1},
{"matrix": [1, 9], "w":1, "h":1, "x":9, "y":1},
{"matrix": [1, 10], "w":1, "h":1, "x":10, "y":1},
{"matrix": [1, 11], "w":1, "h":1, "x":11, "y":1},
{"matrix": [1, 12], "w":1, "h":1, "x":12, "y":1},
{"matrix": [1, 13], "w":1, "h":1, "x":13, "y":1},
{"matrix": [2, 0], "w":1.5, "h":1, "x":0.5, "y":2},
{"matrix": [2, 2], "w":1, "h":1, "x":2, "y":2},
{"matrix": [2, 3], "w":1, "h":1, "x":3, "y":2},
{"matrix": [2, 4], "w":1, "h":1, "x":4, "y":2},
{"matrix": [2, 5], "w":1, "h":1, "x":5, "y":2},
{"matrix": [2, 6], "w":1, "h":1, "x":6, "y":2},
{"matrix": [2, 7], "w":1, "h":1, "x":7, "y":2},
{"matrix": [2, 8], "w":1, "h":1, "x":8, "y":2},
{"matrix": [2, 9], "w":1, "h":1, "x":9, "y":2},
{"matrix": [2, 10], "w":1, "h":1, "x":10, "y":2},
{"matrix": [2, 12], "w":1.5, "h":1, "x":11, "y":2},
{"matrix": [2, 13], "w":1, "h":1, "x":12.5, "y":2},
{"matrix": [3, 0], "w":2, "h":1, "x":1, "y":3},
{"matrix": [3, 3], "w":1, "h":1, "x":3, "y":3},
{"matrix": [3, 4], "w":1, "h":1, "x":4, "y":3},
{"matrix": [3, 5], "w":1, "h":1, "x":5, "y":3},
{"matrix": [3, 6], "w":1, "h":1, "x":6, "y":3},
{"matrix": [3, 7], "w":1, "h":1, "x":7, "y":3},
{"matrix": [3, 8], "w":1, "h":1, "x":8, "y":3},
{"matrix": [3, 9], "w":1, "h":1, "x":9, "y":3},
{"matrix": [3, 10], "w":2, "h":1, "x":10, "y":3},
{"matrix": [3, 13], "w":2, "h":1, "x":12, "y":3},
{"matrix": [4, 0], "w":1.25, "h":1, "x":1.25, "y":4},
{"matrix": [4, 3], "w":1.25, "h":1, "x":2.5, "y":4},
{"matrix": [4, 4], "w":1.25, "h":1, "x":3.75, "y":4},
{"matrix": [4, 5], "w":1.25, "h":1, "x":5, "y":4},
{"matrix": [4, 6], "w":1.25, "h":1, "x":6.25, "y":4},
{"matrix": [4, 7], "w":1.25, "h":1, "x":7.5, "y":4},
{"matrix": [4, 9], "w":1.25, "h":1, "x":8.75, "y":4},
{"matrix": [4, 12], "w":2, "h":1, "x":10.75, "y":4},
{"matrix": [4, 13], "w":1.25, "h":1, "x":12, "y":4},
{"matrix": [5, 0], "w":1, "h":1, "x":0, "y":5},
{"matrix": [5, 3], "w":1, "h":1, "x":3, "y":5},
{"matrix": [5, 4], "w":1, "h":1, "x":4, "y":5},
{"matrix": [5, 5], "w":1, "h":1, "x":5, "y":5},
{"matrix": [5, 6], "w":1, "h":1, "x":6, "y":5}
]
}
},
"rgb_matrix": {
"driver": "ws2812",
"max_brightness": 110,
"animations": {
"alphas_mods": true,
"gradient_up_down": true,
"gradient_left_right": true,
"breathing": true,
"band_sat": true,
"band_val": true,
"band_pinwheel_sat": true,
"band_pinwheel_val": true,
"band_spiral_sat": true,
"band_spiral_val": true,
"cycle_all": true,
"cycle_left_right": true,
"cycle_up_down": true,
"cycle_out_in": true,
"cycle_out_in_dual": true,
"rainbow_moving_chevron": true,
"cycle_pinwheel": true,
"cycle_spiral": true,
"dual_beacon": true,
"rainbow_beacon": true,
"rainbow_pinwheels": true,
"raindrops": true,
"jellybean_raindrops": true,
"hue_breathing": true,
"hue_pendulum": true,
"hue_wave": true,
"pixel_fractal": true,
"pixel_flow": true,
"pixel_rain": true,
"typing_heatmap": true,
"digital_rain": true,
"solid_reactive_simple": true,
"solid_reactive": true,
"solid_reactive_wide": true,
"solid_reactive_multiwide": true,
"solid_reactive_cross": true,
"solid_reactive_multicross": true,
"solid_reactive_nexus": true,
"solid_reactive_multinexus": true,
"splash": true,
"multisplash": true,
"solid_splash": true,
"solid_multisplash": true
},
"layout": [
{"matrix": [0,0], "flags":4, "x":0, "y":0},
{"matrix": [0,1], "flags":4, "x":17, "y":0},
{"matrix": [0,2], "flags":4, "x":34, "y":0},
{"matrix": [0,3], "flags":4, "x":51, "y":0},
{"matrix": [0,4], "flags":4, "x":68, "y":0},
{"matrix": [0,5], "flags":4, "x":85, "y":0},
{"matrix": [0,6], "flags":4, "x":102, "y":0},
{"matrix": [0,7], "flags":4, "x":119, "y":0},
{"matrix": [0,8], "flags":4, "x":136, "y":0},
{"matrix": [0,9], "flags":4, "x":153, "y":0},
{"matrix": [0,10], "flags":4, "x":170, "y":0},
{"matrix": [0,11], "flags":4, "x":187, "y":0},
{"matrix": [0,12], "flags":4, "x":204, "y":0},
{"matrix": [0,13], "flags":4, "x":221, "y":0},
{"matrix": [1,0], "flags":4, "x":0, "y":16},
{"matrix": [1,1], "flags":4, "x":17, "y":16},
{"matrix": [1,2], "flags":4, "x":34, "y":16},
{"matrix": [1,3], "flags":4, "x":51, "y":16},
{"matrix": [1,4], "flags":4, "x":68, "y":16},
{"matrix": [1,5], "flags":4, "x":85, "y":16},
{"matrix": [1,6], "flags":4, "x":102, "y":16},
{"matrix": [1,7], "flags":4, "x":119, "y":16},
{"matrix": [1,8], "flags":4, "x":136, "y":16},
{"matrix": [1,9], "flags":4, "x":153, "y":16},
{"matrix": [1,10], "flags":4, "x":170, "y":16},
{"matrix": [1,11], "flags":4, "x":187, "y":16},
{"matrix": [1,12], "flags":4, "x":204, "y":16},
{"matrix": [1,13], "flags":4, "x":221, "y":16},
{"matrix": [2,0], "flags":4, "x":3, "y":32},
{"matrix": [2,2], "flags":4, "x":23, "y":32},
{"matrix": [2,3], "flags":4, "x":40, "y":32},
{"matrix": [2,4], "flags":4, "x":57, "y":32},
{"matrix": [2,5], "flags":4, "x":74, "y":32},
{"matrix": [2,6], "flags":4, "x":91, "y":32},
{"matrix": [2,7], "flags":4, "x":108, "y":32},
{"matrix": [2,8], "flags":4, "x":125, "y":32},
{"matrix": [2,9], "flags":4, "x":142, "y":32},
{"matrix": [2,10], "flags":4, "x":159, "y":32},
{"matrix": [2,12], "flags":4, "x":176, "y":32},
{"matrix": [2,13], "flags":4, "x":200, "y":32},
{"matrix": [3,0], "flags":4, "x":6, "y":48},
{"matrix": [3,3], "flags":4, "x":31, "y":48},
{"matrix": [3,4], "flags":4, "x":50, "y":48},
{"matrix": [3,5], "flags":4, "x":69, "y":48},
{"matrix": [3,6], "flags":4, "x":88, "y":48},
{"matrix": [3,7], "flags":4, "x":107, "y":48},
{"matrix": [3,8], "flags":4, "x":126, "y":48},
{"matrix": [3,9], "flags":4, "x":145, "y":48},
{"matrix": [3,10], "flags":4, "x":180, "y":48},
{"matrix": [3,13], "flags":4, "x":215, "y":48},
{"matrix": [4,0], "flags":4, "x":22, "y":64},
{"matrix": [4,3], "flags":4, "x":43, "y":64},
{"matrix": [4,4], "flags":4, "x":64, "y":64},
{"matrix": [4,5], "flags":4, "x":95, "y":64},
{"matrix": [4,6], "flags":4, "x":116, "y":64},
{"matrix": [4,7], "flags":4, "x":137, "y":64},
{"matrix": [4,9], "flags":4, "x":158, "y":64},
{"matrix": [4,12], "flags":4, "x":179, "y":64},
{"matrix": [4,13], "flags":4, "x":221, "y":64}
],
"sleep": true
}
}

View File

@ -0,0 +1,63 @@
#include QMK_KEYBOARD_H
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// ┏━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┓
// ┃ ESC ┃ 1 ┃ 2 ┃ 3 ┃ 4 ┃ 5 ┃ 6 ┃ 7 ┃ 8 ┃ 9 ┃ 0 ┃ -_ ┃ += ┃ `~ ┃
// ┣━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┫
// ┃ TAB ┃ Q ┃ W ┃ E ┃ R ┃ T ┃ Y ┃ U ┃ I ┃ O ┃ P ┃ [{ ┃ ]} ┃ :; ┃
// ┗━━━┳━━━┻━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┻━━━┳━━━┛
// ┃ CAPSLOCK ┃ A ┃ S ┃ D ┃ F ┃ G ┃ H ┃ J ┃ K ┃ L ┃ '" ┃ ENTER ┃
// ┗━━━┳━━━━━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━━━━━┻━┳━━━━━┻━━━━━━━┳━━━┛
// ┃ SHIFT ┃ Z ┃ X ┃ C ┃ V ┃ B ┃ N ┃ M ┃ MOUSE1 ┃ MOUSE2 ┃
// ┗━━━┳━━━━━━━┻┳━━━━━━┻━┳━━━━━┻━━┳━━━━┻━━━┳━━━┻━━━━┳━━┻━━━━━┳━┻━━━━━━┳┻━━━━━━━━━━━━━┻┳━━━━━━━━┳━━━┛
// ┃ CTRL ┃ LGUI ┃ LALT ┃ ,< ┃ .> ┃ /? ┃ Fn ┃ SPC ┃ BACK ┃
// ┗━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━┛
// ┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
// ┃ MOUSE3 ┃ → ┃ ↓ ┃ ← ┃ ↑ ┃
// ┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
[0] = LAYOUT(
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINUS, KC_EQUAL, KC_GRAVE,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LEFT_BRACKET, KC_RIGHT_BRACKET, KC_SEMICOLON,
KC_CAPS_LOCK, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_QUOTE, KC_ENTER,
KC_LEFT_SHIFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, QK_MOUSE_BUTTON_1, QK_MOUSE_BUTTON_2,
KC_LEFT_CTRL, KC_LEFT_GUI, KC_LEFT_ALT, KC_COMMA, KC_DOT, KC_SLASH, MO(1), KC_SPC, KC_BACKSPACE,
QK_MOUSE_BUTTON_3, KC_RIGHT, KC_DOWN, KC_LEFT, KC_UP
),
// ┏━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┓
// ┃ ┃ F1 ┃ F2 ┃ F3 ┃ F4 ┃ F5 ┃ F6 ┃ F7 ┃ F8 ┃ F9 ┃ F10 ┃ F11 ┃ F12 ┃ ┃
// ┣━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┫
// ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃RM_HUED┃RM_HUEU┃ ┃ ┃ ┃ ┃
// ┗━━━┳━━━┻━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┻━━━┳━━━┛
// ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃RM_SATD┃RM_SATU┃ ┃ ┃ ┃
// ┗━━━┳━━━━━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━━━━━┻━┳━━━━━┻━━━━━━━┳━━━┛
// ┃ ┃ ┃ ┃ ┃ ┃ ┃RM_SPDD┃RM_SPDU┃ MOUSE1 ┃ MOUSE2 ┃
// ┗━━━┳━━━━━━━┻┳━━━━━━┻━┳━━━━━┻━━┳━━━━┻━━━┳━━━┻━━━━┳━━┻━━━━━┳━┻━━━━━━┳┻━━━━━━━━━━━━━┻┳━━━━━━━━┳━━━┛
// ┃ ┃ ┃ ┃ ┃ ┃ \| ┃ ┃ RM_TOGG ┃ DEL ┃
// ┗━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━┛
// ┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
// ┃ MOUSE3 ┃ RM_PREV ┃ RM_VALD ┃ RM_NEXT ┃ RM_VALU ┃
// ┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
[1] = LAYOUT(
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,
_______, _______, _______, _______, _______, _______, _______, _______, RM_HUED, RM_HUEU, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, RM_SATD, RM_SATU, _______, _______, _______,
_______, _______, _______, _______, _______, _______, RM_SPDD, RM_SPDU, QK_MOUSE_BUTTON_1, QK_MOUSE_BUTTON_2,
_______, _______, _______, _______, _______, KC_BSLS, _______, RM_TOGG, KC_DEL,
QK_MOUSE_BUTTON_3, RM_PREV, RM_VALD, RM_NEXT, RM_VALU
),
};
#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[0] = {ENCODER_CCW_CW(MS_WHLU, MS_WHLD)},
[1] = {ENCODER_CCW_CW(MS_WHLD, MS_WHLU)}
};
#endif

View File

@ -0,0 +1,8 @@
VIA_ENABLE = yes
POINTING_DEVICE_DRIVER = custom
SRC += adns.c
SPI_DRIVER_REQUIRED = yes
ENCODER_MAP_ENABLE = yes
RGB_MATRIX_ENABLE = yes
WS2812_DRIVER = pwm

View File

@ -0,0 +1,26 @@
/* Copyright 2020 QMK
*
* 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
#include_next <mcuconf.h>
#undef STM32_SPI_USE_SPI1
#define STM32_SPI_USE_SPI1 TRUE
/* enable TIM3, used for RGB LED PWM driver */
#undef STM32_PWM_USE_TIM3
#define STM32_PWM_USE_TIM3 TRUE

View File

@ -0,0 +1,29 @@
# One-Handed_Keyboard_ML
![左手大键盘](https://imgur.com/QjQSxhP.jpg)
This is a keyboard with a fan-shaped layout and 59 keys.The commonly used buttons are placed near the thumb.
* Keyboard Maintainer[HTX Studio](https://github.com/htx-studio)
* Hardware SupportedHTX_STUDIO_ONE-HANDEN_KEYBOARD_ML PCB
* Hardware Availability[One-Handed-Keyboard](https://github.com/htx-studio/One-Handed-Keyboard/tree/main/Hardware)
## How to compile
Make example for this keyboard (after setting up your build environment):
`make htx_studio/one_handed_keyboard_ml:default`
Flashing example for this keyboard:
`make htx_studio/one_handed_keyboard_ml:default:flash`
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).
## Bootloader
Enter the bootloader in 3 ways:
* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard
* **Physical reset button**: Hold the "B" button on the back of the PCB (the one closest to the MCU) and briefly press the "R" button on the back of the PCB
* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available

View File

@ -0,0 +1,254 @@
/* Copyright 2020 Richard Sutherland <rich@brickbots.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "spi_master.h"
#include "adns.h"
#include "debug.h"
#include "wait.h"
#include "pointing_device.h"
#include "adns9800_srom_A6.h"
// registers
#define REG_Product_ID 0x00
#define REG_Revision_ID 0x01
#define REG_Motion 0x02
#define REG_Delta_X_L 0x03
#define REG_Delta_X_H 0x04
#define REG_Delta_Y_L 0x05
#define REG_Delta_Y_H 0x06
#define REG_SQUAL 0x07
#define REG_Pixel_Sum 0x08
#define REG_Maximum_Pixel 0x09
#define REG_Minimum_Pixel 0x0a
#define REG_Shutter_Lower 0x0b
#define REG_Shutter_Upper 0x0c
#define REG_Frame_Period_Lower 0x0d
#define REG_Frame_Period_Upper 0x0e
#define REG_Configuration_I 0x0f
#define REG_Configuration_II 0x10
#define REG_Frame_Capture 0x12
#define REG_SROM_Enable 0x13
#define REG_Run_Downshift 0x14
#define REG_Rest1_Rate 0x15
#define REG_Rest1_Downshift 0x16
#define REG_Rest2_Rate 0x17
#define REG_Rest2_Downshift 0x18
#define REG_Rest3_Rate 0x19
#define REG_Frame_Period_Max_Bound_Lower 0x1a
#define REG_Frame_Period_Max_Bound_Upper 0x1b
#define REG_Frame_Period_Min_Bound_Lower 0x1c
#define REG_Frame_Period_Min_Bound_Upper 0x1d
#define REG_Shutter_Max_Bound_Lower 0x1e
#define REG_Shutter_Max_Bound_Upper 0x1f
#define REG_LASER_CTRL0 0x20
#define REG_Observation 0x24
#define REG_Data_Out_Lower 0x25
#define REG_Data_Out_Upper 0x26
#define REG_SROM_ID 0x2a
#define REG_Lift_Detection_Thr 0x2e
#define REG_Configuration_V 0x2f
#define REG_Configuration_IV 0x39
#define REG_Power_Up_Reset 0x3a
#define REG_Shutdown 0x3b
#define REG_Inverse_Product_ID 0x3f
#define REG_Motion_Burst 0x50
#define REG_SROM_Load_Burst 0x62
#define REG_Pixel_Burst 0x64
// pins
#define NCS A4
extern const uint16_t firmware_length;
extern const uint8_t firmware_data[];
enum motion_burst_propertr{
motion = 0,
observation,
delta_x_l,
delta_x_h,
delta_y_l,
delta_y_h,
squal,
pixel_sum,
maximum_pixel,
minimum_pixel,
shutter_upper,
shutter_lower,
frame_period_upper,
frame_period_lower,
end_data
};
void adns_begin(void){
spi_start(NCS, false, 3, 8);
}
void adns_end(void){
spi_stop();
}
void adns_write(uint8_t reg_addr, uint8_t data){
adns_begin();
//send address of the register, with MSBit = 1 to indicate it's a write
spi_write(reg_addr | 0x80 );
spi_write(data);
// tSCLK-NCS for write operation
wait_us(20);
// tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
wait_us(100);
adns_end();
}
uint8_t adns_read(uint8_t reg_addr){
adns_begin();
// send adress of the register, with MSBit = 0 to indicate it's a read
spi_write(reg_addr & 0x7f );
uint8_t data = spi_read();
// tSCLK-NCS for read operation is 120ns
wait_us(1);
// tSRW/tSRR (=20us) minus tSCLK-NCS
wait_us(19);
adns_end();
return data;
}
void pointing_device_init(void) {
dprint("STARTING INTI\n");
spi_init();
// reset serial port
adns_begin();
adns_end();
// reboot
adns_write(REG_Power_Up_Reset, 0x5a);
wait_ms(50);
// read registers and discard
adns_read(REG_Motion);
adns_read(REG_Delta_X_L);
adns_read(REG_Delta_X_H);
adns_read(REG_Delta_Y_L);
adns_read(REG_Delta_Y_H);
// upload firmware
// set the configuration_IV register in 3k firmware mode
// bit 1 = 1 for 3k mode, other bits are reserved
adns_write(REG_Configuration_V, 0x02);
// write 0x1d in SROM_enable reg for initializing
adns_write(REG_SROM_Enable, 0x1d);
// wait for more than one frame period
// assume that the frame rate is as low as 100fps... even if it should never be that low
wait_ms(10);
// write 0x18 to SROM_enable to start SROM download
adns_write(REG_SROM_Enable, 0x18);
// write the SROM file (=firmware data)
// write burst destination adress
adns_begin();
spi_write(REG_SROM_Load_Burst | 0x80);
wait_us(15);
// send all bytes of the firmware
unsigned char c;
for(int i = 0; i < firmware_length; i++){
c = (unsigned char)pgm_read_byte(firmware_data + i);
spi_write(c);
wait_us(15);
}
adns_end();
wait_ms(10);
// enable laser(bit 0 = 0b), in normal mode (bits 3,2,1 = 000b)
// reading the actual value of the register is important because the real
// default value is different from what is said in the datasheet, and if you
// change the reserved bytes (like by writing 0x00...) it would not work.
uint8_t laser_ctrl0 = adns_read(REG_LASER_CTRL0);
adns_write(REG_LASER_CTRL0, laser_ctrl0 & 0xf0);
wait_ms(1);
// set the configuration_I register to set the CPI
// 0x01 = 50, minimum
// 0x44 = 3400, default
// 0x8e = 7100
// 0xA4 = 8200, maximum
adns_write(REG_Configuration_I, 0x1A);
wait_ms(100);
dprint("INIT ENDED\n");
}
int16_t convertDeltaToInt(uint8_t high, uint8_t low){
// join bytes into twos compliment
//int16_t twos_comp = (high << 8) | low;
//return twos_comp;
return (high << 8) | low;
}
motion_delta_t readSensor(void) {
adns_begin();
// read from Motion_Burst to enable burt mode
spi_write(REG_Motion_Burst & 0x7f);
// Wait one frame per docs, thanks u/kbjunky
wait_us(100);
uint8_t burst_data[pixel_sum];
for (int i = 0; i < pixel_sum; ++i) {
burst_data[i] = spi_read();
}
uint16_t delta_x = convertDeltaToInt(burst_data[delta_x_h], burst_data[delta_x_l]);
uint16_t delta_y = convertDeltaToInt(burst_data[delta_y_h], burst_data[delta_y_l]);
// Only consider the MSB for motion as this byte has other status bits
uint8_t motion_ind = burst_data[motion] & 0b10000000;
adns_end();
motion_delta_t delta = {delta_x, delta_y, motion_ind};
return delta;
}
bool pointing_device_task(void) {
motion_delta_t delta = readSensor();
report_mouse_t report = pointing_device_get_report();
if(delta.motion_ind) {
// clamp deltas from -127 to 127
report.x = delta.delta_x < -127 ? -127 : delta.delta_x > 127 ? 127 : delta.delta_x;
report.x = -report.x;
report.y = delta.delta_y < -127 ? -127 : delta.delta_y > 127 ? 127 : delta.delta_y;
}
pointing_device_set_report(report);
return pointing_device_send();
}

View File

@ -0,0 +1,38 @@
/* Copyright 2020 Richard Sutherland <rich@brickbots.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
void adns_begin(void);
void adns_end(void);
void adns_write(uint8_t reg_addr, uint8_t data);
uint8_t adns_read(uint8_t reg_addr);
int16_t convertDeltaToInt(uint8_t high, uint8_t low);
struct _motion_delta {
int16_t delta_x;
int16_t delta_y;
int8_t motion_ind;
};
typedef struct _motion_delta motion_delta_t;
motion_delta_t readSensor(void);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
#pragma once
#define SPI_DRIVER SPID1
#define SPI_SCK_PIN A5
#define SPI_MISO_PIN A6
#define SPI_MOSI_PIN A7
#define POINTING_DEVICE_CS_PIN A4
#define POINTING_DEVICE_MOTION_PIN A3
#define POINTING_DEVICE_TASK_THROTTLE_MS 1
#define ENCODER_RESOLUTION 2
#ifdef RGB_MATRIX_ENABLE
#define WS2812_BITBANG_NOP_FUDGE 0
#define WS2812_PWM_DRIVER PWMD3
#define WS2812_PWM_CHANNEL 1
#define WS2812_DMA_STREAM STM32_DMA1_STREAM1
#define WS2812_DMA_CHANNEL 1
#define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM3_UP
#endif

View File

@ -0,0 +1,25 @@
/* Copyright 2020 QMK
*
* 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 HAL_USE_PWM TRUE
#define HAL_USE_SPI TRUE
#define SPI_USE_WAIT TRUE
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
#include_next <halconf.h>

View File

@ -0,0 +1,232 @@
{
"keyboard_name": "One-Handed_Keyboard_MR",
"manufacturer": "HTXStudio",
"url": "https://github.com/htx-studio",
"maintainer": "HTXStudio",
"usb": {
"vid": "0x475D",
"pid": "0x03BF",
"device_version": "3.1.0"
},
"processor": "STM32G431",
"bootloader": "stm32-dfu",
"diode_direction": "ROW2COL",
"matrix": {
"rows": 6,
"cols": 14
},
"features": {
"bootmagic": true,
"extrakey": true,
"mousekey": true,
"nkro": true,
"pointing_device": true,
"encoder": true,
"rgb_matrix": true
},
"matrix_pins": {
"cols": ["A0", "A1", "A2", "C4", "B0", "B1", "B2", "B7", "B5", "B3", "B10", "C11", "C10", "A15"],
"rows": ["B12", "B15", "C6", "B13", "B14", "A8"]
},
"encoder": {
"rotary": [
{"pin_a": "A9", "pin_b": "A10"}
]
},
"ws2812": {
"pin": "B4",
"driver": "pwm"
},
"layouts": {
"LAYOUT": {
"layout": [
{"matrix": [0, 0], "w":1, "h":1, "x":0, "y":0},
{"matrix": [0, 1], "w":1, "h":1, "x":1, "y":0},
{"matrix": [0, 2], "w":1, "h":1, "x":2, "y":0},
{"matrix": [0, 3], "w":1, "h":1, "x":3, "y":0},
{"matrix": [0, 4], "w":1, "h":1, "x":4, "y":0},
{"matrix": [0, 5], "w":1, "h":1, "x":5, "y":0},
{"matrix": [0, 6], "w":1, "h":1, "x":6, "y":0},
{"matrix": [0, 7], "w":1, "h":1, "x":7, "y":0},
{"matrix": [0, 8], "w":1, "h":1, "x":8, "y":0},
{"matrix": [0, 9], "w":1, "h":1, "x":9, "y":0},
{"matrix": [0, 10], "w":1, "h":1, "x":10, "y":0},
{"matrix": [0, 11], "w":1, "h":1, "x":11, "y":0},
{"matrix": [0, 12], "w":1, "h":1, "x":12, "y":0},
{"matrix": [0, 13], "w":1, "h":1, "x":13, "y":0},
{"matrix": [1, 0], "w":1, "h":1, "x":0, "y":1},
{"matrix": [1, 1], "w":1, "h":1, "x":1, "y":1},
{"matrix": [1, 2], "w":1, "h":1, "x":2, "y":1},
{"matrix": [1, 3], "w":1, "h":1, "x":3, "y":1},
{"matrix": [1, 4], "w":1, "h":1, "x":4, "y":1},
{"matrix": [1, 5], "w":1, "h":1, "x":5, "y":1},
{"matrix": [1, 6], "w":1, "h":1, "x":6, "y":1},
{"matrix": [1, 7], "w":1, "h":1, "x":7, "y":1},
{"matrix": [1, 8], "w":1, "h":1, "x":8, "y":1},
{"matrix": [1, 9], "w":1, "h":1, "x":9, "y":1},
{"matrix": [1, 10], "w":1, "h":1, "x":10, "y":1},
{"matrix": [1, 11], "w":1, "h":1, "x":11, "y":1},
{"matrix": [1, 12], "w":1, "h":1, "x":12, "y":1},
{"matrix": [1, 13], "w":1, "h":1, "x":13, "y":1},
{"matrix": [2, 0], "w":1.5, "h":1, "x":0.5, "y":2},
{"matrix": [2, 1], "w":1, "h":1, "x":2, "y":2},
{"matrix": [2, 2], "w":1, "h":1, "x":3, "y":2},
{"matrix": [2, 3], "w":1, "h":1, "x":4, "y":2},
{"matrix": [2, 5], "w":1, "h":1, "x":5, "y":2},
{"matrix": [2, 6], "w":1, "h":1, "x":6, "y":2},
{"matrix": [2, 7], "w":1, "h":1, "x":7, "y":2},
{"matrix": [2, 8], "w":1, "h":1, "x":8, "y":2},
{"matrix": [2, 9], "w":1, "h":1, "x":9, "y":2},
{"matrix": [2, 10], "w":1, "h":1, "x":10, "y":2},
{"matrix": [2, 11], "w":1.5, "h":1, "x":11, "y":2},
{"matrix": [2, 13], "w":1, "h":1, "x":12.5, "y":2},
{"matrix": [3, 0], "w":2, "h":1, "x":1, "y":3},
{"matrix": [3, 2], "w":1, "h":1, "x":3, "y":3},
{"matrix": [3, 3], "w":1, "h":1, "x":4, "y":3},
{"matrix": [3, 5], "w":1, "h":1, "x":5, "y":3},
{"matrix": [3, 6], "w":1, "h":1, "x":6, "y":3},
{"matrix": [3, 7], "w":1, "h":1, "x":7, "y":3},
{"matrix": [3, 9], "w":1, "h":1, "x":8, "y":3},
{"matrix": [3, 10], "w":1, "h":1, "x":9, "y":3},
{"matrix": [3, 11], "w":2, "h":1, "x":10, "y":3},
{"matrix": [3, 13], "w":2, "h":1, "x":12, "y":3},
{"matrix": [4, 0], "w":1.25, "h":1, "x":1.25, "y":4},
{"matrix": [4, 2], "w":1.25, "h":1, "x":2.5, "y":4},
{"matrix": [4, 3], "w":1.25, "h":1, "x":3.75, "y":4},
{"matrix": [4, 5], "w":1.25, "h":1, "x":5, "y":4},
{"matrix": [4, 7], "w":1.25, "h":1, "x":6.25, "y":4},
{"matrix": [4, 9], "w":1.25, "h":1, "x":7.5, "y":4},
{"matrix": [4, 10], "w":1.25, "h":1, "x":8.75, "y":4},
{"matrix": [4, 12], "w":2, "h":1, "x":10.75, "y":4},
{"matrix": [4, 13], "w":1.25, "h":1, "x":12, "y":4},
{"matrix": [5, 0], "w":1, "h":1, "x":0, "y":5},
{"matrix": [5, 3], "w":1, "h":1, "x":3, "y":5},
{"matrix": [5, 4], "w":1, "h":1, "x":4, "y":5},
{"matrix": [5, 5], "w":1, "h":1, "x":5, "y":5},
{"matrix": [5, 6], "w":1, "h":1, "x":6, "y":5}
]
}
},
"rgb_matrix": {
"driver": "ws2812",
"max_brightness": 110,
"animations": {
"alphas_mods": true,
"gradient_up_down": true,
"gradient_left_right": true,
"breathing": true,
"band_sat": true,
"band_val": true,
"band_pinwheel_sat": true,
"band_pinwheel_val": true,
"band_spiral_sat": true,
"band_spiral_val": true,
"cycle_all": true,
"cycle_left_right": true,
"cycle_up_down": true,
"cycle_out_in": true,
"cycle_out_in_dual": true,
"rainbow_moving_chevron": true,
"cycle_pinwheel": true,
"cycle_spiral": true,
"dual_beacon": true,
"rainbow_beacon": true,
"rainbow_pinwheels": true,
"raindrops": true,
"jellybean_raindrops": true,
"hue_breathing": true,
"hue_pendulum": true,
"hue_wave": true,
"pixel_fractal": true,
"pixel_flow": true,
"pixel_rain": true,
"typing_heatmap": true,
"digital_rain": true,
"solid_reactive_simple": true,
"solid_reactive": true,
"solid_reactive_wide": true,
"solid_reactive_multiwide": true,
"solid_reactive_cross": true,
"solid_reactive_multicross": true,
"solid_reactive_nexus": true,
"solid_reactive_multinexus": true,
"splash": true,
"multisplash": true,
"solid_splash": true,
"solid_multisplash": true
},
"layout": [
{"matrix": [0,0], "flags":4, "x":0, "y":0},
{"matrix": [0,1], "flags":4, "x":17, "y":0},
{"matrix": [0,2], "flags":4, "x":34, "y":0},
{"matrix": [0,3], "flags":4, "x":51, "y":0},
{"matrix": [0,4], "flags":4, "x":68, "y":0},
{"matrix": [0,5], "flags":4, "x":85, "y":0},
{"matrix": [0,6], "flags":4, "x":102, "y":0},
{"matrix": [0,7], "flags":4, "x":119, "y":0},
{"matrix": [0,8], "flags":4, "x":136, "y":0},
{"matrix": [0,9], "flags":4, "x":153, "y":0},
{"matrix": [0,10], "flags":4, "x":170, "y":0},
{"matrix": [0,11], "flags":4, "x":187, "y":0},
{"matrix": [0,12], "flags":4, "x":204, "y":0},
{"matrix": [0,13], "flags":4, "x":221, "y":0},
{"matrix": [1,0], "flags":4, "x":0, "y":16},
{"matrix": [1,1], "flags":4, "x":17, "y":16},
{"matrix": [1,2], "flags":4, "x":34, "y":16},
{"matrix": [1,3], "flags":4, "x":51, "y":16},
{"matrix": [1,4], "flags":4, "x":68, "y":16},
{"matrix": [1,5], "flags":4, "x":85, "y":16},
{"matrix": [1,6], "flags":4, "x":102, "y":16},
{"matrix": [1,7], "flags":4, "x":119, "y":16},
{"matrix": [1,8], "flags":4, "x":136, "y":16},
{"matrix": [1,9], "flags":4, "x":153, "y":16},
{"matrix": [1,10], "flags":4, "x":170, "y":16},
{"matrix": [1,11], "flags":4, "x":187, "y":16},
{"matrix": [1,12], "flags":4, "x":204, "y":16},
{"matrix": [1,13], "flags":4, "x":221, "y":16},
{"matrix": [2,0], "flags":4, "x":3, "y":32},
{"matrix": [2,1], "flags":4, "x":23, "y":32},
{"matrix": [2,2], "flags":4, "x":40, "y":32},
{"matrix": [2,3], "flags":4, "x":57, "y":32},
{"matrix": [2,5], "flags":4, "x":74, "y":32},
{"matrix": [2,6], "flags":4, "x":91, "y":32},
{"matrix": [2,7], "flags":4, "x":108, "y":32},
{"matrix": [2,8], "flags":4, "x":125, "y":32},
{"matrix": [2,9], "flags":4, "x":142, "y":32},
{"matrix": [2,10], "flags":4, "x":159, "y":32},
{"matrix": [2,11], "flags":4, "x":176, "y":32},
{"matrix": [2,13], "flags":4, "x":200, "y":32},
{"matrix": [3,0], "flags":4, "x":21, "y":48},
{"matrix": [3,2], "flags":4, "x":42, "y":48},
{"matrix": [3,3], "flags":4, "x":62, "y":48},
{"matrix": [3,5], "flags":4, "x":81, "y":48},
{"matrix": [3,6], "flags":4, "x":100, "y":48},
{"matrix": [3,7], "flags":4, "x":119, "y":48},
{"matrix": [3,9], "flags":4, "x":138, "y":48},
{"matrix": [3,10], "flags":4, "x":157, "y":48},
{"matrix": [3,11], "flags":4, "x":176, "y":48},
{"matrix": [3,13], "flags":4, "x":200, "y":48},
{"matrix": [4,0], "flags":4, "x":24, "y":64},
{"matrix": [4,2], "flags":4, "x":64, "y":64},
{"matrix": [4,3], "flags":4, "x":95, "y":64},
{"matrix": [4,5], "flags":4, "x":116, "y":64},
{"matrix": [4,7], "flags":4, "x":137, "y":64},
{"matrix": [4,9], "flags":4, "x":158, "y":64},
{"matrix": [4,10], "flags":4, "x":179, "y":64},
{"matrix": [4,12], "flags":4, "x":200, "y":64},
{"matrix": [4,13], "flags":4, "x":221, "y":64}
],
"sleep": true
}
}

View File

@ -0,0 +1,59 @@
#include QMK_KEYBOARD_H
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// ┏━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┓
// ┃ ESC ┃ `~ ┃ 1 ┃ 2 ┃ 3 ┃ 4 ┃ 5 ┃ 6 ┃ 7 ┃ 8 ┃ 9 ┃ 0 ┃ - ┃ + ┃
// ┣━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┫
// ┃ TAB ┃ ;: ┃ Q ┃ W ┃ E ┃ R ┃ T ┃ Y ┃ U ┃ I ┃ O ┃ P ┃ [ ┃ ] ┃
// ┗━━━┳━━━┻━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┻━━━┳━━━┛
// ┃ CAPSLOCK ┃ '" ┃ A ┃ S ┃ D ┃ F ┃ G ┃ H ┃ J ┃ K ┃ L ┃ ENTER ┃
// ┗━━━┳━━━━━━━┻━━┳━━━━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━━━┻━━━━━━━┳━━━┛
// ┃ MOUSE1 ┃ MOUSE2 ┃ Z ┃ X ┃ C ┃ V ┃ B ┃ N ┃ M ┃ SHIFT ┃
// ┗━━━┳━━━━━━┻━┳━━━━━━━━┻━━━━━━┳┻━━━━━━━╋━━━━━━━┻┳━━━━━━┻━┳━━━━━┻━━┳━━━━┻━━━┳━━━┻━━━━┳━━━━━━━━┳━━━┛
// ┃ BSPC ┃ SPC ┃ MO(1) ┃ <, ┃ >. ┃ ?/ ┃ LGUI ┃ LALT ┃ CTRL ┃
// ┗━━━━━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┛
// ┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
// ┃ MOUSE3 ┃ → ┃ ↓ ┃ ← ┃ ↑ ┃
// ┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
[0] = LAYOUT(
KC_ESC, KC_GRAVE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINUS, KC_EQUAL,
KC_TAB, KC_SEMICOLON, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LEFT_BRACKET, KC_RIGHT_BRACKET,
KC_CAPS_LOCK, KC_QUOTE, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_ENTER,
QK_MOUSE_BUTTON_1, QK_MOUSE_BUTTON_2, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_LEFT_SHIFT,
KC_BSPC, KC_SPC, MO(1), KC_COMMA, KC_DOT, KC_SLASH, KC_LEFT_GUI, KC_LEFT_ALT, KC_LEFT_CTRL,
QK_MOUSE_BUTTON_3, KC_RIGHT, KC_DOWN, KC_LEFT, KC_UP
),
// ┏━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┓
// ┃ ┃ ┃ F1 ┃ F2 ┃ F3 ┃ F4 ┃ F5 ┃ F6 ┃ F7 ┃ F8 ┃ F9 ┃ F10 ┃ F11 ┃ F12 ┃
// ┣━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┫
// ┃ ┃ ┃ ┃RM_HUEU┃RM_HUED┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃
// ┗━━━┳━━━┻━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┻━━━┳━━━┛
// ┃ ┃ ┃ ┃RM_SATU┃RM_SATD┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃
// ┗━━━┳━━━━━━━┻━━┳━━━━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━┳━┻━━━━━━━┻━━━━━━━┳━━━┛
// ┃ MOUSE1 ┃ MOUSE2 ┃RM_SPDU┃RM_SPDD┃ ┃ ┃ ┃ ┃ ┃ ┃
// ┗━━━┳━━━━━━┻━┳━━━━━━━━┻━━━━━━┳┻━━━━━━━╋━━━━━━━┻┳━━━━━━┻━┳━━━━━┻━━┳━━━━┻━━━┳━━━┻━━━━┳━━━━━━━━┳━━━┛
// ┃ DEL ┃ RM_TOGG ┃ ┃ ┃ ┃ \| ┃ ┃ ┃ ┃
// ┗━━━━━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┛
// ┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
// ┃ MOUSE3 ┃ RM_PREV ┃ RM_VALD ┃ RM_NEXT ┃ RM_VALU ┃
// ┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
[1] = LAYOUT(
_______, _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
_______, _______, _______, RM_HUEU, RM_HUED, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, RM_SATU, RM_SATD, _______, _______, _______, _______, _______, _______, _______,
QK_MOUSE_BUTTON_1, QK_MOUSE_BUTTON_2, RM_SPDU, RM_SPDD, _______, _______, _______, _______, _______, _______,
KC_DEL, RM_TOGG, _______, _______, _______, KC_BSLS, _______, _______, _______,
QK_MOUSE_BUTTON_3, RM_PREV, RM_VALD, RM_NEXT, RM_VALU
),
};
#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[0] = {ENCODER_CCW_CW(MS_WHLD, MS_WHLU)},
[1] = {ENCODER_CCW_CW(MS_WHLU, MS_WHLD)}
};
#endif

View File

@ -0,0 +1,8 @@
VIA_ENABLE = yes
POINTING_DEVICE_DRIVER = custom
SRC += adns.c
SPI_DRIVER_REQUIRED = yes
ENCODER_MAP_ENABLE = yes
RGB_MATRIX_ENABLE = yes
WS2812_DRIVER = pwm

View File

@ -0,0 +1,27 @@
/* Copyright 2020 QMK
*
* 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
#include_next <mcuconf.h>
#undef STM32_SPI_USE_SPI1
#define STM32_SPI_USE_SPI1 TRUE
/* enable TIM3, used for RGB LED PWM driver */
#undef STM32_PWM_USE_TIM3
#define STM32_PWM_USE_TIM3 TRUE

View File

@ -0,0 +1,29 @@
# One-Handed_Keyboard_MR
![右手大键盘](https://imgur.com/y5O0E2E.jpg)
This is a keyboard with a fan-shaped layout and 59 keys.The commonly used buttons are placed near the thumb.
* Keyboard Maintainer[HTX Studio](https://github.com/htx-studio)
* Hardware SupportedHTX_STUDIO_ONE-HANDEN_KEYBOARD_MR PCB
* Hardware Availability[One-Handed-Keyboard](https://github.com/htx-studio/One-Handed-Keyboard/tree/main/Hardware)
## How to compile
Make example for this keyboard (after setting up your build environment):
`make htx_studio/one_handed_keyboard_mr:default`
Flashing example for this keyboard:
`make htx_studio/one_handed_keyboard_mr:default:flash`
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).
## Bootloader
Enter the bootloader in 3 ways:
* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard
* **Physical reset button**: Hold the "B" button on the back of the PCB (the one closest to the MCU) and briefly press the "R" button on the back of the PCB
* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available

View File

@ -0,0 +1,254 @@
/* Copyright 2020 Richard Sutherland <rich@brickbots.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "spi_master.h"
#include "adns.h"
#include "debug.h"
#include "wait.h"
#include "pointing_device.h"
#include "adns9800_srom_A6.h"
// registers
#define REG_Product_ID 0x00
#define REG_Revision_ID 0x01
#define REG_Motion 0x02
#define REG_Delta_X_L 0x03
#define REG_Delta_X_H 0x04
#define REG_Delta_Y_L 0x05
#define REG_Delta_Y_H 0x06
#define REG_SQUAL 0x07
#define REG_Pixel_Sum 0x08
#define REG_Maximum_Pixel 0x09
#define REG_Minimum_Pixel 0x0a
#define REG_Shutter_Lower 0x0b
#define REG_Shutter_Upper 0x0c
#define REG_Frame_Period_Lower 0x0d
#define REG_Frame_Period_Upper 0x0e
#define REG_Configuration_I 0x0f
#define REG_Configuration_II 0x10
#define REG_Frame_Capture 0x12
#define REG_SROM_Enable 0x13
#define REG_Run_Downshift 0x14
#define REG_Rest1_Rate 0x15
#define REG_Rest1_Downshift 0x16
#define REG_Rest2_Rate 0x17
#define REG_Rest2_Downshift 0x18
#define REG_Rest3_Rate 0x19
#define REG_Frame_Period_Max_Bound_Lower 0x1a
#define REG_Frame_Period_Max_Bound_Upper 0x1b
#define REG_Frame_Period_Min_Bound_Lower 0x1c
#define REG_Frame_Period_Min_Bound_Upper 0x1d
#define REG_Shutter_Max_Bound_Lower 0x1e
#define REG_Shutter_Max_Bound_Upper 0x1f
#define REG_LASER_CTRL0 0x20
#define REG_Observation 0x24
#define REG_Data_Out_Lower 0x25
#define REG_Data_Out_Upper 0x26
#define REG_SROM_ID 0x2a
#define REG_Lift_Detection_Thr 0x2e
#define REG_Configuration_V 0x2f
#define REG_Configuration_IV 0x39
#define REG_Power_Up_Reset 0x3a
#define REG_Shutdown 0x3b
#define REG_Inverse_Product_ID 0x3f
#define REG_Motion_Burst 0x50
#define REG_SROM_Load_Burst 0x62
#define REG_Pixel_Burst 0x64
// pins
#define NCS A4
extern const uint16_t firmware_length;
extern const uint8_t firmware_data[];
enum motion_burst_propertr{
motion = 0,
observation,
delta_x_l,
delta_x_h,
delta_y_l,
delta_y_h,
squal,
pixel_sum,
maximum_pixel,
minimum_pixel,
shutter_upper,
shutter_lower,
frame_period_upper,
frame_period_lower,
end_data
};
void adns_begin(void){
spi_start(NCS, false, 3, 8);
}
void adns_end(void){
spi_stop();
}
void adns_write(uint8_t reg_addr, uint8_t data){
adns_begin();
//send address of the register, with MSBit = 1 to indicate it's a write
spi_write(reg_addr | 0x80 );
spi_write(data);
// tSCLK-NCS for write operation
wait_us(20);
// tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
wait_us(100);
adns_end();
}
uint8_t adns_read(uint8_t reg_addr){
adns_begin();
// send adress of the register, with MSBit = 0 to indicate it's a read
spi_write(reg_addr & 0x7f );
uint8_t data = spi_read();
// tSCLK-NCS for read operation is 120ns
wait_us(1);
// tSRW/tSRR (=20us) minus tSCLK-NCS
wait_us(19);
adns_end();
return data;
}
void pointing_device_init(void) {
dprint("STARTING INTI\n");
spi_init();
// reset serial port
adns_begin();
adns_end();
// reboot
adns_write(REG_Power_Up_Reset, 0x5a);
wait_ms(50);
// read registers and discard
adns_read(REG_Motion);
adns_read(REG_Delta_X_L);
adns_read(REG_Delta_X_H);
adns_read(REG_Delta_Y_L);
adns_read(REG_Delta_Y_H);
// upload firmware
// set the configuration_IV register in 3k firmware mode
// bit 1 = 1 for 3k mode, other bits are reserved
adns_write(REG_Configuration_IV, 0x02);
// write 0x1d in SROM_enable reg for initializing
adns_write(REG_SROM_Enable, 0x1d);
// wait for more than one frame period
// assume that the frame rate is as low as 100fps... even if it should never be that low
wait_ms(10);
// write 0x18 to SROM_enable to start SROM download
adns_write(REG_SROM_Enable, 0x18);
// write the SROM file (=firmware data)
// write burst destination adress
adns_begin();
spi_write(REG_SROM_Load_Burst | 0x80);
wait_us(15);
// send all bytes of the firmware
unsigned char c;
for(int i = 0; i < firmware_length; i++){
c = (unsigned char)pgm_read_byte(firmware_data + i);
spi_write(c);
wait_us(15);
}
adns_end();
wait_ms(10);
// enable laser(bit 0 = 0b), in normal mode (bits 3,2,1 = 000b)
// reading the actual value of the register is important because the real
// default value is different from what is said in the datasheet, and if you
// change the reserved bytes (like by writing 0x00...) it would not work.
uint8_t laser_ctrl0 = adns_read(REG_LASER_CTRL0);
adns_write(REG_LASER_CTRL0, laser_ctrl0 & 0xf0);
wait_ms(1);
// set the configuration_I register to set the CPI
// 0x01 = 50, minimum
// 0x44 = 3400, default
// 0x8e = 7100
// 0xA4 = 8200, maximum
adns_write(REG_Configuration_I, 0x30);
wait_ms(100);
dprint("INIT ENDED\n");
}
int16_t convertDeltaToInt(uint8_t high, uint8_t low){
// join bytes into twos compliment
//int16_t twos_comp = (high << 8) | low;
//return twos_comp;
return (high << 8) | low;
}
motion_delta_t readSensor(void) {
adns_begin();
// read from Motion_Burst to enable burt mode
spi_write(REG_Motion_Burst & 0x7f);
// Wait one frame per docs, thanks u/kbjunky
wait_us(100);
uint8_t burst_data[pixel_sum];
for (int i = 0; i < pixel_sum; ++i) {
burst_data[i] = spi_read();
}
uint16_t delta_x = convertDeltaToInt(burst_data[delta_x_h], burst_data[delta_x_l]);
uint16_t delta_y = convertDeltaToInt(burst_data[delta_y_h], burst_data[delta_y_l]);
// Only consider the MSB for motion as this byte has other status bits
uint8_t motion_ind = burst_data[motion] & 0b10000000;
adns_end();
motion_delta_t delta = {delta_x, delta_y, motion_ind};
return delta;
}
bool pointing_device_task(void) {
motion_delta_t delta = readSensor();
report_mouse_t report = pointing_device_get_report();
if(delta.motion_ind) {
// clamp deltas from -127 to 127
report.x = delta.delta_x < -127 ? -127 : delta.delta_x > 127 ? 127 : delta.delta_x;
report.x = -report.x;
report.y = delta.delta_y < -127 ? -127 : delta.delta_y > 127 ? 127 : delta.delta_y;
}
pointing_device_set_report(report);
return pointing_device_send();
}

View File

@ -0,0 +1,38 @@
/* Copyright 2020 Richard Sutherland <rich@brickbots.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
void adns_begin(void);
void adns_end(void);
void adns_write(uint8_t reg_addr, uint8_t data);
uint8_t adns_read(uint8_t reg_addr);
int16_t convertDeltaToInt(uint8_t high, uint8_t low);
struct _motion_delta {
int16_t delta_x;
int16_t delta_y;
int8_t motion_ind;
};
typedef struct _motion_delta motion_delta_t;
motion_delta_t readSensor(void);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
#pragma once
#define SPI_DRIVER SPID1
#define SPI_SCK_PIN A5
#define SPI_MISO_PIN A6
#define SPI_MOSI_PIN A7
#define POINTING_DEVICE_CS_PIN A4
#define POINTING_DEVICE_MOTION_PIN A3
#define POINTING_DEVICE_TASK_THROTTLE_MS 1
#define ENCODER_RESOLUTION 2

View File

@ -0,0 +1,24 @@
/* Copyright 2020 QMK
*
* 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 HAL_USE_SPI TRUE
#define SPI_USE_WAIT TRUE
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
#include_next <halconf.h>

View File

@ -0,0 +1,112 @@
{
"keyboard_name": "One-Handed_Keyboard_SL",
"manufacturer": "HTXStudio",
"url": "https://github.com/htx-studio",
"maintainer": "HTXStudio",
"usb": {
"vid": "0x475D",
"pid": "0x03BE",
"device_version": "3.1.0"
},
"processor": "STM32G431",
"bootloader": "stm32-dfu",
"diode_direction": "ROW2COL",
"matrix": {
"rows": 6,
"cols": 14
},
"features": {
"bootmagic": true,
"extrakey": true,
"mousekey": true,
"nkro": true,
"pointing_device": true,
"encoder": true
},
"matrix_pins": {
"cols": ["A0", "A1", "A2", "C4", "B0", "B1", "B2", "B7", "B5", "B3", "B10", "C11", "C10", "A15"],
"rows": ["B12", "B15", "C6", "B13", "B14", "A8"]
},
"encoder": {
"rotary": [
{"pin_a": "A9", "pin_b": "A10"}
]
},
"layouts": {
"LAYOUT": {
"layout": [
{"matrix": [0, 0], "w":1, "h":1, "x":0, "y":0},
{"matrix": [0, 1], "w":1, "h":1, "x":1, "y":0},
{"matrix": [0, 2], "w":1, "h":1, "x":2, "y":0},
{"matrix": [0, 3], "w":1, "h":1, "x":3, "y":0},
{"matrix": [0, 4], "w":1, "h":1, "x":4, "y":0},
{"matrix": [0, 5], "w":1, "h":1, "x":5, "y":0},
{"matrix": [0, 6], "w":1, "h":1, "x":6, "y":0},
{"matrix": [0, 7], "w":1, "h":1, "x":7, "y":0},
{"matrix": [0, 8], "w":1, "h":1, "x":8, "y":0},
{"matrix": [0, 9], "w":1, "h":1, "x":9, "y":0},
{"matrix": [0, 10], "w":1, "h":1, "x":10, "y":0},
{"matrix": [0, 11], "w":1, "h":1, "x":11, "y":0},
{"matrix": [0, 12], "w":1, "h":1, "x":12, "y":0},
{"matrix": [0, 13], "w":1, "h":1, "x":13, "y":0},
{"matrix": [1, 0], "w":1, "h":1, "x":0, "y":1},
{"matrix": [1, 1], "w":1, "h":1, "x":1, "y":1},
{"matrix": [1, 2], "w":1, "h":1, "x":2, "y":1},
{"matrix": [1, 3], "w":1, "h":1, "x":3, "y":1},
{"matrix": [1, 4], "w":1, "h":1, "x":4, "y":1},
{"matrix": [1, 5], "w":1, "h":1, "x":5, "y":1},
{"matrix": [1, 6], "w":1, "h":1, "x":6, "y":1},
{"matrix": [1, 7], "w":1, "h":1, "x":7, "y":1},
{"matrix": [1, 8], "w":1, "h":1, "x":8, "y":1},
{"matrix": [1, 9], "w":1, "h":1, "x":9, "y":1},
{"matrix": [1, 10], "w":1, "h":1, "x":10, "y":1},
{"matrix": [1, 11], "w":1, "h":1, "x":11, "y":1},
{"matrix": [1, 12], "w":1, "h":1, "x":12, "y":1},
{"matrix": [1, 13], "w":1, "h":1, "x":13, "y":1},
{"matrix": [2, 0], "w":1.5, "h":1, "x":0.5, "y":2},
{"matrix": [2, 2], "w":1, "h":1, "x":2, "y":2},
{"matrix": [2, 3], "w":1, "h":1, "x":3, "y":2},
{"matrix": [2, 4], "w":1, "h":1, "x":4, "y":2},
{"matrix": [2, 5], "w":1, "h":1, "x":5, "y":2},
{"matrix": [2, 6], "w":1, "h":1, "x":6, "y":2},
{"matrix": [2, 7], "w":1, "h":1, "x":7, "y":2},
{"matrix": [2, 8], "w":1, "h":1, "x":8, "y":2},
{"matrix": [2, 9], "w":1, "h":1, "x":9, "y":2},
{"matrix": [2, 10], "w":1, "h":1, "x":10, "y":2},
{"matrix": [2, 12], "w":1.5, "h":1, "x":11, "y":2},
{"matrix": [2, 13], "w":1, "h":1, "x":12.5, "y":2},
{"matrix": [3, 0], "w":2, "h":1, "x":1, "y":3},
{"matrix": [3, 3], "w":1, "h":1, "x":3, "y":3},
{"matrix": [3, 4], "w":1, "h":1, "x":4, "y":3},
{"matrix": [3, 5], "w":1, "h":1, "x":5, "y":3},
{"matrix": [3, 6], "w":1, "h":1, "x":6, "y":3},
{"matrix": [3, 7], "w":1, "h":1, "x":7, "y":3},
{"matrix": [3, 8], "w":1, "h":1, "x":8, "y":3},
{"matrix": [3, 9], "w":1, "h":1, "x":9, "y":3},
{"matrix": [3, 10], "w":2, "h":1, "x":10, "y":3},
{"matrix": [3, 13], "w":2, "h":1, "x":12, "y":3},
{"matrix": [4, 0], "w":1.25, "h":1, "x":1.25, "y":4},
{"matrix": [4, 3], "w":1.25, "h":1, "x":2.5, "y":4},
{"matrix": [4, 4], "w":1.25, "h":1, "x":3.75, "y":4},
{"matrix": [4, 5], "w":1.25, "h":1, "x":5, "y":4},
{"matrix": [4, 6], "w":1.25, "h":1, "x":6.25, "y":4},
{"matrix": [4, 7], "w":1.25, "h":1, "x":7.5, "y":4},
{"matrix": [4, 9], "w":1.25, "h":1, "x":8.75, "y":4},
{"matrix": [4, 12], "w":2, "h":1, "x":10.75, "y":4},
{"matrix": [4, 13], "w":1.25, "h":1, "x":12, "y":4},
{"matrix": [5, 0], "w":1, "h":1, "x":0, "y":5},
{"matrix": [5, 3], "w":1, "h":1, "x":3, "y":5},
{"matrix": [5, 4], "w":1, "h":1, "x":4, "y":5},
{"matrix": [5, 5], "w":1, "h":1, "x":5, "y":5},
{"matrix": [5, 6], "w":1, "h":1, "x":6, "y":5}
]
}
}
}

View File

@ -0,0 +1,43 @@
#include QMK_KEYBOARD_H
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// ┏━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┓
// ┃ ESC ┃ 1 ┃ 2 ┃ 3 ┃ 4 ┃ 5 ┃ 6 ┃ 7 ┃ 8 ┃ 9 ┃ 0 ┃ -_ ┃ += ┃ `~ ┃
// ┣━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┫
// ┃ TAB ┃ Q ┃ W ┃ E ┃ R ┃ T ┃ Y ┃ U ┃ I ┃ O ┃ P ┃ [{ ┃ ]} ┃ '" ┃
// ┗━━━┳━━━┻━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━━┻━━┳━━━━┻━━━┳━━━┛
// ┃ CAPSLOCK ┃ A ┃ S ┃ D ┃ F ┃ G ┃ H ┃ J ┃ K ┃ L ┃ ENTER ┃ ;: ┃
// ┗━━━┳━━━━━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━┳━━━┻━━━━━━━┻━┳━━━━━━━━┻━━━━┳━━━┛
// ┃ SHIFT ┃ Z ┃ X ┃ C ┃ V ┃ B ┃ N ┃ M ┃ MOUSE1 ┃ MOUSE2 ┃
// ┗━━━┳━━━━━━━┻┳━━━━━━┻━┳━━━━━┻━━┳━━━━┻━━━┳━━━┻━━━━┳━━┻━━━━━┳━┻━━━━━━┳┻━━━━━━━━━━━━━┻┳━━━━━━━━┳━━━┛
// ┃ CTRL ┃ LGUI ┃ LALT ┃ ,< ┃ .> ┃ /? ┃ \| ┃ SPC ┃ BACK ┃
// ┗━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━┛
// ┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
// ┃ MOUSE3 ┃ → ┃ ↓ ┃ ← ┃ ↑ ┃
// ┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
[0] = LAYOUT(
// ESC 1 2 3 4 5 6 7 8 9 0 - = `
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINUS, KC_EQUAL, KC_GRAVE,
// TAB Q W E R T Y U I O P [ ] '
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LEFT_BRACKET, KC_RIGHT_BRACKET, KC_QUOTE,
// CAPS A S D F G H J K L ; ENTER
KC_CAPS_LOCK, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_ENTER, KC_SEMICOLON,
// LSHIFT Z X C V B N M MOUSE1 MOUSE2
KC_LEFT_SHIFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, QK_MOUSE_BUTTON_1, QK_MOUSE_BUTTON_2,
// LCTRL LGUI LALT , . / \ SPC BACKSPACE
KC_LEFT_CTRL, KC_LEFT_GUI, KC_LEFT_ALT, KC_COMMA, KC_DOT, KC_SCLN, KC_BSLS, KC_SPC, KC_BACKSPACE,
// MOUSE3 → ↓ ← ↑
QK_MOUSE_BUTTON_3, KC_RIGHT, KC_DOWN, KC_LEFT, KC_UP)
};
#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
// Encoders: Left, Right, Big
[0] = {ENCODER_CCW_CW(MS_WHLU, MS_WHLD)}
};
#endif

View File

@ -0,0 +1,5 @@
VIA_ENABLE = yes
POINTING_DEVICE_DRIVER = custom
SRC += adns.c
SPI_DRIVER_REQUIRED = yes
ENCODER_MAP_ENABLE = yes

View File

@ -0,0 +1,23 @@
/* Copyright 2020 QMK
*
* 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
#include_next <mcuconf.h>
#undef STM32_SPI_USE_SPI1
#define STM32_SPI_USE_SPI1 TRUE

View File

@ -0,0 +1,29 @@
# One-Handed_Keyboard_SL
![左手小键盘](https://imgur.com/eaDoxL4.jpg)
This is a keyboard with a fan-shaped layout and 59 keys.The commonly used buttons are placed near the thumb.
* Keyboard Maintainer[HTX Studio](https://github.com/htx-studio)
* Hardware SupportedHTX_STUDIO_ONE-HANDEN_KEYBOARD_SL PCB
* Hardware Availability[One-Handed-Keyboard](https://github.com/htx-studio/One-Handed-Keyboard/tree/main/Hardware)
## How to compile
Make example for this keyboard (after setting up your build environment):
`make htx_studio/one_handed_keyboard_sl:default`
Flashing example for this keyboard:
`make htx_studio/one_handed_keyboard_sl:default:flash`
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).
## Bootloader
Enter the bootloader in 3 ways:
* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard
* **Physical reset button**: Hold the "B" button on the back of the PCB (the one closest to the MCU) and briefly press the "R" button on the back of the PCB
* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available