aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.mk2
-rw-r--r--common/avr/timer.c (renamed from common/timer.c)1
-rw-r--r--common/mbed/timer.c40
-rw-r--r--common/timer.h19
-rw-r--r--keyboard/mbed_onekey/common.mk29
-rw-r--r--keyboard/mbed_onekey/main.cpp21
6 files changed, 73 insertions, 39 deletions
diff --git a/common.mk b/common.mk
index 62ac0ff78..9d58fa214 100644
--- a/common.mk
+++ b/common.mk
@@ -7,7 +7,7 @@ SRC += $(COMMON_DIR)/host.c \
7 $(COMMON_DIR)/action_layer.c \ 7 $(COMMON_DIR)/action_layer.c \
8 $(COMMON_DIR)/action_util.c \ 8 $(COMMON_DIR)/action_util.c \
9 $(COMMON_DIR)/keymap.c \ 9 $(COMMON_DIR)/keymap.c \
10 $(COMMON_DIR)/timer.c \ 10 $(COMMON_DIR)/avr/timer.c \
11 $(COMMON_DIR)/print.c \ 11 $(COMMON_DIR)/print.c \
12 $(COMMON_DIR)/bootloader.c \ 12 $(COMMON_DIR)/bootloader.c \
13 $(COMMON_DIR)/suspend.c \ 13 $(COMMON_DIR)/suspend.c \
diff --git a/common/timer.c b/common/avr/timer.c
index e0dec6cef..292b41c3a 100644
--- a/common/timer.c
+++ b/common/avr/timer.c
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include <avr/io.h> 18#include <avr/io.h>
19#include <avr/interrupt.h> 19#include <avr/interrupt.h>
20#include <stdint.h> 20#include <stdint.h>
21#include "timer_avr.h"
21#include "timer.h" 22#include "timer.h"
22 23
23 24
diff --git a/common/mbed/timer.c b/common/mbed/timer.c
new file mode 100644
index 000000000..a64a77239
--- /dev/null
+++ b/common/mbed/timer.c
@@ -0,0 +1,40 @@
1#include "cmsis.h"
2#include "timer.h"
3
4/* Mill second tick count */
5volatile uint32_t timer_count = 0;
6
7/* Timer interrupt handler */
8void SysTick_Handler(void) {
9 timer_count++;
10}
11
12void timer_init(void)
13{
14 SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
15}
16
17void timer_clear(void)
18{
19 timer_count = 0;
20}
21
22uint16_t timer_read(void)
23{
24 return (uint16_t)(timer_count & 0xFFFF);
25}
26
27uint32_t timer_read32(void)
28{
29 return timer_count;
30}
31
32uint16_t timer_elapsed(uint16_t last)
33{
34 return TIMER_DIFF_16(timer_read(), last);
35}
36
37uint32_t timer_elapsed32(uint32_t last)
38{
39 return TIMER_DIFF_32(timer_read32(), last);
40}
diff --git a/common/timer.h b/common/timer.h
index 6437473ff..f0c5ffc98 100644
--- a/common/timer.h
+++ b/common/timer.h
@@ -20,25 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21#include <stdint.h> 21#include <stdint.h>
22 22
23#ifndef TIMER_PRESCALER
24# if F_CPU > 16000000
25# define TIMER_PRESCALER 256
26# elif F_CPU > 2000000
27# define TIMER_PRESCALER 64
28# elif F_CPU > 250000
29# define TIMER_PRESCALER 8
30# else
31# define TIMER_PRESCALER 1
32# endif
33#endif
34#define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER)
35#define TIMER_RAW TCNT0
36#define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000)
37
38#if (TIMER_RAW_TOP > 255)
39# error "Timer0 can't count 1ms at this clock freq. Use larger prescaler."
40#endif
41
42#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) 23#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a))
43#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) 24#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX)
44#define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) 25#define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX)
diff --git a/keyboard/mbed_onekey/common.mk b/keyboard/mbed_onekey/common.mk
index f21fce886..975ae9d0d 100644
--- a/keyboard/mbed_onekey/common.mk
+++ b/keyboard/mbed_onekey/common.mk
@@ -1,19 +1,20 @@
1COMMON_DIR = common 1COMMON_DIR = common
2OBJECTS += \ 2OBJECTS += \
3# $(COMMON_DIR)/host.o \ 3 $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \
4# $(COMMON_DIR)/keyboard.o \
5# $(COMMON_DIR)/action.o \
6# $(COMMON_DIR)/action_tapping.o \
7# $(COMMON_DIR)/action_macro.o \
8# $(COMMON_DIR)/action_layer.o \
9# $(COMMON_DIR)/action_util.o \
10# $(COMMON_DIR)/keymap.o \
11# $(COMMON_DIR)/timer.o \
12 $(COMMON_DIR)/print.o \
13# $(COMMON_DIR)/bootloader.o \
14# $(COMMON_DIR)/suspend.o \
15 $(COMMON_DIR)/xprintf.o \
16 $(COMMON_DIR)/util.o
17 4
18INCLUDE_PATHS += \ 5INCLUDE_PATHS += \
19 -I$(TMK_DIR)/$(COMMON_DIR) 6 -I$(TMK_DIR)/$(COMMON_DIR)
7
8
9
10
11# $(OBJDIR)/$(COMMON_DIR)/host.o \
12# $(OBJDIR)/$(COMMON_DIR)/keyboard.o \
13# $(OBJDIR)/$(COMMON_DIR)/action.o \
14# $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \
15# $(OBJDIR)/$(COMMON_DIR)/action_macro.o \
16# $(OBJDIR)/$(COMMON_DIR)/action_layer.o \
17# $(OBJDIR)/$(COMMON_DIR)/action_util.o \
18# $(OBJDIR)/$(COMMON_DIR)/keymap.o \
19# $(OBJDIR)/$(COMMON_DIR)/bootloader.o \
20# $(OBJDIR)/$(COMMON_DIR)/suspend.o \
diff --git a/keyboard/mbed_onekey/main.cpp b/keyboard/mbed_onekey/main.cpp
index 581534e02..1df940aa9 100644
--- a/keyboard/mbed_onekey/main.cpp
+++ b/keyboard/mbed_onekey/main.cpp
@@ -1,6 +1,7 @@
1#include "mbed.h" 1#include "mbed.h"
2#include "HIDKeyboard.h" 2#include "HIDKeyboard.h"
3#include "debug.h" 3#include "debug.h"
4#include "timer.h"
4 5
5/* 6/*
6//#define DEBUG 7//#define DEBUG
@@ -27,11 +28,16 @@ int main(void) {
27 //led_red = 0; 28 //led_red = 0;
28 //led_green = 0; 29 //led_green = 0;
29 debug_enable = true; 30 debug_enable = true;
30 dprintf("HIDKeyboard:\n"); 31 dprintf("HIDKeyboard:\r\n");
31 print("aaa"); 32
33 timer_init();
34 xprintf("timer: %i\r\n", timer_read());
32 35
33 report_keyboard_t report = { 2, 0, 4, }; //a 36 report_keyboard_t report = { 2, 0, 4, }; //a
34 report_keyboard_t report_off = { 0 }; 37 report_keyboard_t report_off = { 0 };
38
39 bool last_isp = isp;
40 uint32_t last_timer;
35 while (1) { 41 while (1) {
36 //keyboard.mediaControl(KEY_VOLUME_DOWN); 42 //keyboard.mediaControl(KEY_VOLUME_DOWN);
37 //keyboard.printf("Hello World from Mbed\r\n"); 43 //keyboard.printf("Hello World from Mbed\r\n");
@@ -42,14 +48,19 @@ int main(void) {
42 //leds = keyboard.lockStatus(); 48 //leds = keyboard.lockStatus();
43 //ser.putc(ser.getc()); 49 //ser.putc(ser.getc());
44 50
51 if (last_isp == isp) continue;
45 if (isp == 0) { 52 if (isp == 0) {
46 led_red = 0; // on 53 led_red = 0; // on
47 keyboard.sendReport(report); 54 xprintf("timer: %i\r\n", timer_read32());
55 xprintf("diff: %i\r\n", timer_elapsed32(last_timer));
56 //keyboard.sendReport(report);
48 } else { 57 } else {
49 led_red = 1; // off 58 led_red = 1; // off
50 keyboard.sendReport(report_off); 59 //keyboard.sendReport(report_off);
51 } 60 }
52 led_green = !led_green; 61 last_isp = isp;
62 last_timer = timer_read();
63 //led_green = !led_green;
53 //wait(0.5); 64 //wait(0.5);
54 } 65 }
55} 66}