From 1d03a2ce3f1c013225b5f33156592be8a1ed1223 Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Sun, 7 Feb 2021 22:04:44 +0000 Subject: [PATCH] Added display debug to part7 to help resolve Bluetooth issues --- part7-bluetooth/kernel.c | 55 ++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/part7-bluetooth/kernel.c b/part7-bluetooth/kernel.c index 4aaafba..460f2b7 100644 --- a/part7-bluetooth/kernel.c +++ b/part7-bluetooth/kernel.c @@ -1,35 +1,70 @@ #include "io.h" #include "bt.h" +#include "fb.h" + +int curx = 0; +int cury = 0; + +int strlen(const char *str) { + const char *s; + + for (s = str; *s; ++s); + return (s - str); +} + +void debugstr(char *str) { + if (curx + (strlen(str) * 8) >= 1920) { + curx = 0; cury += 8; + } + drawString(curx, cury, str, 0x0f, 1); + curx += (strlen(str) * 8); +} + +void debugcrlf(void) { + curx = 0; cury += 8; +} + +void debugch(unsigned char b) { + unsigned int n; + int c; + for(c=4;c>=0;c-=4) { + n=(b>>c)&0xF; + n+=n>9?0x37:0x30; + debugstr((char *)&n); + } + debugstr(" "); +} void main() { + fb_init(); uart_init(); bt_init(); - uart_writeText("Initialising Bluetooth: "); - uart_writeText(">> reset: "); + debugstr("Initialising Bluetooth: "); + debugstr(">> reset: "); bt_reset(); - uart_writeText(">> firmware load: "); + debugstr(">> firmware load: "); bt_loadfirmware(); - uart_writeText(">> set baud: "); + debugstr(">> set baud: "); bt_setbaud(); - uart_writeText(">> set bdaddr: "); + debugstr(">> set bdaddr: "); bt_setbdaddr(); // Print the BD_ADDR unsigned char local_addr[6]; bt_getbdaddr(local_addr); - for (int c=5;c>=0;c--) uart_byte(local_addr[c]); - uart_writeText("\n"); + for (int c=5;c>=0;c--) debugch(local_addr[c]); + debugcrlf(); // Start advertising - uart_writeText("Setting event mask... "); + debugstr("Setting event mask... "); setLEeventmask(0xff); - uart_writeText("Starting advertsing... "); + debugstr("Starting advertsing... "); startActiveAdvertising(); // Enter an infinite loop - uart_writeText("Going loopy..."); + debugstr("Going loopy..."); while (1) { uart_update(); }