cmsis_vio.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /******************************************************************************
  2. * @file cmsis_vio.h
  3. * @brief CMSIS Virtual I/O header file
  4. * @version V0.1.0
  5. * @date 23. March 2020
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2019-2020 Arm Limited. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #ifndef __CMSIS_VIO_H
  25. #define __CMSIS_VIO_H
  26. #include <stdint.h>
  27. /*******************************************************************************
  28. * Generic I/O mapping recommended for CMSIS-VIO
  29. * Note: not every I/O must be physically available
  30. */
  31. // vioSetSignal: mask values
  32. #define vioLED0 (1U << 0) ///< \ref vioSetSignal \a mask parameter: LED 0 (for 3-color: red)
  33. #define vioLED1 (1U << 1) ///< \ref vioSetSignal \a mask parameter: LED 1 (for 3-color: green)
  34. #define vioLED2 (1U << 2) ///< \ref vioSetSignal \a mask parameter: LED 2 (for 3-color: blue)
  35. #define vioLED3 (1U << 3) ///< \ref vioSetSignal \a mask parameter: LED 3
  36. #define vioLED4 (1U << 4) ///< \ref vioSetSignal \a mask parameter: LED 4
  37. #define vioLED5 (1U << 5) ///< \ref vioSetSignal \a mask parameter: LED 5
  38. #define vioLED6 (1U << 6) ///< \ref vioSetSignal \a mask parameter: LED 6
  39. #define vioLED7 (1U << 7) ///< \ref vioSetSignal \a mask parameter: LED 7
  40. // vioSetSignal: signal values
  41. #define vioLEDon (0xFFU) ///< \ref vioSetSignal \a signal parameter: pattern to turn any LED on
  42. #define vioLEDoff (0x00U) ///< \ref vioSetSignal \a signal parameter: pattern to turn any LED off
  43. // vioGetSignal: mask values and return values
  44. #define vioBUTTON0 (1U << 0) ///< \ref vioGetSignal \a mask parameter: Push button 0
  45. #define vioBUTTON1 (1U << 1) ///< \ref vioGetSignal \a mask parameter: Push button 1
  46. #define vioBUTTON2 (1U << 2) ///< \ref vioGetSignal \a mask parameter: Push button 2
  47. #define vioBUTTON3 (1U << 3) ///< \ref vioGetSignal \a mask parameter: Push button 3
  48. #define vioJOYup (1U << 4) ///< \ref vioGetSignal \a mask parameter: Joystick button: up
  49. #define vioJOYdown (1U << 5) ///< \ref vioGetSignal \a mask parameter: Joystick button: down
  50. #define vioJOYleft (1U << 6) ///< \ref vioGetSignal \a mask parameter: Joystick button: left
  51. #define vioJOYright (1U << 7) ///< \ref vioGetSignal \a mask parameter: Joystick button: right
  52. #define vioJOYselect (1U << 8) ///< \ref vioGetSignal \a mask parameter: Joystick button: select
  53. #define vioJOYall (vioJOYup | \
  54. vioJOYdown | \
  55. vioJOYleft | \
  56. vioJOYright | \
  57. vioJOYselect) ///< \ref vioGetSignal \a mask Joystick button: all
  58. // vioSetValue / vioGetValue: id values
  59. #define vioAIN0 (0U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog input value 0
  60. #define vioAIN1 (1U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog input value 1
  61. #define vioAIN2 (2U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog input value 2
  62. #define vioAIN3 (3U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog input value 3
  63. #define vioAOUT0 (3U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog output value 0
  64. // vioSetXYZ / vioGetXZY: id values
  65. #define vioMotionGyro (0U) ///< \ref vioSetXYZ / \ref vioGetXYZ \a id parameter: for Gyroscope
  66. #define vioMotionAccelero (1U) ///< \ref vioSetXYZ / \ref vioGetXYZ \a id parameter: for Accelerometer
  67. #define vioMotionMagneto (2U) ///< \ref vioSetXYZ / \ref vioGetXYZ \a id parameter: for Magnetometer
  68. // vioPrint: levels
  69. #define vioLevelNone (0U) ///< \ref vioPrint \a level parameter: None
  70. #define vioLevelHeading (1U) ///< \ref vioPrint \a level parameter: Heading
  71. #define vioLevelMessage (2U) ///< \ref vioPrint \a level parameter: Message
  72. #define vioLevelError (3U) ///< \ref vioPrint \a level parameter: Error
  73. /// 3-D vector value
  74. typedef struct {
  75. int32_t X; ///< X coordinate
  76. int32_t Y; ///< Y coordinate
  77. int32_t Z; ///< Z coordinate
  78. } vioValueXYZ_t;
  79. /// IPv4 Internet Address
  80. typedef struct {
  81. uint8_t addr[4]; ///< IPv4 address value used in \ref vioSetIPv4 / \ref vioGetIPv4
  82. } vioAddrIPv4_t;
  83. /// IPv6 Internet Address
  84. typedef struct {
  85. uint8_t addr[16]; ///< IPv6 address value used in \ref vioSetIPv6 / \ref vioGetIPv6
  86. } vioAddrIPv6_t;
  87. #ifdef __cplusplus
  88. extern "C"
  89. {
  90. #endif
  91. /// Initialize test input, output.
  92. /// \return none.
  93. void vioInit (void);
  94. /// Print formated string to test terminal.
  95. /// \param[in] level level (vioLevel...).
  96. /// \param[in] format formated string to print.
  97. /// \param[in] ... optional arguments (depending on format string).
  98. /// \return number of characters written or -1 in case of error.
  99. int32_t vioPrint (uint32_t level, const char *format, ...);
  100. /// Set signal output.
  101. /// \param[in] mask bit mask of signals to set.
  102. /// \param[in] signal signal value to set.
  103. /// \return none.
  104. void vioSetSignal (uint32_t mask, uint32_t signal);
  105. /// Get signal input.
  106. /// \param[in] mask bit mask of signals to read.
  107. /// \return signal value.
  108. uint32_t vioGetSignal (uint32_t mask);
  109. /// Set value output.
  110. /// \param[in] id output identifier.
  111. /// \param[in] value value to set.
  112. /// \return none.
  113. void vioSetValue (uint32_t id, int32_t value);
  114. /// Get value input.
  115. /// \param[in] id input identifier.
  116. /// \return value retrieved from input.
  117. int32_t vioGetValue (uint32_t id);
  118. /// Set XYZ value output.
  119. /// \param[in] id output identifier.
  120. /// \param[in] valueXYZ XYZ data to set.
  121. /// \return none.
  122. void vioSetXYZ (uint32_t id, vioValueXYZ_t valueXYZ);
  123. /// Get XYZ value input.
  124. /// \param[in] id input identifier.
  125. /// \return XYZ data retrieved from XYZ peripheral.
  126. vioValueXYZ_t vioGetXYZ (uint32_t id);
  127. /// Set IPv4 address output.
  128. /// \param[in] id output identifier.
  129. /// \param[in] addrIPv4 pointer to IPv4 address.
  130. /// \return none.
  131. void vioSetIPv4 (uint32_t id, vioAddrIPv4_t addrIPv4);
  132. /// Get IPv4 address input.
  133. /// \param[in] id input identifier.
  134. /// \return IPv4 address retrieved from peripheral.
  135. vioAddrIPv4_t vioGetIPv4 (uint32_t id);
  136. /// Set IPv6 address output.
  137. /// \param[in] id output identifier.
  138. /// \param[in] addrIPv6 pointer to IPv6 address.
  139. /// \return none.
  140. void vioSetIPv6 (uint32_t id, vioAddrIPv6_t addrIPv6);
  141. /// Get IPv6 address from peripheral.
  142. /// \param[in] id input identifier.
  143. /// \return IPv6 address retrieved from peripheral.
  144. vioAddrIPv6_t vioGetIPv6 (uint32_t id);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif /* __CMSIS_VIO_H */