Wrapped Freescale Cup code for the UT CS summer boot camp.

Dependencies:   MMA8451Q mbed

Committer:
ccoleman
Date:
Fri Aug 23 00:43:43 2013 +0000
Revision:
6:4b101f051a1f
Parent:
TFC.h@4:4233d072b5af
Trivial abstraction

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ccoleman 0:2010bcffbae0 1
ccoleman 0:2010bcffbae0 2 #include "mbed.h"
ccoleman 0:2010bcffbae0 3
ccoleman 0:2010bcffbae0 4 /** @file test.h*/
ccoleman 0:2010bcffbae0 5
ccoleman 0:2010bcffbae0 6 /**
ccoleman 0:2010bcffbae0 7 * @defgroup FRDM-TFC_API FRDM-TFC_API
ccoleman 0:2010bcffbae0 8 *
ccoleman 0:2010bcffbae0 9 * @{
ccoleman 0:2010bcffbae0 10 */
ccoleman 0:2010bcffbae0 11
ccoleman 0:2010bcffbae0 12
ccoleman 0:2010bcffbae0 13 /**
ccoleman 0:2010bcffbae0 14
ccoleman 0:2010bcffbae0 15 @addtogroup FRDM-TFC_API
ccoleman 0:2010bcffbae0 16
ccoleman 0:2010bcffbae0 17 @{
ccoleman 0:2010bcffbae0 18
ccoleman 0:2010bcffbae0 19 Resources used by the TFC Library\n
ccoleman 0:2010bcffbae0 20
ccoleman 0:2010bcffbae0 21 I/O:\n
ccoleman 0:2010bcffbae0 22 -------------------------------------------------------------------------------------------------\n
ccoleman 0:2010bcffbae0 23
ccoleman 0:2010bcffbae0 24 PTB0 (Servo Channel 0 - TPM1)\n
ccoleman 0:2010bcffbae0 25 PTB1 (Servo Channel 1 - TPM1)\n
ccoleman 0:2010bcffbae0 26 \n
ccoleman 0:2010bcffbae0 27 PTB8 (Battery LED0)\n
ccoleman 0:2010bcffbae0 28 PTB9 (Battery LED1)\n
ccoleman 0:2010bcffbae0 29 PTB10 (Battery LED2)\n
ccoleman 0:2010bcffbae0 30 PTB11 (Battery LED3)\n
ccoleman 0:2010bcffbae0 31 \n
ccoleman 0:2010bcffbae0 32 PTD7 (Camera SI)\n
ccoleman 0:2010bcffbae0 33 PTE0 (Camera CLK)\n
ccoleman 0:2010bcffbae0 34 PTD5 (Camera A0 - ADC_SE6b)\n
ccoleman 0:2010bcffbae0 35 PTD6 (Camera A1 - ADC_SE7b)\n
ccoleman 0:2010bcffbae0 36 \n
ccoleman 0:2010bcffbae0 37 PTE2 DIP Switch 0\n
ccoleman 0:2010bcffbae0 38 PTE3 DIP Switch 1\n
ccoleman 0:2010bcffbae0 39 PTE4 DIP Switch 2\n
ccoleman 0:2010bcffbae0 40 PTE5 DIP Switch 3\n
ccoleman 0:2010bcffbae0 41
ccoleman 0:2010bcffbae0 42 PTC13 Pushbutton SW1\n
ccoleman 0:2010bcffbae0 43 PTC17 Pushbutton SW2\n
ccoleman 0:2010bcffbae0 44
ccoleman 0:2010bcffbae0 45 PTC3 H-Bridge A - 1 FTM0_CH3\n
ccoleman 0:2010bcffbae0 46 PTC4 H-Bridge A - 2 FTM0_CH4\n
ccoleman 0:2010bcffbae0 47 PTC1 H-Bridge B - 1 FTM0_CH1\n
ccoleman 0:2010bcffbae0 48 PTC2 H-Bridge B - 2 FTM0_CH2\n
ccoleman 0:2010bcffbae0 49
ccoleman 0:2010bcffbae0 50 PTE21 H-Bridge Enable\n
ccoleman 0:2010bcffbae0 51 PTE20 H-Bridge Fault\n
ccoleman 0:2010bcffbae0 52
ccoleman 0:2010bcffbae0 53 PTE23 H-Bridge A - IFB\n
ccoleman 0:2010bcffbae0 54 PTE22 H-Bridge B - IFB\n
ccoleman 0:2010bcffbae0 55
ccoleman 0:2010bcffbae0 56 }
ccoleman 0:2010bcffbae0 57 */
ccoleman 0:2010bcffbae0 58
ccoleman 0:2010bcffbae0 59
ccoleman 0:2010bcffbae0 60
ccoleman 0:2010bcffbae0 61 #ifndef _TFC_H
ccoleman 0:2010bcffbae0 62 #define _TFC_H
ccoleman 0:2010bcffbae0 63
ccoleman 0:2010bcffbae0 64 #define TFC_HBRIDGE_EN_LOC (uint32_t)(1<<21)
ccoleman 0:2010bcffbae0 65 #define TFC_HBRIDGE_FAULT_LOC (uint32_t)(1<<20)
ccoleman 0:2010bcffbae0 66
ccoleman 0:2010bcffbae0 67 #define TFC_HBRIDGE_ENABLE PTE->PSOR = TFC_HBRIDGE_EN_LOC
ccoleman 0:2010bcffbae0 68 #define TFC_HBRIDGE_DISABLE PTE->PCOR = TFC_HBRIDGE_EN_LOC
ccoleman 0:2010bcffbae0 69
ccoleman 0:2010bcffbae0 70 #define TFC_DIP_SWITCH0_LOC ((uint32_t)(1<<2))
ccoleman 0:2010bcffbae0 71 #define TFC_DIP_SWITCH1_LOC ((uint32_t)(1<<3))
ccoleman 0:2010bcffbae0 72 #define TFC_DIP_SWITCH2_LOC ((uint32_t)(1<<4))
ccoleman 0:2010bcffbae0 73 #define TFC_DIP_SWITCH3_LOC ((uint32_t)(1<<5))
ccoleman 0:2010bcffbae0 74
ccoleman 0:2010bcffbae0 75 #define TFC_PUSH_BUTT0N0_LOC ((uint32_t)(1<<13))
ccoleman 0:2010bcffbae0 76 #define TFC_PUSH_BUTT0N1_LOC ((uint32_t)(1<<17))
ccoleman 0:2010bcffbae0 77
ccoleman 0:2010bcffbae0 78 #define TFC_BAT_LED0_LOC ((uint32_t)(1<<11))
ccoleman 0:2010bcffbae0 79 #define TFC_BAT_LED1_LOC ((uint32_t)(1<<10))
ccoleman 0:2010bcffbae0 80 #define TFC_BAT_LED2_LOC ((uint32_t)(1<<9))
ccoleman 0:2010bcffbae0 81 #define TFC_BAT_LED3_LOC ((uint32_t)(1<<8))
ccoleman 0:2010bcffbae0 82
ccoleman 0:2010bcffbae0 83 #define TAOS_CLK_HIGH PTE->PSOR = (1<<1)
ccoleman 0:2010bcffbae0 84 #define TAOS_CLK_LOW PTE->PCOR = (1<<1)
ccoleman 0:2010bcffbae0 85 #define TAOS_SI_HIGH PTD->PSOR = (1<<7)
ccoleman 0:2010bcffbae0 86 #define TAOS_SI_LOW PTD->PCOR = (1<<7)
ccoleman 0:2010bcffbae0 87
ccoleman 0:2010bcffbae0 88
ccoleman 0:2010bcffbae0 89 /**
ccoleman 0:2010bcffbae0 90
ccoleman 0:2010bcffbae0 91 @addtogroup FRDM-TFC_API
ccoleman 0:2010bcffbae0 92 @{
ccoleman 0:2010bcffbae0 93 */
ccoleman 0:2010bcffbae0 94
ccoleman 0:2010bcffbae0 95 /**Macro to turn on LED 0 in the battery indicator array*/
ccoleman 0:2010bcffbae0 96 #define TFC_BAT_LED0_ON PTB->PSOR = TFC_BAT_LED0_LOC
ccoleman 0:2010bcffbae0 97 /** Macro to turn on LED 1 in the battery indicator array*/
ccoleman 0:2010bcffbae0 98 #define TFC_BAT_LED1_ON PTB->PSOR = TFC_BAT_LED1_LOC
ccoleman 0:2010bcffbae0 99 /** Macro to turn on LED 2 in the battery indicator array*/
ccoleman 0:2010bcffbae0 100 #define TFC_BAT_LED2_ON PTB->PSOR = TFC_BAT_LED2_LOC
ccoleman 0:2010bcffbae0 101 /** Macro to turn on LED 3 in the battery indicator array*/
ccoleman 0:2010bcffbae0 102 #define TFC_BAT_LED3_ON PTB->PSOR = TFC_BAT_LED3_LOC
ccoleman 0:2010bcffbae0 103
ccoleman 0:2010bcffbae0 104
ccoleman 0:2010bcffbae0 105 /** Macro to turn off LED 0 in the battery indicator array*/
ccoleman 0:2010bcffbae0 106 #define TFC_BAT_LED0_OFF PTB->PCOR = TFC_BAT_LED0_LOC
ccoleman 0:2010bcffbae0 107 /** Macro to turn off LED 1 in the battery indicator array*/
ccoleman 0:2010bcffbae0 108 #define TFC_BAT_LED1_OFF PTB->PCOR = TFC_BAT_LED1_LOC
ccoleman 0:2010bcffbae0 109 /** Macro to turn off LED 2 in the battery indicator array*/
ccoleman 0:2010bcffbae0 110 #define TFC_BAT_LED2_OFF PTB->PCOR = TFC_BAT_LED2_LOC
ccoleman 0:2010bcffbae0 111 /** Macro to turn off LED 3 in the battery indicator array*/
ccoleman 0:2010bcffbae0 112 #define TFC_BAT_LED3_OFF PTB->PCOR = TFC_BAT_LED3_LOC
ccoleman 0:2010bcffbae0 113
ccoleman 0:2010bcffbae0 114
ccoleman 0:2010bcffbae0 115 /** Macro to toggle LED 0 in the battery indicator array*/
ccoleman 0:2010bcffbae0 116 #define TFC_BAT_LED0_TOGGLE PTB->PTOR = TFC_BAT_LED0_LOC
ccoleman 0:2010bcffbae0 117 /** Macro to toggle LED 1 in the battery indicator array*/
ccoleman 0:2010bcffbae0 118 #define TFC_BAT_LED1_TOGGLE PTB->PTOR = TFC_BAT_LED1_LOC
ccoleman 0:2010bcffbae0 119 /** Macro to toggle LED 2 in the battery indicator array*/
ccoleman 0:2010bcffbae0 120 #define TFC_BAT_LED2_TOGGLE PTB->PTOR = TFC_BAT_LED2_LOC
ccoleman 0:2010bcffbae0 121 /** Macro to toggle LED 3 in the battery indicator array*/
ccoleman 0:2010bcffbae0 122 #define TFC_BAT_LED3_TOGGLE PTB->PTOR = TFC_BAT_LED3_LOC
ccoleman 0:2010bcffbae0 123
ccoleman 0:2010bcffbae0 124
ccoleman 0:2010bcffbae0 125 /** Macro to read the state of the pushbutton SW1*/
ccoleman 0:2010bcffbae0 126 #define TFC_PUSH_BUTTON_0_PRESSED ((PTC->PDIR&TFC_PUSH_BUTT0N0_LOC)>0)
ccoleman 0:2010bcffbae0 127 /** Macro to read the state of the pushbutton SW1*/
ccoleman 0:2010bcffbae0 128 #define TFC_PUSH_BUTTON_1_PRESSED ((PTC->PDIR&TFC_PUSH_BUTT0N1_LOC)>0)
ccoleman 0:2010bcffbae0 129
ccoleman 0:2010bcffbae0 130 /** Macro to read the state of switch 0 in the 4 position DIP switch*/
ccoleman 0:2010bcffbae0 131 #define TFC_DIP_SWITCH_0_ON ((TFC_GetDIP_Switch()&0x01)>0)
ccoleman 0:2010bcffbae0 132
ccoleman 0:2010bcffbae0 133 /** Macro to read the state of switch 1 in the 4 position DIP switch*/
ccoleman 0:2010bcffbae0 134 #define TFC_DIP_SWITCH_1_ON ((TFC_GetDIP_Switch()&0x02)>0)
ccoleman 0:2010bcffbae0 135
ccoleman 0:2010bcffbae0 136 /** Macro to read the state of switch 2 in the 4 position DIP switch*/
ccoleman 0:2010bcffbae0 137 #define TFC_DIP_SWITCH_2_ON ((TFC_GetDIP_Switch()&0x04)>0)
ccoleman 0:2010bcffbae0 138
ccoleman 0:2010bcffbae0 139 /** Macro to read the state of switch 3 in the 4 position DIP switch*/
ccoleman 0:2010bcffbae0 140 #define TFC_DIP_SWITCH_3_ON ((TFC_GetDIP_Switch()&0x08)>0)
ccoleman 0:2010bcffbae0 141
ccoleman 0:2010bcffbae0 142
ccoleman 0:2010bcffbae0 143 /** Initialized the TFC API. Call before using any other API calls.
ccoleman 0:2010bcffbae0 144 *
ccoleman 0:2010bcffbae0 145 */
ccoleman 0:2010bcffbae0 146 void TFC_Init();
ccoleman 0:2010bcffbae0 147
ccoleman 0:2010bcffbae0 148 /** ServoTicker will increment once every servo cycle.
ccoleman 0:2010bcffbae0 149 * It can be used to synchronize events to the start of a servo cycle. ServoTicker is a volatile uint32_t and is updated in the TPM1 overlflow interrupt. This means you will see ServoTicker increment on the rising edge of the servo PWM signal
ccoleman 0:2010bcffbae0 150 *
ccoleman 0:2010bcffbae0 151 */
ccoleman 0:2010bcffbae0 152 extern volatile uint32_t TFC_ServoTicker;
ccoleman 0:2010bcffbae0 153
ccoleman 0:2010bcffbae0 154
ccoleman 0:2010bcffbae0 155 /** Gets the state of the 4-positiomn DIP switch on the FRDM-TFC
ccoleman 0:2010bcffbae0 156 *
ccoleman 0:2010bcffbae0 157 * @returns The lower 4-bits of the return value map to the 4-bits of the DIP switch
ccoleman 0:2010bcffbae0 158 */
ccoleman 0:2010bcffbae0 159 uint8_t TFC_GetDIP_Switch();
ccoleman 0:2010bcffbae0 160
ccoleman 0:2010bcffbae0 161
ccoleman 0:2010bcffbae0 162 /** Reads the state of the pushbuttons (SW1, SW2) on the FRDM-TFC
ccoleman 0:2010bcffbae0 163 * @param Index Selects the pushbutton (0 for SW1 and 1 for SW2)
ccoleman 0:2010bcffbae0 164 * @returns A non-zero value if the button is pushed
ccoleman 0:2010bcffbae0 165 */
ccoleman 0:2010bcffbae0 166 uint8_t TFC_ReadPushButton(uint8_t Index);
ccoleman 0:2010bcffbae0 167
ccoleman 0:2010bcffbae0 168
ccoleman 0:2010bcffbae0 169 /** Controls the 4 battery level LEDs on the FRDM-TFC boards.
ccoleman 0:2010bcffbae0 170 *
ccoleman 0:2010bcffbae0 171 * @param Value The lower 4-bits of the parameter maps to the 4 LEDs.
ccoleman 0:2010bcffbae0 172 */
ccoleman 0:2010bcffbae0 173 void TFC_SetBatteryLED(uint8_t Value);
ccoleman 0:2010bcffbae0 174
ccoleman 0:2010bcffbae0 175
ccoleman 0:2010bcffbae0 176 /** Sets the servo channels
ccoleman 0:2010bcffbae0 177 *
ccoleman 0:2010bcffbae0 178 * @param ServoNumber Which servo channel on the FRDM-TFC to use (0 or 1). 0 is the default channel for steering
ccoleman 0:2010bcffbae0 179 * @param Position Angle setting for servo in a normalized (-1.0 to 1.0) form. The range of the servo can be changed with the InitServos function.
ccoleman 0:2010bcffbae0 180 * This is called in the TFC constructor with some useful default values--> 20mSec period, 0.5mS min and 2.0mSec max. you may need to adjust these for your own particular setup.
ccoleman 0:2010bcffbae0 181 */
ccoleman 0:2010bcffbae0 182 void TFC_SetServo(uint8_t ServoNumber, float Position);
ccoleman 0:2010bcffbae0 183
ccoleman 0:2010bcffbae0 184 /** Initializes TPM for the servoes. It also sets the max and min ranges
ccoleman 0:2010bcffbae0 185 *
ccoleman 0:2010bcffbae0 186 * @param ServoPulseWidthMin Minimum pulse width (in seconds) for the servo. The value of -1.0 in SetServo is mapped to this pulse width. I.E. .001
ccoleman 0:2010bcffbae0 187 * @param ServoPulseWidthMax Maximum pulse width (in seconds) for the servo. The value of +1.0 in SetServo is mapped to this pulse width. I.E. .002
ccoleman 0:2010bcffbae0 188 * @param ServoPeriod Period of the servo pulses (in seconds). I.e. .020 for 20mSec
ccoleman 0:2010bcffbae0 189 */
ccoleman 0:2010bcffbae0 190
ccoleman 0:2010bcffbae0 191 void TFC_InitServos(float ServoPulseWidthMin, float ServoPulseWidthMax, float ServoPeriod);
ccoleman 0:2010bcffbae0 192
ccoleman 0:2010bcffbae0 193
ccoleman 0:2010bcffbae0 194 /** Initialized TPM0 to be used for generating PWM signals for the the dual drive motors. This method is called in the TFC constructor with a default value of 4000.0Hz
ccoleman 0:2010bcffbae0 195 *
ccoleman 0:2010bcffbae0 196 * @param SwitchingFrequency PWM Switching Frequency in floating point format. Pick something between 1000 and 9000. Maybe you can modulate it and make a tune.
ccoleman 0:2010bcffbae0 197 */
ccoleman 0:2010bcffbae0 198 void TFC_InitMotorPWM(float SwitchingFrequency);
ccoleman 0:2010bcffbae0 199
ccoleman 0:2010bcffbae0 200 /** Sets the PWM value for each motor.
ccoleman 0:2010bcffbae0 201 *
ccoleman 0:2010bcffbae0 202 * @param MotorA The PWM value for HBridgeA. The value is normalized to the floating point range of -1.0 to +1.0. -1.0 is 0% (Full Reverse on the H-Bridge) and 1.0 is 100% (Full Forward on the H-Bridge)
ccoleman 0:2010bcffbae0 203 * @param MotorB The PWM value for HBridgeB. The value is normalized to the floating point range of -1.0 to +1.0. -1.0 is 0% (Full Reverse on the H-Bridge) and 1.0 is 100% (Full Forward on the H-Bridge)
ccoleman 0:2010bcffbae0 204 */
ccoleman 0:2010bcffbae0 205 void TFC_SetMotorPWM(float MotorA ,float MotorB);
ccoleman 0:2010bcffbae0 206
ccoleman 0:2010bcffbae0 207 /** Reads the potentiometers
ccoleman 0:2010bcffbae0 208 *
ccoleman 0:2010bcffbae0 209 * @param Channel Selects which pot is read. I.e. 0 for POT0 or 1 for POT1
ccoleman 0:2010bcffbae0 210 * @returns Pot value from -1.0 to 1.0
ccoleman 0:2010bcffbae0 211 */
ccoleman 0:2010bcffbae0 212 float TFC_ReadPot(uint8_t Channel);
ccoleman 0:2010bcffbae0 213
ccoleman 0:2010bcffbae0 214 /** Gets the current battery voltage
ccoleman 0:2010bcffbae0 215 *
ccoleman 0:2010bcffbae0 216 * @returns Battery voltage in floating point form.
ccoleman 0:2010bcffbae0 217 */
ccoleman 0:2010bcffbae0 218 float TFC_ReadBatteryVoltage();
ccoleman 0:2010bcffbae0 219
ccoleman 0:2010bcffbae0 220
ccoleman 0:2010bcffbae0 221 /** Pointer to two channels of line scan camera data. Each channel is 128 points of uint8_t's. Note that the underlying implementation is ping-pong buffer These pointers will point to the
ccoleman 0:2010bcffbae0 222 *inactive buffer.
ccoleman 0:2010bcffbae0 223 *
ccoleman 0:2010bcffbae0 224 */
ccoleman 0:2010bcffbae0 225
ccoleman 0:2010bcffbae0 226 extern volatile uint8_t * TFC_LineScanCameraData[2];
ccoleman 0:2010bcffbae0 227
ccoleman 0:2010bcffbae0 228 /** This flag will increment when a new frame is ready. Check for a non zero value (and reset to zero!) when you want to read the camera(s)
ccoleman 0:2010bcffbae0 229 *
ccoleman 0:2010bcffbae0 230 */
ccoleman 0:2010bcffbae0 231
ccoleman 0:2010bcffbae0 232 extern volatile uint8_t TFC_LineScanCameraDataReady;
ccoleman 0:2010bcffbae0 233
ccoleman 4:4233d072b5af 234 float getLine();
ccoleman 4:4233d072b5af 235 float init2();
ccoleman 4:4233d072b5af 236
ccoleman 4:4233d072b5af 237 void TFC_GPIO_Init();
ccoleman 4:4233d072b5af 238
ccoleman 4:4233d072b5af 239 void TFC_InitADC_System(); // Always call this before the Servo init function.... The IRQ for the Servo code modifies ADC registers and the clocks need enable to the ADC peripherals 1st!
ccoleman 4:4233d072b5af 240
ccoleman 4:4233d072b5af 241 void TFC_InitLineScanCamera();
ccoleman 4:4233d072b5af 242
ccoleman 0:2010bcffbae0 243
ccoleman 0:2010bcffbae0 244 /** @} */
ccoleman 0:2010bcffbae0 245
ccoleman 0:2010bcffbae0 246
ccoleman 4:4233d072b5af 247 #endif