summaryrefslogtreecommitdiff
path: root/firmware/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/debug.c')
-rw-r--r--firmware/debug.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/firmware/debug.c b/firmware/debug.c
new file mode 100644
index 0000000..539a3e2
--- /dev/null
+++ b/firmware/debug.c
@@ -0,0 +1,72 @@
+#include <inttypes.h>
+#include <avr/io.h>
+
+#include "uart.h"
+#include "debug.h"
+#include "common.h"
+#include "protocol.h"
+
+#define UART_PORT 0
+
+void debug_init(void) {
+ uart_init(UART_PORT);
+ uart_baudrate(UART_PORT, 25, 0, 0, 0);
+ uart_stopbits(UART_PORT, 1);
+ uart_databits(UART_PORT, 8);
+ uart_parity(UART_PORT, 'N');
+}
+
+void debug_deinit(void) {
+ uart_deinit(UART_PORT);
+}
+
+void debug_write(char *buf) {
+ while(*buf)
+ uart_putchar(UART_PORT, *buf++);
+}
+
+unsigned char debug_AsciiToHex(unsigned char high, unsigned char low)
+{
+ unsigned char new;
+
+ // check if lower equal 9 ( ascii 57 )
+ if(high <= 57) // high is a number
+ high = high -48;
+ else // high is a letter
+ high = high -87;
+
+ high = high << 4;
+ high = high & 0xF0;
+
+ // check if lower equal 9 ( ascii 57 )
+ if(low <= 57) // high is a number
+ low = low -48;
+ else // high is a letter
+ low = low -87;
+ low = low & 0x0F;
+
+ new = high | low;
+
+ return new;
+}
+
+void debug_SendHex(unsigned char hex)
+{
+ unsigned char high,low;
+ // get highnibble
+ high = hex & 0xF0;
+ high = high >> 4;
+
+ // get lownibble
+ low = hex & 0x0F;
+
+ if(high<=9)
+ uart_putchar(UART_PORT, high+48);
+ else
+ uart_putchar(UART_PORT, high+87);
+
+ if(low<=9)
+ uart_putchar(UART_PORT, low+48);
+ else
+ uart_putchar(UART_PORT, low+87);
+}