diff options
Diffstat (limited to 'keyboard/atomic')
-rw-r--r-- | keyboard/atomic/Makefile | 2 | ||||
-rw-r--r-- | keyboard/atomic/backlight.c | 49 | ||||
-rw-r--r-- | keyboard/atomic/keymap_common.h | 25 | ||||
-rw-r--r-- | keyboard/atomic/keymap_grid.c | 40 | ||||
-rw-r--r-- | keyboard/atomic/matrix.c | 94 |
5 files changed, 166 insertions, 44 deletions
diff --git a/keyboard/atomic/Makefile b/keyboard/atomic/Makefile index 12351b990b..ed1d331766 100644 --- a/keyboard/atomic/Makefile +++ b/keyboard/atomic/Makefile @@ -47,8 +47,6 @@ TOP_DIR = ../.. # Directory keyboard dependent files exist TARGET_DIR = . - - # # project specific files ifdef COMMON diff --git a/keyboard/atomic/backlight.c b/keyboard/atomic/backlight.c new file mode 100644 index 0000000000..06f103b4ac --- /dev/null +++ b/keyboard/atomic/backlight.c @@ -0,0 +1,49 @@ + +#include <avr/io.h> +#include "backlight.h" + +#define CHANNEL OCR1C + +void backlight_init_ports() +{ + + // Setup PB7 as output and output low. + DDRB |= (1<<7); + PORTB &= ~(1<<7); + + // Use full 16-bit resolution. + ICR1 = 0xFFFF; + + // I could write a wall of text here to explain... but TL;DW + // Go read the ATmega32u4 datasheet. + // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on + + // Pin PB7 = OCR1C (Timer 1, Channel C) + // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 + // (i.e. start high, go low when counter matches.) + // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 + // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 + + TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; + TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; + + backlight_init(); +} + +void backlight_set(uint8_t level) +{ + if ( level == 0 ) + { + // Turn off PWM control on PB7, revert to output low. + TCCR1A &= ~(_BV(COM1C1)); + // CHANNEL = level << OFFSET | 0x0FFF; + CHANNEL = ((1 << level) - 1); + } + else + { + // Turn on PWM control of PB7 + TCCR1A |= _BV(COM1C1); + // CHANNEL = level << OFFSET | 0x0FFF; + CHANNEL = ((1 << level) - 1); + } +}
\ No newline at end of file diff --git a/keyboard/atomic/keymap_common.h b/keyboard/atomic/keymap_common.h index 4a0bcfbb08..7c167eb51a 100644 --- a/keyboard/atomic/keymap_common.h +++ b/keyboard/atomic/keymap_common.h @@ -110,19 +110,20 @@ extern const uint16_t fn_actions[]; #define KEYMAP_AND_SWAP(args...) KEYMAP(args), KEYMAP_SWAP(args) -/* - Keymap for the Planck 48 key variant. - */ -#define KEYMAP_48( \ - K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, 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 \ +// GRD: Grid layout + +#define KEYMAP_GRD( \ + K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, \ + K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \ + K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, \ + K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E, \ + K40, K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B, K4C, K4D, K4E \ ) { \ - { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B }, \ - { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B }, \ - { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B }, \ - { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B }, \ + { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E }, \ + { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E }, \ + { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E }, \ + { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E }, \ + { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47, KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E } \ } diff --git a/keyboard/atomic/keymap_grid.c b/keyboard/atomic/keymap_grid.c new file mode 100644 index 0000000000..9d42272e64 --- /dev/null +++ b/keyboard/atomic/keymap_grid.c @@ -0,0 +1,40 @@ +#include "keymap_common.h" + +// GRD: Grid layout + +const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = KEYMAP_GRD(FN29, FN30, FN31, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSLS, GRV, \ + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC, RBRC, BSPC, DEL, \ + CAPS, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, ENT, PGUP, \ + LSFT, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, RSFT, UP, PGDN, \ + LCTL, LALT, LGUI, SPC, SPC, SPC, SPC, SPC, SPC, RALT, APP, RCTL, LEFT, DOWN, RGHT), \ + +}; +const uint16_t PROGMEM fn_actions[] = { + [1] = ACTION_LAYER_MOMENTARY(2), // to Fn overlay + [3] = ACTION_DEFAULT_LAYER_SET(0), + [4] = ACTION_DEFAULT_LAYER_SET(1), + + [9] = ACTION_MODS_KEY(MOD_LSFT | MOD_RSFT, KC_PAUSE), + + [10] = ACTION_MODS_KEY(MOD_LSFT, KC_1), + [11] = ACTION_MODS_KEY(MOD_LSFT, KC_2), + [12] = ACTION_MODS_KEY(MOD_LSFT, KC_3), + [13] = ACTION_MODS_KEY(MOD_LSFT, KC_4), + [14] = ACTION_MODS_KEY(MOD_LSFT, KC_5), + [15] = ACTION_MODS_KEY(MOD_LSFT, KC_6), + [16] = ACTION_MODS_KEY(MOD_LSFT, KC_7), + [17] = ACTION_MODS_KEY(MOD_LSFT, KC_8), + [18] = ACTION_MODS_KEY(MOD_LSFT, KC_9), + [19] = ACTION_MODS_KEY(MOD_LSFT, KC_0), + [20] = ACTION_MODS_KEY(MOD_LSFT, KC_MINS), + [21] = ACTION_MODS_KEY(MOD_LSFT, KC_EQL), + [22] = ACTION_MODS_KEY(MOD_LSFT, KC_GRV), + [23] = ACTION_MODS_KEY(MOD_LSFT, KC_LBRC), + [24] = ACTION_MODS_KEY(MOD_LSFT, KC_RBRC), + [28] = ACTION_MODS_KEY(MOD_LSFT, KC_BSLS), + + [29] = ACTION_BACKLIGHT_TOGGLE(), + [30] = ACTION_BACKLIGHT_INCREASE(), + [31] = ACTION_BACKLIGHT_DECREASE() +}; diff --git a/keyboard/atomic/matrix.c b/keyboard/atomic/matrix.c index 2f2dbdb108..01f66e90fb 100644 --- a/keyboard/atomic/matrix.c +++ b/keyboard/atomic/matrix.c @@ -57,6 +57,16 @@ uint8_t matrix_cols(void) void matrix_init(void) { + // To use PORTF disable JTAG with writing JTD bit twice within four cycles. + MCUCR |= (1<<JTD); + MCUCR |= (1<<JTD); + + backlight_init_ports(); + + // Turn status LED on + DDRE |= (1<<6); + PORTE |= (1<<6); + // initialize row and col unselect_rows(); init_cols(); @@ -134,60 +144,84 @@ uint8_t matrix_key_count(void) return count; } +// +// Atomic PCB Rev 0 Pin Assignments +// +// Column: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 +// Pin: F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7, D3, D2, D1 +// + static void init_cols(void) { - DDRB &= ~(1<<6 | 1<<5 | 1<<4); - PORTB |= (1<<6 | 1<<5 | 1<<4); - DDRD &= ~(1<<7 | 1<<6 | 1<<4); - PORTD |= (1<<7 | 1<<6 | 1<<4); + DDRB &= ~(1<<4 | 1<<0); + PORTB |= (1<<4 | 1<<0); + DDRC &= ~(1<<7); + PORTC |= (1<<7); + DDRD &= ~(1<<7 | 1<<6 | 1<<4 | 1<<3 | 1<<2 | 1<<1); + PORTD |= (1<<7 | 1<<6 | 1<<4 | 1<<3 | 1<<2 | 1<<1); DDRF &= ~(1<<0 | 1<<1 | 1<<4 | 1<<5 | 1<<6 | 1<<7); PORTF |= (1<<0 | 1<<1 | 1<<4 | 1<<5 | 1<<6 | 1<<7); - } static matrix_row_t read_cols(void) { - return (PIND&(1<<4) ? 0 : (1<<0)) | - (PIND&(1<<6) ? 0 : (1<<1)) | - (PIND&(1<<7) ? 0 : (1<<2)) | - (PINB&(1<<4) ? 0 : (1<<3)) | - (PINB&(1<<5) ? 0 : (1<<4)) | - (PINB&(1<<6) ? 0 : (1<<5)) | - (PINF&(1<<7) ? 0 : (1<<6)) | - (PINF&(1<<6) ? 0 : (1<<7)) | - (PINF&(1<<5) ? 0 : (1<<8)) | - (PINF&(1<<4) ? 0 : (1<<9)) | - (PINF&(1<<1) ? 0 : (1<<10)) | - (PINF&(1<<0) ? 0 : (1<<11)); - + return (PINF&(1<<1) ? 0 : (1<<0)) | + (PINF&(1<<0) ? 0 : (1<<1)) | + (PINB&(1<<0) ? 0 : (1<<2)) | + (PINC&(1<<7) ? 0 : (1<<3)) | + (PINF&(1<<4) ? 0 : (1<<4)) | + (PINF&(1<<5) ? 0 : (1<<5)) | + (PINF&(1<<6) ? 0 : (1<<6)) | + (PINF&(1<<7) ? 0 : (1<<7)) | + (PIND&(1<<4) ? 0 : (1<<8)) | + (PIND&(1<<6) ? 0 : (1<<9)) | + (PINB&(1<<4) ? 0 : (1<<10)) | + (PIND&(1<<7) ? 0 : (1<<11)) | + (PIND&(1<<3) ? 0 : (1<<12)) | + (PIND&(1<<2) ? 0 : (1<<13)) | + (PIND&(1<<1) ? 0 : (1<<14)); } + +// +// Atomic PCB Rev 0 Pin Assignments +// +// Row: 0, 1, 2, 3, 4 +// Pin: D0, D5, B5, B6, C6 +// + static void unselect_rows(void) { - DDRB &= ~(1<<0 | 1<<1 | 1<<2 | 1<<3); - PORTB |= (1<<0 | 1<<1 | 1<<2 | 1<<3); - + DDRB &= ~(1<<5 | 1<<6); + PORTB |= (1<<5 | 1<<6); + DDRD &= ~(1<<0 | 1<<5); + PORTD |= (1<<0 | 1<<5); + DDRC &= ~(1<<6); + PORTC |= (1<<6); } static void select_row(uint8_t row) { switch (row) { case 0: - DDRB |= (1<<0); - PORTB &= ~(1<<0); + DDRD |= (1<<0); + PORTD &= ~(1<<0); break; case 1: - DDRB |= (1<<1); - PORTB &= ~(1<<1); + DDRD |= (1<<5); + PORTD &= ~(1<<5); break; case 2: - DDRB |= (1<<2); - PORTB &= ~(1<<2); + DDRB |= (1<<5); + PORTB &= ~(1<<5); break; case 3: - DDRB |= (1<<3); - PORTB &= ~(1<<3); + DDRB |= (1<<6); + PORTB &= ~(1<<6); break; - + case 4: + DDRC |= (1<<6); + PORTC &= ~(1<<6); + break; } } |