forked from mirrors/qmk_userspace
Fix common files for mbed
This commit is contained in:
parent
ee70fe59ee
commit
e81c70149e
23 changed files with 323 additions and 110 deletions
4
common/mbed/bootloader.c
Normal file
4
common/mbed/bootloader.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include "bootloader.h"
|
||||
|
||||
|
||||
void bootloader_jump(void) {}
|
6
common/mbed/suspend.c
Normal file
6
common/mbed/suspend.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
|
||||
void suspend_power_down(void) {}
|
||||
bool suspend_wakeup_condition(void) { return true; }
|
||||
void suspend_wakeup_init(void) {}
|
46
common/mbed/xprintf.cpp
Normal file
46
common/mbed/xprintf.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include <cstdarg>
|
||||
//#include <stdarg.h>
|
||||
#include "mbed.h"
|
||||
#include "mbed/xprintf.h"
|
||||
|
||||
|
||||
#define STRING_STACK_LIMIT 120
|
||||
|
||||
/* 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;
|
||||
*/
|
||||
}
|
17
common/mbed/xprintf.h
Normal file
17
common/mbed/xprintf.h
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue