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.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Name: oddebug.h
  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.h 692 2008-11-07 15:07:40Z cs $
  9. */
  10. #ifndef __oddebug_h_included__
  11. #define __oddebug_h_included__
  12. /*
  13. General Description:
  14. This module implements a function for debug logs on the serial line of the
  15. AVR microcontroller. Debugging can be configured with the define
  16. 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging
  17. calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is
  18. 2, DBG1 and DBG2 logs will be printed.
  19. A debug log consists of a label ('prefix') to indicate which debug log created
  20. the output and a memory block to dump in hex ('data' and 'len').
  21. */
  22. #ifndef F_CPU
  23. # define F_CPU 12000000 /* 12 MHz */
  24. #endif
  25. /* make sure we have the UART defines: */
  26. #include "usbportability.h"
  27. #ifndef uchar
  28. # define uchar unsigned char
  29. #endif
  30. #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
  31. # warning "Debugging disabled because device has no UART"
  32. # undef DEBUG_LEVEL
  33. #endif
  34. #ifndef DEBUG_LEVEL
  35. # define DEBUG_LEVEL 0
  36. #endif
  37. /* ------------------------------------------------------------------------- */
  38. #if DEBUG_LEVEL > 0
  39. # define DBG1(prefix, data, len) odDebug(prefix, data, len)
  40. #else
  41. # define DBG1(prefix, data, len)
  42. #endif
  43. #if DEBUG_LEVEL > 1
  44. # define DBG2(prefix, data, len) odDebug(prefix, data, len)
  45. #else
  46. # define DBG2(prefix, data, len)
  47. #endif
  48. /* ------------------------------------------------------------------------- */
  49. extern void odDebug(uchar prefix, uchar *data, uchar len);
  50. void uartPutc(char c);
  51. void printHex(uchar c);
  52. /* Try to find our control registers; ATMEL likes to rename these */
  53. #if defined UBRR
  54. # define ODDBG_UBRR UBRR
  55. #elif defined UBRRL
  56. # define ODDBG_UBRR UBRRL
  57. #elif defined UBRR0
  58. # define ODDBG_UBRR UBRR0
  59. #elif defined UBRR0L
  60. # define ODDBG_UBRR UBRR0L
  61. #endif
  62. #if defined UCR
  63. # define ODDBG_UCR UCR
  64. #elif defined UCSRB
  65. # define ODDBG_UCR UCSRB
  66. #elif defined UCSR0B
  67. # define ODDBG_UCR UCSR0B
  68. #endif
  69. #if defined TXEN
  70. # define ODDBG_TXEN TXEN
  71. #else
  72. # define ODDBG_TXEN TXEN0
  73. #endif
  74. #if defined USR
  75. # define ODDBG_USR USR
  76. #elif defined UCSRA
  77. # define ODDBG_USR UCSRA
  78. #elif defined UCSR0A
  79. # define ODDBG_USR UCSR0A
  80. #endif
  81. #if defined UDRE
  82. # define ODDBG_UDRE UDRE
  83. #else
  84. # define ODDBG_UDRE UDRE0
  85. #endif
  86. #if defined UDR
  87. # define ODDBG_UDR UDR
  88. #elif defined UDR0
  89. # define ODDBG_UDR UDR0
  90. #endif
  91. static inline void odDebugInit(void)
  92. {
  93. ODDBG_UCR |= (1<<ODDBG_TXEN);
  94. ODDBG_UBRR = F_CPU / (57600 * 16L) - 1;
  95. }
  96. /* ------------------------------------------------------------------------- */
  97. #endif /* __oddebug_h_included__ */