All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vexdigital.h
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) James Pearman */
4 /* 2013 */
5 /* All Rights Reserved */
6 /* */
7 /*-----------------------------------------------------------------------------*/
8 /* */
9 /* Module: vexdigital.h */
10 /* Author: James Pearman */
11 /* Created: 7 May 2013 */
12 /* */
13 /* Revisions: */
14 /* V1.00 4 July 2013 - Initial release */
15 /* */
16 /*-----------------------------------------------------------------------------*/
17 /* */
18 /* This file is part of ConVEX. */
19 /* */
20 /* The author is supplying this software for use with the VEX cortex */
21 /* control system. ConVEX is free software; you can redistribute it */
22 /* and/or modify it under the terms of the GNU General Public License */
23 /* as published by the Free Software Foundation; either version 3 of */
24 /* the License, or (at your option) any later version. */
25 /* */
26 /* ConVEX is distributed in the hope that it will be useful, */
27 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
28 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
29 /* GNU General Public License for more details. */
30 /* */
31 /* You should have received a copy of the GNU General Public License */
32 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 /* */
34 /* A special exception to the GPL can be applied should you wish to */
35 /* distribute a combined work that includes ConVEX, without being obliged */
36 /* to provide the source code for any proprietary components. */
37 /* See the file exception.txt for full details of how and when the */
38 /* exception can be applied. */
39 /* */
40 /* The author can be contacted on the vex forums as jpearman */
41 /* or electronic mail using jbpearman_at_mac_dot_com */
42 /* Mentor for team 8888 RoboLancers, Pasadena CA. */
43 /* */
44 /*-----------------------------------------------------------------------------*/
45 
46 #ifndef __VEXDIGITAL__
47 #define __VEXDIGITAL__
48 
49 /*-----------------------------------------------------------------------------*/
50 /** @file vexdigital.h
51  * @brief Header for the digital port driver
52 *//*---------------------------------------------------------------------------*/
53 
54 /*-----------------------------------------------------------------------------*/
55 /** @brief correlate a port on the cortex with a port/pin combo on the STM32 */
56 /*-----------------------------------------------------------------------------*/
57 /** @name Digital IO Pins
58  * The STM32F103 has five 16 bit GPIO ports, A through E. We define the 12
59  * digital port/pad pairs in the board.h file but then dereference them
60  * once more here.
61  * @{
62  */
63 
64 #define VEX_DIGIO_1_PAD GPIOE_DIGIO_1
65 #define VEX_DIGIO_2_PAD GPIOE_DIGIO_2
66 #define VEX_DIGIO_3_PAD GPIOC_DIGIO_3
67 #define VEX_DIGIO_4_PAD GPIOC_DIGIO_4
68 #define VEX_DIGIO_5_PAD GPIOE_DIGIO_5
69 #define VEX_DIGIO_6_PAD GPIOE_DIGIO_6
70 #define VEX_DIGIO_7_PAD GPIOE_DIGIO_7
71 #define VEX_DIGIO_8_PAD GPIOE_DIGIO_8
72 #define VEX_DIGIO_9_PAD GPIOE_DIGIO_9
73 #define VEX_DIGIO_10_PAD GPIOE_DIGIO_10
74 #define VEX_DIGIO_11_PAD GPIOD_DIGIO_11
75 #define VEX_DIGIO_12_PAD GPIOD_DIGIO_12
76 
77 #define VEX_DIGIO_1_PORT PORT_DIGIO_1
78 #define VEX_DIGIO_2_PORT PORT_DIGIO_2
79 #define VEX_DIGIO_3_PORT PORT_DIGIO_3
80 #define VEX_DIGIO_4_PORT PORT_DIGIO_4
81 #define VEX_DIGIO_5_PORT PORT_DIGIO_5
82 #define VEX_DIGIO_6_PORT PORT_DIGIO_6
83 #define VEX_DIGIO_7_PORT PORT_DIGIO_7
84 #define VEX_DIGIO_8_PORT PORT_DIGIO_8
85 #define VEX_DIGIO_9_PORT PORT_DIGIO_9
86 #define VEX_DIGIO_10_PORT PORT_DIGIO_10
87 #define VEX_DIGIO_11_PORT PORT_DIGIO_11
88 #define VEX_DIGIO_12_PORT PORT_DIGIO_12
89 /** @} */
90 
91 /*-----------------------------------------------------------------------------*/
92 /** @name Fast IO pin access
93  * These are used to bypass IO pin boundary checks when maximum speed
94  * is desired. Normal IO pin access should be done using vexDigitalPinSet
95  * @{
96  */
97 /*-----------------------------------------------------------------------------*/
98 
99 #define VexDigInput_1() palReadPad( VEX_DIGIO_1_PORT, VEX_DIGIO_1_PAD )
100 #define VexDigInput_2() palReadPad( VEX_DIGIO_2_PORT, VEX_DIGIO_2_PAD )
101 #define VexDigInput_3() palReadPad( VEX_DIGIO_3_PORT, VEX_DIGIO_3_PAD )
102 #define VexDigInput_4() palReadPad( VEX_DIGIO_4_PORT, VEX_DIGIO_4_PAD )
103 #define VexDigInput_5() palReadPad( VEX_DIGIO_5_PORT, VEX_DIGIO_5_PAD )
104 #define VexDigInput_6() palReadPad( VEX_DIGIO_6_PORT, VEX_DIGIO_6_PAD )
105 #define VexDigInput_7() palReadPad( VEX_DIGIO_7_PORT, VEX_DIGIO_7_PAD )
106 #define VexDigInput_8() palReadPad( VEX_DIGIO_8_PORT, VEX_DIGIO_8_PAD )
107 #define VexDigInput_9() palReadPad( VEX_DIGIO_9_PORT, VEX_DIGIO_9_PAD )
108 #define VexDigInput_10() palReadPad( VEX_DIGIO_10_PORT, VEX_DIGIO_10_PAD )
109 #define VexDigInput_11() palReadPad( VEX_DIGIO_11_PORT, VEX_DIGIO_11_PAD )
110 #define VexDigInput_12() palReadPad( VEX_DIGIO_12_PORT, VEX_DIGIO_12_PAD )
111 
112 #define VexPinOutput_1(x) { (x==0) ? palClearPad( VEX_DIGIO_1_PORT, VEX_DIGIO_1_PAD ) : \
113  palSetPad( VEX_DIGIO_1_PORT, VEX_DIGIO_1_PAD ) ; }
114 #define VexPinOutput_2(x) { (x==0) ? palClearPad( VEX_DIGIO_2_PORT, VEX_DIGIO_2_PAD ) : \
115  palSetPad( VEX_DIGIO_2_PORT, VEX_DIGIO_2_PAD ) ; }
116 #define VexPinOutput_3(x) { (x==0) ? palClearPad( VEX_DIGIO_3_PORT, VEX_DIGIO_3_PAD ) : \
117  palSetPad( VEX_DIGIO_3_PORT, VEX_DIGIO_3_PAD ) ; }
118 #define VexPinOutput_4(x) { (x==0) ? palClearPad( VEX_DIGIO_4_PORT, VEX_DIGIO_4_PAD ) : \
119  palSetPad( VEX_DIGIO_4_PORT, VEX_DIGIO_4_PAD ) ; }
120 #define VexPinOutput_5(x) { (x==0) ? palClearPad( VEX_DIGIO_5_PORT, VEX_DIGIO_5_PAD ) : \
121  palSetPad( VEX_DIGIO_5_PORT, VEX_DIGIO_5_PAD ) ; }
122 #define VexPinOutput_6(x) { (x==0) ? palClearPad( VEX_DIGIO_6_PORT, VEX_DIGIO_6_PAD ) : \
123  palSetPad( VEX_DIGIO_6_PORT, VEX_DIGIO_6_PAD ) ; }
124 #define VexPinOutput_7(x) { (x==0) ? palClearPad( VEX_DIGIO_7_PORT, VEX_DIGIO_7_PAD ) : \
125  palSetPad( VEX_DIGIO_7_PORT, VEX_DIGIO_7_PAD ) ; }
126 #define VexPinOutput_8(x) { (x==0) ? palClearPad( VEX_DIGIO_8_PORT, VEX_DIGIO_8_PAD ) : \
127  palSetPad( VEX_DIGIO_8_PORT, VEX_DIGIO_8_PAD ) ; }
128 #define VexPinOutput_9(x) { (x==0) ? palClearPad( VEX_DIGIO_9_PORT, VEX_DIGIO_9_PAD ) : \
129  palSetPad( VEX_DIGIO_9_PORT, VEX_DIGIO_9_PAD ) ; }
130 #define VexPinOutput_10(x) { (x==0) ? palClearPad( VEX_DIGIO_10_PORT, VEX_DIGIO_10_PAD ) : \
131  palSetPad( VEX_DIGIO_10_PORT, VEX_DIGIO_10_PAD ) ; }
132 #define VexPinOutput_11(x) { (x==0) ? palClearPad( VEX_DIGIO_11_PORT, VEX_DIGIO_11_PAD ) : \
133  palSetPad( VEX_DIGIO_11_PORT, VEX_DIGIO_11_PAD ) ; }
134 #define VexPinOutput_12(x) { (x==0) ? palClearPad( VEX_DIGIO_12_PORT, VEX_DIGIO_12_PAD ) : \
135  palSetPad( VEX_DIGIO_12_PORT, VEX_DIGIO_12_PAD ) ; }
136 /** @} */
137 
138 /*-----------------------------------------------------------------------------*/
139 /** @brief Digital pin indexes */
140 /*-----------------------------------------------------------------------------*/
141 typedef enum {
155 
157  } tVexDigitalPin;
158 
159 /*-----------------------------------------------------------------------------*/
160 /** @brief Digital pin types */
161 /*-----------------------------------------------------------------------------*/
162 typedef enum {
165  } tVexDigitalMode;
166 
167 /*-----------------------------------------------------------------------------*/
168 /** @brief Digital pin states */
169 /*-----------------------------------------------------------------------------*/
170 typedef enum {
174 
175 /*-----------------------------------------------------------------------------*/
176 /** @brief Holds port, pad and mode for a given cortex digital IO pin */
177 /*-----------------------------------------------------------------------------*/
178 typedef struct _ioDef {
179  ioportid_t port;
180  int16_t pad;
182  int32_t intrCount;
183 } ioDef;
184 
185 #ifdef __cplusplus
186 extern "C" {
187 #endif
188 
189 // vexioDefinition is a global, one of the few
191 
192 // Safe IO
197 
199 void vexDigitalIntrRun(void);
201 
202 // External interrupts
203 void vexExtIrqInit(void);
204 void vexExtSet( ioportid_t port, uint16_t channel, uint32_t mode, extcallback_t cb );
205 
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 
211 #endif // __VEXDIGITAL__