From 138156d4a0be4470f9653d7191d152c16f0678fc Mon Sep 17 00:00:00 2001 From: Wilba6582 Date: Tue, 30 Jun 2015 17:35:18 +1000 Subject: [PATCH] Update for Atomic PCB Rev 0 --- keyboard/atomic/Makefile | 4 +- keyboard/atomic/backlight.c | 49 ++++++++++++++ keyboard/atomic/config.h | 4 ++ keyboard/atomic/keymap_common.h | 18 +++++- keyboard/atomic/keymap_grid.c | 40 ++++++++++++ keyboard/atomic/matrix.c | 109 +++++++++++++++++++------------- keyboard/planck/matrix_pcb.c | 14 ++-- 7 files changed, 184 insertions(+), 54 deletions(-) create mode 100644 keyboard/atomic/backlight.c create mode 100644 keyboard/atomic/keymap_grid.c diff --git a/keyboard/atomic/Makefile b/keyboard/atomic/Makefile index c4e0cb45d..0d5baa9fa 100644 --- a/keyboard/atomic/Makefile +++ b/keyboard/atomic/Makefile @@ -50,7 +50,8 @@ TARGET_DIR = . # project specific files SRC = keymap_common.c \ matrix.c \ - led.c + led.c \ + backlight.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) @@ -121,6 +122,7 @@ CONSOLE_ENABLE = yes # Console for debug(+400) COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality # Optimize size but this may cause error "relocation truncated to fit" diff --git a/keyboard/atomic/backlight.c b/keyboard/atomic/backlight.c new file mode 100644 index 000000000..06f103b4a --- /dev/null +++ b/keyboard/atomic/backlight.c @@ -0,0 +1,49 @@ + +#include +#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/config.h b/keyboard/atomic/config.h index 5ea953805..41f7bd8b9 100644 --- a/keyboard/atomic/config.h +++ b/keyboard/atomic/config.h @@ -34,6 +34,10 @@ along with this program. If not, see . /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST +/* number of backlight levels */ +/* NOTE: this is the max value of 0..BACKLIGHT_LEVELS so really 16 levels. */ +#define BACKLIGHT_LEVELS 15 + /* Set 0 if debouncing isn't needed */ #define DEBOUNCE 5 diff --git a/keyboard/atomic/keymap_common.h b/keyboard/atomic/keymap_common.h index c582c0135..cfb0cb361 100644 --- a/keyboard/atomic/keymap_common.h +++ b/keyboard/atomic/keymap_common.h @@ -80,7 +80,23 @@ extern const uint16_t fn_actions[]; // MLO: Semi-Grid layout -// KLN: Grid layout +// 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_##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 } \ +} + + // PKR: Standard layout diff --git a/keyboard/atomic/keymap_grid.c b/keyboard/atomic/keymap_grid.c new file mode 100644 index 000000000..9d42272e6 --- /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 98102cb69..fd233ff53 100644 --- a/keyboard/atomic/matrix.c +++ b/keyboard/atomic/matrix.c @@ -59,6 +59,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<