You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
750 B
39 lines
750 B
#include "debug.h"
|
|
#include <stdio.h>
|
|
|
|
char debugStr[DEBUGCHARS];
|
|
volatile char dbgCurChar;
|
|
volatile uint8_t dbgStrFill; // amount of available chars in debugStr
|
|
volatile uint8_t dbgHasNewSPI;
|
|
|
|
void dbgLog(const char* fmt, ...) {
|
|
uint8_t maxwrite = DEBUGCHARS - dbgStrFill;
|
|
va_list va;
|
|
va_start(va,fmt);
|
|
char* pos = debugStr + dbgStrFill;
|
|
dbgStrFill += vsnprintf(pos, maxwrite, fmt, va);
|
|
va_end(va);
|
|
}
|
|
|
|
uint8_t dbgHasNew() {
|
|
dbgHasNewSPI = (dbgStrFill > 0);
|
|
return (dbgStrFill > 0);
|
|
}
|
|
|
|
char dbgReadChar() {
|
|
if(dbgHasNew()) {
|
|
char ret = debugStr[0];
|
|
for(int i=0; i<dbgStrFill-1; i++) {
|
|
debugStr[i] = debugStr[i+1];
|
|
}
|
|
dbgStrFill--;
|
|
return ret;
|
|
} else {
|
|
return 0xFF;
|
|
}
|
|
}
|
|
|
|
void dbgAdvanceChar() {
|
|
dbgCurChar = dbgReadChar();
|
|
}
|