1
0

Add keyboard/mbed_onekey

This commit is contained in:
tmk 2014-06-15 13:56:17 +09:00
parent 472603fe3e
commit 89d19ff866
3 changed files with 74 additions and 93 deletions

View File

@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define dprint(s) do { if (debug_enable) print(s); } while (0)
#define dprintln() do { if (debug_enable) print_crlf(); } while (0)
#define dprintf(fmt, ...) do { if (debug_enable) __xprintf(PSTR(fmt), ##__VA_ARGS__); } while (0)
#define dprintf(fmt, ...) do { if (debug_enable) xprintf(fmt, ##__VA_ARGS__); } while (0)
#define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s))
/* DO NOT USE these anymore */

View File

@ -37,26 +37,4 @@ void print_set_sendchar(int8_t (*sendchar_func)(uint8_t))
xdev_out(sendchar_func);
}
void print_S(const char *s)
{
uint8_t c;
while (1) {
c = *s++;
if (!c) break;
if (c == '\n') sendchar('\r');
sendchar(c);
}
}
void print_lf(void)
{
sendchar('\n');
}
void print_crlf(void)
{
sendchar('\r');
sendchar('\n');
}
#endif

View File

@ -27,98 +27,79 @@
#include <stdint.h>
#include <stdbool.h>
#include <avr/pgmspace.h>
#include "xprintf.h"
#include "util.h"
// this macro allows you to write print("some text") and
// the string is automatically placed into flash memory :)
// TODO: avoid collision with arduino/Print.h
#ifndef __cplusplus
#define print(s) print_P(PSTR(s))
#endif
#define println(s) print_P(PSTR(s "\n"))
/* for old name */
#define pdec(data) print_dec(data)
#define pdec16(data) print_dec(data)
#define phex(data) print_hex8(data)
#define phex16(data) print_hex16(data)
#define pbin(data) print_bin8(data)
#define pbin16(data) print_bin16(data)
#define pbin_reverse(data) print_bin_reverse8(data)
#define pbin_reverse16(data) print_bin_reverse16(data)
/* print value utility */
#define print_val_dec(v) xprintf(#v ": %u\n", v)
#define print_val_decs(v) xprintf(#v ": %d\n", v)
#define print_val_hex8(v) xprintf(#v ": %X\n", v)
#define print_val_hex16(v) xprintf(#v ": %02X\n", v)
#define print_val_hex32(v) xprintf(#v ": %04lX\n", v)
#define print_val_bin8(v) xprintf(#v ": %08b\n", v)
#define print_val_bin16(v) xprintf(#v ": %016b\n", v)
#define print_val_bin32(v) xprintf(#v ": %032lb\n", v)
#define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v))
#define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v))
#define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v))
#ifndef NO_PRINT
#ifdef __AVR__
#include "xprintf.h"
// TODO: avoid collision with arduino/Print.h
#ifndef __cplusplus
#define print(s) xputs(PSTR(s))
#endif
#define println(s) xputs(PSTR(s "\n"))
#ifdef __cplusplus
extern "C" {
#endif
/* function pointer of sendchar to be used by print utility */
void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
/* print string stored in data memory(SRAM)
* print_S("hello world");
* This consumes precious SRAM memory space for string.
*/
void print_S(const char *s);
#elif __arm__
void print_lf(void);
void print_crlf(void);
#include "mbed.h"
Serial ser(UART_TX, UART_RX);
#define xprintf ser.printf
#define print(s) xprintf(s)
#define println(s) xprintf(s "\n")
/* TODO: to select output destinations: UART/USBSerial */
#define print_set_sendchar(func)
#endif /* __AVR__ */
/* print string stored in program memory(FLASH)
* print_P(PSTR("hello world");
* This consumes relatively abundant FLASH memory area not SRAM.
*/
#define print_P(s) xputs(s)
/* decimal */
#define print_dec(i) xprintf("%u", i)
#define print_decs(i) xprintf("%d", i)
#define print_dec(i) xprintf("%u", i)
#define print_decs(i) xprintf("%d", i)
/* hex */
#define print_hex4(i) xprintf("%X", i)
#define print_hex8(i) xprintf("%02X", i)
#define print_hex16(i) xprintf("%04X", i)
#define print_hex32(i) xprintf("%08lX", i)
#define print_hex4(i) xprintf("%X", i)
#define print_hex8(i) xprintf("%02X", i)
#define print_hex16(i) xprintf("%04X", i)
#define print_hex32(i) xprintf("%08lX", i)
/* binary */
#define print_bin4(i) xprintf("%04b", i)
#define print_bin8(i) xprintf("%08b", i)
#define print_bin16(i) xprintf("%016b", i)
#define print_bin32(i) xprintf("%032lb", i)
#define print_bin4(i) xprintf("%04b", i)
#define print_bin8(i) xprintf("%08b", i)
#define print_bin16(i) xprintf("%016b", i)
#define print_bin32(i) xprintf("%032lb", i)
#define print_bin_reverse8(i) xprintf("%08b", bitrev(i))
#define print_bin_reverse16(i) xprintf("%016b", bitrev16(i))
#define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i))
/* print value utility */
#define print_val_dec(v) xprintf(#v ": %u\n", v)
#define print_val_decs(v) xprintf(#v ": %d\n", v)
#define print_val_hex8(v) xprintf(#v ": %X\n", v)
#define print_val_hex16(v) xprintf(#v ": %02X\n", v)
#define print_val_hex32(v) xprintf(#v ": %04lX\n", v)
#define print_val_bin8(v) xprintf(#v ": %08b\n", v)
#define print_val_bin16(v) xprintf(#v ": %016b\n", v)
#define print_val_bin32(v) xprintf(#v ": %032lb\n", v)
#define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v))
#define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v))
#define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v))
#define print_bin_reverse8(i) xprintf("%08b", bitrev(i))
#define print_bin_reverse16(i) xprintf("%016b", bitrev16(i))
#define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i))
#ifdef __cplusplus
}
#endif
#else
#else /* NO_PRINT */
#define xprintf
#define print
#define println
#define print_set_sendchar(func)
#define print_S(s)
#define print_P(s)
#define print_dec(data)
#define print_decs(data)
#define print_hex4(data)
@ -132,8 +113,30 @@ void print_crlf(void);
#define print_bin_reverse8(data)
#define print_bin_reverse16(data)
#define print_bin_reverse32(data)
#define print_val_dec(v)
#define print_val_decs(v)
#define print_val_hex8(v)
#define print_val_hex16(v)
#define print_val_hex32(v)
#define print_val_bin8(v)
#define print_val_bin16(v)
#define print_val_bin32(v)
#define print_val_bin_reverse8(v)
#define print_val_bin_reverse16(v)
#define print_val_bin_reverse32(v)
#endif
#endif /* NO_PRINT */
/* Backward compatiblitly for old name */
#define pdec(data) print_dec(data)
#define pdec16(data) print_dec(data)
#define phex(data) print_hex8(data)
#define phex16(data) print_hex16(data)
#define pbin(data) print_bin8(data)
#define pbin16(data) print_bin16(data)
#define pbin_reverse(data) print_bin_reverse8(data)
#define pbin_reverse16(data) print_bin_reverse16(data)
#endif