Skip to content

Commit

Permalink
[Keyboard] Added D48 keyboard (qmk#8548)
Browse files Browse the repository at this point in the history
* [Keyboard] Added D48 keyboard.

* Updated README.

* Cleanups.

* Moved d48 to handwired/

* Added link to build process album.

* Coding conventions cleanups.

* Added DS1307 RTC!

* Minor cleanups.

* Apply suggestions from code review

Co-Authored-By: Drashna Jaelre <[email protected]>

* Minor refactoring.

* Readme fix.

* Moved leftover keymap-specific code from keyboard space into keymap.

* Added encoder button pins to extra matrix row.

* Updated README, updated pinout & cleaned up the glcdfont

* Apply suggestions from code review

Co-Authored-By: Drashna Jaelre <[email protected]>

* Update config.h

* Apply suggestions from code review

Co-Authored-By: Ryan <[email protected]>

* Added default keymap. Refactored existing keymap.

* Update keyboards/handwired/d48/README.md

Co-Authored-By: Ryan <[email protected]>

* Apply suggestions from code review

Co-Authored-By: Joel Challis <[email protected]>

* Minor alignment fix.

* Update keyboards/handwired/d48/glcdfont_d48.c

Co-Authored-By: Ryan <[email protected]>

* Changes as per PR.

* Apply suggestions from code review

Co-authored-by: James Young <[email protected]>

Co-authored-by: Drashna Jaelre <[email protected]>
Co-authored-by: Ryan <[email protected]>
Co-authored-by: Joel Challis <[email protected]>
Co-authored-by: James Young <[email protected]>
  • Loading branch information
5 people authored and sowbug committed May 24, 2020
1 parent edcaea7 commit 33b52a4
Show file tree
Hide file tree
Showing 21 changed files with 1,348 additions and 0 deletions.
87 changes: 87 additions & 0 deletions keyboards/handwired/d48/README.md
Original file line number Diff line number Diff line change
@@ -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 I<sup>2</sup>C OLED
- Small buzzer mounted inside (still waiting for the AST1109MLTRQ boys)
- WS2812 strip (14 LEDs)
- DS1307 I<sup>2</sup>C 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.

## I<sup>2</sup>C/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 I<sup>2</sup>C and for some reason
there are 2 pairs of SDA/SCL for I<sup>2</sup>C<sup>1</sup> 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 I<sup>2</sup> 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!
77 changes: 77 additions & 0 deletions keyboards/handwired/d48/config.h
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions keyboards/handwired/d48/d48.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "d48.h"
19 changes: 19 additions & 0 deletions keyboards/handwired/d48/d48.h
Original file line number Diff line number Diff line change
@@ -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 } \
}
21 changes: 21 additions & 0 deletions keyboards/handwired/d48/ds1307.c
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 6 additions & 0 deletions keyboards/handwired/d48/ds1307.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <stdint.h>

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);
Loading

0 comments on commit 33b52a4

Please sign in to comment.