Naze32 clone with Frysky receiver
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

serial.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /** \addtogroup uart UART Library
  33. * UART Library enabling you to control all available
  34. * UART Modules. With XON/XOFF Flow Control and buffered
  35. * Receiving and Transmitting.
  36. * @{
  37. */
  38. /** \file serial.h
  39. * UART Library Header File
  40. */
  41. /** Calculate Baudrate Register Value */
  42. #define BAUD(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
  43. /** Get number of available UART modules.
  44. * \returns number of modules
  45. */
  46. uint8_t serialAvailable(void);
  47. /** Initialize the UART Hardware.
  48. * \param uart UART Module to initialize
  49. * \param baud Baudrate. Use the BAUD() macro!
  50. */
  51. void serialInit(uint8_t uart, uint16_t baud);
  52. /** Stop the UART Hardware.
  53. * \param uart UART Module to stop
  54. */
  55. void serialClose(uint8_t uart);
  56. /** Manually change the flow control.
  57. * Flow Control has to be compiled into the library!
  58. * \param uart UART Module to operate on
  59. * \param on 1 of on, 0 if off
  60. */
  61. void setFlow(uint8_t uart, uint8_t on);
  62. /** Check if a byte was received.
  63. * \param uart UART Module to check
  64. * \returns 1 if a byte was received, 0 if not
  65. */
  66. uint8_t serialHasChar(uint8_t uart);
  67. /** Read a single byte.
  68. * \param uart UART Module to read from
  69. * \returns Received byte or 0
  70. */
  71. uint8_t serialGet(uint8_t uart);
  72. /** Wait until a character is received.
  73. * \param uart UART Module to read from
  74. * \returns Received byte
  75. */
  76. uint8_t serialGetBlocking(uint8_t uart);
  77. /** Check if the receive buffer is full.
  78. * \param uart UART Module to check
  79. * \returns 1 if buffer is full, 0 if not
  80. */
  81. uint8_t serialRxBufferFull(uint8_t uart);
  82. /** Check if the receive buffer is empty.
  83. * \param uart UART Module to check
  84. * \returns 1 if buffer is empty, 0 if not.
  85. */
  86. uint8_t serialRxBufferEmpty(uint8_t uart);
  87. /** Send a byte.
  88. * \param uart UART Module to write to
  89. * \param data Byte to send
  90. */
  91. void serialWrite(uint8_t uart, uint8_t data);
  92. /** Send a string.
  93. * \param uart UART Module to write to
  94. * \param data Null-Terminated String
  95. */
  96. void serialWriteString(uint8_t uart, const char *data);
  97. /** Check if the transmit buffer is full.
  98. * \param uart UART Module to check
  99. * \returns 1 if buffer is full, 0 if not
  100. */
  101. uint8_t serialTxBufferFull(uint8_t uart);
  102. /** Check if the transmit buffer is empty.
  103. * \param uart UART Module to check
  104. * \returns 1 if buffer is empty, 0 if not.
  105. */
  106. uint8_t serialTxBufferEmpty(uint8_t uart);
  107. void serialWriteHex(uint8_t uart, uint8_t value);
  108. void serialWriteUnsigned8(uint8_t uart, uint8_t value);
  109. void serialWriteUnsigned16(uint8_t uart, uint16_t value);
  110. void serialWriteUnsigned32(uint8_t uart, uint32_t value);
  111. void serialWriteUnsigned64(uint8_t uart, uint64_t value);
  112. #endif // _serial_h
  113. /** @} */