Keyboard firmwares for Atmel AVR and Cortex-M
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.

usart_print.c 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Name: oddebug.c
  2. * Project: AVR library
  3. * Author: Christian Starkjohann
  4. * Creation Date: 2005-01-16
  5. * Tabsize: 4
  6. * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
  7. * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
  8. * This Revision: $Id: oddebug.c 692 2008-11-07 15:07:40Z cs $
  9. */
  10. #include "usart_print.h"
  11. #include "sendchar.h"
  12. int8_t sendchar(uint8_t c)
  13. {
  14. while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
  15. ODDBG_UDR = c;
  16. return 0;
  17. }
  18. void uartPutc(char c)
  19. {
  20. while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
  21. ODDBG_UDR = c;
  22. }
  23. static uchar hexAscii(uchar h)
  24. {
  25. h &= 0xf;
  26. if(h >= 10)
  27. h += 'a' - (uchar)10 - '0';
  28. h += '0';
  29. return h;
  30. }
  31. void printHex(uchar c)
  32. {
  33. uartPutc(hexAscii(c >> 4));
  34. uartPutc(hexAscii(c));
  35. }
  36. void odDebug(uchar prefix, uchar *data, uchar len)
  37. {
  38. printHex(prefix);
  39. uartPutc(':');
  40. while(len--){
  41. uartPutc(' ');
  42. printHex(*data++);
  43. }
  44. uartPutc('\r');
  45. uartPutc('\n');
  46. }