All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vexmotor.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: vexmotor.h */
10 /* Author: James Pearman */
11 /* Created: 14 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 /* Description: */
47 /* */
48 /* */
49 /*-----------------------------------------------------------------------------*/
50 /* */
51 
52 #ifndef _VEXMOTOR
53 #define _VEXMOTOR
54 
55 /*-----------------------------------------------------------------------------*/
56 /** @file vexmotor.h
57  * @brief Motor port driver, macros and prototypes
58 *//*---------------------------------------------------------------------------*/
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /** @cond */
65 #ifdef BOARD_OLIMEX_STM32_P103
66 // Debugging on the eval card
67 #define VEX_PWM_PORT GPIOC
68 
69 #define VEX_EBL_T0_N_PIN 0
70 #define VEX_EBL_T0_P_PIN 1
71 #define VEX_EBL_T9_N_PIN 2
72 #define VEX_EBL_T9_P_PIN 3
73 
74 #define VEX_PWM_T0_N_PIN 6
75 #define VEX_PWM_T0_P_PIN 7
76 #define VEX_PWM_T9_N_PIN 8
77 #define VEX_PWM_T9_P_PIN 9
78 
79 #else
80 // On the real cortex
81 #define VEX_PWM_PORT GPIOD
82 
83 #define VEX_EBL_T0_N_PIN 3
84 #define VEX_EBL_T0_P_PIN 4
85 #define VEX_EBL_T9_N_PIN 7
86 #define VEX_EBL_T9_P_PIN 8
87 
88 #define VEX_PWM_T0_N_PIN 12
89 #define VEX_PWM_T0_P_PIN 13
90 #define VEX_PWM_T9_N_PIN 14
91 #define VEX_PWM_T9_P_PIN 15
92 #endif
93 /** @endcond */
94 
95 
96 /*-----------------------------------------------------------------------------*/
97 /** @brief Motor types */
98 /*-----------------------------------------------------------------------------*/
99 typedef enum {
104 } tVexMotorType;
105 
106 /*-----------------------------------------------------------------------------*/
107 /** @brief Motor port numbers */
108 /*-----------------------------------------------------------------------------*/
109 typedef enum {
121 
123 } tVexMotor;
124 
125 
126 #define kVexMotorNormal FALSE ///< Motor command causes normal movement
127 #define kVexMotorReversed TRUE ///< Motor command causes reversed movement
128 
129 /*-----------------------------------------------------------------------------*/
130 /** @brief Holds data for a motor */
131 /*-----------------------------------------------------------------------------*/
132 typedef struct _vexMotor {
133  volatile int16_t value;
135  bool_t reversed;
136  int32_t (*motorPositionGet)( int16_t port );
137  void (*motorPositionSet)( int16_t port, int32_t value );
138  int16_t (*getEncoderId)( int16_t port );
139  int16_t port;
140  } vexMotor;
141 
142 /*-----------------------------------------------------------------------------*/
143 
144 void vexMotorInit(void);
145 void vexMotorSet( int16_t index, int16_t value );
146 int16_t vexMotorGet( int16_t index );
147 void vexMotorStopAll(void);
148 
149 void vexMotorTypeSet( int16_t index, tVexMotorType type );
150 tVexMotorType vexMotorTypeGet( int16_t index );
151 void vexMotorDirectionSet( int16_t index, bool_t reversed );
152 bool_t vexMotorDirectionGet( int16_t index );
153 void vexMotorDebug(vexStream *chp, int argc, char *argv[]);
154 void vexMotorPositionSet( int16_t index, int32_t value );
155 int32_t vexMotorPositionGet( int16_t index );
156 void vexMotorPositionGetCallback( int16_t index, int32_t (*cb)(int16_t), int16_t port );
157 void vexMotorPositionSetCallback( int16_t index, void (*cb)(int16_t, int32_t), int16_t port );
158 void vexMotorEncoderIdCallback( int16_t index, int16_t (*cb)(int16_t), int16_t port );
159 int16_t vexMotorEncoderIdGet( int16_t index );
160 
161 // do not call these
162 /** @private */
163 void _vexMotorPwmInit( TIM_TypeDef *tim );
164 /** @private */
165 void _vexMotorPwmSet_0( int16_t value );
166 /** @private */
167 void _vexMotorPwmSet_9( int16_t value );
168 
169 #ifdef __cplusplus
170 } // Close scope of extern "C" declaration
171 #endif
172 
173 #endif /* _VEXMOTOR */
174