Debug
Overview
Section titled “Overview”The debug methods allow you to print text and numbers on a simple character grid. Some functions use an internal cursor, which can be set with Debug_SetCursorPosition. The units are character cells, not pixels, so setting the cursor to (1,1) refers to the second character on the second line.
Other functions, like Debug_Printf, bypass the cursor at (1,1) means the second line second character.
Methods
Section titled “Methods”Cursor Position
Section titled “Cursor Position”int Debug_SetCursorPosition(unsigned int x, unsigned int y);void Debug_GetCursorPosition(unsigned int *x, unsigned int *y);x and y are the position of the internal text cursor. Debug_PrintString will print text starting at this location.
Print String
Section titled “Print String”bool Debug_PrintString(const char *string, bool invert);Prints a string at the current cursor position. The invert parameter controls the color scheme: false for black-on-white, true for white-on-black.
Print Advanced String
Section titled “Print Advanced String”void Debug_Printf(unsigned int x, unsigned int y, bool invert, int zero, const char *format, ...);Prints a formatted string at the specified character coordinates (x, y), ignoring the internal cursor. The zero parameter must always be 0.
Supports most format specifiers:
%sfor strings%dfor integers%xfor hexadecimal
Print Hex Numbers
Section titled “Print Hex Numbers”void Debug_PrintNumberHex_Nibble(uint8_t value, unsigned int x, unsigned int y);void Debug_PrintNumberHex_Byte(uint8_t value, unsigned int x, unsigned int y);void Debug_PrintNumberHex_Word(uint16_t value, unsigned int x, unsigned int y);void Debug_PrintNumberHex_Dword(uint32_t value, unsigned int x, unsigned int y);Prints the hexadecimal representation of a number at the specified coordinates (x, y).
- nibble: 4-bit number
- byte: 8-bit number
- word: 16-bit number
- dword: 32-bit number
Wait for a Key
Section titled “Wait for a Key”int Debug_WaitKey();Waits until a key is pressed, then returns a number representing the key. It primarily reacts to number keys (returning 0x30-0x39) and the Power/Clear key (returning 0x98).
More details about its return and behavior in the SDK source code
#include <sdk/os/debug.h>#include <sdk/os/lcd.h>
// Print "Hello, world!" at (0, 0) in black on whiteDebug_SetCursorPosition(0, 0);Debug_PrintString("Hello, world!", false);
// Print "Inverted text" at (1, 1) in white on blackDebug_SetCursorPosition(1, 1);Debug_PrintString("Inverted text", true);
// Print the hex number 0x1322 at coordinates (3, 7) directlyDebug_PrintNumberHex_Word(0x1322, 3, 7);
// Print small text with a format stringDebug_Printf(10, 10, false, 0, "Just one number : %d", 42);Debug_Printf(20, 20, false, 0, "Format are still %s in %d!", "cool", 2025);
// Draw the changes we made to VRAM onto the LCDLCD_Refresh();
// Block until the user presses a keyDebug_WaitKey();