summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilba6582 <Jason.S.Wiliams@gmail.com>2015-06-30 17:35:18 +1000
committerWilba6582 <Jason.S.Wiliams@gmail.com>2015-06-30 17:35:18 +1000
commit138156d4a0be4470f9653d7191d152c16f0678fc (patch)
treee42a7f3e9741d4f31b5e902681b76173990aab71
parentefe8304e7977eb23a6738b047fb64aa2e08f7636 (diff)
downloadqmk_firmware-138156d4a0be4470f9653d7191d152c16f0678fc.tar.gz
qmk_firmware-138156d4a0be4470f9653d7191d152c16f0678fc.zip
Update for Atomic PCB Rev 0
-rw-r--r--keyboard/atomic/Makefile4
-rw-r--r--keyboard/atomic/backlight.c49
-rw-r--r--keyboard/atomic/config.h4
-rw-r--r--keyboard/atomic/keymap_common.h18
-rw-r--r--keyboard/atomic/keymap_grid.c40
-rw-r--r--keyboard/atomic/matrix.c109
-rw-r--r--keyboard/planck/matrix_pcb.c14
7 files changed, 184 insertions, 54 deletions
diff --git a/keyboard/atomic/Makefile b/keyboard/atomic/Makefile
index c4e0cb45d7..0d5baa9fa1 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 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/config.h b/keyboard/atomic/config.h
index 5ea953805f..41f7bd8b9f 100644
--- a/keyboard/atomic/config.h
+++ b/keyboard/atomic/config.h
@@ -34,6 +34,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* 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 c582c0135f..cfb0cb3611 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 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 98102cb694..fd233ff53f 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<<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();
@@ -137,75 +147,84 @@ uint8_t matrix_key_count(void)
return count;
}
-/* Column pin configuration
- * col: 0 1 2 3 4 5 6 7 8 9 10 11
- * pin: F0 F1 F4 F5 F6 F7 B6 B5 B4 D7 D5 D4
- */
+//
+// 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)
{
- DDRC &= ~(1<<6 | 1<<7);
- PORTC |= (1<<6 | 1<<7);
- DDRD &= ~(1<<4 | 1<<5 | 1<<6 | 1<<7);
- PORTD |= (1<<4 | 1<<5 | 1<<6 | 1<<7);
- DDRB &= ~(1<<4 | 1<<5 | 1<<6);
- PORTB |= (1<<4 | 1<<5 | 1<<6);
- 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);
+ 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 (PINC&(1<<6) ? 0 : (1<< 0)) |
- (PINC&(1<<7) ? 0 : (1<< 1)) |
- (PIND&(1<<5) ? 0 : (1<< 2)) |
- (PIND&(1<<4) ? 0 : (1<< 3)) |
- (PIND&(1<<6) ? 0 : (1<< 4)) |
- (PIND&(1<<7) ? 0 : (1<< 5)) |
- (PINB&(1<<4) ? 0 : (1<< 6)) |
- (PINB&(1<<5) ? 0 : (1<< 7)) |
- (PINB&(1<<6) ? 0 : (1<< 8)) |
- (PINF&(1<<7) ? 0 : (1<< 9)) |
- (PINF&(1<<6) ? 0 : (1<<10)) |
- (PINF&(1<<5) ? 0 : (1<<11)) |
- (PINF&(1<<4) ? 0 : (1<<12)) |
- (PINF&(1<<1) ? 0 : (1<<13)) |
- (PINF&(1<<0) ? 0 : (1<<14));
+ 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));
}
-/* Row pin configuration
- * row: 0 1 2 3
- * pin: B0 B1 B2 B3
- */
+
+//
+// Atomic PCB Rev 0 Pin Assignments
+//
+// Row: 0, 1, 2, 3, 4
+// Pin: D0, D5, B5, B6, C6
+//
+
static void unselect_rows(void)
{
- // Hi-Z(DDR:0, PORT:0) to unselect
- DDRB &= ~(1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<7);
- PORTB |= (1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<7);
+ 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:
- DDRB |= (1<<7);
- PORTB &= ~(1<<7);
- break;
+ DDRC |= (1<<6);
+ PORTC &= ~(1<<6);
+ break;
}
}
diff --git a/keyboard/planck/matrix_pcb.c b/keyboard/planck/matrix_pcb.c
index 7d46baf3de..11a7376d86 100644
--- a/keyboard/planck/matrix_pcb.c
+++ b/keyboard/planck/matrix_pcb.c
@@ -182,6 +182,13 @@ static matrix_row_t read_cols(void)
}
+//
+// Planck PCB Rev 1 Pin Assignments
+//
+// Row: 0, 1, 2, 3
+// Pin: D0, D5, B5, B6
+//
+
static void unselect_rows(void)
{
DDRB &= ~(1<<5 | 1<<6);
@@ -191,13 +198,6 @@ static void unselect_rows(void)
}
-//
-// Planck PCB Rev 1 Pin Assignments
-//
-// Row: 0, 1, 2, 3
-// Pin: D0, D5, B5, B6
-//
-
static void select_row(uint8_t row)
{
switch (row) {