abstracted led handling -- PCB changes done
- added high-level (logical) led macros, so that the top level firmware doens't need to know what numbers leds are (or how many there are) - left low-level (processor specific) led macros in keyboard/.../teensy-2-0.h , where they were - put non processor|layout specific led macros in keyboard/.../led.h - put layout specific led macros into keyboard/.../layout/*.h (with default empty macro definitions in keyboard/.../layout.h) also - cleaned up some typos and such - moved the debounce time macro to 'keyboard/ergodox.h', since it's technically keyboard (keyswitch) specific aggregate changes for PCB update - documentation updated to reflect that the columns are now the driving pins, and the columns are the read pins. both are still treated as open drain. - macros for led pins 1 and 2 were swapped - update functions now cycle through columns->low, read rows - added a matrix macro to map from how we want the key layouts represented, to how things are scanned into the matrixf13
parent
4972c81a96
commit
9c86906f7f
|
@ -14,10 +14,22 @@
|
|||
#include "lib/data-types.h"
|
||||
|
||||
#include "ergodox/layout.h" // number of layers, layout
|
||||
#include "ergodox/led.h" // logical led controls
|
||||
#include "ergodox/matrix.h" // kb dimensions, matrix status
|
||||
#include "ergodox/mcp23018.h" // (nothing right now)
|
||||
#include "ergodox/teensy-2-0.h" // LED controls
|
||||
|
||||
|
||||
// note:
|
||||
// - see your keyswitch specification for the necessary value. for
|
||||
// cherry mx switches, the switch bounce time is speced to be <= 5ms.
|
||||
// it looks like most switches are speced to be between 5 and 8 ms.
|
||||
// - if timing is important, balance this value with the main() loop
|
||||
// run time (~5ms, last i checked, nearly all of it in the i2c
|
||||
// update() function)
|
||||
#define KB_DEBOUNCE_TIME 5 // in ms
|
||||
|
||||
|
||||
uint8_t kb_init(void);
|
||||
uint8_t kb_update_matrix(bool matrix[KB_ROWS][KB_COLUMNS]);
|
||||
|
||||
|
|
|
@ -86,5 +86,38 @@
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
// default logical LED macros (all defined to nothing)
|
||||
#ifndef kb_led_num_on
|
||||
#define kb_led_num_on()
|
||||
#endif
|
||||
#ifndef kb_led_num_off
|
||||
#define kb_led_num_off()
|
||||
#endif
|
||||
#ifndef kb_led_caps_on
|
||||
#define kb_led_caps_on()
|
||||
#endif
|
||||
#ifndef kb_led_caps_off
|
||||
#define kb_led_caps_off()
|
||||
#endif
|
||||
#ifndef kb_led_scroll_on
|
||||
#define kb_led_scroll_on()
|
||||
#endif
|
||||
#ifndef kb_led_scroll_off
|
||||
#define kb_led_scroll_off()
|
||||
#endif
|
||||
#ifndef kb_led_compose_on
|
||||
#define kb_led_compose_on()
|
||||
#endif
|
||||
#ifndef kb_led_compose_off
|
||||
#define kb_led_compose_off()
|
||||
#endif
|
||||
#ifndef kb_led_kana_on
|
||||
#define kb_led_kana_on()
|
||||
#endif
|
||||
#ifndef kb_led_kana_off
|
||||
#define kb_led_kana_off()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
uint8_t PROGMEM _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
|
||||
LAYER( // layer 0: default
|
||||
// unused
|
||||
0,
|
||||
// left hand
|
||||
_grave, _1, _2, _3, _4, _5, _equal,
|
||||
_tab, _Q, _W, _E, _R, _T, _esc,
|
||||
|
@ -49,11 +51,11 @@ _altR, _pageU, _pageD )
|
|||
|
||||
|
||||
kbfun_funptr_t PROGMEM _kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
|
||||
LAYER_SET_ALL(&kbfun_press); // layer 0: default
|
||||
LAYER_SET_ALL(NULL, &kbfun_press) // layer 0: default
|
||||
};
|
||||
|
||||
|
||||
kbfun_funptr_t PROGMEM _kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
|
||||
LAYER_SET_ALL(&kbfun_release); // layer 0: default
|
||||
LAYER_SET_ALL(NULL, &kbfun_release) // layer 0: default
|
||||
};
|
||||
|
||||
|
|
|
@ -10,8 +10,17 @@
|
|||
#ifndef LAYOUT_QWERTY_h
|
||||
#define LAYOUT_QWERTY_h
|
||||
|
||||
#define KB_LAYERS 1 // must match what's defined in the layout '.c'
|
||||
// file
|
||||
#include "../led.h"
|
||||
|
||||
|
||||
#define KB_LAYERS 1 // must match what's defined in "qwerty.c"
|
||||
|
||||
#define kb_led_num_on() _led_1_on()
|
||||
#define kb_led_num_off() _led_1_off()
|
||||
#define kb_led_caps_on() _led_2_on()
|
||||
#define kb_led_caps_off() _led_2_off()
|
||||
#define kb_led_scroll_on() _led_3_on()
|
||||
#define kb_led_scroll_off() _led_3_off()
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* led stuff that isn't microprocessor or layout specific
|
||||
*
|
||||
* you should also include this file for low-level led macros, as it will
|
||||
* always include the file(s) containing those
|
||||
*
|
||||
* - low level led macros should all start with '_led_'
|
||||
* - public led macros should start with 'kb_led_'
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
|
||||
* Released under The MIT License (MIT) (see "license.md")
|
||||
* Project located at <https://github.com/benblazak/ergodox-firmware>
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef LED_h
|
||||
#define LED_h
|
||||
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "teensy-2-0.h" // for low-level led macros
|
||||
|
||||
|
||||
#define kb_led_state_power_on() do { \
|
||||
_led_all_set_percent(0.05); \
|
||||
_led_all_on(); \
|
||||
} while(0)
|
||||
|
||||
// note: need to delay for a total of ~1 second
|
||||
#define kb_led_delay_usb_init() do { \
|
||||
_led_1_set_percent(0.5); \
|
||||
_delay_ms(333); \
|
||||
_led_2_set_percent(0.5); \
|
||||
_delay_ms(333); \
|
||||
_led_3_set_percent(0.5); \
|
||||
_delay_ms(333); \
|
||||
} while(0)
|
||||
|
||||
#define kb_led_state_ready() do { \
|
||||
_led_all_off(); \
|
||||
_led_all_set_percent(0.5); \
|
||||
} while(0)
|
||||
|
||||
#endif
|
||||
|
|
@ -21,13 +21,6 @@
|
|||
|
||||
#ifdef KEYBOARD_INCLUDE_PRIVATE
|
||||
|
||||
//error check: since these macros are used for both keycodes
|
||||
// and function pointers
|
||||
#if NULL != 0
|
||||
#error "NULL != 0 ; macros in matrix.h must be revised"
|
||||
#endif
|
||||
|
||||
|
||||
/* mapping from spatial position to matrix position
|
||||
* - spatial position: where the key is spatially, relative to
|
||||
* other keys both on the keyboard and in the layout
|
||||
|
@ -49,6 +42,9 @@
|
|||
* ------------------------------------------------------------
|
||||
*/
|
||||
#define LAYER( \
|
||||
/* for unused positions */ \
|
||||
na, \
|
||||
\
|
||||
/* left hand, spatial positions */ \
|
||||
kB6,kB5,kB4,kB3,kB2,kB1,kB0, \
|
||||
kA6,kA5,kA4,kA3,kA2,kA1,kA0, \
|
||||
|
@ -70,22 +66,24 @@
|
|||
k01,k02,k05 ) \
|
||||
\
|
||||
/* matrix positions */ \
|
||||
{ { k00,k01,k02,k03,k04,k05, 0,}, \
|
||||
{ 0, 0,k12,k13,k14,k15,k16,}, \
|
||||
{ { k00,k01,k02,k03,k04,k05, na,}, \
|
||||
{ na, na,k12,k13,k14,k15,k16,}, \
|
||||
{ k20,k21,k22,k23,k24,k25,k26,}, \
|
||||
{ 0,k31,k32,k33,k34,k35,k36,}, \
|
||||
{ na,k31,k32,k33,k34,k35,k36,}, \
|
||||
{ k40,k41,k42,k43,k44,k45,k46,}, \
|
||||
{ k50,k51,k52,k53,k54,k55,k56,}, \
|
||||
{ k60,k61,k62,k63,k64,k65, 0,}, \
|
||||
{ 0, 0,k72,k73,k74,k75,k76,}, \
|
||||
{ k60,k61,k62,k63,k64,k65, na,}, \
|
||||
{ na, na,k72,k73,k74,k75,k76,}, \
|
||||
{ k80,k81,k82,k83,k84,k85,k86,}, \
|
||||
{ 0,k91,k92,k93,k94,k95,k96,}, \
|
||||
{ na,k91,k92,k93,k94,k95,k96,}, \
|
||||
{ kA0,kA1,kA2,kA3,kA4,kA5,kA6,}, \
|
||||
{ kB0,kB1,kB2,kB3,kB4,kB5,kB6 } }
|
||||
|
||||
|
||||
#define LAYER_SET_ALL(kxx) \
|
||||
#define LAYER_SET_ALL(na, kxx) \
|
||||
LAYER( \
|
||||
na, \
|
||||
\
|
||||
kxx,kxx,kxx,kxx,kxx,kxx,kxx, \
|
||||
kxx,kxx,kxx,kxx,kxx,kxx,kxx, \
|
||||
kxx,kxx,kxx,kxx,kxx,kxx, \
|
||||
|
|
|
@ -120,14 +120,10 @@ uint8_t teensy_init(void) {
|
|||
PORTD &= ~(1<<6); // set D(6) internal pull-up disabled
|
||||
|
||||
// keyboard LEDs (see "PWM on ports OC1(A|B|C)" in "teensy-2-0.md")
|
||||
DDRB |= 0b11100000; // set B(7,6,5) as output
|
||||
_led_all_off(); // (just to put the pins in a known state)
|
||||
TCCR1A = 0b10101001; // set and configure fast PWM
|
||||
TCCR1B = 0b00001001; // set and configure fast PWM
|
||||
|
||||
kb_led1_set_percent(0.5); kb_led1_off();
|
||||
kb_led2_set_percent(0.5); kb_led2_off();
|
||||
kb_led3_set_percent(0.5); kb_led3_off();
|
||||
|
||||
// I2C (TWI)
|
||||
twi_init(); // on pins D(1,0)
|
||||
|
||||
|
|
|
@ -15,21 +15,43 @@
|
|||
|
||||
#include "matrix.h"
|
||||
|
||||
|
||||
// LED control
|
||||
#define kb_led1_on() (DDRB |= (1<<6))
|
||||
#define kb_led1_off() (DDRB &= ~(1<<6))
|
||||
#define kb_led1_set(n) (OCR1B = (uint8_t)(n))
|
||||
#define kb_led1_set_percent(n) (OCR1B = (uint8_t)((n) * 0xFF))
|
||||
#define _led_1_on() (DDRB |= (1<<6))
|
||||
#define _led_1_off() (DDRB &= ~(1<<6))
|
||||
#define _led_1_set(n) (OCR1B = (uint8_t)(n))
|
||||
#define _led_1_set_percent(n) (OCR1B = (uint8_t)((n) * 0xFF))
|
||||
//
|
||||
#define kb_led2_on() (DDRB |= (1<<5))
|
||||
#define kb_led2_off() (DDRB &= ~(1<<5))
|
||||
#define kb_led2_set(n) (OCR1A = (uint8_t)(n))
|
||||
#define kb_led2_set_percent(n) (OCR1A = (uint8_t)((n) * 0xFF))
|
||||
#define _led_2_on() (DDRB |= (1<<5))
|
||||
#define _led_2_off() (DDRB &= ~(1<<5))
|
||||
#define _led_2_set(n) (OCR1A = (uint8_t)(n))
|
||||
#define _led_2_set_percent(n) (OCR1A = (uint8_t)((n) * 0xFF))
|
||||
//
|
||||
#define kb_led3_on() (DDRB |= (1<<7))
|
||||
#define kb_led3_off() (DDRB &= ~(1<<7))
|
||||
#define kb_led3_set(n) (OCR1C = (uint8_t)(n))
|
||||
#define kb_led3_set_percent(n) (OCR1C = (uint8_t)((n) * 0xFF))
|
||||
#define _led_3_on() (DDRB |= (1<<7))
|
||||
#define _led_3_off() (DDRB &= ~(1<<7))
|
||||
#define _led_3_set(n) (OCR1C = (uint8_t)(n))
|
||||
#define _led_3_set_percent(n) (OCR1C = (uint8_t)((n) * 0xFF))
|
||||
// ---
|
||||
#define _led_all_on() do { \
|
||||
_led_1_on(); \
|
||||
_led_2_on(); \
|
||||
_led_3_on(); \
|
||||
} while(0)
|
||||
#define _led_all_off() do { \
|
||||
_led_1_off(); \
|
||||
_led_2_off(); \
|
||||
_led_3_off(); \
|
||||
} while(0)
|
||||
#define _led_all_set(n) do { \
|
||||
_led_1_set(n); \
|
||||
_led_2_set(n); \
|
||||
_led_3_set(n); \
|
||||
} while(0)
|
||||
#define _led_all_set_percent(n) do { \
|
||||
_led_1_set_percent(n); \
|
||||
_led_2_set_percent(n); \
|
||||
_led_3_set_percent(n); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#ifdef KEYBOARD_INCLUDE_PRIVATE
|
||||
|
|
38
src/main.c
38
src/main.c
|
@ -15,29 +15,16 @@
|
|||
#include "keyboard.h"
|
||||
|
||||
|
||||
// note:
|
||||
// - see your keyswitch specification for the necessary value. for cherry mx
|
||||
// switches, bounce time should be <= 5ms. it looks like most switches are
|
||||
// speced between 5 and 8 ms.
|
||||
// - if timing is important, balance this value with the main() loop run time
|
||||
// (~5ms, last i checked, nearly all of it in the i2c update() function)
|
||||
#define DEBOUNCE_TIME 5 // in ms
|
||||
|
||||
|
||||
int main(void) {
|
||||
kb_init(); // does controller initialization too
|
||||
|
||||
kb_led1_on();
|
||||
kb_led2_on();
|
||||
kb_led3_on();
|
||||
kb_led_state_power_on();
|
||||
|
||||
usb_init();
|
||||
while (!usb_configured());
|
||||
_delay_ms(1000); // make sure the OS has had time to load drivers, etc.
|
||||
kb_led_delay_usb_init(); // give the OS time to load drivers, etc.
|
||||
|
||||
kb_led1_off();
|
||||
kb_led2_off();
|
||||
kb_led3_off();
|
||||
kb_led_state_ready();
|
||||
|
||||
for (;;) {
|
||||
static uint8_t current_layer = 0;
|
||||
|
@ -79,19 +66,22 @@ int main(void) {
|
|||
}
|
||||
|
||||
usb_keyboard_send();
|
||||
_delay_ms(DEBOUNCE_TIME);
|
||||
_delay_ms(KB_DEBOUNCE_TIME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update LEDs
|
||||
(keyboard_leds & (1<<0)) ? kb_led1_on() : kb_led1_off(); // num lock
|
||||
(keyboard_leds & (1<<1)) ? kb_led2_on() : kb_led2_off(); // caps lock
|
||||
(keyboard_leds & (1<<2)) ? kb_led3_on() : kb_led3_off(); // scroll lock
|
||||
#if 0 // not implemented right now
|
||||
(keyboard_leds & (1<<3)) ? kb_led4_on() : kb_led4_off(); // compose
|
||||
(keyboard_leds & (1<<4)) ? kb_led5_on() : kb_led5_off(); // kana
|
||||
#endif
|
||||
if (keyboard_leds & (1<<0)) { kb_led_num_on(); }
|
||||
else { kb_led_num_off(); }
|
||||
if (keyboard_leds & (1<<1)) { kb_led_caps_on(); }
|
||||
else { kb_led_caps_off(); }
|
||||
if (keyboard_leds & (1<<2)) { kb_led_scroll_on(); }
|
||||
else { kb_led_scroll_off(); }
|
||||
if (keyboard_leds & (1<<3)) { kb_led_compose_on(); }
|
||||
else { kb_led_compose_off(); }
|
||||
if (keyboard_leds & (1<<4)) { kb_led_kana_on(); }
|
||||
else { kb_led_kana_off(); }
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue