main: add printing utilities
This commit is contained in:
parent
3e9a10ac08
commit
07e2df9fde
34
main.c
34
main.c
|
@ -57,6 +57,40 @@ static void wait_10us(uint32_t us10)
|
||||||
while (us10--); // burn energy
|
while (us10--); // burn energy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void putc(char c)
|
||||||
|
{
|
||||||
|
while (!UART1->SR.fields.TXE); // wait until TX buffer is empty
|
||||||
|
UART1->DR.reg = c; // put character in buffer to be transmitted
|
||||||
|
// don't wait until the transmission is complete
|
||||||
|
}
|
||||||
|
|
||||||
|
void puts(const char* s)
|
||||||
|
{
|
||||||
|
if (NULL == s) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (*s) {
|
||||||
|
putc(*s++);
|
||||||
|
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void putn(uint8_t n)
|
||||||
|
{
|
||||||
|
n &= 0x0f; // ensure it's a nibble
|
||||||
|
if (n < 0xa) {
|
||||||
|
putc('0' + n);
|
||||||
|
} else {
|
||||||
|
putc('a' + (n - 0x0a));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void puth(uint8_t h)
|
||||||
|
{
|
||||||
|
putn(h >> 4);
|
||||||
|
putn(h & 0x0f);
|
||||||
|
}
|
||||||
|
|
||||||
// verify (E-)EDID checksums
|
// verify (E-)EDID checksums
|
||||||
// the sum of the bytes (including checksum at the end) must be 0
|
// the sum of the bytes (including checksum at the end) must be 0
|
||||||
static bool checksum_ok(const uint8_t* data, uint16_t length)
|
static bool checksum_ok(const uint8_t* data, uint16_t length)
|
||||||
|
|
9
main.h
9
main.h
|
@ -35,3 +35,12 @@
|
||||||
|
|
||||||
// address of I²C EEPROM slave device containing EDID information
|
// address of I²C EEPROM slave device containing EDID information
|
||||||
#define I2C_SLAVE 0x50
|
#define I2C_SLAVE 0x50
|
||||||
|
|
||||||
|
/** print character
|
||||||
|
* @param[in] c character to print
|
||||||
|
*/
|
||||||
|
void putc(char c);
|
||||||
|
/** print string
|
||||||
|
* @param[in] s string to print
|
||||||
|
*/
|
||||||
|
void puts(const char* s);
|
||||||
|
|
Loading…
Reference in New Issue