Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0-3.1 support #12

Merged
merged 8 commits into from
Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
*.lst
*.map
*.sym
*.swp
tags
build/
*.bak
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "protocol/lufa/LUFA-git"]
path = protocol/lufa/LUFA-git
url = https://github.com/abcminiuser/lufa.git
[submodule "teensy-sdk"]
path = teensy-sdk
url = https://github.com/apmorton/teensy-template
29 changes: 22 additions & 7 deletions common.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
ifndef PLATFORM
PLATFORM=avr
endif

COMMON_DIR = common
PLATFORM_DIR = $(COMMON_DIR)/$(PLATFORM)

SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/keyboard.c \
$(COMMON_DIR)/action.c \
Expand All @@ -7,19 +13,28 @@ SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/action_layer.c \
$(COMMON_DIR)/action_util.c \
$(COMMON_DIR)/keymap.c \
$(COMMON_DIR)/timer.c \
$(COMMON_DIR)/print.c \
$(COMMON_DIR)/debug.c \
$(COMMON_DIR)/bootloader.c \
$(COMMON_DIR)/suspend.c \
$(COMMON_DIR)/xprintf.S \
$(COMMON_DIR)/util.c
$(COMMON_DIR)/util.c \
$(PLATFORM_DIR)/suspend.c \
$(PLATFORM_DIR)/bootloader.c

ifeq (PLATFORM,avr)
$(COMMON_DIR)/print.c \
SRC += $(PLATFORM_DIR)/xprintf.S
else
SRCPP += $(PLATFORM_DIR)/xprintf.cpp
endif

ifeq (PLATFORM,teensy)
SRCPP += $(PLATFORM_DIR)/timer.cpp
else
SRC += $(PLATFORM_DIR)/timer.c
endif

# Option modules
ifdef BOOTMAGIC_ENABLE
SRC += $(COMMON_DIR)/bootmagic.c
SRC += $(COMMON_DIR)/eeconfig.c
SRC += $(PLATFORM_DIR)/eeconfig.c
OPT_DEFS += -DBOOTMAGIC_ENABLE
endif

Expand Down
2 changes: 1 addition & 1 deletion common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void clear_keyboard_but_mods(void)
#endif
}

bool is_tap_key(key_t key)
bool is_tap_key(keypos_t key)
{
action_t action = layer_switch_get_action(key);

Expand Down
13 changes: 10 additions & 3 deletions common/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "action_macro.h"


#ifdef __cplusplus
extern "C" {
#endif

/* tapping count and state */
typedef struct {
bool interrupted :1;
Expand All @@ -42,12 +46,11 @@ typedef struct {
#endif
} keyrecord_t;


/* Execute action per keyevent */
void action_exec(keyevent_t event);

/* action for key */
action_t action_for_key(uint8_t layer, key_t key);
action_t action_for_key(uint8_t layer, keypos_t key);

/* macro */
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
Expand All @@ -65,11 +68,15 @@ void unregister_mods(uint8_t mods);
void clear_keyboard(void);
void clear_keyboard_but_mods(void);
void layer_switch(uint8_t new_layer);
bool is_tap_key(key_t key);
bool is_tap_key(keypos_t key);

/* debug */
void debug_event(keyevent_t event);
void debug_record(keyrecord_t record);
void debug_action(action_t action);

#ifdef __cplusplus
}
#endif

#endif /* ACTION_H */
2 changes: 1 addition & 1 deletion common/action_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void layer_debug(void)



action_t layer_switch_get_action(key_t key)
action_t layer_switch_get_action(keypos_t key)
{
action_t action;
action.code = ACTION_TRANSPARENT;
Expand Down
2 changes: 1 addition & 1 deletion common/action_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ void layer_xor(uint32_t state);


/* return action depending on current layer status */
action_t layer_switch_get_action(key_t key);
action_t layer_switch_get_action(keypos_t key);

#endif
8 changes: 4 additions & 4 deletions common/action_macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <util/delay.h>
#include "action.h"
#include "action_util.h"
#include "action_macro.h"
#include "wait.h"

#ifdef DEBUG_ACTION
#include "debug.h"
Expand All @@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef NO_ACTION_MACRO

#define MACRO_READ() (macro = pgm_read_byte(macro_p++))
#define MACRO_READ() (macro = MACRO_GET(macro_p++))
void action_macro_play(const macro_t *macro_p)
{
macro_t macro = END;
Expand Down Expand Up @@ -58,7 +58,7 @@ void action_macro_play(const macro_t *macro_p)
case WAIT:
MACRO_READ();
dprintf("WAIT(%u)\n", macro);
{ uint8_t ms = macro; while (ms--) _delay_ms(1); }
{ uint8_t ms = macro; while (ms--) wait_ms(1); }
break;
case INTERVAL:
interval = MACRO_READ();
Expand All @@ -77,7 +77,7 @@ void action_macro_play(const macro_t *macro_p)
return;
}
// interval
{ uint8_t ms = interval; while (ms--) _delay_ms(1); }
{ uint8_t ms = interval; while (ms--) wait_ms(1); }
}
}
#endif
8 changes: 4 additions & 4 deletions common/action_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef ACTION_MACRO_H
#define ACTION_MACRO_H
#include <stdint.h>
#include <avr/pgmspace.h>
#include "progmem.h"


#define MACRO_NONE 0
#define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })

#define MACRO_NONE 0
#define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
#define MACRO_GET(p) pgm_read_byte(p)

typedef uint8_t macro_t;

Expand Down
20 changes: 10 additions & 10 deletions common/action_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ static uint8_t real_mods = 0;
static uint8_t weak_mods = 0;

#ifdef USB_6KRO_ENABLE
#define RO_ADD(a, b) ((a + b) % REPORT_KEYS)
#define RO_SUB(a, b) ((a - b + REPORT_KEYS) % REPORT_KEYS)
#define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS)
#define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS)
#define RO_INC(a) RO_ADD(a, 1)
#define RO_DEC(a) RO_SUB(a, 1)
static int8_t cb_head = 0;
Expand Down Expand Up @@ -98,7 +98,7 @@ void del_key(uint8_t key)
void clear_keys(void)
{
// not clear mods
for (int8_t i = 1; i < REPORT_SIZE; i++) {
for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
keyboard_report->raw[i] = 0;
}
}
Expand Down Expand Up @@ -145,7 +145,7 @@ void clear_oneshot_mods(void)
uint8_t has_anykey(void)
{
uint8_t cnt = 0;
for (uint8_t i = 1; i < REPORT_SIZE; i++) {
for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
if (keyboard_report->raw[i])
cnt++;
}
Expand All @@ -162,7 +162,7 @@ uint8_t get_first_key(void)
#ifdef NKRO_ENABLE
if (keyboard_nkro) {
uint8_t i = 0;
for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
;
return i<<3 | biton(keyboard_report->nkro.bits[i]);
}
Expand Down Expand Up @@ -234,15 +234,15 @@ static inline void add_key_byte(uint8_t code)
#else
int8_t i = 0;
int8_t empty = -1;
for (; i < REPORT_KEYS; i++) {
for (; i < KEYBOARD_REPORT_KEYS; i++) {
if (keyboard_report->keys[i] == code) {
break;
}
if (empty == -1 && keyboard_report->keys[i] == 0) {
empty = i;
}
}
if (i == REPORT_KEYS) {
if (i == KEYBOARD_REPORT_KEYS) {
if (empty != -1) {
keyboard_report->keys[empty] = code;
}
Expand Down Expand Up @@ -278,7 +278,7 @@ static inline void del_key_byte(uint8_t code)
} while (i != cb_tail);
}
#else
for (uint8_t i = 0; i < REPORT_KEYS; i++) {
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
if (keyboard_report->keys[i] == code) {
keyboard_report->keys[i] = 0;
}
Expand All @@ -289,7 +289,7 @@ static inline void del_key_byte(uint8_t code)
#ifdef NKRO_ENABLE
static inline void add_key_bit(uint8_t code)
{
if ((code>>3) < REPORT_BITS) {
if ((code>>3) < KEYBOARD_REPORT_BITS) {
keyboard_report->nkro.bits[code>>3] |= 1<<(code&7);
} else {
dprintf("add_key_bit: can't add: %02X\n", code);
Expand All @@ -298,7 +298,7 @@ static inline void add_key_bit(uint8_t code)

static inline void del_key_bit(uint8_t code)
{
if ((code>>3) < REPORT_BITS) {
if ((code>>3) < KEYBOARD_REPORT_BITS) {
keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7));
} else {
dprintf("del_key_bit: can't del: %02X\n", code);
Expand Down
9 changes: 9 additions & 0 deletions common/action_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include "report.h"

#ifdef __cplusplus
extern "C" {
#endif

extern report_keyboard_t *keyboard_report;

void send_keyboard_report(void);
Expand Down Expand Up @@ -54,4 +58,9 @@ void oneshot_disable(void);
uint8_t has_anykey(void);
uint8_t has_anymod(void);
uint8_t get_first_key(void);

#ifdef __cplusplus
}
#endif

#endif
File renamed without changes.
File renamed without changes.
24 changes: 23 additions & 1 deletion common/suspend.c → common/avr/suspend.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
#include "suspend.h"
#include <stdbool.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include "matrix.h"
#include "action.h"
#include "backlight.h"
#include "suspend_avr.h"
#include "suspend.h"


#define wdt_intr_enable(value) \
__asm__ __volatile__ ( \
"in __tmp_reg__,__SREG__" "\n\t" \
"cli" "\n\t" \
"wdr" "\n\t" \
"sts %0,%1" "\n\t" \
"out __SREG__,__tmp_reg__" "\n\t" \
"sts %0,%2" "\n\t" \
: /* no outputs */ \
: "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
"r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
"r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
_BV(WDIE) | (value & 0x07)) ) \
: "r0" \
)


void suspend_power_down(void)
Expand Down
27 changes: 27 additions & 0 deletions common/avr/suspend_avr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef SUSPEND_AVR_H
#define SUSPEND_AVR_H

#include <stdint.h>
#include <stdbool.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>


#define wdt_intr_enable(value) \
__asm__ __volatile__ ( \
"in __tmp_reg__,__SREG__" "\n\t" \
"cli" "\n\t" \
"wdr" "\n\t" \
"sts %0,%1" "\n\t" \
"out __SREG__,__tmp_reg__" "\n\t" \
"sts %0,%2" "\n\t" \
: /* no outputs */ \
: "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
"r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
"r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
_BV(WDIE) | (value & 0x07)) ) \
: "r0" \
)

#endif
1 change: 1 addition & 0 deletions common/timer.c → common/avr/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include "timer_avr.h"
#include "timer.h"


Expand Down
42 changes: 42 additions & 0 deletions common/avr/timer_avr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2011 Jun Wako <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TIMER_AVR_H
#define TIMER_AVR_H 1

#include <stdint.h>

#ifndef TIMER_PRESCALER
# if F_CPU > 16000000
# define TIMER_PRESCALER 256
# elif F_CPU > 2000000
# define TIMER_PRESCALER 64
# elif F_CPU > 250000
# define TIMER_PRESCALER 8
# else
# define TIMER_PRESCALER 1
# endif
#endif
#define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER)
#define TIMER_RAW TCNT0
#define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000)

#if (TIMER_RAW_TOP > 255)
# error "Timer0 can't count 1ms at this clock freq. Use larger prescaler."
#endif

#endif
File renamed without changes.
File renamed without changes.
Loading