Kiibohd Controller
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

print.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Copyright (C) 2011-2016 by Jacob Alexander
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. #pragma once
  22. // ----- Includes -----
  23. // Compiler Includes
  24. #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
  25. #include <avr/pgmspace.h>
  26. #endif
  27. // Project Includes
  28. #include <output_com.h>
  29. // ----- Defines -----
  30. #define NL "\r\n"
  31. // ----- Functions and Corresponding Function Aliases -----
  32. /* XXX
  33. * Note that all the variadic functions below, take comma separated string lists, they are purposely not printf style (simplicity)
  34. */
  35. // Function Aliases
  36. #define dPrint(c) Output_putstr(c)
  37. #define dPrintStr(c) Output_putstr(c)
  38. #define dPrintStrs(...) printstrs(__VA_ARGS__, "\0\0\0") // Convenience Variadic Macro
  39. #define dPrintStrNL(c) dPrintStrs (c, NL) // Appends New Line Macro
  40. #define dPrintStrsNL(...) printstrs(__VA_ARGS__, NL, "\0\0\0") // Appends New Line Macro
  41. // Special Msg Constructs (Uses VT100 tags)
  42. #define dPrintMsg(colour_code_str,msg,...) \
  43. printstrs("\033[", colour_code_str, "m", msg, "\033[0m - ", __VA_ARGS__, NL, "\0\0\0")
  44. #define printMsgNL(colour_code_str,msg,str) \
  45. print("\033[" colour_code_str "m" msg "\033[0m - " str NL)
  46. #define printMsg(colour_code_str,msg,str) \
  47. print("\033[" colour_code_str "m" msg "\033[0m - " str)
  48. // Info Messages
  49. #define info_dPrint(...) dPrintMsg ("1;32", "INFO", __VA_ARGS__) // Info Msg
  50. #define info_print(str) printMsgNL ("1;32", "INFO", str) // Info Msg
  51. #define info_msg(str) printMsg ("1;32", "INFO", str) // Info Msg
  52. // Warning Messages
  53. #define warn_dPrint(...) dPrintMsg ("1;33", "WARNING", __VA_ARGS__) // Warning Msg
  54. #define warn_print(str) printMsgNL ("1;33", "WARNING", str) // Warning Msg
  55. #define warn_msg(str) printMsg ("1;33", "WARNING", str) // Warning Msg
  56. // Error Messages
  57. #define erro_dPrint(...) dPrintMsg ("1;5;31", "ERROR", __VA_ARGS__) // Error Msg
  58. #define erro_print(str) printMsgNL ("1;5;31", "ERROR", str) // Error Msg
  59. #define erro_msg(str) printMsg ("1;5;31", "ERROR", str) // Error Msg
  60. // Debug Messages
  61. #define dbug_dPrint(...) dPrintMsg ("1;35", "DEBUG", __VA_ARGS__) // Debug Msg
  62. #define dbug_print(str) printMsgNL ("1;35", "DEBUG", str) // Debug Msg
  63. #define dbug_msg(str) printMsg ("1;35", "DEBUG", str) // Debug Msg
  64. // Static String Printing
  65. #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
  66. #define print(s) _print(PSTR(s))
  67. #else
  68. #define print(s) _print(s)
  69. #endif
  70. void _print( const char *s );
  71. void printstrs( char* first, ... );
  72. // Printing numbers
  73. #define printHex(hex) printHex_op(hex, 1)
  74. #define printHex32(hex) printHex32_op(hex, 1)
  75. void printInt8 ( uint8_t in );
  76. void printInt16 ( uint16_t in );
  77. void printInt32 ( uint32_t in );
  78. void printHex_op ( uint16_t in, uint8_t op );
  79. void printHex32_op( uint32_t in, uint8_t op );
  80. // String Functions
  81. #define hexToStr(hex, out) hexToStr_op(hex, out, 1)
  82. void int8ToStr ( uint8_t in, char* out );
  83. void int16ToStr ( uint16_t in, char* out );
  84. void int32ToStr ( uint32_t in, char* out );
  85. void hexToStr_op ( uint16_t in, char* out, uint8_t op );
  86. void hex32ToStr_op( uint32_t in, char* out, uint8_t op );
  87. void revsStr ( char* in );
  88. uint16_t lenStr ( char* in );
  89. int16_t eqStr ( char* str1, char* str2 ); // Returns -1 if identical, last character of str1 comparison (0 if str1 is like str2)
  90. int numToInt ( char* in ); // Returns the int representation of a string
  91. void hex32ToStr16 ( uint32_t in, uint16_t* out, uint8_t op ); // Used for USB Descriptors