diff --git a/keyboards/handwired/d48/README.md b/keyboards/handwired/d48/README.md new file mode 100644 index 000000000000..a20b8a4251b4 --- /dev/null +++ b/keyboards/handwired/d48/README.md @@ -0,0 +1,87 @@ +# D48 + +![Proton C based handwired 40% keyboard](https://i.imgur.com/2wCYuno.jpg) + +A Proton C based handwired 48 key keyboard with 2 rotary encoders, I2C OLED, WS2812 strip, buzzer & clock! + +- Keyboard Maintainer: Andrew Dunai +- Hardware Supported: Proton C handwired + +Make example for this keyboard (after setting up your build environment): + + make handwired/d48:default + +## Details + +- Proton C based handwired keyboard +- 2x custom 1.25mm stainless steel plates +- Kailh Choc White (clicky) +- 2x rotary encoders +- 0.91" 128x32 I2C OLED +- Small buzzer mounted inside (still waiting for the AST1109MLTRQ boys) +- WS2812 strip (14 LEDs) +- DS1307 I2C module real-time clock + +Build process: [album](https://imgur.com/gallery/zZZGdDw) + +## Pinout + +![D48 pinout](https://imgur.com/QoStCvD.jpg) + +## Challenges + +I'm very happy with the result, but at some point Proton C was driving me nuts. + +I did a lot of trial and error during assembly & programming. +There were a lot of *yet* undocumented caveats, +so I'll outline them here so that you guys can avoid the same issues I had. + +## Matrix & encoders + +Although this is a 48-key board with a 12-col & 4-row matrix, I've decided to add an extra row above the first one +to make my matrix 12x5 and wire encoders' push buttons as 2 extra keys, thus making it a total of 50 (12x4 + 2 encoders). +I used 2 columns (9 & 12) for those buttons. + +So, a first row actually has 2 buttons on columns 9 & 12 (because encoders are located near those columns). +Encoders' push buttons are also configured via QMK's keymap. + +Check out the `d48.h` & `config.h` for pins used & keymap macro definition. + +## I2C/OLED + +Most of the stuff worked out of the box, except me choosing the right pins for my OLED. + +On the Proton C pinout, there are 3 labels for I2C and for some reason +there are 2 pairs of SDA/SCL for I2C1 channel: `B8`/`B9` (rear left side) and `B6`/`B7` (rear right side). +I'm not sure if this is a mistake or if I was doing something wrong. So initially I picked `B8`/`B9` +which were not working. When I switched to B6/B7, things worked like a charm. +Later I used B9 for matrix row. No issues so far. + +Oh, and by the way, while using `B8`/`B9`, keyboard was sometimes *swallowing* quick keypresses. +I believe this was due to I(2)C timeouts (because incorrect pins were used for OLED). + +## Buzzer + +It turns out once you switch on `AUDIO_ENABLE`, you cannot use A4 & A5 because they interfere with the buzzer. +My guess is that buzzer uses DAC channels (not sure why both). + +I couldn't find this in documentation. Honestly, Proton C has almost zero documentation and this was +the biggest challenge. Anyway, apart from almost going crazy from those challenges, I really liked it! + +## RGB + +I used pin `A15` for my WS28128 RGB strip. + +## D1307 real-time clock + +Connecting DS1307 RTC was a piece of cake: same I2 pins as OLED (SDA/SCL), GND to GND and power to Proton C VUSB pin (5v). + +## Other issues + +- `B5` could not be used for matrix. +- `TAP_CODE_DELAY` had to be increased to 10 to fix `tap_code(KC_VOLU/KC_VOLD)` calls being swallowed in encoder callback. +- Be extremely attentive about the pinout: keep in mind that **the official Proton C pinout displays the rear of the board, not the front.** Being used to front pinouts, I ended up soldering entire matrix to the wrong side, so I had to desolder every wire and connect it to the opposite side. + +## Conclusion + +I had a lot of fun. The layout was inspired by the Planck THK. Feel free to ask any questions! diff --git a/keyboards/handwired/d48/config.h b/keyboards/handwired/d48/config.h new file mode 100644 index 000000000000..9c23442997d7 --- /dev/null +++ b/keyboards/handwired/d48/config.h @@ -0,0 +1,77 @@ +#pragma once + +#include "config_common.h" + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x6060 +#define DEVICE_VER 0x0001 +#define MANUFACTURER Andrew Dunai +#define PRODUCT D48 + +/* Key matrix size */ +#define MATRIX_ROWS 5 +#define MATRIX_COLS 12 + +/* Key matrix pins */ +#define MATRIX_ROW_PINS { B8, B9, B1, B2, B4 } + +#define MATRIX_COL_PINS { A2, B0, A7, A8, A13, A14, B12, B11, B10, B15, B14, B13 } +#define UNUSED_PINS + +/* COL2ROW or ROW2COL */ +#define DIODE_DIRECTION COL2ROW + +/* Set 0 if debouncing isn't needed */ +// #define DEBOUNCE 5 + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +// #define LOCKING_SUPPORT_ENABLE + +/* Locking resynchronize hack */ +// #define LOCKING_RESYNC_ENABLE + +/* prevent stuck modifiers */ +// #define PREVENT_STUCK_MODIFIERS + +/* RGB Underglow */ +#ifdef RGBLIGHT_ENABLE +#define RGB_DI_PIN A15 +#define RGBLED_NUM 14 +#define RGBLIGHT_HUE_STEP 8 +#define RGBLIGHT_SAT_STEP 8 +#define RGBLIGHT_VAL_STEP 8 +#define RGBLIGHT_ANIMATIONS +#endif + +/* Audio */ +#ifdef AUDIO_ENABLE +#define STARTUP_SONG_DOOM SONG(E1M1_DOOM) +#define STARTUP_SONG SONG( \ + Q__NOTE(_E6), \ + Q__NOTE(_A6), \ + H__NOTE(_E7), \ + Q__NOTE(_E6), \ + Q__NOTE(_E7) \ +) +#endif + +/* Encoders */ +#define ENCODERS_PAD_A { B3, A0 } +#define ENCODERS_PAD_B { A6, A1 } +/* #define ENCODER_RESOLUTION 4 */ + +/* OLED */ +#define OLED_FONT_H "glcdfont_d48.c" +#define OLED_TIMEOUT 0 +// #define OLED_SCROLL_TIMEOUT 1000 + +/* Taps (encoder tap_code) */ +#define TAP_CODE_DELAY 10 + +/* I2C */ +//#define I2C1_DUTY_CYCLE FAST_DUTY_CYCLE_2 +//#define PAL_MODE_STM32_ALTERNATE_OPENDRAIN (PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN) + +/* DS1307 */ +#define DS1307_ADDR (0x68 << 1) diff --git a/keyboards/handwired/d48/d48.c b/keyboards/handwired/d48/d48.c new file mode 100644 index 000000000000..3cc2097bf871 --- /dev/null +++ b/keyboards/handwired/d48/d48.c @@ -0,0 +1 @@ +#include "d48.h" diff --git a/keyboards/handwired/d48/d48.h b/keyboards/handwired/d48/d48.h new file mode 100644 index 000000000000..b698ca187f0f --- /dev/null +++ b/keyboards/handwired/d48/d48.h @@ -0,0 +1,19 @@ +#pragma once + +#include "quantum.h" + +#define ___ KC_NO + +#define LAYOUT( \ + K08, K0B, \ + K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, \ + K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, \ + K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, \ + K40, K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B \ +) { \ + { ___, ___, ___, ___, ___, ___, ___, ___, K08, ___, ___, K0B }, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B }, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B }, \ + { K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B }, \ + { K40, K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B } \ +} diff --git a/keyboards/handwired/d48/ds1307.c b/keyboards/handwired/d48/ds1307.c new file mode 100644 index 000000000000..f6b57d50d2ed --- /dev/null +++ b/keyboards/handwired/d48/ds1307.c @@ -0,0 +1,21 @@ +#include "ds1307.h" +#include "i2c_master.h" + +void ds1307_set_time(uint8_t h, uint8_t m, uint8_t s) { + uint8_t data[] = { + ((s % 10) | ((s / 10) << 4)) & 0x7F, + ((m % 10) | ((m / 10) << 4)) & 0x7F, + ((h % 10) | ((h / 10) << 4)) & 0x3F, + 0, 0, 0, 0, 0 + }; // 24-hour mode + i2c_writeReg(DS1307_ADDR, 0, data, 8, 100); +} + +void ds1307_get_time(uint8_t *h, uint8_t *m, uint8_t *s) { + uint8_t data[3]; + i2c_readReg(DS1307_ADDR, 0, data, 3, 100); + i2c_stop(); + *s = (data[0] & 0b1111) + ((data[0] & 0b1110000) >> 4) * 10; + *m = (data[1] & 0b1111) + ((data[1] & 0b1110000) >> 4) * 10; + *h = (data[2] & 0b1111) + ((data[2] & 0b0110000) >> 4) * 10; +} diff --git a/keyboards/handwired/d48/ds1307.h b/keyboards/handwired/d48/ds1307.h new file mode 100644 index 000000000000..6f76db250897 --- /dev/null +++ b/keyboards/handwired/d48/ds1307.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +void ds1307_set_time(uint8_t h, uint8_t m, uint8_t s); +void ds1307_get_time(uint8_t *h, uint8_t *m, uint8_t *s); diff --git a/keyboards/handwired/d48/glcdfont_d48.c b/keyboards/handwired/d48/glcdfont_d48.c new file mode 100644 index 000000000000..19063b00ceb2 --- /dev/null +++ b/keyboards/handwired/d48/glcdfont_d48.c @@ -0,0 +1,231 @@ +#include "progmem.h" + +// Helidox 8x6 font with QMK Firmware Logo +// Online editor: http://teripom.x0.com/ + +static const unsigned char font[] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, + 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, + 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, + 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00, + 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, + 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, + 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, + 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, + 0x00, 0x18, 0x24, 0x18, 0x00, 0x00, + 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, + 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, + 0x26, 0x29, 0x79, 0x29, 0x26, 0x00, + 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, + 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, + 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00, + 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, + 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, + 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, + 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, + 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, + 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, + 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, + 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, + 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00, + 0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, + 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, + 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, + 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, + 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, + 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, + 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, + 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, + 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, + 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, + 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, + 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, + 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, + 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, + 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00, + 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, + 0x00, 0x80, 0x70, 0x30, 0x00, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, + 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, + 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, + 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, + 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, + 0x72, 0x49, 0x49, 0x49, 0x46, 0x00, + 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00, + 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, + 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, + 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00, + 0x41, 0x21, 0x11, 0x09, 0x07, 0x00, + 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, + 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, + 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, + 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, + 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, + 0x02, 0x01, 0x59, 0x09, 0x06, 0x00, + 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, + 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, + 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, + 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, + 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, + 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, + 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, + 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00, + 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, + 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, + 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, + 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, + 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, + 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00, + 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, + 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, + 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, + 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, + 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, + 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, + 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00, + 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, + 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, + 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, + 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, + 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, + 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, + 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00, + 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, + 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00, + 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, + 0x00, 0x03, 0x07, 0x08, 0x00, 0x00, + 0x20, 0x54, 0x54, 0x78, 0x40, 0x00, + 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00, + 0x38, 0x44, 0x44, 0x44, 0x28, 0x00, + 0x38, 0x44, 0x44, 0x28, 0x7F, 0x00, + 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, + 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, + 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x00, + 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, + 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00, + 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00, + 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, + 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, + 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00, + 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00, + 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, + 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00, + 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00, + 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00, + 0x48, 0x54, 0x54, 0x54, 0x24, 0x00, + 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00, + 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00, + 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, + 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, + 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, + 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00, + 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, + 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, + 0x00, 0x41, 0x36, 0x08, 0x00, 0x00, + 0x02, 0x01, 0x02, 0x04, 0x02, 0x00, + 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x60, 0x70, 0x78, 0x3C, + 0x1E, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, + 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, + 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F, + 0x1F, 0xFE, 0xFE, 0xF8, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xF0, 0xFC, 0xFE, 0xFE, 0x3F, + 0x1F, 0x0F, 0x0F, 0x0F, 0x0F, 0x9F, + 0xFF, 0xFE, 0xFE, 0xFC, 0xF0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3E, 0x22, 0x22, 0x00, 0x02, 0x3E, + 0x02, 0x00, 0x3E, 0x20, 0x20, 0x00, + 0x00, 0x3C, 0x0A, 0x3C, 0x00, 0x3E, + 0x20, 0x20, 0x02, 0x3E, 0x02, 0x00, + 0x00, 0x1C, 0x22, 0x32, 0x00, 0x1E, + 0x20, 0x20, 0x1E, 0x00, 0x3E, 0x00, + 0x00, 0x2C, 0x2A, 0x1A, 0x00, 0x3E, + 0x0A, 0x02, 0x00, 0x02, 0x3E, 0x02, + 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xC0, 0xF8, 0xFF, 0xFF, + 0xFF, 0xE7, 0xE0, 0xE0, 0xE7, 0xFF, + 0xFF, 0xFF, 0xF8, 0xC0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x3C, + 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x7E, + 0xFF, 0xE7, 0xE7, 0x81, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, + 0xF0, 0xF8, 0x7C, 0x3E, 0x1F, 0x0F, + 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x22, 0x22, 0x00, 0x00, + 0x0F, 0x0F, 0x2F, 0x2F, 0x0F, 0x0F, + 0xF0, 0xF0, 0xF2, 0xF2, 0xF0, 0xF0, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x22, 0x22, 0x00, 0xFF, + 0x0F, 0x0F, 0x2F, 0x2F, 0x0F, 0xFF, + 0xF0, 0xF0, 0xF2, 0xF2, 0xF0, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF0, 0xFE, 0xFF, 0xFF, 0x0F, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x0F, 0xFF, 0xFF, 0xFE, 0xF0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, + 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, + 0xF8, 0x7F, 0x7F, 0x1F, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, + 0xF9, 0xF0, 0xF0, 0xF0, 0xF0, 0xF8, + 0xFC, 0x7F, 0x7F, 0x3F, 0x0F, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xFF, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0xFF, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x11, +}; diff --git a/keyboards/handwired/d48/keymaps/anderson/keymap.c b/keyboards/handwired/d48/keymaps/anderson/keymap.c new file mode 100644 index 000000000000..25837a3591bd --- /dev/null +++ b/keyboards/handwired/d48/keymaps/anderson/keymap.c @@ -0,0 +1,340 @@ +#include QMK_KEYBOARD_H +#include "taphold.h" +#include "seq.h" +#include "ds1307.h" +#include "lightmode.h" +#include + +/* Note: don't forget there's some more code in qmk_firmware/users/anderson dir */ + +#define _MAIN 0 +#define _ALPHA 1 +#define _BETA 2 + +enum custom_keycodes { + KC_MAIN = SAFE_RANGE, + KC_ALPHA, + KC_BETA, +#ifdef LIGHTMODE_ENABLE + KC_LIGHT_MODE, +#endif + KC_SEQ, + KC_SET_TIME, +}; +#ifdef LIGHTMODE_ENABLE +#endif + +/* TapHold is my own implementation of the `LT` macro. It's processed in `process_record_user()`. */ +#define TAPHOLD_CONFIG_SIZE 3 +taphold_t taphold_config[TAPHOLD_CONFIG_SIZE] = { + {.key=KC_ALPHA, .mode=TAPHOLD_LAYER, .shortAction=KC_ESC, .longAction=_ALPHA}, + {.key=KC_BETA, .mode=TAPHOLD_LAYER, .shortAction=KC_EQL, .longAction=_BETA}, + {.key=KC_RCTRL, .mode=TAPHOLD_MOD, .shortAction=KC_MINS, .longAction=KC_LCTRL}, +}; +uint16_t taphold_config_size = TAPHOLD_CONFIG_SIZE; +uint32_t taphold_timeout = 90; + +/* Seq is implementation of unicode macros similar to UCIS, but with unicode strings. */ +#define SEQ_CONFIG_SIZE 3 +seq_t seq_config[SEQ_CONFIG_SIZE] = { + {.sequence="temp", .result="42°C"}, + {.sequence="table", .result="┳━━┳"}, + {.sequence="shrug", .result="¯\\_(ツ)_/¯"} +}; +uint16_t seq_config_size = SEQ_CONFIG_SIZE; + +/* Colors */ +uint32_t layer_colors[3] = { + [_MAIN] = 0xFF0010, + [_ALPHA] = 0x4020FF, + [_BETA] = 0x20FF00, +}; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* Main layer + │MUTE │ │L_MOD│ + ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓ + ┃ TAB ┃ Q │ W │ E │ R │ T ┃ Y │ U │ I │ O │ P ┃ BSP ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃𝛼/ESC┃ A │ S │ D │ F │ G ┃ H │ J │ K │ L │ ; ┃ RET ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃SHIFT┃ Z │ X │ C │ V │ B ┃ N │ M │ , │ . │ / ┃CTL/-┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃LCTRL┃ │ │ ALT │ GUI │SPACE┃SPACE│ 𝛽/= │ ' │ │ ┃ \ ┃ + ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛ + */ + [_MAIN] = LAYOUT( \ + KC_MUTE, LCTL(KC_D), + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \ + KC_ALPHA,KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RCTRL,\ + KC_LCTRL,_______, _______, KC_LALT, KC_LGUI, KC_SPC, KC_SPC, KC_BETA, KC_QUOT, _______, _______, KC_BSLS \ + ), + + /* Alpha layer (𝛼) + │ │ │ │ + ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓ + ┃ ┃PREV │PLAY │NEXT │ │NUMLK┃ - │ ^^^ │ ^ │ vvv │ ~ ┃ DEL ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃ │VOL -│VOL +│ │CPSLK┃HOME │ <-- │ v │ --> │ ` ┃ \ ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃ │ │ │ │SCRLK┃ END │ = │ [ │ ] │ ( ┃ ) ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃ │ │ │ │ ┃ │ │ │ │ ┃ ┃ + ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛ + */ + [_ALPHA] = LAYOUT( \ + _______, _______, \ + _______, KC_MPRV, KC_MPLY, KC_MNXT, _______, KC_NLCK, KC_MINS, KC_PGUP, KC_UP, KC_PGDN, KC_TILD, KC_DEL, \ + _______, _______, KC_VOLD, KC_VOLU, _______, KC_CAPS, KC_HOME, KC_LEFT, KC_DOWN, KC_RIGHT,KC_GRV, KC_BSLS, \ + _______, _______, _______, _______, _______, KC_SLCK, KC_END, KC_EQL, KC_LBRC, KC_RBRC, KC_LPRN ,KC_RPRN, \ + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \ + ), + + /* Beta layer (𝛽) + │ │ │ │ + ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓ + ┃ RGB ┃ 1 │ 2 │ 3 │ 4 │ 5 ┃ 6 │ 7 │ 8 │ 9 │ 0 ┃ F12 ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃L_MOD┃ F1 │ F2 │ F3 │ F4 │ F5 ┃ F6 │ F7 │ F8 │ F9 │ F10 ┃ F11 ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃RESET│DEBUG│ │ │TIME ┃SLEEP│ SEQ │ { │ } │PTSCR┃ ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃ │ │ │ │ ┃ │ │ │ │ ┃ ┃ + ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛ + */ + [_BETA] = LAYOUT( \ + _______, _______, \ + RGB_TOG, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_F12, +#ifdef LIGHTMODE_ENABLE + KC_LIGHT_MODE, +#else + _______, +#endif + KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, \ + _______, RESET, DEBUG, _______, _______, KC_SET_TIME,KC_SLEP,KC_SEQ,KC_LCBR, KC_RCBR, KC_PSCR, _______, \ + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \ + ) +}; + +static bool alpha_pressed = false; +static bool beta_pressed = false; + +static bool ctrl_pressed = false; +static bool alt_pressed = false; +static bool shift_pressed = false; +static bool gui_pressed = false; + +static bool is_in_seq = false; + +void keyboard_post_init_user(void) { + /* debug_enable = true; */ + /* debug_matrix = true; */ +} + +void eeconfig_init_user(void) { + set_unicode_input_mode(UC_LNX); +} + +void matrix_init_user(void) { +#ifdef LIGHTMODE_ENABLE + set_light_mode(SMOOTHLED, layer_colors[_MAIN]); +#endif +} + +static uint32_t last_update = 0; +static uint8_t hours, minutes, seconds; + +void matrix_scan_user(void) { + uint32_t now = timer_read32(); + if (now - last_update > 500) { + ds1307_get_time(&hours, &minutes, &seconds); + last_update = now; + } +} + +static bool is_in_set_time = false; +static char new_time[6]; +static uint8_t new_time_index = 0; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (keycode == KC_SEQ && record->event.pressed) { + seq_start(); + layer_off(_BETA); + is_in_seq = true; + return false; + } else if (is_in_seq) { + if (record->event.pressed) { + if (!seq_feed(keycode)) { + is_in_seq = false; + } + } + return false; + } + if (keycode == KC_SET_TIME && record->event.pressed) { + is_in_set_time = true; + new_time_index = 0; + } else if (is_in_set_time) { + if (!record->event.pressed && keycode >= KC_1 && keycode <= KC_0) { + new_time[new_time_index++] = (keycode == KC_0) ? 0 : keycode - KC_1 + 1; + if (new_time_index == 6) { + is_in_set_time = false; + ds1307_set_time( + (new_time[0]) * 10 + (new_time[1]), + (new_time[2]) * 10 + (new_time[3]), + (new_time[4]) * 10 + (new_time[5]) + ); + for (int i = 0; i < 6; i++) { + tap_code(KC_BSPACE); + } + } + } + } + + if (keycode == KC_LCTRL || keycode == KC_RCTRL) { + ctrl_pressed = record->event.pressed; + } else if (keycode == KC_LALT) { + alt_pressed = record->event.pressed; + } else if (keycode == KC_LSFT) { + shift_pressed = record->event.pressed; + } else if (keycode == KC_LGUI) { + gui_pressed = record->event.pressed; + } else if (keycode == KC_ALPHA) { + alpha_pressed = record->event.pressed; + } else if (keycode == KC_BETA) { + beta_pressed = record->event.pressed; + } + + if (keycode == RESET) { + rgblight_setrgb(255, 255, 0); + } +#ifdef LIGHTMODE_ENABLE + if (record->event.pressed && keycode == KC_LIGHT_MODE) { + next_light_mode(layer_colors[_MAIN]); + } +#endif + if (keycode == KC_LCTRL) { + /* Some Overlay1_Enable fuckery! */ + (record->event.pressed ? register_code : unregister_code)(KC_LCTRL); + return false; + } + return taphold_process(keycode, record); +} + +layer_state_t layer_state_set_user(layer_state_t state) { +#ifdef LIGHTMODE_ENABLE + uint8_t layer = get_highest_layer(state); + update_light_mode(layer_colors[layer]); +#endif + return state; +} + +void encoder_update_user(uint8_t index, bool clockwise) { + if (index == 0) { + if (!alpha_pressed) { + tap_code(clockwise ? KC_VOLD : KC_VOLU); + } else { + tap_code(clockwise ? KC_MPRV : KC_MNXT); + } + } else if (index == 1) { + if (!alpha_pressed) { + tap_code(clockwise ? KC_UP : KC_DOWN); + } else { + tap_code(clockwise ? KC_PGUP : KC_PGDN); + } + } +} + +#ifdef OLED_DRIVER_ENABLE +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + return OLED_ROTATION_0; +} + +void oled_task_user(void) { + /* Host Keyboard Layer Status */ + uint8_t current_layer = get_highest_layer(layer_state); + + /* Layer */ + static const char PROGMEM icons[4][3][6] = { + { + { 0x80, 0x81, 0x82, 0x83, 0x84, 0 }, + { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0 }, + { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0 } + }, + { + { 0x85, 0x86, 0x87, 0x88, 0x89, 0 }, + { 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0 }, + { 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0 } + }, + { + { 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0 }, + { 0xaa, 0xab, 0xac, 0xad, 0xae, 0 }, + { 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0 } + }, + { + { 0x8f, 0x90, 0x91, 0x92, 0x93, 0 }, + { 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0 }, + { 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0 } + } + }; + + uint8_t icon_index = current_layer == _MAIN ? 3 : current_layer == _ALPHA ? 1 : 2; + for (int i = 0; i < 3; i++) { + oled_set_cursor(0, i + 1); + oled_write_P(icons[icon_index][i], false); + } + + /* Time */ + oled_set_cursor(6, 0); + // oled_write_P(PSTR("-D48 Custom-\n"), false); + char buf[16]; + sprintf( + buf, + "%02d:%02d:%02d", hours, minutes, seconds + ); + oled_write(buf, false); + + /* Modifiers */ + static const char PROGMEM mods[][2] = { + {0x94, 0x95}, // CTL + {0x96, 0x97}, // ALT + {0x98, 0x99}, // GUI + {0x9a, 0x9b}, // SFT + /* {0x9c, 0x9d}, // EMPTY */ + }; + + char mod_data[13] = "\x9c\x9d\x9c\x9d\x9c\x9d\x9c\x9d \x07\x07\x07\0"; + if (ctrl_pressed) strncpy(mod_data, mods[0], 2); + if (alt_pressed) strncpy(mod_data + 2, mods[1], 2); + if (gui_pressed) strncpy(mod_data + 4, mods[2], 2); + if (shift_pressed) strncpy(mod_data + 6, mods[3], 2); + led_t led_usb_state = host_keyboard_led_state(); + if (led_usb_state.num_lock) mod_data[9] = 'N'; + if (led_usb_state.caps_lock) mod_data[10] = 'C'; + if (led_usb_state.scroll_lock) mod_data[11] = 'S'; + + oled_set_cursor(6, 1); + oled_write(mod_data, false); + + /* Matrix */ + static const char PROGMEM matrix_chars[] = { + 0xb4, // None + 0xb5, // Upper + 0xb6, // Lower + 0xb7 // Both + }; + + for (uint8_t row = 1; row < MATRIX_ROWS; row += 2) { + // Skip first row because it's used by the encoders. + uint16_t bits1 = matrix_get_row(row); + uint16_t bits2 = matrix_get_row(row + 1); + + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + uint8_t matrix_char = matrix_chars[((bits1 & (1 << col)) ? 1 : 0) | ((bits2 & (1 << col)) ? 2 : 0)]; + oled_set_cursor(6 + col, 2 + (row - 1) / 2); + oled_write_char(matrix_char, false); + } + } + +} +#endif diff --git a/keyboards/handwired/d48/keymaps/anderson/lightmode.c b/keyboards/handwired/d48/keymaps/anderson/lightmode.c new file mode 100644 index 000000000000..bc059562144c --- /dev/null +++ b/keyboards/handwired/d48/keymaps/anderson/lightmode.c @@ -0,0 +1,44 @@ +#include "lightmode.h" + +#ifdef LIGHTMODE_ENABLE + +/* Light modes switcher */ + +uint8_t light_mode = SMOOTHLED; + +void set_light_mode(light_mode_t value, uint32_t color) { + light_mode = value; + if (light_mode == SMOOTHLED) { + smoothled_set(color); + } else { + dmc12_start(color, true); + } +} + +void process_light_mode(void) { + if (light_mode == SMOOTHLED) { + smoothled_process(); + } else { + dmc12_process(); + } +} + +void update_light_mode(uint32_t color) { + if (light_mode == SMOOTHLED) { + smoothled_set(color); + } else { + dmc12_start(color, false); + } +} + +void next_light_mode(uint32_t color) { + light_mode = (light_mode + 1) % LIGHT_MODE_SIZE; + set_light_mode(light_mode, color); +} + +void matrix_scan_kb(void) { + process_light_mode(); + matrix_scan_user(); +} + +#endif diff --git a/keyboards/handwired/d48/keymaps/anderson/lightmode.h b/keyboards/handwired/d48/keymaps/anderson/lightmode.h new file mode 100644 index 000000000000..0c81e476bbe1 --- /dev/null +++ b/keyboards/handwired/d48/keymaps/anderson/lightmode.h @@ -0,0 +1,12 @@ +#include "smoothled.h" +#include "dmc12.h" +#include "quantum.h" + +/* Light modes */ +enum light_mode_enum { SMOOTHLED, DMC12, LIGHT_MODE_SIZE }; +typedef enum light_mode_enum light_mode_t; + +void set_light_mode(light_mode_t value, uint32_t color); +void process_light_mode(void); +void update_light_mode(uint32_t color); +void next_light_mode(uint32_t color); diff --git a/keyboards/handwired/d48/keymaps/anderson/rules.mk b/keyboards/handwired/d48/keymaps/anderson/rules.mk new file mode 100644 index 000000000000..e925b9a89f7d --- /dev/null +++ b/keyboards/handwired/d48/keymaps/anderson/rules.mk @@ -0,0 +1,2 @@ +OPT_DEFS += -DLIGHTMODE_ENABLE +SRC += smoothled.c dmc12.c seq.c lightmode.c diff --git a/keyboards/handwired/d48/keymaps/default/keymap.c b/keyboards/handwired/d48/keymaps/default/keymap.c new file mode 100644 index 000000000000..b7914f3bcd5b --- /dev/null +++ b/keyboards/handwired/d48/keymaps/default/keymap.c @@ -0,0 +1,285 @@ +#include QMK_KEYBOARD_H +#include +#include +#include "taphold.h" +#include "ds1307.h" + +/* Note: don't forget there's some more code in qmk_firmware/users/anderson dir */ + +#define _MAIN 0 +#define _ALPHA 1 +#define _BETA 2 + +enum custom_keycodes { + KC_MAIN = SAFE_RANGE, + KC_ALPHA, + KC_BETA, + KC_SET_TIME, +}; + +/* TapHold is my own implementation of the `LT` macro. It's processed in `process_record_user()`. */ +#define TAPHOLD_CONFIG_SIZE 3 +taphold_t taphold_config[TAPHOLD_CONFIG_SIZE] = { + {.key=KC_ALPHA, .mode=TAPHOLD_LAYER, .shortAction=KC_ESC, .longAction=_ALPHA}, + {.key=KC_BETA, .mode=TAPHOLD_LAYER, .shortAction=KC_EQL, .longAction=_BETA}, + {.key=KC_RCTRL, .mode=TAPHOLD_MOD, .shortAction=KC_MINS, .longAction=KC_LCTRL}, +}; +uint16_t taphold_config_size = TAPHOLD_CONFIG_SIZE; +uint32_t taphold_timeout = 90; + +/* Colors */ +uint32_t layer_colors[3] = { + [_MAIN] = 0xFF0010, + [_ALPHA] = 0x4020FF, + [_BETA] = 0x20FF00, +}; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* Main layer + │MUTE │ │L_MOD│ + ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓ + ┃ TAB ┃ Q │ W │ E │ R │ T ┃ Y │ U │ I │ O │ P ┃ BSP ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃𝛼/ESC┃ A │ S │ D │ F │ G ┃ H │ J │ K │ L │ ; ┃ RET ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃SHIFT┃ Z │ X │ C │ V │ B ┃ N │ M │ , │ . │ / ┃CTL/-┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃LCTRL┃ │ │ ALT │ GUI │SPACE┃SPACE│ 𝛽/= │ ' │ │ ┃ \ ┃ + ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛ + */ + [_MAIN] = LAYOUT( \ + KC_MUTE, _______, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \ + KC_ALPHA,KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RCTRL,\ + KC_LCTRL,_______, _______, KC_LALT, KC_LGUI, KC_SPC, KC_SPC, KC_BETA, KC_QUOT, _______, _______, KC_BSLS \ + ), + + /* Alpha layer (𝛼) + │ │ │ │ + ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓ + ┃ ┃PREV │PLAY │NEXT │ │NUMLK┃ - │ ^^^ │ ^ │ vvv │ ~ ┃ DEL ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃ │VOL -│VOL +│ │CPSLK┃HOME │ <-- │ v │ --> │ ` ┃ \ ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃ │ │ │ │SCRLK┃ END │ = │ [ │ ] │ ( ┃ ) ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃ │ │ │ │ ┃ │ │ │ │ ┃ ┃ + ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛ + */ + [_ALPHA] = LAYOUT( \ + _______, _______, \ + _______, KC_MPRV, KC_MPLY, KC_MNXT, _______, KC_NLCK, KC_MINS, KC_PGUP, KC_UP, KC_PGDN, KC_TILD, KC_DEL, \ + _______, _______, KC_VOLD, KC_VOLU, _______, KC_CAPS, KC_HOME, KC_LEFT, KC_DOWN, KC_RIGHT,KC_GRV, KC_BSLS, \ + _______, _______, _______, _______, _______, KC_SLCK, KC_END, KC_EQL, KC_LBRC, KC_RBRC, KC_LPRN ,KC_RPRN, \ + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \ + ), + + /* Beta layer (𝛽) + │ │ │ │ + ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓ + ┃ RGB ┃ 1 │ 2 │ 3 │ 4 │ 5 ┃ 6 │ 7 │ 8 │ 9 │ 0 ┃ F12 ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃L_MOD┃ F1 │ F2 │ F3 │ F4 │ F5 ┃ F6 │ F7 │ F8 │ F9 │ F10 ┃ F11 ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃RESET│DEBUG│ │ │TIME ┃SLEEP│ │ { │ } │PTSCR┃ ┃ + ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫ + ┃ ┃ │ │ │ │ ┃ │ │ │ │ ┃ ┃ + ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛ + */ + [_BETA] = LAYOUT( \ + _______, _______, \ + RGB_TOG, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_F12, + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, \ + _______, RESET, DEBUG, _______, _______, KC_SET_TIME,KC_SLEP,_______,KC_LCBR,KC_RCBR, KC_PSCR, _______, \ + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \ + ) +}; + +static bool alpha_pressed = false; +static bool beta_pressed = false; + +static bool ctrl_pressed = false; +static bool alt_pressed = false; +static bool shift_pressed = false; +static bool gui_pressed = false; + +void keyboard_post_init_user(void) { + /* debug_enable = true; */ + /* debug_matrix = true; */ +} + +void eeconfig_init_user(void) { + set_unicode_input_mode(UC_LNX); +} + +static uint32_t last_update = 0; +static uint8_t hours, minutes, seconds; + +void matrix_scan_user(void) { + uint32_t now = timer_read32(); + if (now - last_update > 500) { + ds1307_get_time(&hours, &minutes, &seconds); + last_update = now; + } +} + +static bool is_in_set_time = false; +static char new_time[6]; +static uint8_t new_time_index = 0; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (keycode == KC_SET_TIME && record->event.pressed) { + is_in_set_time = true; + new_time_index = 0; + } else if (is_in_set_time) { + if (!record->event.pressed && keycode >= KC_1 && keycode <= KC_0) { + new_time[new_time_index++] = (keycode == KC_0) ? 0 : keycode - KC_1 + 1; + if (new_time_index == 6) { + is_in_set_time = false; + ds1307_set_time( + (new_time[0]) * 10 + (new_time[1]), + (new_time[2]) * 10 + (new_time[3]), + (new_time[4]) * 10 + (new_time[5]) + ); + for (int i = 0; i < 6; i++) { + tap_code(KC_BSPACE); + } + } + } + } + + if (keycode == KC_LCTRL || keycode == KC_RCTRL) { + ctrl_pressed = record->event.pressed; + } else if (keycode == KC_LALT) { + alt_pressed = record->event.pressed; + } else if (keycode == KC_LSFT) { + shift_pressed = record->event.pressed; + } else if (keycode == KC_LGUI) { + gui_pressed = record->event.pressed; + } else if (keycode == KC_ALPHA) { + alpha_pressed = record->event.pressed; + } else if (keycode == KC_BETA) { + beta_pressed = record->event.pressed; + } + + if (keycode == RESET) { + rgblight_setrgb(255, 255, 0); + } + if (keycode == KC_LCTRL) { + /* Some Overlay1_Enable fuckery! */ + (record->event.pressed ? register_code : unregister_code)(KC_LCTRL); + return false; + } + return taphold_process(keycode, record); +} + +void encoder_update_user(uint8_t index, bool clockwise) { + if (index == 0) { + if (!alpha_pressed) { + tap_code(clockwise ? KC_VOLD : KC_VOLU); + } else { + tap_code(clockwise ? KC_MPRV : KC_MNXT); + } + } else if (index == 1) { + if (!alpha_pressed) { + tap_code(clockwise ? KC_UP : KC_DOWN); + } else { + tap_code(clockwise ? KC_PGUP : KC_PGDN); + } + } +} + +#ifdef OLED_DRIVER_ENABLE +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + return OLED_ROTATION_0; +} + +void oled_task_user(void) { + /* Host Keyboard Layer Status */ + uint8_t current_layer = get_highest_layer(layer_state); + + /* Layer */ + static const char PROGMEM icons[4][3][6] = { + { + { 0x80, 0x81, 0x82, 0x83, 0x84, 0 }, + { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0 }, + { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0 } + }, + { + { 0x85, 0x86, 0x87, 0x88, 0x89, 0 }, + { 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0 }, + { 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0 } + }, + { + { 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0 }, + { 0xaa, 0xab, 0xac, 0xad, 0xae, 0 }, + { 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0 } + }, + { + { 0x8f, 0x90, 0x91, 0x92, 0x93, 0 }, + { 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0 }, + { 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0 } + } + }; + + uint8_t icon_index = current_layer == _MAIN ? 3 : current_layer == _ALPHA ? 1 : 2; + for (int i = 0; i < 3; i++) { + oled_set_cursor(0, i + 1); + oled_write_P(icons[icon_index][i], false); + } + + /* Time */ + oled_set_cursor(6, 0); + // oled_write_P(PSTR("-D48 Custom-\n"), false); + char buf[16]; + sprintf( + buf, + "%02d:%02d:%02d", hours, minutes, seconds + ); + oled_write(buf, false); + + /* Modifiers */ + static const char PROGMEM mods[][2] = { + {0x94, 0x95}, // CTL + {0x96, 0x97}, // ALT + {0x98, 0x99}, // GUI + {0x9a, 0x9b}, // SFT + /* {0x9c, 0x9d}, // EMPTY */ + }; + + char mod_data[13] = "\x9c\x9d\x9c\x9d\x9c\x9d\x9c\x9d \x07\x07\x07\0"; + if (ctrl_pressed) strncpy(mod_data, mods[0], 2); + if (alt_pressed) strncpy(mod_data + 2, mods[1], 2); + if (gui_pressed) strncpy(mod_data + 4, mods[2], 2); + if (shift_pressed) strncpy(mod_data + 6, mods[3], 2); + led_t led_usb_state = host_keyboard_led_state(); + if (led_usb_state.num_lock) mod_data[9] = 'N'; + if (led_usb_state.caps_lock) mod_data[10] = 'C'; + if (led_usb_state.scroll_lock) mod_data[11] = 'S'; + + oled_set_cursor(6, 1); + oled_write(mod_data, false); + + /* Matrix */ + static const char PROGMEM matrix_chars[] = { + 0xb4, // None + 0xb5, // Upper + 0xb6, // Lower + 0xb7 // Both + }; + + for (uint8_t row = 1; row < MATRIX_ROWS; row += 2) { + // Skip first row because it's used by the encoders. + uint16_t bits1 = matrix_get_row(row); + uint16_t bits2 = matrix_get_row(row + 1); + + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + uint8_t matrix_char = matrix_chars[((bits1 & (1 << col)) ? 1 : 0) | ((bits2 & (1 << col)) ? 2 : 0)]; + oled_set_cursor(6 + col, 2 + (row - 1) / 2); + oled_write_char(matrix_char, false); + } + } + +} +#endif diff --git a/keyboards/handwired/d48/rules.mk b/keyboards/handwired/d48/rules.mk new file mode 100644 index 000000000000..57c83694e1d5 --- /dev/null +++ b/keyboards/handwired/d48/rules.mk @@ -0,0 +1,22 @@ +# MCU name +MCU = STM32F303 + +# Build Options +# change yes to no to disable +# +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration +MOUSEKEY_ENABLE = no # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = yes # Console for debug +COMMAND_ENABLE = no # Commands for debug and configuration +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend +NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +AUDIO_ENABLE = yes +USE_I2C = no +RGBLIGHT_ENABLE = yes +ENCODER_ENABLE = yes +OLED_DRIVER_ENABLE = yes +UNICODE_ENABLE = yes + +SRC += ds1307.c taphold.c diff --git a/keyboards/handwired/d48/taphold.c b/keyboards/handwired/d48/taphold.c new file mode 100644 index 000000000000..0b56a5a6a10e --- /dev/null +++ b/keyboards/handwired/d48/taphold.c @@ -0,0 +1,29 @@ +#include "taphold.h" + +bool taphold_process(uint16_t keycode, keyrecord_t *record) { + for (int i = 0; i < taphold_config_size; i++) { + taphold_t *config = &taphold_config[i]; + if (config->key == keycode && record->event.pressed) { + if (config->mode == TAPHOLD_LAYER) { + layer_on(config->longAction); + } else { + register_code(config->longAction); + } + config->time = timer_read32(); + config->keypos = record->event.key; + return false; + } else if (KEYEQ(record->event.key, config->keypos) && !record->event.pressed) { + if (config->mode == TAPHOLD_LAYER) { + layer_off(config->longAction); + } else { + unregister_code(config->longAction); + } + if (timer_elapsed32(config->time) < taphold_timeout) { + tap_code(config->shortAction); + } + config->keypos.row = 255; + return false; + } + } + return true; +} diff --git a/keyboards/handwired/d48/taphold.h b/keyboards/handwired/d48/taphold.h new file mode 100644 index 000000000000..3bc5ca02756d --- /dev/null +++ b/keyboards/handwired/d48/taphold.h @@ -0,0 +1,25 @@ +#include "quantum.h" + +typedef enum taphold_mode_t { + TAPHOLD_LAYER, + TAPHOLD_MOD +} taphold_mode_t; + +typedef struct taphold_t { + uint16_t key; + uint32_t time; + taphold_mode_t mode; + uint16_t shortAction; + uint16_t longAction; + keypos_t keypos; + // We store key pos to properly release the key + // even when a different layer is active and the key has a different action now +} taphold_t; + +extern taphold_t taphold_config[]; +extern uint16_t taphold_config_size; +// Dual keys tap/hold timeout. +// If key is tapped for less than this value, send key in addition to primary action after completing the action. +extern uint32_t taphold_timeout; + +bool taphold_process(uint16_t keycode, keyrecord_t *record); diff --git a/users/anderson/dmc12.c b/users/anderson/dmc12.c new file mode 100644 index 000000000000..1dd89dce418f --- /dev/null +++ b/users/anderson/dmc12.c @@ -0,0 +1,46 @@ +#include "dmc12.h" + +static uint32_t dmc12_color = 0; +static uint16_t dmc12_timer = 0; +static int8_t dmc12_current = 0; +static uint8_t dmc12_direction = 1; + +void dmc12_start(uint32_t color, bool reset) { + dmc12_color = color; + if (reset) { + dmc12_timer = 0; + dmc12_current = 0; + dmc12_direction = 1; + } +} + +void dmc12_process(void) { + if (!dmc12_timer) { + dmc12_timer = timer_read(); + return; + } + float dist_from_center = ((float)abs(dmc12_current - RGBLED_NUM / 2)) / ((float)RGBLED_NUM); + if (timer_elapsed(dmc12_timer) > dist_from_center * LED_INTERVAL) { + dmc12_current += dmc12_direction; + if (dmc12_current == 0 || dmc12_current == RGBLED_NUM - 1) { + dmc12_direction *= -1; + } + dmc12_timer = timer_read(); + for (int i = 0; i < RGBLED_NUM; i++) { + if (i > dmc12_current - LED_RADIUS && i < dmc12_current + LED_RADIUS) { + float intensity = (LED_RADIUS - abs(i - dmc12_current)) / ((float)LED_RADIUS); + if (i != dmc12_current) { + intensity /= 4.0; + } + rgblight_setrgb_at( + ((dmc12_color >> 16) & 0xFF) * intensity, + ((dmc12_color >> 8) & 0xFF) * intensity, + (dmc12_color & 0xFF) * intensity, + i + ); + } else { + rgblight_setrgb_at(0, 0, 0, i); + } + } + } +} diff --git a/users/anderson/dmc12.h b/users/anderson/dmc12.h new file mode 100644 index 000000000000..6b2bf94a518e --- /dev/null +++ b/users/anderson/dmc12.h @@ -0,0 +1,9 @@ +// Sexy LED animation. + +#include "quantum.h" + +#define LED_INTERVAL 160 +#define LED_RADIUS 6 + +void dmc12_start(uint32_t color, bool reset); +void dmc12_process(void); diff --git a/users/anderson/seq.c b/users/anderson/seq.c new file mode 100644 index 000000000000..ff506485990d --- /dev/null +++ b/users/anderson/seq.c @@ -0,0 +1,38 @@ +#include "seq.h" + +static char buffer[32]; +static uint8_t buffer_size = 0; + +void seq_start(void) { + buffer_size = 0; + SEND_STRING(":"); +} + +bool seq_feed(uint16_t keycode) { + if (keycode == KC_ENTER) { + for (int i = 0; i < buffer_size + 1; i++) { + tap_code(KC_BSPACE); + } + for (int i = 0; i < seq_config_size; i++) { + seq_t item = seq_config[i]; + if (strncmp(item.sequence, buffer, buffer_size) == 0) { + send_unicode_string(item.result); + } + } + buffer_size = 0; + return false; + } else if (keycode == KC_BSPACE) { + if (buffer_size) { + buffer_size--; + tap_code(keycode); + } + return true; + } else { + if (keycode >= KC_A && keycode <= KC_Z) { + buffer[buffer_size++] = keycode - KC_A + 'a'; + tap_code(keycode); + } + return true; + } +} + diff --git a/users/anderson/seq.h b/users/anderson/seq.h new file mode 100644 index 000000000000..2da4e761544a --- /dev/null +++ b/users/anderson/seq.h @@ -0,0 +1,14 @@ +#include "quantum.h" + +#include + +typedef struct seq_t { + const char *sequence; + const char *result; +} seq_t; + +extern seq_t seq_config[]; +extern uint16_t seq_config_size; + +void seq_start(void); +bool seq_feed(uint16_t keycode); diff --git a/users/anderson/smoothled.c b/users/anderson/smoothled.c new file mode 100644 index 000000000000..3af729563cc8 --- /dev/null +++ b/users/anderson/smoothled.c @@ -0,0 +1,34 @@ +#include + +static uint32_t sourceColor = 0x000000; +static uint32_t currentColor = 0x000000; +static uint32_t targetColor = 0x000000; +static int32_t smoothledTimer = -1; + +void smoothled_set(uint32_t color) { + smoothledTimer = timer_read32(); + sourceColor = currentColor; + targetColor = color; +} + +void smoothled_process(void) { + if (smoothledTimer < 0) { + return; + } + int32_t kb = timer_elapsed32(smoothledTimer); + int32_t ka = SMOOTH_DURATION - kb; + if (kb > SMOOTH_DURATION) { + kb = SMOOTH_DURATION; + ka = 0; + smoothledTimer = -1; + } + currentColor = 0; + for (int i = 2; i >= 0; i--) { + uint32_t shift = i * 8; + currentColor |= (ka * ((uint32_t)(sourceColor >> shift) & 0xFF) + kb * ((uint32_t)(targetColor >> shift) & 0xFF)) / SMOOTH_DURATION; + /*currentColor |= ((targetColor >> shift) & 0xFF);*/ + currentColor <<= 8; + } + currentColor >>= 8; + rgblight_setrgb((currentColor >> 16) & 0xFF, (currentColor >> 8) & 0xFF, currentColor & 0xFF); +} diff --git a/users/anderson/smoothled.h b/users/anderson/smoothled.h new file mode 100644 index 000000000000..bf4f8c17700e --- /dev/null +++ b/users/anderson/smoothled.h @@ -0,0 +1,6 @@ +#include "quantum.h" + +#define SMOOTH_DURATION 160 + +void smoothled_set(uint32_t color); +void smoothled_process(void);