Naze32 clone with Frysky receiver
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

serial.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * serial.h
  3. *
  4. * Copyright (c) 2012, 2013, Thomas Buck <xythobuz@me.com>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * - Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. *
  14. * - Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  20. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _serial_h
  31. #define _serial_h
  32. #include <stdint.h>
  33. /** \addtogroup uart UART Library
  34. * UART Library enabling you to control all available
  35. * UART Modules. With XON/XOFF Flow Control and buffered
  36. * Receiving and Transmitting.
  37. * @{
  38. */
  39. /** \file serial.h
  40. * UART Library Header File
  41. */
  42. #if defined(__AVR__)
  43. /** Calculate Baudrate Register Value */
  44. #define BAUD(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
  45. #else
  46. #define BAUD(baudRate,xtalCpu) (baudRate)
  47. #endif
  48. /** Get number of available UART modules.
  49. * \returns number of modules
  50. */
  51. uint8_t serialAvailable(void);
  52. /** Initialize the UART Hardware.
  53. * \param uart UART Module to initialize
  54. * \param baud Baudrate. Use the BAUD() macro!
  55. */
  56. #if defined(__AVR__)
  57. void serialInit(uint8_t uart, uint16_t baud);
  58. #else
  59. void serialInit(uint8_t uart, uint32_t baud);
  60. #endif
  61. /** Stop the UART Hardware.
  62. * \param uart UART Module to stop
  63. */
  64. void serialClose(uint8_t uart);
  65. /** Manually change the flow control.
  66. * Flow Control has to be compiled into the library!
  67. * \param uart UART Module to operate on
  68. * \param on 1 of on, 0 if off
  69. */
  70. void setFlow(uint8_t uart, uint8_t on);
  71. /** Check if a byte was received.
  72. * \param uart UART Module to check
  73. * \returns 1 if a byte was received, 0 if not
  74. */
  75. uint8_t serialHasChar(uint8_t uart);
  76. /** Read a single byte.
  77. * \param uart UART Module to read from
  78. * \returns Received byte or 0
  79. */
  80. uint8_t serialGet(uint8_t uart);
  81. /** Wait until a character is received.
  82. * \param uart UART Module to read from
  83. * \returns Received byte
  84. */
  85. uint8_t serialGetBlocking(uint8_t uart);
  86. /** Check if the receive buffer is full.
  87. * \param uart UART Module to check
  88. * \returns 1 if buffer is full, 0 if not
  89. */
  90. uint8_t serialRxBufferFull(uint8_t uart);
  91. /** Check if the receive buffer is empty.
  92. * \param uart UART Module to check
  93. * \returns 1 if buffer is empty, 0 if not.
  94. */
  95. uint8_t serialRxBufferEmpty(uint8_t uart);
  96. /** Send a byte.
  97. * \param uart UART Module to write to
  98. * \param data Byte to send
  99. */
  100. void serialWrite(uint8_t uart, uint8_t data);
  101. /** Send a string.
  102. * \param uart UART Module to write to
  103. * \param data Null-Terminated String
  104. */
  105. void serialWriteString(uint8_t uart, const char *data);
  106. /** Check if the transmit buffer is full.
  107. * \param uart UART Module to check
  108. * \returns 1 if buffer is full, 0 if not
  109. */
  110. uint8_t serialTxBufferFull(uint8_t uart);
  111. /** Check if the transmit buffer is empty.
  112. * \param uart UART Module to check
  113. * \returns 1 if buffer is empty, 0 if not.
  114. */
  115. uint8_t serialTxBufferEmpty(uint8_t uart);
  116. void serialWriteHex(uint8_t uart, uint8_t value);
  117. void serialWriteUnsigned8(uint8_t uart, uint8_t value);
  118. void serialWriteUnsigned16(uint8_t uart, uint16_t value);
  119. void serialWriteUnsigned32(uint8_t uart, uint32_t value);
  120. void serialWriteUnsigned64(uint8_t uart, uint64_t value);
  121. #endif // _serial_h
  122. /** @} */