9 #error Commands over 255 bytes not supported, change type of cmdbuf_len
12 /**************************************************************/
15 static uint8_t cmdbuf_len; // number of bytes in command buf
16 static uint8_t cmdbuf[CMDBUF_SIZ+1]; // null terminator space
17 static bool got_line = false;
19 static void prompt(void)
24 void console_init(void)
29 bool console_rx_ready_callback(void)
34 void console_rx_callback(uint8_t c)
36 if (got_line) // throw away chars until the line is handled
46 case '\b': // backspace
57 if (cmdbuf_len < sizeof(cmdbuf)-1)
60 cmdbuf[cmdbuf_len++] = c;
63 console_putc('\a'); // bell
68 void console_tick(void)
74 cmdbuf[cmdbuf_len] = 0; // terminate it
75 shell_eval((char *)cmdbuf);
83 void console_putc(uint8_t c)
88 void console_newline(void)
94 void console_puts(char *str)
100 static char nibble_to_char(uint8_t nibble)
104 return nibble - 0xA + 'A';
107 void console_puthex8(uint8_t h)
109 console_putc(nibble_to_char((h & 0xF0)>>4));
110 console_putc(nibble_to_char(h & 0x0F));
113 void console_puthex16(uint16_t h)
115 console_puthex8((h & 0xFF00) >> 8);
116 console_puthex8(h & 0xFF);
119 void console_put0x8(uint8_t h)
126 void console_putsmem(const uint8_t *a, const uint8_t *b)
135 void console_putdec(uint32_t n)
138 bool in_leading_zeroes = true;
140 for (m = 1000000000; m != 1; m/=10)
143 in_leading_zeroes = false;
144 if (!in_leading_zeroes)
145 console_putc(nibble_to_char(n / m));
148 console_putc(nibble_to_char(n));
151 void console_putbin(uint8_t b)
154 (b & 0x80) ? console_putc('1') : console_putc('0');
155 (b & 0x40) ? console_putc('1') : console_putc('0');
156 (b & 0x20) ? console_putc('1') : console_putc('0');
157 (b & 0x10) ? console_putc('1') : console_putc('0');
158 (b & 0x08) ? console_putc('1') : console_putc('0');
159 (b & 0x04) ? console_putc('1') : console_putc('0');
160 (b & 0x02) ? console_putc('1') : console_putc('0');
161 (b & 0x01) ? console_putc('1') : console_putc('0');