aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/avr/bootloader.c12
-rw-r--r--tmk_core/common/avr/suspend.c11
-rw-r--r--tmk_core/common/avr/timer.c69
-rw-r--r--tmk_core/common/backlight.c4
-rw-r--r--tmk_core/common/command.c9
-rw-r--r--tmk_core/common/host_driver.h9
-rw-r--r--tmk_core/common/keyboard.c2
-rw-r--r--tmk_core/common/keycode.h2
-rw-r--r--tmk_core/common/raw_hid.h8
9 files changed, 84 insertions, 42 deletions
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c
index ad547b985..34db8d0b0 100644
--- a/tmk_core/common/avr/bootloader.c
+++ b/tmk_core/common/avr/bootloader.c
@@ -1,6 +1,7 @@
1#include <stdint.h> 1#include <stdint.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include <avr/io.h> 3#include <avr/io.h>
4#include <avr/eeprom.h>
4#include <avr/interrupt.h> 5#include <avr/interrupt.h>
5#include <avr/wdt.h> 6#include <avr/wdt.h>
6#include <util/delay.h> 7#include <util/delay.h>
@@ -89,6 +90,12 @@ void bootloader_jump(void) {
89 _delay_ms(5); 90 _delay_ms(5);
90 #endif 91 #endif
91 92
93 #ifdef BOOTLOADHID_BOOTLOADER
94 // force bootloadHID to stay in bootloader mode, so that it waits
95 // for a new firmware to be flashed
96 eeprom_write_byte((uint8_t *)1, 0x00);
97 #endif
98
92 // watchdog reset 99 // watchdog reset
93 reset_key = BOOTLOADER_RESET_KEY; 100 reset_key = BOOTLOADER_RESET_KEY;
94 wdt_enable(WDTO_250MS); 101 wdt_enable(WDTO_250MS);
@@ -114,6 +121,11 @@ void bootloader_jump(void) {
114 #endif 121 #endif
115} 122}
116 123
124#ifdef __AVR_ATmega32A__
125// MCUSR is actually called MCUCSR in ATmega32A
126#define MCUSR MCUCSR
127#endif
128
117/* this runs before main() */ 129/* this runs before main() */
118void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); 130void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3")));
119void bootloader_jump_after_watchdog_reset(void) 131void bootloader_jump_after_watchdog_reset(void)
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index 8a7272bbc..0c81e8361 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -47,6 +47,7 @@ void suspend_idle(uint8_t time)
47 sleep_disable(); 47 sleep_disable();
48} 48}
49 49
50#ifndef NO_SUSPEND_POWER_DOWN
50/* Power down MCU with watchdog timer 51/* Power down MCU with watchdog timer
51 * wdto: watchdog timer timeout defined in <avr/wdt.h> 52 * wdto: watchdog timer timeout defined in <avr/wdt.h>
52 * WDTO_15MS 53 * WDTO_15MS
@@ -61,6 +62,7 @@ void suspend_idle(uint8_t time)
61 * WDTO_8S 62 * WDTO_8S
62 */ 63 */
63static uint8_t wdt_timeout = 0; 64static uint8_t wdt_timeout = 0;
65
64static void power_down(uint8_t wdto) 66static void power_down(uint8_t wdto)
65{ 67{
66#ifdef PROTOCOL_LUFA 68#ifdef PROTOCOL_LUFA
@@ -98,19 +100,19 @@ static void power_down(uint8_t wdto)
98 // Disable watchdog after sleep 100 // Disable watchdog after sleep
99 wdt_disable(); 101 wdt_disable();
100} 102}
103#endif
101 104
102void suspend_power_down(void) 105void suspend_power_down(void)
103{ 106{
107#ifndef NO_SUSPEND_POWER_DOWN
104 power_down(WDTO_15MS); 108 power_down(WDTO_15MS);
109#endif
105} 110}
106 111
107__attribute__ ((weak)) void matrix_power_up(void) {} 112__attribute__ ((weak)) void matrix_power_up(void) {}
108__attribute__ ((weak)) void matrix_power_down(void) {} 113__attribute__ ((weak)) void matrix_power_down(void) {}
109bool suspend_wakeup_condition(void) 114bool suspend_wakeup_condition(void)
110{ 115{
111#ifdef BACKLIGHT_ENABLE
112 backlight_set(0);
113#endif
114 matrix_power_up(); 116 matrix_power_up();
115 matrix_scan(); 117 matrix_scan();
116 matrix_power_down(); 118 matrix_power_down();
@@ -126,10 +128,9 @@ void suspend_wakeup_init(void)
126 // clear keyboard state 128 // clear keyboard state
127 clear_keyboard(); 129 clear_keyboard();
128#ifdef BACKLIGHT_ENABLE 130#ifdef BACKLIGHT_ENABLE
129 backlight_set(0);
130 backlight_init(); 131 backlight_init();
131#endif 132#endif
132led_set(host_keyboard_leds()); 133 led_set(host_keyboard_leds());
133} 134}
134 135
135#ifndef NO_SUSPEND_POWER_DOWN 136#ifndef NO_SUSPEND_POWER_DOWN
diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c
index 292b41c3a..369015200 100644
--- a/tmk_core/common/avr/timer.c
+++ b/tmk_core/common/avr/timer.c
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18#include <avr/io.h> 18#include <avr/io.h>
19#include <avr/interrupt.h> 19#include <avr/interrupt.h>
20#include <util/atomic.h>
20#include <stdint.h> 21#include <stdint.h>
21#include "timer_avr.h" 22#include "timer_avr.h"
22#include "timer.h" 23#include "timer.h"
@@ -24,38 +25,47 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24 25
25// counter resolution 1ms 26// counter resolution 1ms
26// NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }} 27// NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }}
27volatile uint32_t timer_count = 0; 28volatile uint32_t timer_count;
28 29
29void timer_init(void) 30void timer_init(void)
30{ 31{
31 // Timer0 CTC mode
32 TCCR0A = 0x02;
33
34#if TIMER_PRESCALER == 1 32#if TIMER_PRESCALER == 1
35 TCCR0B = 0x01; 33 uint8_t prescaler = 0x01;
36#elif TIMER_PRESCALER == 8 34#elif TIMER_PRESCALER == 8
37 TCCR0B = 0x02; 35 uint8_t prescaler = 0x02;
38#elif TIMER_PRESCALER == 64 36#elif TIMER_PRESCALER == 64
39 TCCR0B = 0x03; 37 uint8_t prescaler = 0x03;
40#elif TIMER_PRESCALER == 256 38#elif TIMER_PRESCALER == 256
41 TCCR0B = 0x04; 39 uint8_t prescaler = 0x04;
42#elif TIMER_PRESCALER == 1024 40#elif TIMER_PRESCALER == 1024
43 TCCR0B = 0x05; 41 uint8_t prescaler = 0x05;
44#else 42#else
45# error "Timer prescaler value is NOT vaild." 43# error "Timer prescaler value is NOT vaild."
46#endif 44#endif
47 45
46#ifndef __AVR_ATmega32A__
47 // Timer0 CTC mode
48 TCCR0A = 0x02;
49
50 TCCR0B = prescaler;
51
48 OCR0A = TIMER_RAW_TOP; 52 OCR0A = TIMER_RAW_TOP;
49 TIMSK0 = (1<<OCIE0A); 53 TIMSK0 = (1<<OCIE0A);
54#else
55 // Timer0 CTC mode
56 TCCR0 = (1 << WGM01) | prescaler;
57
58 OCR0 = TIMER_RAW_TOP;
59 TIMSK = (1 << OCIE0);
60#endif
50} 61}
51 62
52inline 63inline
53void timer_clear(void) 64void timer_clear(void)
54{ 65{
55 uint8_t sreg = SREG; 66 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
56 cli();
57 timer_count = 0; 67 timer_count = 0;
58 SREG = sreg; 68 }
59} 69}
60 70
61inline 71inline
@@ -63,10 +73,9 @@ uint16_t timer_read(void)
63{ 73{
64 uint32_t t; 74 uint32_t t;
65 75
66 uint8_t sreg = SREG; 76 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
67 cli(); 77 t = timer_count;
68 t = timer_count; 78 }
69 SREG = sreg;
70 79
71 return (t & 0xFFFF); 80 return (t & 0xFFFF);
72} 81}
@@ -76,10 +85,9 @@ uint32_t timer_read32(void)
76{ 85{
77 uint32_t t; 86 uint32_t t;
78 87
79 uint8_t sreg = SREG; 88 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
80 cli(); 89 t = timer_count;
81 t = timer_count; 90 }
82 SREG = sreg;
83 91
84 return t; 92 return t;
85} 93}
@@ -89,10 +97,9 @@ uint16_t timer_elapsed(uint16_t last)
89{ 97{
90 uint32_t t; 98 uint32_t t;
91 99
92 uint8_t sreg = SREG; 100 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
93 cli(); 101 t = timer_count;
94 t = timer_count; 102 }
95 SREG = sreg;
96 103
97 return TIMER_DIFF_16((t & 0xFFFF), last); 104 return TIMER_DIFF_16((t & 0xFFFF), last);
98} 105}
@@ -102,16 +109,20 @@ uint32_t timer_elapsed32(uint32_t last)
102{ 109{
103 uint32_t t; 110 uint32_t t;
104 111
105 uint8_t sreg = SREG; 112 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
106 cli(); 113 t = timer_count;
107 t = timer_count; 114 }
108 SREG = sreg;
109 115
110 return TIMER_DIFF_32(t, last); 116 return TIMER_DIFF_32(t, last);
111} 117}
112 118
113// excecuted once per 1ms.(excess for just timer count?) 119// excecuted once per 1ms.(excess for just timer count?)
114ISR(TIMER0_COMPA_vect) 120#ifndef __AVR_ATmega32A__
121#define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect
122#else
123#define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect
124#endif
125ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK)
115{ 126{
116 timer_count++; 127 timer_count++;
117} 128}
diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c
index c9e8fd3fd..0e0ad2d15 100644
--- a/tmk_core/common/backlight.c
+++ b/tmk_core/common/backlight.c
@@ -36,9 +36,9 @@ void backlight_increase(void)
36 if(backlight_config.level < BACKLIGHT_LEVELS) 36 if(backlight_config.level < BACKLIGHT_LEVELS)
37 { 37 {
38 backlight_config.level++; 38 backlight_config.level++;
39 backlight_config.enable = 1;
40 eeconfig_update_backlight(backlight_config.raw);
41 } 39 }
40 backlight_config.enable = 1;
41 eeconfig_update_backlight(backlight_config.raw);
42 dprintf("backlight increase: %u\n", backlight_config.level); 42 dprintf("backlight increase: %u\n", backlight_config.level);
43 backlight_set(backlight_config.level); 43 backlight_set(backlight_config.level);
44} 44}
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index f3e1bf623..f79d5a257 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -235,8 +235,11 @@ static void print_status(void)
235 print("\n\t- Status -\n"); 235 print("\n\t- Status -\n");
236 236
237 print_val_hex8(host_keyboard_leds()); 237 print_val_hex8(host_keyboard_leds());
238#ifndef PROTOCOL_VUSB
239 // these aren't set on the V-USB protocol, so we just ignore them for now
238 print_val_hex8(keyboard_protocol); 240 print_val_hex8(keyboard_protocol);
239 print_val_hex8(keyboard_idle); 241 print_val_hex8(keyboard_idle);
242#endif
240#ifdef NKRO_ENABLE 243#ifdef NKRO_ENABLE
241 print_val_hex8(keymap_config.nkro); 244 print_val_hex8(keymap_config.nkro);
242#endif 245#endif
@@ -379,11 +382,11 @@ static bool command_common(uint8_t code)
379 debug_enable = !debug_enable; 382 debug_enable = !debug_enable;
380 if (debug_enable) { 383 if (debug_enable) {
381 print("\ndebug: on\n"); 384 print("\ndebug: on\n");
382 debug_matrix = true;
383 debug_keyboard = true;
384 debug_mouse = true;
385 } else { 385 } else {
386 print("\ndebug: off\n"); 386 print("\ndebug: off\n");
387 debug_matrix = false;
388 debug_keyboard = false;
389 debug_mouse = false;
387 } 390 }
388 break; 391 break;
389 392
diff --git a/tmk_core/common/host_driver.h b/tmk_core/common/host_driver.h
index edb9e5dd9..588d1c0be 100644
--- a/tmk_core/common/host_driver.h
+++ b/tmk_core/common/host_driver.h
@@ -20,7 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21#include <stdint.h> 21#include <stdint.h>
22#include "report.h" 22#include "report.h"
23 23#ifdef MIDI_ENABLE
24 #include "midi.h"
25#endif
24 26
25typedef struct { 27typedef struct {
26 uint8_t (*keyboard_leds)(void); 28 uint8_t (*keyboard_leds)(void);
@@ -28,6 +30,11 @@ typedef struct {
28 void (*send_mouse)(report_mouse_t *); 30 void (*send_mouse)(report_mouse_t *);
29 void (*send_system)(uint16_t); 31 void (*send_system)(uint16_t);
30 void (*send_consumer)(uint16_t); 32 void (*send_consumer)(uint16_t);
33#ifdef MIDI_ENABLE
34 void (*usb_send_func)(MidiDevice *, uint16_t, uint8_t, uint8_t, uint8_t);
35 void (*usb_get_midi)(MidiDevice *);
36 void (*midi_usb_init)(MidiDevice *);
37#endif
31} host_driver_t; 38} host_driver_t;
32 39
33#endif 40#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 371d93f3e..765350792 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -188,7 +188,7 @@ MATRIX_LOOP_END:
188#endif 188#endif
189 189
190#ifdef VISUALIZER_ENABLE 190#ifdef VISUALIZER_ENABLE
191 visualizer_update(default_layer_state, layer_state, host_keyboard_leds()); 191 visualizer_update(default_layer_state, layer_state, visualizer_get_mods(), host_keyboard_leds());
192#endif 192#endif
193 193
194 // update LED 194 // update LED
diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h
index 2f208c54e..54e9c322c 100644
--- a/tmk_core/common/keycode.h
+++ b/tmk_core/common/keycode.h
@@ -85,7 +85,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
85#define KC_LCAP KC_LOCKING_CAPS 85#define KC_LCAP KC_LOCKING_CAPS
86#define KC_LNUM KC_LOCKING_NUM 86#define KC_LNUM KC_LOCKING_NUM
87#define KC_LSCR KC_LOCKING_SCROLL 87#define KC_LSCR KC_LOCKING_SCROLL
88#define KC_ERAS KC_ALT_ERASE, 88#define KC_ERAS KC_ALT_ERASE
89#define KC_CLR KC_CLEAR 89#define KC_CLR KC_CLEAR
90/* Japanese specific */ 90/* Japanese specific */
91#define KC_ZKHK KC_GRAVE 91#define KC_ZKHK KC_GRAVE
diff --git a/tmk_core/common/raw_hid.h b/tmk_core/common/raw_hid.h
new file mode 100644
index 000000000..86da02fd1
--- /dev/null
+++ b/tmk_core/common/raw_hid.h
@@ -0,0 +1,8 @@
1#ifndef _RAW_HID_H_
2#define _RAW_HID_H_
3
4void raw_hid_receive( uint8_t *data, uint8_t length );
5
6void raw_hid_send( uint8_t *data, uint8_t length );
7
8#endif