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 25 #ifndef __CMSIS_VIO_H 26 #define __CMSIS_VIO_H 27 28 #include <stdint.h> 29 30 /******************************************************************************* 31 * Generic I/O mapping recommended for CMSIS-VIO 32 * Note: not every I/O must be physically available 33 */ 34 35 // vioSetSignal: mask values 36 #define vioLED0 (1U << 0) ///< \ref vioSetSignal \a mask parameter: LED 0 (for 3-color: red) 37 #define vioLED1 (1U << 1) ///< \ref vioSetSignal \a mask parameter: LED 1 (for 3-color: green) 38 #define vioLED2 (1U << 2) ///< \ref vioSetSignal \a mask parameter: LED 2 (for 3-color: blue) 39 #define vioLED3 (1U << 3) ///< \ref vioSetSignal \a mask parameter: LED 3 40 #define vioLED4 (1U << 4) ///< \ref vioSetSignal \a mask parameter: LED 4 41 #define vioLED5 (1U << 5) ///< \ref vioSetSignal \a mask parameter: LED 5 42 #define vioLED6 (1U << 6) ///< \ref vioSetSignal \a mask parameter: LED 6 43 #define vioLED7 (1U << 7) ///< \ref vioSetSignal \a mask parameter: LED 7 44 45 // vioSetSignal: signal values 46 #define vioLEDon (0xFFU) ///< \ref vioSetSignal \a signal parameter: pattern to turn any LED on 47 #define vioLEDoff (0x00U) ///< \ref vioSetSignal \a signal parameter: pattern to turn any LED off 48 49 // vioGetSignal: mask values and return values 50 #define vioBUTTON0 (1U << 0) ///< \ref vioGetSignal \a mask parameter: Push button 0 51 #define vioBUTTON1 (1U << 1) ///< \ref vioGetSignal \a mask parameter: Push button 1 52 #define vioBUTTON2 (1U << 2) ///< \ref vioGetSignal \a mask parameter: Push button 2 53 #define vioBUTTON3 (1U << 3) ///< \ref vioGetSignal \a mask parameter: Push button 3 54 #define vioJOYup (1U << 4) ///< \ref vioGetSignal \a mask parameter: Joystick button: up 55 #define vioJOYdown (1U << 5) ///< \ref vioGetSignal \a mask parameter: Joystick button: down 56 #define vioJOYleft (1U << 6) ///< \ref vioGetSignal \a mask parameter: Joystick button: left 57 #define vioJOYright (1U << 7) ///< \ref vioGetSignal \a mask parameter: Joystick button: right 58 #define vioJOYselect (1U << 8) ///< \ref vioGetSignal \a mask parameter: Joystick button: select 59 #define vioJOYall (vioJOYup | \ 60 vioJOYdown | \ 61 vioJOYleft | \ 62 vioJOYright | \ 63 vioJOYselect) ///< \ref vioGetSignal \a mask Joystick button: all 64 65 // vioSetValue / vioGetValue: id values 66 #define vioAIN0 (0U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog input value 0 67 #define vioAIN1 (1U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog input value 1 68 #define vioAIN2 (2U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog input value 2 69 #define vioAIN3 (3U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog input value 3 70 #define vioAOUT0 (3U) ///< \ref vioSetValue / \ref vioGetValue \a id parameter: Analog output value 0 71 72 // vioSetXYZ / vioGetXZY: id values 73 #define vioMotionGyro (0U) ///< \ref vioSetXYZ / \ref vioGetXYZ \a id parameter: for Gyroscope 74 #define vioMotionAccelero (1U) ///< \ref vioSetXYZ / \ref vioGetXYZ \a id parameter: for Accelerometer 75 #define vioMotionMagneto (2U) ///< \ref vioSetXYZ / \ref vioGetXYZ \a id parameter: for Magnetometer 76 77 // vioPrint: levels 78 #define vioLevelNone (0U) ///< \ref vioPrint \a level parameter: None 79 #define vioLevelHeading (1U) ///< \ref vioPrint \a level parameter: Heading 80 #define vioLevelMessage (2U) ///< \ref vioPrint \a level parameter: Message 81 #define vioLevelError (3U) ///< \ref vioPrint \a level parameter: Error 82 83 /// 3-D vector value 84 typedef struct { 85 int32_t X; ///< X coordinate 86 int32_t Y; ///< Y coordinate 87 int32_t Z; ///< Z coordinate 88 } vioValueXYZ_t; 89 90 /// IPv4 Internet Address 91 typedef struct { 92 uint8_t addr[4]; ///< IPv4 address value used in \ref vioSetIPv4 / \ref vioGetIPv4 93 } vioAddrIPv4_t; 94 95 /// IPv6 Internet Address 96 typedef struct { 97 uint8_t addr[16]; ///< IPv6 address value used in \ref vioSetIPv6 / \ref vioGetIPv6 98 } vioAddrIPv6_t; 99 100 #ifdef __cplusplus 101 extern "C" 102 { 103 #endif 104 105 /// Initialize test input, output. 106 /// \return none. 107 void vioInit (void); 108 109 /// Print formated string to test terminal. 110 /// \param[in] level level (vioLevel...). 111 /// \param[in] format formated string to print. 112 /// \param[in] ... optional arguments (depending on format string). 113 /// \return number of characters written or -1 in case of error. 114 int32_t vioPrint (uint32_t level, const char *format, ...); 115 116 /// Set signal output. 117 /// \param[in] mask bit mask of signals to set. 118 /// \param[in] signal signal value to set. 119 /// \return none. 120 void vioSetSignal (uint32_t mask, uint32_t signal); 121 122 /// Get signal input. 123 /// \param[in] mask bit mask of signals to read. 124 /// \return signal value. 125 uint32_t vioGetSignal (uint32_t mask); 126 127 /// Set value output. 128 /// \param[in] id output identifier. 129 /// \param[in] value value to set. 130 /// \return none. 131 void vioSetValue (uint32_t id, int32_t value); 132 133 /// Get value input. 134 /// \param[in] id input identifier. 135 /// \return value retrieved from input. 136 int32_t vioGetValue (uint32_t id); 137 138 /// Set XYZ value output. 139 /// \param[in] id output identifier. 140 /// \param[in] valueXYZ XYZ data to set. 141 /// \return none. 142 void vioSetXYZ (uint32_t id, vioValueXYZ_t valueXYZ); 143 144 /// Get XYZ value input. 145 /// \param[in] id input identifier. 146 /// \return XYZ data retrieved from XYZ peripheral. 147 vioValueXYZ_t vioGetXYZ (uint32_t id); 148 149 /// Set IPv4 address output. 150 /// \param[in] id output identifier. 151 /// \param[in] addrIPv4 pointer to IPv4 address. 152 /// \return none. 153 void vioSetIPv4 (uint32_t id, vioAddrIPv4_t addrIPv4); 154 155 /// Get IPv4 address input. 156 /// \param[in] id input identifier. 157 /// \return IPv4 address retrieved from peripheral. 158 vioAddrIPv4_t vioGetIPv4 (uint32_t id); 159 160 /// Set IPv6 address output. 161 /// \param[in] id output identifier. 162 /// \param[in] addrIPv6 pointer to IPv6 address. 163 /// \return none. 164 void vioSetIPv6 (uint32_t id, vioAddrIPv6_t addrIPv6); 165 166 /// Get IPv6 address from peripheral. 167 /// \param[in] id input identifier. 168 /// \return IPv6 address retrieved from peripheral. 169 vioAddrIPv6_t vioGetIPv6 (uint32_t id); 170 171 #ifdef __cplusplus 172 } 173 #endif 174 175 #endif /* __CMSIS_VIO_H */ 176