Skip to content

Commit

Permalink
add Eevee keyboards
Browse files Browse the repository at this point in the history
  • Loading branch information
yangdigi committed Sep 26, 2024
1 parent 6f36874 commit 09de99d
Show file tree
Hide file tree
Showing 49 changed files with 2,162 additions and 2 deletions.
1 change: 1 addition & 0 deletions builddefs/bootloader.mk
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ ifeq ($(strip $(BOOTLOADER)), lufa-ms)
BOOTLOADER_TYPE = dfu

BOOTLOADER_SIZE ?= 8192
RESERVE_SIZE ?= 0
FIRMWARE_FORMAT = bin
cpfirmware: lufa_warning
.INTERMEDIATE: lufa_warning
Expand Down
2 changes: 1 addition & 1 deletion builddefs/common_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ SIZE_MARGIN = 1024
check-size:
$(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) platforms/avr/bootloader_size.c 2> /dev/null | $(SED) -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0))
$(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi))
$(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE)))
$(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE) - $(RESERVE_SIZE)))
$(eval OVER_SIZE=$(shell expr $(CURRENT_SIZE) - $(MAX_SIZE)))
$(eval PERCENT_SIZE=$(shell expr $(CURRENT_SIZE) \* 100 / $(MAX_SIZE)))
if [ $(MAX_SIZE) -gt 0 ] && [ $(CURRENT_SIZE) -gt 0 ]; then \
Expand Down
47 changes: 47 additions & 0 deletions keyboards/ydkb/eevee/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include "config_common.h"
#include "config_ble51.h"

/* USB Device descriptor parameter */
#define FW_VER_DATE DO94
#define VENDOR_ID 0x5944
#define PRODUCT_ID 0x23EE
#define DEVICE_VER 0x0001
#define MANUFACTURER YDKB
#define PRODUCT Eevee Keyboard Uni (FW_VER)

#define EC_INIT_CHECK_TIMES 0
#define EPC_LV KC_P5

/* key matrix size */
#define MATRIX_ROWS 7
#define MATRIX_COLS 16
#define DEBOUNCE_DN 3
#define DEBOUNCE_UP 3

#define DEFAULT_6KRO // macOS's Capslock switching between Chinese and English has compatibility issues with NKRO

#define ws2812_PORTREG PORTE
#define ws2812_DDRREG DDRE
#define ws2812_pin PE6
#define RGBLED_NUM 16 // Number of LEDs
#define RGBLIGHT_MODES 14 //less rgblight mode to save some space for vial

/* BT Power Control */
#define BT_POWERED (~PORTD & (1<<5))
#define bt_power_init() do { DDRD |= (1<<5); PORTD &= ~(1<<5); } while(0)
#define bt_power_reset() do {PORTD |= (1<<5); WAIT_MS(100); PORTD &= ~(1<<5);} while(0)
#define turn_off_bt() do { PORTD |= (1<<5); UCSR1B = (1<<RXCIE1 | 1<<RXEN1); } while(0)
#define turn_on_bt() do { PORTD &= ~(1<<5); if (UCSR1B == (1<<RXCIE1 | 1<<RXEN1)) WAIT_MS(200); UCSR1B = (1<<RXCIE1 | 1<<RXEN1 | 1<<TXEN1); } while(0)

#define BLE_NAME "Eevee!BLE"
#define BLE_LIGHT_ON (PORTD & (1<<7)) //RGB Power IO

#define UPDATE_BATTERY_WHEN_CHARGING
#define BATTERY_CHARGING (~PINE & (1<<2))
#define CHARGING_FIX_VALUE 50
#define CHARGING_STATE_INIT() do { DDRE &= ~(1<<2); PORTE |= (1<<2);} while(0)

#define BLE51_CONSUMER_ON_DELAY 128

169 changes: 169 additions & 0 deletions keyboards/ydkb/eevee/ec_matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
Copyright 2023 YANG <[email protected]>
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 <avr/interrupt.h>
#include "ec_matrix.h"

#include "print.h"
#include "wait.h"
#include "ble51.h"

/* ADC */
#define ADC_MUX (_BV(MUX5) | _BV(MUX0)) //D6 ADC9 MUX5..0:100001
#define AREF _BV(REFS0) // AVCC with external capacitor on AREF pin

#define ADC_PRESCALER (_BV(ADPS1) | _BV(ADPS0))
#define C_CHARGE_WAIT() {if (col == 0 && row == 0) _delay_us(1);}
#define C_DISCHARGE_WAIT()

static void ec_matrix_check(void);

void adc_init(void) {
// High speed mode and MUX5
ADCSRB = _BV(ADHSM) | (ADC_MUX & _BV(MUX5));
//ADLAR 1, left adjusted, and MUX4..0
ADMUX = AREF | _BV(ADLAR) | (ADC_MUX & 0b11111);
}

uint8_t adc_read8(void) {
uint8_t adc_value;
// Enable ADC and configure prescaler. Start ADC
ADCSRA = _BV(ADEN) | _BV(ADSC) | ADC_PRESCALER;

// Wait for result
while (ADCSRA & _BV(ADSC));
adc_value = ADCH;
// turn off the ADC
//ADCSRA &= ~(1 << ADEN);
ADCSRA = 0;

return adc_value;
}

/* EC Matrix */
#ifdef APC_ADJ_ENABLE
#define EC_APC_VALUE ec_apc_value
static uint8_t ec_apc_value = 120;
#else
#define EC_APC_VALUE 128 //ec_apc_value // 120 for EC, 80 for MX
#endif
#define EC_RESET_OFFSET 10
uint8_t ec_actuation_point[MATRIX_ROWS][MATRIX_COLS] = {0};
uint8_t ec_key_value[MATRIX_ROWS][MATRIX_COLS];

static inline void C_CHARGE_READY(void) { DDRD &= ~(1<<4); }
static inline void C_DISCHARGE(void) { DDRD |= (1<<4); }

static inline void ec_unselect_rows(void) {
// Clear row pin. Output low.
PORTB = 0;
DDRB = 0x7f;
if (BLE51_PowerState < 2) _delay_us(6);
}

static inline void ec_select_row(uint8_t row) {
// Select row. Hi-Z
DDRB &= ~(1<<row);
PORTB = (1<<row);
}

void ec_matrix_init(void) {
DDRF |= 0b11110010;
PORTF = 0b10000010;

//discharge pin
DDRD |= (1<<4);
PORTD &= ~(1<<4);

adc_init();

//ec_matrix_check();
#if 0 //CONSOLE_ENABLE
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
ec_actuation_point[row][col] = EC_APC_VALUE;
}
}
#endif
}

void ec_select_col(uint8_t col)
{
// select col, PF4(s0),PF5(s1),PF6(s2)
// PF7: 4051_1, PF1:4051_2. LOW EN.
PORTF = (col<<4);
// 如果使用 PF1 控制 4051_2
if (col < 8) PORTF |= (1<<1);
// 如果使用PF7加NMOS控制4051_2。则NMOS断开时,需要延迟。
//if (col == 0) _delay_us(6);
}


// Read adc raw
uint8_t ec_get_key(uint8_t row, uint8_t col)
{
cli();
C_CHARGE_READY();
ec_select_row(row);
C_CHARGE_WAIT();
ec_key_value[row][col] = adc_read8();
sei();

ec_unselect_rows();
C_DISCHARGE();
C_DISCHARGE_WAIT();

if (ec_key_value[row][col] < (EC_APC_VALUE - EC_RESET_OFFSET)) return 0;
else if (ec_key_value[row][col] >= EC_APC_VALUE) return 0x80;
else return 0b10;
}

#ifdef APC_ADJ_ENABLE
#define EC_APC_KEY_POS (VIA_EEPROM_CONFIG_END+1 + (APC_KEY_ROW * MATRIX_COLS + APC_KEY_COL) * 2)
void ec_apc_update(void) {
static uint8_t ec_apc_level[10] = {88, 96, 104, 112, 120, 128, 136, 144, 152, 80};
/* 暂时使用方法:
保存层0的某个按键内,检测它如果有变化,就更新
数字0到9设置,0->9: 39,30->38; P0->P9, 98, 89->97
*/
uint8_t apc_eeprom = eeprom_read_byte(EC_APC_KEY_POS);
if (apc_eeprom >= 89) apc_eeprom -= 59; //P1 to P0
apc_eeprom -= 30;
if (apc_eeprom < 10) ec_apc_value = ec_apc_level[apc_eeprom];
}
#endif

extern uint16_t scan_speed;
void ec_matrix_print(void)
{
xprintf("\n%3d ",scan_speed);
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
xprintf("[%X],", col);
}
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
xprintf("\n[%d]:",row);
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
#if 0 //(EC_INIT_CHECK_TIMES)
if (ec_actuation_point[row][col] == 0) xprintf("-%2d,", ec_key_value[row][col]);
else
#endif
xprintf("%3d,", ec_key_value[row][col]);
//xprintf("%3d,", ec_actuation_point[row][col]);
}
}
print("\n");
}
12 changes: 12 additions & 0 deletions keyboards/ydkb/eevee/ec_matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>

extern uint8_t ec_actuation_point[MATRIX_ROWS][MATRIX_COLS];
extern uint8_t ec_key_value[MATRIX_ROWS][MATRIX_COLS];

void ec_matrix_init(void);
void ec_matrix_print(void);
void ec_select_col(uint8_t col);
uint8_t ec_get_key(uint8_t row, uint8_t col);
9 changes: 9 additions & 0 deletions keyboards/ydkb/eevee/eevee.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "quantum.h"

#define LAYOUT_all( \
k00 \
) { \
{ k00 } \
}
22 changes: 22 additions & 0 deletions keyboards/ydkb/eevee/keymaps/40a_vial/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#undef PRODUCT_ID
#define PRODUCT_ID 0x23C0

#undef PRODUCT
#define PRODUCT Eevee #40A (FW_VER)

#undef MATRIX_ROWS
#define MATRIX_ROWS 6
#undef MATRIX_COLS
#define MATRIX_COLS 8
#define MATRIX_KEYS 43

#define APC_KEY_ROW 1
#define APC_KEY_COL 7

#undef BLE_NAME
#define BLE_NAME "Eevee #40A BLE"

#define DYNAMIC_KEYMAP_LAYER_COUNT 6
#define FLASH_KEYMAP_COUNT 1
#define VIAL_KEYBOARD_UID {0x2E, 0xE6, 0x0E, 0x23, 0x34, 0xEF, 0x99, 0x37}
20 changes: 20 additions & 0 deletions keyboards/ydkb/eevee/keymaps/40a_vial/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include QMK_KEYBOARD_H

#if 0
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {LAYOUT_all(KC_NO)};
#else
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] =
{
{
{KC_GESC, KC_TAB, KC_LSHIFT, KC_Z, KC_P, KC_BSPACE, KC_ENTER, KC_RSHIFT},
{KC_Q, KC_A, KC_Z, KC_LCTRL, KC_NO, KC_NO, KC_NO, EPC_LV},
{KC_W, KC_S, KC_X, KC_LALT, KC_O, KC_L, KC_DOT, KC_RCTRL},
{KC_E, KC_D, KC_C, KC_X, KC_I, KC_K, KC_COMMA, KC_RALT},
{KC_R, KC_F, KC_V, KC_NO, KC_U, KC_J, KC_M, KC_SPACE},
{KC_T, KC_G, KC_B, KC_SPACE, KC_Y, KC_H, KC_N, KC_NO}
}
};

#endif


7 changes: 7 additions & 0 deletions keyboards/ydkb/eevee/keymaps/40a_vial/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
VIAL_INSECURE = yes
QMK_SETTINGS = no
TAP_DANCE_ENABLE = yes
COMBO_ENABLE = yes
KEY_OVERRIDE_ENABLE = no
31 changes: 31 additions & 0 deletions keyboards/ydkb/eevee/keymaps/40a_vial/vial.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"lighting": "none",
"matrix": {"rows": 6, "cols": 8},
"customKeycodes": [
{"name": "BT/USB", "title": "", "shortName": "BT/U"},
{"name": "RESET", "title": "", "shortName": "BLERST"},
{"name": "BAT%", "title": "", "shortName": "BAT%"},
{"name": "LkMode", "title": "", "shortName": "Lk.M"},
{"name": "RGB_TG", "title": "", "shortName": "R.TG"},
{"name": "RGB_M-", "title": "", "shortName": "R.M-"},
{"name": "RGB_M+", "title": "", "shortName": "R.M+"},
{"name": "HUE-", "title": "", "shortName": "HUE-"},
{"name": "HUE+", "title": "", "shortName": "HUE+"},
{"name": "SAT-", "title": "", "shortName": "SAT-"},
{"name": "SAT+", "title": "", "shortName": "SAT+"},
{"name": "LUM-", "title": "", "shortName": "LUM-"},
{"name": "LUM+", "title": "", "shortName": "LUM+"}
],
"layouts": {
"labels":["ISO Enter", "Split LShift", ["Space", "6.25u", "2u+2.25u", "1.75u+2u"]],
"keymap": [
[{"y":0.16,"c":"#777777","w":1.5},"0,0",{"c":"#cccccc"},"1,0","2,0","3,0","4,0","5,0","5,4","4,4","3,4","2,4","0,4",{"c":"#aaaaaa","w":1.5},"0,5\n\n\n0,0",{"x":1.5,"c":"#777777","w":1.25,"h":2,"w2":1.5,"h2":1,"x2":-0.25},"0,5\n\n\n0,1"],
[{"c":"#aaaaaa","w":1.75},"0,1",{"c":"#cccccc"},"1,1","2,1","3,1","4,1","5,1","5,5","4,5","3,5","2,5",{"c":"#777777","w":2.25},"0,6\n\n\n0,0",{"x":0.5,"c":"#cccccc"},"0,6\n\n\n0,1"],
[{"c":"#aaaaaa","w":2.25},"0,2\n\n\n1,0",{"c":"#cccccc"},"1,2","2,2","3,2","4,2","5,2","5,6","4,6","3,6","2,6",{"c":"#aaaaaa","w":1.75},"0,7"],
[{"x":1.13},"1,3",{"w":1.25},"2,3",{"c":"#cccccc","w":6.25},"5,3\n\n\n2,0",{"c":"#aaaaaa","w":1.25},"3,7","2,7"],
[{"w":1.25},"0,2\n\n\n1,1",{"c":"#cccccc"},"0,3\n\n\n1,1",{"x":1.13,"c":"#aaaaaa"},"3,3\n\n\n2,1",{"c":"#cccccc","w":2},"4,3\n\n\n2,1",{"w":2.25},"5,7\n\n\n2,1",{"c":"#aaaaaa"},"4,7\n\n\n2,1"],
[{"x":3.38,"w":1.25},"3,3\n\n\n2,2",{"c":"#cccccc","w":1.75},"4,3\n\n\n2,2",{"w":2},"5,7\n\n\n2,2",{"c":"#aaaaaa","w":1.25},"4,7\n\n\n2,2"]
]
}

}
23 changes: 23 additions & 0 deletions keyboards/ydkb/eevee/keymaps/40b_vial/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#undef PRODUCT_ID
#define PRODUCT_ID 0x23C1

#undef PRODUCT
#define PRODUCT Eevee #40B (FW_VER)

#undef MATRIX_ROWS
#define MATRIX_ROWS 6
#undef MATRIX_COLS
#define MATRIX_COLS 8
#define MATRIX_KEYS 45

#define APC_KEY_ROW 1
#define APC_KEY_COL 7

#undef BLE_NAME
#define BLE_NAME "Eevee #40B BLE"


#define DYNAMIC_KEYMAP_LAYER_COUNT 6
#define FLASH_KEYMAP_COUNT 1
#define VIAL_KEYBOARD_UID {0x2E, 0xE6, 0x0E, 0x23, 0x34, 0xEF, 0x99, 0x37}
20 changes: 20 additions & 0 deletions keyboards/ydkb/eevee/keymaps/40b_vial/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include QMK_KEYBOARD_H

#if 0
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {LAYOUT_all(KC_NO)};
#else
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] =
{
{
{KC_GESC, KC_TAB, KC_LSHIFT, KC_NO, KC_BSLASH, KC_BSPACE, KC_ENTER, KC_RSHIFT},
{KC_Q, KC_A, KC_Z, KC_LCTRL, KC_P, KC_SCOLON, KC_SLASH, EPC_LV},
{KC_W, KC_S, KC_X, KC_LALT, KC_O, KC_L, KC_DOT, KC_RCTRL},
{KC_E, KC_D, KC_C, KC_X, KC_I, KC_K, KC_COMMA, KC_RALT},
{KC_R, KC_F, KC_V, KC_NO, KC_U, KC_J, KC_M, KC_SPACE},
{KC_T, KC_G, KC_B, KC_SPACE, KC_Y, KC_H, KC_N, KC_NO}
}
};

#endif


7 changes: 7 additions & 0 deletions keyboards/ydkb/eevee/keymaps/40b_vial/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
VIAL_INSECURE = yes
QMK_SETTINGS = no
TAP_DANCE_ENABLE = yes
COMBO_ENABLE = yes
KEY_OVERRIDE_ENABLE = no
Loading

0 comments on commit 09de99d

Please sign in to comment.