diff options
| author | tmk <nobody@nowhere> | 2012-10-25 03:28:25 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-10-27 02:27:09 +0900 |
| commit | 220de27bed198c2ea27886986de7afd8013d5545 (patch) | |
| tree | 7360d98d3d0280596a2d69ba39e160d854f31ea1 /common/print.c | |
| parent | ad24858e4fec8bb9af9d89ebf42cda3fffcfdff5 (diff) | |
| download | qmk_firmware-220de27bed198c2ea27886986de7afd8013d5545.tar.gz qmk_firmware-220de27bed198c2ea27886986de7afd8013d5545.zip | |
Add print_dec() and debug_dec().
Diffstat (limited to 'common/print.c')
| -rw-r--r-- | common/print.c | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/common/print.c b/common/print.c index dd73ff59d..6a8a725bc 100644 --- a/common/print.c +++ b/common/print.c | |||
| @@ -22,16 +22,18 @@ | |||
| 22 | * THE SOFTWARE. | 22 | * THE SOFTWARE. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include <stdio.h> | ||
| 26 | #include <avr/io.h> | 25 | #include <avr/io.h> |
| 27 | #include <avr/pgmspace.h> | 26 | #include <avr/pgmspace.h> |
| 28 | #include "print.h" | 27 | #include "print.h" |
| 28 | |||
| 29 | |||
| 29 | #define sendchar(c) do { if (print_enable && print_sendchar_func) (print_sendchar_func)(c); } while (0) | 30 | #define sendchar(c) do { if (print_enable && print_sendchar_func) (print_sendchar_func)(c); } while (0) |
| 30 | 31 | ||
| 31 | 32 | ||
| 32 | int8_t (*print_sendchar_func)(uint8_t) = NULL; | 33 | int8_t (*print_sendchar_func)(uint8_t) = 0; |
| 33 | bool print_enable = false; | 34 | bool print_enable = false; |
| 34 | 35 | ||
| 36 | |||
| 35 | /* print string stored in data memory(SRAM) | 37 | /* print string stored in data memory(SRAM) |
| 36 | * print_P("hello world"); | 38 | * print_P("hello world"); |
| 37 | * This consumes precious SRAM memory space for string. | 39 | * This consumes precious SRAM memory space for string. |
| @@ -62,6 +64,55 @@ void print_P(const char *s) | |||
| 62 | } | 64 | } |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 67 | void print_CRLF(void) | ||
| 68 | { | ||
| 69 | sendchar('\r'); sendchar('\n'); | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | #define SIGNED 0x80 | ||
| 74 | #define BIN 2 | ||
| 75 | #define OCT 8 | ||
| 76 | #define DEC 10 | ||
| 77 | #define HEX 16 | ||
| 78 | |||
| 79 | static inline | ||
| 80 | char itoc(uint8_t i) | ||
| 81 | { | ||
| 82 | return (i < 10 ? '0' + i : 'A' + i - 10); | ||
| 83 | } | ||
| 84 | |||
| 85 | static inline | ||
| 86 | void print_int(uint16_t data, uint8_t base) | ||
| 87 | { | ||
| 88 | char buf[7] = {'\0'}; | ||
| 89 | char *p = &buf[6]; | ||
| 90 | if ((base & SIGNED) && (data & 0x8000)) { | ||
| 91 | data = -data; | ||
| 92 | buf[0] = '-'; | ||
| 93 | } | ||
| 94 | base &= ~SIGNED; | ||
| 95 | uint16_t n; | ||
| 96 | do { | ||
| 97 | n = data; | ||
| 98 | data /= base; | ||
| 99 | *(--p) = itoc(n - data*base); | ||
| 100 | } while (data); | ||
| 101 | if (buf[0]) *(--p) = buf[0]; | ||
| 102 | print_S(p); | ||
| 103 | } | ||
| 104 | |||
| 105 | void print_dec(uint16_t data) | ||
| 106 | { | ||
| 107 | print_int(data, DEC); | ||
| 108 | } | ||
| 109 | |||
| 110 | void print_decs(int16_t data) | ||
| 111 | { | ||
| 112 | print_int(data, DEC|SIGNED); | ||
| 113 | } | ||
| 114 | |||
| 115 | |||
| 65 | static inline | 116 | static inline |
| 66 | void print_hex4(uint8_t data) | 117 | void print_hex4(uint8_t data) |
| 67 | { | 118 | { |
| @@ -86,22 +137,6 @@ void print_hex32(uint32_t data) | |||
| 86 | print_hex16(data); | 137 | print_hex16(data); |
| 87 | } | 138 | } |
| 88 | 139 | ||
| 89 | void print_dec8(uint8_t data) | ||
| 90 | { | ||
| 91 | if (data/100) sendchar('0' + (data/100)); | ||
| 92 | if (data/100 || data%100/10) sendchar('0' + (data%100/10)); | ||
| 93 | sendchar('0' + (data%10)); | ||
| 94 | } | ||
| 95 | |||
| 96 | void print_dec16(uint16_t data) | ||
| 97 | { | ||
| 98 | // TODO | ||
| 99 | } | ||
| 100 | |||
| 101 | void print_dec32(uint32_t data) | ||
| 102 | { | ||
| 103 | // TODO | ||
| 104 | } | ||
| 105 | 140 | ||
| 106 | void print_bin(uint8_t data) | 141 | void print_bin(uint8_t data) |
| 107 | { | 142 | { |
