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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. void serialInit(uint8_t uart, uint16_t baud);
  57. /** Stop the UART Hardware.
  58. * \param uart UART Module to stop
  59. */
  60. void serialClose(uint8_t uart);
  61. /** Manually change the flow control.
  62. * Flow Control has to be compiled into the library!
  63. * \param uart UART Module to operate on
  64. * \param on 1 of on, 0 if off
  65. */
  66. void setFlow(uint8_t uart, uint8_t on);
  67. /** Check if a byte was received.
  68. * \param uart UART Module to check
  69. * \returns 1 if a byte was received, 0 if not
  70. */
  71. uint8_t serialHasChar(uint8_t uart);
  72. /** Read a single byte.
  73. * \param uart UART Module to read from
  74. * \returns Received byte or 0
  75. */
  76. uint8_t serialGet(uint8_t uart);
  77. /** Wait until a character is received.
  78. * \param uart UART Module to read from
  79. * \returns Received byte
  80. */
  81. uint8_t serialGetBlocking(uint8_t uart);
  82. /** Check if the receive buffer is full.
  83. * \param uart UART Module to check
  84. * \returns 1 if buffer is full, 0 if not
  85. */
  86. uint8_t serialRxBufferFull(uint8_t uart);
  87. /** Check if the receive buffer is empty.
  88. * \param uart UART Module to check
  89. * \returns 1 if buffer is empty, 0 if not.
  90. */
  91. uint8_t serialRxBufferEmpty(uint8_t uart);
  92. /** Send a byte.
  93. * \param uart UART Module to write to
  94. * \param data Byte to send
  95. */
  96. void serialWrite(uint8_t uart, uint8_t data);
  97. /** Send a string.
  98. * \param uart UART Module to write to
  99. * \param data Null-Terminated String
  100. */
  101. void serialWriteString(uint8_t uart, const char *data);
  102. /** Check if the transmit buffer is full.
  103. * \param uart UART Module to check
  104. * \returns 1 if buffer is full, 0 if not
  105. */
  106. uint8_t serialTxBufferFull(uint8_t uart);
  107. /** Check if the transmit buffer is empty.
  108. * \param uart UART Module to check
  109. * \returns 1 if buffer is empty, 0 if not.
  110. */
  111. uint8_t serialTxBufferEmpty(uint8_t uart);
  112. void serialWriteHex(uint8_t uart, uint8_t value);
  113. void serialWriteUnsigned8(uint8_t uart, uint8_t value);
  114. void serialWriteUnsigned16(uint8_t uart, uint16_t value);
  115. void serialWriteUnsigned32(uint8_t uart, uint32_t value);
  116. void serialWriteUnsigned64(uint8_t uart, uint64_t value);
  117. #endif // _serial_h
  118. /** @} */