summaryrefslogtreecommitdiffstats
path: root/tmk_core/common/mbed
diff options
context:
space:
mode:
authortmk <hasu@tmk-kbd.com>2015-04-09 18:32:04 +0200
committertmk <hasu@tmk-kbd.com>2015-04-09 18:32:04 +0200
commit1a02ebcc612e9a9c0d87e02295c7258de3a70ccc (patch)
treee517f3c70bb2d542797e57d13e9023c84af230fb /tmk_core/common/mbed
parent6746e37088ce8ba03529c1226bd216705edb2b1f (diff)
parenta074364c3731d66b56d988c8a6c960a83ea0e0a1 (diff)
downloadqmk_firmware-1a02ebcc612e9a9c0d87e02295c7258de3a70ccc.tar.gz
qmk_firmware-1a02ebcc612e9a9c0d87e02295c7258de3a70ccc.tar.xz
Merge commit 'a074364c3731d66b56d988c8a6c960a83ea0e0a1' as 'tmk_core'
Diffstat (limited to 'tmk_core/common/mbed')
-rw-r--r--tmk_core/common/mbed/bootloader.c4
-rw-r--r--tmk_core/common/mbed/suspend.c6
-rw-r--r--tmk_core/common/mbed/timer.c41
-rw-r--r--tmk_core/common/mbed/xprintf.cpp51
-rw-r--r--tmk_core/common/mbed/xprintf.h17
5 files changed, 119 insertions, 0 deletions
diff --git a/tmk_core/common/mbed/bootloader.c b/tmk_core/common/mbed/bootloader.c
new file mode 100644
index 000000000..b51e83943
--- /dev/null
+++ b/tmk_core/common/mbed/bootloader.c
@@ -0,0 +1,4 @@
+#include "bootloader.h"
+
+
+void bootloader_jump(void) {}
diff --git a/tmk_core/common/mbed/suspend.c b/tmk_core/common/mbed/suspend.c
new file mode 100644
index 000000000..32651574f
--- /dev/null
+++ b/tmk_core/common/mbed/suspend.c
@@ -0,0 +1,6 @@
+#include <stdbool.h>
+
+
+void suspend_power_down(void) {}
+bool suspend_wakeup_condition(void) { return true; }
+void suspend_wakeup_init(void) {}
diff --git a/tmk_core/common/mbed/timer.c b/tmk_core/common/mbed/timer.c
new file mode 100644
index 000000000..c357ceb78
--- /dev/null
+++ b/tmk_core/common/mbed/timer.c
@@ -0,0 +1,41 @@
+#include "cmsis.h"
+#include "timer.h"
+
+/* Mill second tick count */
+volatile uint32_t timer_count = 0;
+
+/* Timer interrupt handler */
+void SysTick_Handler(void) {
+ timer_count++;
+}
+
+void timer_init(void)
+{
+ timer_count = 0;
+ SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
+}
+
+void timer_clear(void)
+{
+ timer_count = 0;
+}
+
+uint16_t timer_read(void)
+{
+ return (uint16_t)(timer_count & 0xFFFF);
+}
+
+uint32_t timer_read32(void)
+{
+ return timer_count;
+}
+
+uint16_t timer_elapsed(uint16_t last)
+{
+ return TIMER_DIFF_16(timer_read(), last);
+}
+
+uint32_t timer_elapsed32(uint32_t last)
+{
+ return TIMER_DIFF_32(timer_read32(), last);
+}
diff --git a/tmk_core/common/mbed/xprintf.cpp b/tmk_core/common/mbed/xprintf.cpp
new file mode 100644
index 000000000..3647ece75
--- /dev/null
+++ b/tmk_core/common/mbed/xprintf.cpp
@@ -0,0 +1,51 @@
+#include <cstdarg>
+//#include <stdarg.h>
+#include "mbed.h"
+#include "mbed/xprintf.h"
+
+
+#define STRING_STACK_LIMIT 120
+
+//TODO
+int xprintf(const char* format, ...) { return 0; }
+
+#if 0
+/* mbed Serial */
+Serial ser(UART_TX, UART_RX);
+
+/* TODO: Need small implementation for embedded */
+int xprintf(const char* format, ...)
+{
+ /* copy from mbed/common/RawSerial.cpp */
+ std::va_list arg;
+ va_start(arg, format);
+ int len = vsnprintf(NULL, 0, format, arg);
+ if (len < STRING_STACK_LIMIT) {
+ char temp[STRING_STACK_LIMIT];
+ vsprintf(temp, format, arg);
+ ser.puts(temp);
+ } else {
+ char *temp = new char[len + 1];
+ vsprintf(temp, format, arg);
+ ser.puts(temp);
+ delete[] temp;
+ }
+ va_end(arg);
+ return len;
+
+/* Fail: __builtin_va_arg_pack?
+ * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
+ void *arg = __builtin_apply_args();
+ void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
+ __builtin_return(ret)
+*/
+/* Fail: varargs can not be passed to printf
+ //int r = ser.printf("test %i\r\n", 123);
+ va_list arg;
+ va_start(arg, format);
+ int r = ser.printf(format, arg);
+ va_end(arg);
+ return r;
+*/
+}
+#endif
diff --git a/tmk_core/common/mbed/xprintf.h b/tmk_core/common/mbed/xprintf.h
new file mode 100644
index 000000000..26bc529e5
--- /dev/null
+++ b/tmk_core/common/mbed/xprintf.h
@@ -0,0 +1,17 @@
+#ifndef XPRINTF_H
+#define XPRINTF_H
+
+//#define xprintf(format, ...) __xprintf(format, ##__VA_ARGS__)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int xprintf(const char *format, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif