moved keyboard layout to program space

partial-rewrite
Ben Blazak 2012-04-29 00:17:17 -07:00
parent 229a2446a7
commit 0b423bef70
7 changed files with 50 additions and 25 deletions

View File

@ -116,6 +116,10 @@
(http://www.nongnu.org/avr-libc/user-manual/modules.html)
One of my main references.
* [AVR : Data in Program Space]
(http://www.nongnu.org/avr-libc/user-manual/pgmspace.html)
How to use '<avr/pgmspace.h>'.
* [avr-libc/include/avr/iom32u4.h]
(http://svn.savannah.nongnu.org/viewvc/trunk/avr-libc/include/avr/iom32u4.h?revision=2288&root=avr-libc&view=markup)
List of registers and associated bit numbers for the ATmega32U4
@ -125,7 +129,7 @@
by Chris Kuethe
Goes over a bunch of stuff pretty generally. Useful to me because it was
talking about exactly what I was trying to do (e.g. program the thing
directly instead of messing around with gratuitous libraries)
directly instead of messing around with gratuitous libraries).
* [Optimisations of AVR programs using avr-gcc]
(http://www.tty1.net/blog/2008-04-29-avr-gcc-optimisations_en.html)

View File

@ -33,7 +33,7 @@
#undef _inc
// default layout 'get' functions
// default layout 'get' macros
//
// these are for when the matrices are stored solely in RAM. they're
// here so layouts can redefine them if they with and use RAM, Flash,

View File

@ -9,6 +9,7 @@
* ------------------------------------------------------------------------- */
#include <avr/pgmspace.h>
#include "lib/data-types.h"
#include "lib/usb/keyboard-usage-page--short-names.h"
#include "lib/key-functions.h"
@ -24,7 +25,7 @@
#endif
uint8_t _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
uint8_t PROGMEM _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
{ /* layer 0: default */
/* right hand */
/* ---- 0 ---- ---- 1 ---- ---- 2 ---- ---- 3 ---- ---- 4 ---- ---- 5 ---- ---- 6 ---- */
@ -47,11 +48,11 @@ uint8_t _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
}
};
kbfun_funptr_t _kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
kbfun_funptr_t PROGMEM _kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
/* layer 0: default */ DEFAULT_LAYER_PRESS
};
kbfun_funptr_t _kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
kbfun_funptr_t PROGMEM _kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
/* layer 0: default */ DEFAULT_LAYER_RELEASE
};

View File

@ -9,10 +9,28 @@
* ------------------------------------------------------------------------- */
#include <avr/pgmspace.h>
#define KB_LAYERS 1 // must match what's defined in the layout '.c' file
extern uint8_t _kb_layout [KB_LAYERS][KB_ROWS][KB_COLUMNS];
extern kbfun_funptr_t _kb_layout_press [KB_LAYERS][KB_ROWS][KB_COLUMNS];
extern kbfun_funptr_t _kb_layout_release [KB_LAYERS][KB_ROWS][KB_COLUMNS];
// override the defaults so we can use program space
#define kb_layout_get(layer,row,column) \
( (uint8_t) (pgm_read_byte(&( \
_kb_layout[layer][row][column] ))) )
#define kb_layout_press_get(layer,row,column) \
( (kbfun_funptr_t) (pgm_read_word(&( \
_kb_layout_press[layer][row][column] ))) )
#define kb_layout_release_get(layer,row,column) \
( (kbfun_funptr_t) (pgm_read_word(&( \
_kb_layout_release[layer][row][column] ))) )
extern uint8_t PROGMEM _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS];
extern kbfun_funptr_t PROGMEM _kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS];
extern kbfun_funptr_t PROGMEM
_kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS];

View File

@ -45,15 +45,15 @@ static uint8_t _dec_current_layer(uint8_t * current_layer) {
// ----------------------------------------------------------------------------
void kbfun_press(
uint8_t * keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col ) {
uint8_t keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col ) {
// no-op
if (*keycode == 0)
if (keycode == 0)
return;
// modifier keys
switch (*keycode) {
switch (keycode) {
case KEY_LeftControl: keyboard_modifier_keys |= (1<<0);
return;
case KEY_LeftShift: keyboard_modifier_keys |= (1<<1);
@ -75,21 +75,21 @@ void kbfun_press(
// all others
for (uint8_t i=0; i<6; i++)
if (keyboard_keys[i] == 0) {
keyboard_keys[i] = *keycode;
keyboard_keys[i] = keycode;
break;
}
}
void kbfun_release(
uint8_t * keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col ) {
uint8_t keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col ) {
// no-op
if (*keycode == 0)
if (keycode == 0)
return;
// modifier keys
switch (*keycode) {
switch (keycode) {
case KEY_LeftControl: keyboard_modifier_keys &= ~(1<<0);
return;
case KEY_LeftShift: keyboard_modifier_keys &= ~(1<<1);
@ -110,7 +110,7 @@ void kbfun_release(
// all others
for (uint8_t i=0; i<6; i++)
if (keyboard_keys[i] == *keycode) {
if (keyboard_keys[i] == keycode) {
keyboard_keys[i] = 0;
break;
}

View File

@ -12,14 +12,16 @@
#include "lib/data-types.h"
typedef void (*kbfun_funptr_t)(uint8_t*, uint8_t*, uint8_t*, uint8_t*);
typedef void (*kbfun_funptr_t)(
uint8_t, uint8_t *,
uint8_t *, uint8_t * );
void kbfun_press(
uint8_t * keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col );
uint8_t keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col );
void kbfun_release(
uint8_t * keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col );
uint8_t keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col );
#endif

View File

@ -65,7 +65,7 @@ int main(void) {
kb_layout_press_get(current_layer, row, col);
if (press_function) {
(*press_function)(
&kb_layout_get(current_layer, row, col),
kb_layout_get(current_layer, row, col),
&current_layer, &row, &col );
}
} else {
@ -73,7 +73,7 @@ int main(void) {
kb_layout_release_get(current_layer, row, col);
if (release_function) {
(*release_function)(
&kb_layout_get(current_layer, row, col),
kb_layout_get(current_layer, row, col),
&current_layer, &row, &col );
}
}