Update for Atomic PCB Rev 0

This commit is contained in:
Wilba6582 2015-06-30 17:35:18 +10:00
parent efe8304e79
commit 138156d4a0
7 changed files with 184 additions and 54 deletions

View File

@ -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"

View File

@ -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);
}
}

View File

@ -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

View File

@ -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

View File

@ -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()
};

View File

@ -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;
}
}

View File

@ -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) {