Skip to content

Commit e329c0a

Browse files
v0.8.0: Add Corne ECWL and Keyboard Quantizer
1 parent 76a5abd commit e329c0a

File tree

37 files changed

+1928
-150
lines changed

37 files changed

+1928
-150
lines changed

keyboards/crkbd_ecwl/bmp/bmp.c

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/* Copyright 2020 sekigon-gonnoc
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#include <string.h>
18+
19+
#include "crkbd_ecwl.h"
20+
#include "quantum.h"
21+
#include "bmp_matrix.h"
22+
23+
#include "debug.h"
24+
#include "i2c_master.h"
25+
26+
#include "apidef.h"
27+
#include "debug.h"
28+
29+
#define POWER_PIN 11
30+
#define APLEX_EN_PIN 10
31+
#define OPA_SHDN_PIN 20
32+
#define ANALOG_PORT 6
33+
#define DISCHARGE_PIN 16
34+
const uint8_t row_pins[] = {7, 8, 9};
35+
const uint8_t col_pins[] = {15, 14, 13};
36+
const uint8_t col_sels[] = {6, 4, 3, 0, 1, 2, 5};
37+
38+
#define ERROR_TH 3000
39+
#define HIGH_TH 1000
40+
#define LOW_TH 800
41+
42+
#define LEN(x) (sizeof(x) / sizeof(x[0]))
43+
44+
bool bmp_config_overwrite(bmp_api_config_t const *const config_on_storage,
45+
bmp_api_config_t *const keyboard_config) {
46+
// User can overwrite partial settings
47+
keyboard_config->mode = config_on_storage->mode;
48+
keyboard_config->startup = config_on_storage->startup;
49+
keyboard_config->matrix.debounce = config_on_storage->matrix.debounce;
50+
keyboard_config->matrix.is_left_hand =
51+
config_on_storage->matrix.is_left_hand;
52+
keyboard_config->param_central = config_on_storage->param_central;
53+
keyboard_config->param_peripheral = config_on_storage->param_peripheral;
54+
keyboard_config->keymap = config_on_storage->keymap;
55+
keyboard_config->reserved[2] = config_on_storage->reserved[2];
56+
57+
return true;
58+
}
59+
60+
void keyboard_post_init_kb() {
61+
debug_enable = false;
62+
debug_keyboard = false;
63+
debug_mouse = false;
64+
}
65+
66+
const bmp_ecs_config_t ecs_config = {.pins = row_pins,
67+
.cnt = LEN(row_pins),
68+
.adc_port = ANALOG_PORT,
69+
.shdn_pin = OPA_SHDN_PIN,
70+
.discharge_pin = DISCHARGE_PIN};
71+
72+
void ecs_matrix_init() {
73+
// init driver
74+
BMPAPI->ecs.init(&ecs_config);
75+
76+
// init col_pins
77+
for (int idx = 0; idx < LEN(col_pins); idx++) {
78+
setPinOutput(col_pins[idx]);
79+
writePinLow(col_pins[idx]);
80+
}
81+
82+
// power_on
83+
setPinOutput(POWER_PIN);
84+
writePinHigh(POWER_PIN);
85+
86+
// enable multiplexer
87+
setPinOutput(APLEX_EN_PIN);
88+
writePinLow(APLEX_EN_PIN);
89+
}
90+
91+
uint16_t sw_read[32] = {0};
92+
uint32_t ecs_get_device_row() { return MATRIX_ROWS_DEFAULT; }
93+
uint32_t ecs_get_device_col() { return MATRIX_COLS_DEFAULT; }
94+
uint32_t ecs_matrix_scan(matrix_row_t *matrix_raw) {
95+
uint16_t sw_idx = 0;
96+
97+
for (int col_sel_idx = 0; col_sel_idx < LEN(col_sels); col_sel_idx++) {
98+
BMPAPI->ecs.discharge_capacitor();
99+
100+
writePinHigh(APLEX_EN_PIN);
101+
// select col
102+
for (int col_pin_idx = 0; col_pin_idx < LEN(col_pins); col_pin_idx++) {
103+
writePin(col_pins[col_pin_idx],
104+
col_sels[col_sel_idx] & (1 << col_pin_idx) ? 1 : 0);
105+
}
106+
writePinLow(APLEX_EN_PIN);
107+
108+
for (int row = 0; row < sizeof(row_pins); row++) {
109+
BMPAPI->ecs.discharge_capacitor();
110+
111+
// assign_ecs_drive_pin
112+
BMPAPI->ecs.assign_drive_pin(row_pins[row]);
113+
114+
// drive prev row low
115+
BMPAPI->ecs.clear_drive_pins(&ecs_config);
116+
117+
// read switch value
118+
BMPAPI->ecs.sw_read(&sw_read[col_sel_idx + row * LEN(col_sels)]);
119+
sw_idx++;
120+
}
121+
}
122+
123+
BMPAPI->ecs.discharge_capacitor();
124+
125+
// select first col
126+
for (int col_pin_idx = 0; col_pin_idx < LEN(col_pins); col_pin_idx++) {
127+
writePin(col_pins[col_pin_idx],
128+
col_sels[0] & (1 << col_pin_idx) ? 1 : 0);
129+
}
130+
131+
// clear all row
132+
BMPAPI->ecs.clear_drive_pins(&ecs_config);
133+
134+
// stop_adc
135+
BMPAPI->ecs.schedule_next_scan();
136+
137+
uint8_t matrix_changed = 0;
138+
139+
for (int row = 0; row < THIS_DEVICE_ROWS; row++) {
140+
for (int col = 0; col < THIS_DEVICE_COLS; col++) {
141+
if (sw_read[col + row * LEN(col_sels)] > ERROR_TH) {
142+
// error value
143+
144+
dprintf("ERROR(%d,%d):%d", row, col,
145+
sw_read[col + row * LEN(col_sels)]);
146+
147+
sw_read[col + row * LEN(col_sels)] = 0;
148+
}
149+
150+
if (matrix_raw[row] & (1 << col)) {
151+
if (sw_read[col + row * LEN(col_sels)] < LOW_TH) {
152+
matrix_raw[row] &= ~(1 << col);
153+
matrix_changed++;
154+
155+
dprintf("UP(%d,%d):%d", row, col,
156+
sw_read[col + row * LEN(col_sels)]);
157+
}
158+
} else {
159+
if (sw_read[col + row * LEN(col_sels)] > HIGH_TH) {
160+
matrix_raw[row] |= (1 << col);
161+
matrix_changed++;
162+
163+
dprintf("DOWN(%d,%d):%d", row, col,
164+
sw_read[col + row * LEN(col_sels)]);
165+
}
166+
}
167+
}
168+
}
169+
170+
static int cnt = 0;
171+
if (cnt++ == 30) {
172+
cnt = 0;
173+
for (int row = 0; row < sizeof(row_pins); row++) {
174+
for (int col_sel_idx = 0; col_sel_idx < LEN(col_sels);
175+
col_sel_idx++) {
176+
dprintf("%5d", sw_read[col_sel_idx + row * LEN(col_sels)]);
177+
}
178+
dprintf("\n");
179+
}
180+
dprintf("\n");
181+
}
182+
183+
return matrix_changed;
184+
}
185+
186+
static const bmp_matrix_func_t matrix_func = {
187+
ecs_matrix_init, ecs_get_device_row, ecs_get_device_col, ecs_matrix_scan};
188+
189+
const bmp_matrix_func_t *get_matrix_func_user() { return &matrix_func; }
190+
191+
void bmp_before_sleep() {}
192+
193+
bool checkSafemodeFlag(bmp_api_config_t const *const config) { return false; }

keyboards/crkbd_ecwl/bmp/config.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
#pragma once
3+
4+
#define BMP_BOOTPIN_AS_RESET
5+
/* key matrix size */
6+
#define MATRIX_ROWS_DEFAULT 6
7+
#define MATRIX_COLS_DEFAULT 7
8+
#define THIS_DEVICE_ROWS 3
9+
#define THIS_DEVICE_COLS 7
10+
#define IS_LEFT_HAND true
11+
#define BMP_DEFAULT_MODE SPLIT_MASTER
12+
13+
#define MATRIX_ROW_PINS \
14+
{ 16, 16, 16 }
15+
#define MATRIX_COL_PINS \
16+
{ 18, 18, 18, 18, 18, 18 }
17+
#define MATRIX_LAYOUT \
18+
{ 1, 2, 3, 4, 5, 6, 27,26,25,24,23,22,0,\
19+
8, 9, 10,11,12,13, 34,33,32,31,30,29,0,\
20+
15,16,17,18,19,20, 41,40,39,38,37,36,0,\
21+
7,14,21, 42,35,28,255\
22+
}
23+
24+
#define KEYMAP_PRIOR_LOCALE 0
25+
#define KEYMAP_ASCII 0
26+
#define CONFIG_RESERVED \
27+
{ 0, 1, 0, 0, 0, 0, 0, 0 }
28+
29+
#define RGBLIGHT_SPLIT
30+
#define RGB_DI_PIN 255
31+
#ifdef RGB_DI_PIN
32+
# define RGBLED_NUM_DEFAULT 128
33+
# define RGBLIGHT_HUE_STEP 8
34+
# define RGBLIGHT_SAT_STEP 8
35+
# define RGBLIGHT_VAL_STEP 8
36+
# define RGBLIGHT_LIMIT_VAL 255 /* The maximum brightness level */
37+
# define RGBLIGHT_SLEEP /* If defined, the RGB lighting will be switched \
38+
off when the host goes to sleep */
39+
/*== all animations enable ==*/
40+
# define RGBLIGHT_ANIMATIONS
41+
/*== or choose animations ==*/
42+
# define RGBLIGHT_EFFECT_BREATHING
43+
# define RGBLIGHT_EFFECT_RAINBOW_MOOD
44+
# define RGBLIGHT_EFFECT_RAINBOW_SWIRL
45+
# define RGBLIGHT_EFFECT_SNAKE
46+
# define RGBLIGHT_EFFECT_KNIGHT
47+
# define RGBLIGHT_EFFECT_CHRISTMAS
48+
# define RGBLIGHT_EFFECT_STATIC_GRADIENT
49+
# define RGBLIGHT_EFFECT_RGB_TEST
50+
# define RGBLIGHT_EFFECT_ALTERNATING
51+
/*== customize breathing effect ==*/
52+
/*==== (DEFAULT) use fixed table instead of exp() and sin() ====*/
53+
# define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256(default) or 128 or 64
54+
/*==== use exp() and sin() ====*/
55+
# define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1 to 2.7
56+
# define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0 to 255
57+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Copyright 2020 sekigon-gonnoc
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#pragma once
18+
19+
// place overrides here
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* Copyright 2020 sekigon-gonnoc
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
#include "keycode.h"
17+
#include QMK_KEYBOARD_H
18+
#include "bmp.h"
19+
#include "bmp_custom_keycode.h"
20+
#include "keycode_str_converter.h"
21+
22+
#include <stdio.h>
23+
24+
// Defines the keycodes used by our macros in process_record_user
25+
enum custom_keycodes {
26+
CUSTOM_KEYCODE_START = BMP_SAFE_RANGE,
27+
SW0_READ = CUSTOM_KEYCODE_START,
28+
};
29+
30+
const key_string_map_t custom_keys_user = {.start_kc = CUSTOM_KEYCODE_START,
31+
.end_kc = CUSTOM_KEYCODE_START,
32+
.key_strings = "SW0\0"};
33+
34+
const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {{{KC_NO}}};
35+
36+
uint32_t keymaps_len() { return 42; }
37+
38+
extern uint16_t sw_read[32];
39+
40+
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
41+
bool continue_process = process_record_user_bmp(keycode, record);
42+
if (continue_process == false) {
43+
return false;
44+
}
45+
46+
char str[32];
47+
if (record->event.pressed) {
48+
switch (keycode) {
49+
case SW0_READ:
50+
snprintf(str, sizeof(str), "%4d", sw_read[0]);
51+
send_string(str);
52+
return false;
53+
break;
54+
}
55+
}
56+
57+
return true;
58+
}
59+
60+
void matrix_init_user(void) {}
61+
62+
void matrix_scan_user(void) {}
63+
64+
void led_set_user(uint8_t usb_led) {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# The default keymap for toybox
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Copyright 2020 sekigon-gonnoc
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#pragma once
18+
19+
#define DISABLE_MSC 1
20+
21+
// place overrides here

0 commit comments

Comments
 (0)