Mirror with some correction
Dependencies: mbed FastIO FastPWM USBDevice
config.h@53:9b2611964afc, 2016-04-22 (annotated)
- Committer:
- mjr
- Date:
- Fri Apr 22 17:58:35 2016 +0000
- Revision:
- 53:9b2611964afc
- Parent:
- 52:8298b2a73eb2
- Child:
- 54:fd77a6b2f76c
Save some debugging instrumentation to be removed for release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjr | 17:ab3cec0c8bf4 | 1 | // Pinscape Controller Configuration |
mjr | 17:ab3cec0c8bf4 | 2 | // |
mjr | 35:e959ffba78fd | 3 | // New for 2016: dynamic configuration! To configure the controller, connect |
mjr | 35:e959ffba78fd | 4 | // the KL25Z to your PC, install the .bin file, and run the Windows config tool. |
mjr | 35:e959ffba78fd | 5 | // There's no need (as there was in the past) to edit this file or to compile a |
mjr | 35:e959ffba78fd | 6 | // custom version of the binary (.bin) to customize setup options. |
mjr | 35:e959ffba78fd | 7 | // |
mjr | 35:e959ffba78fd | 8 | // In earlier versions, configuration was largely handled with compile-time |
mjr | 35:e959ffba78fd | 9 | // constants. To customize the setup, you had to create a private forked copy |
mjr | 35:e959ffba78fd | 10 | // of the source code, edit the constants defined in config.h, and compile a |
mjr | 35:e959ffba78fd | 11 | // custom binary. That's no longer necessary! |
mjr | 35:e959ffba78fd | 12 | // |
mjr | 35:e959ffba78fd | 13 | // The new approach is to do everything (or as much as possible, anyway) |
mjr | 35:e959ffba78fd | 14 | // via the Windows config tool. You shouldn't have to recompile a custom |
mjr | 35:e959ffba78fd | 15 | // version just to make a configurable change. Of course, you're still free |
mjr | 35:e959ffba78fd | 16 | // to create a custom version if you need to add or change features in ways |
mjr | 35:e959ffba78fd | 17 | // that weren't anticipated in the original design. |
mjr | 35:e959ffba78fd | 18 | // |
mjr | 35:e959ffba78fd | 19 | |
mjr | 48:058ace2aed1d | 20 | // $$$ TESTING CONFIGURATIONS |
mjr | 48:058ace2aed1d | 21 | #define TEST_CONFIG_EXPAN 0 |
mjr | 48:058ace2aed1d | 22 | #define TEST_CONFIG_CAB 1 |
mjr | 52:8298b2a73eb2 | 23 | #define TEST_KEEP_PRINTF 0 |
mjr | 48:058ace2aed1d | 24 | |
mjr | 17:ab3cec0c8bf4 | 25 | |
mjr | 25:e22b88bd783a | 26 | #ifndef CONFIG_H |
mjr | 25:e22b88bd783a | 27 | #define CONFIG_H |
mjr | 17:ab3cec0c8bf4 | 28 | |
mjr | 35:e959ffba78fd | 29 | // Plunger type codes |
mjr | 35:e959ffba78fd | 30 | // NOTE! These values are part of the external USB interface. New |
mjr | 35:e959ffba78fd | 31 | // values can be added, but the meaning of an existing assigned number |
mjr | 35:e959ffba78fd | 32 | // should remain fixed to keep the PC-side config tool compatible across |
mjr | 35:e959ffba78fd | 33 | // versions. |
mjr | 35:e959ffba78fd | 34 | const int PlungerType_None = 0; // no plunger |
mjr | 35:e959ffba78fd | 35 | const int PlungerType_TSL1410RS = 1; // TSL1410R linear image sensor (1280x1 pixels, 400dpi), serial mode |
mjr | 35:e959ffba78fd | 36 | const int PlungerType_TSL1410RP = 2; // TSL1410R, parallel mode (reads the two sensor sections concurrently) |
mjr | 35:e959ffba78fd | 37 | const int PlungerType_TSL1412RS = 3; // TSL1412R linear image sensor (1536x1 pixels, 400dpi), serial mode |
mjr | 35:e959ffba78fd | 38 | const int PlungerType_TSL1412RP = 4; // TSL1412R, parallel mode |
mjr | 35:e959ffba78fd | 39 | const int PlungerType_Pot = 5; // potentionmeter |
mjr | 35:e959ffba78fd | 40 | const int PlungerType_OptQuad = 6; // AEDR8300 optical quadrature sensor |
mjr | 35:e959ffba78fd | 41 | const int PlungerType_MagQuad = 7; // AS5304 magnetic quadrature sensor |
mjr | 21:5048e16cc9ef | 42 | |
mjr | 35:e959ffba78fd | 43 | // Accelerometer orientation codes |
mjr | 35:e959ffba78fd | 44 | // These values are part of the external USB interface |
mjr | 35:e959ffba78fd | 45 | const int OrientationFront = 0; // USB ports pointed toward front of cabinet |
mjr | 35:e959ffba78fd | 46 | const int OrientationLeft = 1; // ports pointed toward left side of cabinet |
mjr | 35:e959ffba78fd | 47 | const int OrientationRight = 2; // ports pointed toward right side of cabinet |
mjr | 35:e959ffba78fd | 48 | const int OrientationRear = 3; // ports pointed toward back of cabinet |
mjr | 25:e22b88bd783a | 49 | |
mjr | 35:e959ffba78fd | 50 | // input button types |
mjr | 53:9b2611964afc | 51 | const int BtnTypeNone = 0; // unused |
mjr | 35:e959ffba78fd | 52 | const int BtnTypeJoystick = 1; // joystick button |
mjr | 53:9b2611964afc | 53 | const int BtnTypeKey = 2; // keyboard key |
mjr | 38:091e511ce8a0 | 54 | |
mjr | 38:091e511ce8a0 | 55 | // input button flags |
mjr | 38:091e511ce8a0 | 56 | const uint8_t BtnFlagPulse = 0x01; // pulse mode - reports each change in the physical switch state |
mjr | 38:091e511ce8a0 | 57 | // as a brief press of the logical button/keyboard key |
mjr | 40:cc0d9814522b | 58 | |
mjr | 40:cc0d9814522b | 59 | // button setup structure |
mjr | 40:cc0d9814522b | 60 | struct ButtonCfg |
mjr | 40:cc0d9814522b | 61 | { |
mjr | 40:cc0d9814522b | 62 | uint8_t pin; // physical input GPIO pin - a USB-to-PinName mapping index |
mjr | 40:cc0d9814522b | 63 | uint8_t typ; // key type reported to PC - a BtnTypeXxx value |
mjr | 53:9b2611964afc | 64 | uint8_t val; // key value reported - meaning depends on 'typ' value: |
mjr | 53:9b2611964afc | 65 | // none -> no PC input reports (val is unused) |
mjr | 53:9b2611964afc | 66 | // joystick -> val is joystick button number (1..32) |
mjr | 53:9b2611964afc | 67 | // keyboard -> val is USB scan code |
mjr | 40:cc0d9814522b | 68 | uint8_t flags; // key flags - a bitwise combination of BtnFlagXxx values |
mjr | 40:cc0d9814522b | 69 | |
mjr | 40:cc0d9814522b | 70 | void set(uint8_t pin, uint8_t typ, uint8_t val, uint8_t flags = 0) |
mjr | 40:cc0d9814522b | 71 | { |
mjr | 40:cc0d9814522b | 72 | this->pin = pin; |
mjr | 40:cc0d9814522b | 73 | this->typ = typ; |
mjr | 40:cc0d9814522b | 74 | this->val = val; |
mjr | 40:cc0d9814522b | 75 | this->flags = flags; |
mjr | 40:cc0d9814522b | 76 | } |
mjr | 40:cc0d9814522b | 77 | |
mjr | 40:cc0d9814522b | 78 | } __attribute__((packed)); |
mjr | 40:cc0d9814522b | 79 | |
mjr | 33:d832bcab089e | 80 | |
mjr | 35:e959ffba78fd | 81 | // maximum number of input button mappings |
mjr | 53:9b2611964afc | 82 | const int MAX_EXT_BUTTONS = 32; // buttons visible through USB interface |
mjr | 53:9b2611964afc | 83 | const int VIRTUAL_BUTTONS = 1; // number of internal virtual buttons |
mjr | 53:9b2611964afc | 84 | const int ZBL_BUTTON = MAX_EXT_BUTTONS; // index of virtual ZB Launch Ball button |
mjr | 53:9b2611964afc | 85 | const int MAX_BUTTONS = MAX_EXT_BUTTONS + VIRTUAL_BUTTONS; // total button slots |
mjr | 33:d832bcab089e | 86 | |
mjr | 35:e959ffba78fd | 87 | // LedWiz output port type codes |
mjr | 35:e959ffba78fd | 88 | // These values are part of the external USB interface |
mjr | 35:e959ffba78fd | 89 | const int PortTypeDisabled = 0; // port is disabled - not visible to LedWiz/DOF host |
mjr | 35:e959ffba78fd | 90 | const int PortTypeGPIOPWM = 1; // GPIO port, PWM enabled |
mjr | 35:e959ffba78fd | 91 | const int PortTypeGPIODig = 2; // GPIO port, digital out |
mjr | 35:e959ffba78fd | 92 | const int PortTypeTLC5940 = 3; // TLC5940 port |
mjr | 35:e959ffba78fd | 93 | const int PortType74HC595 = 4; // 74HC595 port |
mjr | 53:9b2611964afc | 94 | const int PortTypeVirtual = 5; // Virtual port - visible to host software, but not connected |
mjr | 53:9b2611964afc | 95 | // to a physical output |
mjr | 17:ab3cec0c8bf4 | 96 | |
mjr | 35:e959ffba78fd | 97 | // LedWiz output port flag bits |
mjr | 38:091e511ce8a0 | 98 | const uint8_t PortFlagActiveLow = 0x01; // physical output is active-low |
mjr | 38:091e511ce8a0 | 99 | const uint8_t PortFlagNoisemaker = 0x02; // noisemaker device - disable when night mode is engaged |
mjr | 40:cc0d9814522b | 100 | const uint8_t PortFlagGamma = 0x04; // apply gamma correction to this output |
mjr | 35:e959ffba78fd | 101 | |
mjr | 35:e959ffba78fd | 102 | // maximum number of output ports |
mjr | 48:058ace2aed1d | 103 | const int MAX_OUT_PORTS = 128; |
mjr | 33:d832bcab089e | 104 | |
mjr | 38:091e511ce8a0 | 105 | // port configuration data |
mjr | 38:091e511ce8a0 | 106 | struct LedWizPortCfg |
mjr | 38:091e511ce8a0 | 107 | { |
mjr | 38:091e511ce8a0 | 108 | uint8_t typ; // port type: a PortTypeXxx value |
mjr | 38:091e511ce8a0 | 109 | uint8_t pin; // physical output pin: for a GPIO port, this is an index in the |
mjr | 38:091e511ce8a0 | 110 | // USB-to-PinName mapping list; for a TLC5940 or 74HC595 port, it's |
mjr | 38:091e511ce8a0 | 111 | // the output number, starting from 0 for OUT0 on the first chip in |
mjr | 38:091e511ce8a0 | 112 | // the daisy chain. For inactive and virtual ports, it's unused. |
mjr | 38:091e511ce8a0 | 113 | uint8_t flags; // flags: a combination of PortFlagXxx values |
mjr | 40:cc0d9814522b | 114 | |
mjr | 40:cc0d9814522b | 115 | void set(uint8_t typ, uint8_t pin, uint8_t flags = 0) |
mjr | 40:cc0d9814522b | 116 | { |
mjr | 40:cc0d9814522b | 117 | this->typ = typ; |
mjr | 40:cc0d9814522b | 118 | this->pin = pin; |
mjr | 40:cc0d9814522b | 119 | this->flags = flags; |
mjr | 40:cc0d9814522b | 120 | } |
mjr | 40:cc0d9814522b | 121 | |
mjr | 38:091e511ce8a0 | 122 | } __attribute__((packed)); |
mjr | 38:091e511ce8a0 | 123 | |
mjr | 38:091e511ce8a0 | 124 | |
mjr | 53:9b2611964afc | 125 | // Convert a physical pin name to a wire pin name |
mjr | 53:9b2611964afc | 126 | #define PINNAME_TO_WIRE(p) \ |
mjr | 53:9b2611964afc | 127 | uint8_t((p) == NC ? 0xFF : \ |
mjr | 53:9b2611964afc | 128 | (((p) & 0xF000 ) >> (PORT_SHIFT - 5)) | (((p) & 0xFF) >> 2)) |
mjr | 53:9b2611964afc | 129 | |
mjr | 35:e959ffba78fd | 130 | struct Config |
mjr | 35:e959ffba78fd | 131 | { |
mjr | 35:e959ffba78fd | 132 | // set all values to factory defaults |
mjr | 35:e959ffba78fd | 133 | void setFactoryDefaults() |
mjr | 35:e959ffba78fd | 134 | { |
mjr | 35:e959ffba78fd | 135 | // By default, pretend to be LedWiz unit #8. This can be from 1 to 16. Real |
mjr | 35:e959ffba78fd | 136 | // LedWiz units have their unit number set at the factory, and the vast majority |
mjr | 35:e959ffba78fd | 137 | // are set up as unit #1, since that's the default for anyone who doesn't ask |
mjr | 35:e959ffba78fd | 138 | // for a different setting. It seems rare for anyone to use more than one unit |
mjr | 35:e959ffba78fd | 139 | // in a pin cab, but for the few who do, the others will probably be numbered |
mjr | 35:e959ffba78fd | 140 | // sequentially as #2, #3, etc. It seems safe to assume that no one out there |
mjr | 48:058ace2aed1d | 141 | // has a unit #8, so we'll use that as our default. This can be changed from |
mjr | 48:058ace2aed1d | 142 | // the config tool, but for the sake of convenience, it's better to pick a |
mjr | 48:058ace2aed1d | 143 | // default that most people won't have to change. |
mjr | 35:e959ffba78fd | 144 | usbVendorID = 0xFAFA; // LedWiz vendor code |
mjr | 48:058ace2aed1d | 145 | usbProductID = 0x00F7; // LedWiz product code for unit #8 |
mjr | 35:e959ffba78fd | 146 | psUnitNo = 8; |
mjr | 35:e959ffba78fd | 147 | |
mjr | 51:57eb311faafa | 148 | // set a disconnect reboot timeout of 10 seconds by default |
mjr | 51:57eb311faafa | 149 | disconnectRebootTimeout = 10; |
mjr | 51:57eb311faafa | 150 | |
mjr | 35:e959ffba78fd | 151 | // enable joystick reports |
mjr | 35:e959ffba78fd | 152 | joystickEnabled = true; |
mjr | 35:e959ffba78fd | 153 | |
mjr | 35:e959ffba78fd | 154 | // assume standard orientation, with USB ports toward front of cabinet |
mjr | 35:e959ffba78fd | 155 | orientation = OrientationFront; |
mjr | 25:e22b88bd783a | 156 | |
mjr | 52:8298b2a73eb2 | 157 | // assume a basic setup with no expansion boards |
mjr | 53:9b2611964afc | 158 | expan.typ = 0; |
mjr | 53:9b2611964afc | 159 | expan.vsn = 0; |
mjr | 53:9b2611964afc | 160 | memset(expan.ext, 0, sizeof(expan.ext)); |
mjr | 52:8298b2a73eb2 | 161 | |
mjr | 35:e959ffba78fd | 162 | // assume no plunger is attached |
mjr | 35:e959ffba78fd | 163 | plunger.enabled = false; |
mjr | 35:e959ffba78fd | 164 | plunger.sensorType = PlungerType_None; |
mjr | 35:e959ffba78fd | 165 | |
mjr | 48:058ace2aed1d | 166 | #if TEST_CONFIG_EXPAN || TEST_CONFIG_CAB // $$$ |
mjr | 43:7a6364d82a41 | 167 | plunger.enabled = true; |
mjr | 43:7a6364d82a41 | 168 | plunger.sensorType = PlungerType_TSL1410RS; |
mjr | 53:9b2611964afc | 169 | plunger.sensorPin[0] = PINNAME_TO_WIRE(PTE20); // SI |
mjr | 53:9b2611964afc | 170 | plunger.sensorPin[1] = PINNAME_TO_WIRE(PTE21); // SCLK |
mjr | 53:9b2611964afc | 171 | plunger.sensorPin[2] = PINNAME_TO_WIRE(PTB0); // AO1 = PTB0 = ADC0_SE8 |
mjr | 53:9b2611964afc | 172 | plunger.sensorPin[3] = PINNAME_TO_WIRE(PTE22); // AO2 (parallel mode) = PTE22 = ADC0_SE3 |
mjr | 43:7a6364d82a41 | 173 | #endif |
mjr | 43:7a6364d82a41 | 174 | |
mjr | 48:058ace2aed1d | 175 | // default plunger calibration button settings |
mjr | 53:9b2611964afc | 176 | plunger.cal.btn = PINNAME_TO_WIRE(PTE29); |
mjr | 53:9b2611964afc | 177 | plunger.cal.led = PINNAME_TO_WIRE(PTE23); |
mjr | 35:e959ffba78fd | 178 | |
mjr | 44:b5ac89b9cd5d | 179 | // set the default plunger calibration |
mjr | 44:b5ac89b9cd5d | 180 | plunger.cal.setDefaults(); |
mjr | 35:e959ffba78fd | 181 | |
mjr | 35:e959ffba78fd | 182 | // disable the ZB Launch Ball by default |
mjr | 53:9b2611964afc | 183 | plunger.zbLaunchBall.port = 0; // 0 = disabled |
mjr | 53:9b2611964afc | 184 | plunger.zbLaunchBall.keytype = 2; // keyboard key |
mjr | 53:9b2611964afc | 185 | plunger.zbLaunchBall.keycode = 0x28; // Enter key (USB scan code) |
mjr | 53:9b2611964afc | 186 | plunger.zbLaunchBall.pushDistance = 63; // about 1/16" |
mjr | 35:e959ffba78fd | 187 | |
mjr | 35:e959ffba78fd | 188 | // assume no TV ON switch |
mjr | 53:9b2611964afc | 189 | TVON.statusPin = PINNAME_TO_WIRE(NC); |
mjr | 53:9b2611964afc | 190 | TVON.latchPin = PINNAME_TO_WIRE(NC); |
mjr | 53:9b2611964afc | 191 | TVON.relayPin = PINNAME_TO_WIRE(NC); |
mjr | 53:9b2611964afc | 192 | TVON.delayTime = 700; // 7 seconds |
mjr | 48:058ace2aed1d | 193 | #if TEST_CONFIG_EXPAN //$$$ |
mjr | 53:9b2611964afc | 194 | TVON.statusPin = PINNAME_TO_WIRE(PTD2); |
mjr | 53:9b2611964afc | 195 | TVON.latchPin = PINNAME_TO_WIRE(PTE0); |
mjr | 53:9b2611964afc | 196 | TVON.relayPin = PINNAME_TO_WIRE(PTD3); |
mjr | 53:9b2611964afc | 197 | TVON.delayTime = 700; // 7 seconds |
mjr | 38:091e511ce8a0 | 198 | #endif |
mjr | 53:9b2611964afc | 199 | |
mjr | 53:9b2611964afc | 200 | // assume no night mode switch or indicator lamp |
mjr | 53:9b2611964afc | 201 | nightMode.btn = 0; |
mjr | 53:9b2611964afc | 202 | nightMode.flags = 0; |
mjr | 53:9b2611964afc | 203 | nightMode.port = 0; |
mjr | 35:e959ffba78fd | 204 | |
mjr | 35:e959ffba78fd | 205 | // assume no TLC5940 chips |
mjr | 35:e959ffba78fd | 206 | tlc5940.nchips = 0; |
mjr | 48:058ace2aed1d | 207 | #if TEST_CONFIG_EXPAN // $$$ |
mjr | 48:058ace2aed1d | 208 | tlc5940.nchips = 4; |
mjr | 38:091e511ce8a0 | 209 | #endif |
mjr | 38:091e511ce8a0 | 210 | |
mjr | 38:091e511ce8a0 | 211 | // default TLC5940 pin assignments |
mjr | 53:9b2611964afc | 212 | tlc5940.sin = PINNAME_TO_WIRE(PTC6); |
mjr | 53:9b2611964afc | 213 | tlc5940.sclk = PINNAME_TO_WIRE(PTC5); |
mjr | 53:9b2611964afc | 214 | tlc5940.xlat = PINNAME_TO_WIRE(PTC10); |
mjr | 53:9b2611964afc | 215 | tlc5940.blank = PINNAME_TO_WIRE(PTC7); |
mjr | 53:9b2611964afc | 216 | tlc5940.gsclk = PINNAME_TO_WIRE(PTA1); |
mjr | 35:e959ffba78fd | 217 | |
mjr | 35:e959ffba78fd | 218 | // assume no 74HC595 chips |
mjr | 35:e959ffba78fd | 219 | hc595.nchips = 0; |
mjr | 48:058ace2aed1d | 220 | #if TEST_CONFIG_EXPAN // $$$ |
mjr | 48:058ace2aed1d | 221 | hc595.nchips = 1; |
mjr | 40:cc0d9814522b | 222 | #endif |
mjr | 40:cc0d9814522b | 223 | |
mjr | 38:091e511ce8a0 | 224 | // default 74HC595 pin assignments |
mjr | 53:9b2611964afc | 225 | hc595.sin = PINNAME_TO_WIRE(PTA5); |
mjr | 53:9b2611964afc | 226 | hc595.sclk = PINNAME_TO_WIRE(PTA4); |
mjr | 53:9b2611964afc | 227 | hc595.latch = PINNAME_TO_WIRE(PTA12); |
mjr | 53:9b2611964afc | 228 | hc595.ena = PINNAME_TO_WIRE(PTD4); |
mjr | 38:091e511ce8a0 | 229 | |
mjr | 35:e959ffba78fd | 230 | // initially configure with no LedWiz output ports |
mjr | 35:e959ffba78fd | 231 | outPort[0].typ = PortTypeDisabled; |
mjr | 53:9b2611964afc | 232 | |
mjr | 35:e959ffba78fd | 233 | // initially configure with no input buttons |
mjr | 35:e959ffba78fd | 234 | for (int i = 0 ; i < MAX_BUTTONS ; ++i) |
mjr | 53:9b2611964afc | 235 | button[i].set(PINNAME_TO_WIRE(NC), BtnTypeNone, 0); |
mjr | 38:091e511ce8a0 | 236 | |
mjr | 48:058ace2aed1d | 237 | #if TEST_CONFIG_EXPAN | TEST_CONFIG_CAB |
mjr | 38:091e511ce8a0 | 238 | for (int i = 0 ; i < 24 ; ++i) { |
mjr | 38:091e511ce8a0 | 239 | static int bp[] = { |
mjr | 53:9b2611964afc | 240 | PINNAME_TO_WIRE(PTC2), // 1 |
mjr | 53:9b2611964afc | 241 | PINNAME_TO_WIRE(PTB3), // 2 |
mjr | 53:9b2611964afc | 242 | PINNAME_TO_WIRE(PTB2), // 3 |
mjr | 53:9b2611964afc | 243 | PINNAME_TO_WIRE(PTB1), // 4 |
mjr | 53:9b2611964afc | 244 | PINNAME_TO_WIRE(PTE30), // 5 |
mjr | 48:058ace2aed1d | 245 | #if TEST_CONFIG_EXPAN |
mjr | 53:9b2611964afc | 246 | PINNAME_TO_WIRE(PTC11), // 6 |
mjr | 53:9b2611964afc | 247 | #elif TEST_CONFIG_CAB |
mjr | 53:9b2611964afc | 248 | PINNAME_TO_WIRE(PTE22), // 6 |
mjr | 48:058ace2aed1d | 249 | #endif |
mjr | 53:9b2611964afc | 250 | PINNAME_TO_WIRE(PTE5), // 7 |
mjr | 53:9b2611964afc | 251 | PINNAME_TO_WIRE(PTE4), // 8 |
mjr | 53:9b2611964afc | 252 | PINNAME_TO_WIRE(PTE3), // 9 |
mjr | 53:9b2611964afc | 253 | PINNAME_TO_WIRE(PTE2), // 10 |
mjr | 53:9b2611964afc | 254 | PINNAME_TO_WIRE(PTB11), // 11 |
mjr | 53:9b2611964afc | 255 | PINNAME_TO_WIRE(PTB10), // 12 |
mjr | 53:9b2611964afc | 256 | PINNAME_TO_WIRE(PTB9), // 13 |
mjr | 53:9b2611964afc | 257 | PINNAME_TO_WIRE(PTB8), // 14 |
mjr | 53:9b2611964afc | 258 | PINNAME_TO_WIRE(PTC12), // 15 |
mjr | 53:9b2611964afc | 259 | PINNAME_TO_WIRE(PTC13), // 16 |
mjr | 53:9b2611964afc | 260 | PINNAME_TO_WIRE(PTC16), // 17 |
mjr | 53:9b2611964afc | 261 | PINNAME_TO_WIRE(PTC17), // 18 |
mjr | 53:9b2611964afc | 262 | PINNAME_TO_WIRE(PTA16), // 19 |
mjr | 53:9b2611964afc | 263 | PINNAME_TO_WIRE(PTA17), // 20 |
mjr | 53:9b2611964afc | 264 | PINNAME_TO_WIRE(PTE31), // 21 |
mjr | 53:9b2611964afc | 265 | PINNAME_TO_WIRE(PTD6), // 22 |
mjr | 53:9b2611964afc | 266 | PINNAME_TO_WIRE(PTD7), // 23 |
mjr | 53:9b2611964afc | 267 | PINNAME_TO_WIRE(PTE1) // 24 |
mjr | 40:cc0d9814522b | 268 | }; |
mjr | 48:058ace2aed1d | 269 | button[i].set(bp[i], |
mjr | 48:058ace2aed1d | 270 | #if TEST_CONFIG_EXPAN |
mjr | 48:058ace2aed1d | 271 | BtnTypeKey, i+4); // keyboard key A, B, C... |
mjr | 48:058ace2aed1d | 272 | #elif TEST_CONFIG_CAB |
mjr | 53:9b2611964afc | 273 | BtnTypeJoystick, i+1); // joystick button 0, 1, ... |
mjr | 48:058ace2aed1d | 274 | #endif |
mjr | 48:058ace2aed1d | 275 | |
mjr | 38:091e511ce8a0 | 276 | } |
mjr | 38:091e511ce8a0 | 277 | #endif |
mjr | 38:091e511ce8a0 | 278 | |
mjr | 38:091e511ce8a0 | 279 | #if 0 |
mjr | 38:091e511ce8a0 | 280 | button[23].typ = BtnTypeJoystick; |
mjr | 38:091e511ce8a0 | 281 | button[23].val = 5; // B |
mjr | 38:091e511ce8a0 | 282 | button[23].flags = 0x01; // pulse button |
mjr | 38:091e511ce8a0 | 283 | |
mjr | 38:091e511ce8a0 | 284 | button[22].typ = BtnTypeModKey; |
mjr | 53:9b2611964afc | 285 | button[22].val = 0xE1; // left shift |
mjr | 38:091e511ce8a0 | 286 | |
mjr | 53:9b2611964afc | 287 | button[21].typ = BtnTypeKey; |
mjr | 53:9b2611964afc | 288 | button[21].val = 0x81; // vol down |
mjr | 38:091e511ce8a0 | 289 | |
mjr | 53:9b2611964afc | 290 | button[20].typ = BtnTypeKey; |
mjr | 53:9b2611964afc | 291 | button[20].val = 0x80; // vol up |
mjr | 39:b3815a1c3802 | 292 | |
mjr | 38:091e511ce8a0 | 293 | #endif |
mjr | 38:091e511ce8a0 | 294 | |
mjr | 43:7a6364d82a41 | 295 | |
mjr | 48:058ace2aed1d | 296 | #if TEST_CONFIG_EXPAN // $$$ |
mjr | 40:cc0d9814522b | 297 | // CONFIGURE EXPANSION BOARD PORTS |
mjr | 40:cc0d9814522b | 298 | // |
mjr | 40:cc0d9814522b | 299 | // We have the following hardware attached: |
mjr | 40:cc0d9814522b | 300 | // |
mjr | 40:cc0d9814522b | 301 | // Main board |
mjr | 40:cc0d9814522b | 302 | // TLC ports 0-15 -> flashers |
mjr | 40:cc0d9814522b | 303 | // TLC ports 16 -> strobe |
mjr | 40:cc0d9814522b | 304 | // TLC ports 17-31 -> flippers |
mjr | 40:cc0d9814522b | 305 | // Dig GPIO PTC8 -> knocker (timer-protected outputs) |
mjr | 40:cc0d9814522b | 306 | // |
mjr | 40:cc0d9814522b | 307 | // Power board: |
mjr | 40:cc0d9814522b | 308 | // TLC ports 32-63 -> general purpose outputs |
mjr | 40:cc0d9814522b | 309 | // |
mjr | 40:cc0d9814522b | 310 | // Chime board: |
mjr | 40:cc0d9814522b | 311 | // HC595 ports 0-7 -> timer-protected outputs |
mjr | 40:cc0d9814522b | 312 | // |
mjr | 38:091e511ce8a0 | 313 | { |
mjr | 38:091e511ce8a0 | 314 | int n = 0; |
mjr | 40:cc0d9814522b | 315 | |
mjr | 40:cc0d9814522b | 316 | // 1-15 = flashers (TLC ports 0-15) |
mjr | 40:cc0d9814522b | 317 | // 16 = strobe (TLC port 15) |
mjr | 40:cc0d9814522b | 318 | for (int i = 0 ; i < 16 ; ++i) |
mjr | 40:cc0d9814522b | 319 | outPort[n++].set(PortTypeTLC5940, i, PortFlagGamma); |
mjr | 40:cc0d9814522b | 320 | |
mjr | 53:9b2611964afc | 321 | // 17 = knocker (PTC8) |
mjr | 53:9b2611964afc | 322 | outPort[n++].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC8)); |
mjr | 35:e959ffba78fd | 323 | |
mjr | 40:cc0d9814522b | 324 | // 18-49 = power board outputs 1-32 (TLC ports 32-63) |
mjr | 40:cc0d9814522b | 325 | for (int i = 0 ; i < 32 ; ++i) |
mjr | 40:cc0d9814522b | 326 | outPort[n++].set(PortTypeTLC5940, i+32); |
mjr | 40:cc0d9814522b | 327 | |
mjr | 40:cc0d9814522b | 328 | // 50-65 = flipper RGB (TLC ports 16-31) |
mjr | 40:cc0d9814522b | 329 | for (int i = 0 ; i < 16 ; ++i) |
mjr | 40:cc0d9814522b | 330 | outPort[n++].set(PortTypeTLC5940, i+16, PortFlagGamma); |
mjr | 40:cc0d9814522b | 331 | |
mjr | 40:cc0d9814522b | 332 | // 66-73 = chime board ports 1-8 (74HC595 ports 0-7) |
mjr | 40:cc0d9814522b | 333 | for (int i = 0 ; i < 8 ; ++i) |
mjr | 40:cc0d9814522b | 334 | outPort[n++].set(PortType74HC595, i); |
mjr | 40:cc0d9814522b | 335 | |
mjr | 40:cc0d9814522b | 336 | // set Disabled to signify end of configured outputs |
mjr | 38:091e511ce8a0 | 337 | outPort[n].typ = PortTypeDisabled; |
mjr | 38:091e511ce8a0 | 338 | } |
mjr | 38:091e511ce8a0 | 339 | #endif |
mjr | 48:058ace2aed1d | 340 | |
mjr | 48:058ace2aed1d | 341 | #if TEST_CONFIG_CAB |
mjr | 48:058ace2aed1d | 342 | #if TEST_KEEP_PRINTF |
mjr | 53:9b2611964afc | 343 | outPort[ 0].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(NC)); // port 1 = NC to keep debug printf (PTA1 is UART) |
mjr | 53:9b2611964afc | 344 | outPort[ 1].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(NC)); // port 2 = NC to keep debug printf (PTA2 is UART) |
mjr | 48:058ace2aed1d | 345 | #else |
mjr | 53:9b2611964afc | 346 | outPort[ 0].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTA1)); // port 1 = PTA1 |
mjr | 53:9b2611964afc | 347 | outPort[ 1].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTA2)); // port 2 = PTA2 |
mjr | 48:058ace2aed1d | 348 | #endif |
mjr | 53:9b2611964afc | 349 | outPort[ 2].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTD4)); // port 3 = PTD4 |
mjr | 53:9b2611964afc | 350 | outPort[ 3].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTA12)); // port 4 = PTA12 |
mjr | 53:9b2611964afc | 351 | outPort[ 4].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTA4)); // port 5 = PTA4 |
mjr | 53:9b2611964afc | 352 | outPort[ 5].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTA5)); // port 6 = PTA5 |
mjr | 53:9b2611964afc | 353 | outPort[ 6].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTA13)); // port 7 = PTA13 |
mjr | 53:9b2611964afc | 354 | outPort[ 7].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTD5)); // port 8 = PTD5 |
mjr | 53:9b2611964afc | 355 | outPort[ 8].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTD0)); // port 9 = PTD0 |
mjr | 53:9b2611964afc | 356 | outPort[ 9].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(PTD3)); // port 10 = PTD3 |
mjr | 53:9b2611964afc | 357 | outPort[10].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTD2)); // port 11 = PTD2 |
mjr | 53:9b2611964afc | 358 | outPort[11].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC8)); // port 12 = PTC8 |
mjr | 53:9b2611964afc | 359 | outPort[12].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC9)); // port 13 = PTC9 |
mjr | 53:9b2611964afc | 360 | outPort[13].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC7)); // port 14 = PTC7 |
mjr | 53:9b2611964afc | 361 | outPort[14].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC0)); // port 15 = PTC0 |
mjr | 53:9b2611964afc | 362 | outPort[15].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC3)); // port 16 = PTC3 |
mjr | 53:9b2611964afc | 363 | outPort[16].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC4)); // port 17 = PTC4 |
mjr | 53:9b2611964afc | 364 | outPort[17].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC5)); // port 18 = PTC5 |
mjr | 53:9b2611964afc | 365 | outPort[18].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC6)); // port 19 = PTC6 |
mjr | 53:9b2611964afc | 366 | outPort[19].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC10)); // port 20 = PTC10 |
mjr | 53:9b2611964afc | 367 | outPort[20].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTC11)); // port 21 = PTC11 |
mjr | 53:9b2611964afc | 368 | outPort[21].set(PortTypeGPIODig, PINNAME_TO_WIRE(PTE0)); // port 22 = PTE0 |
mjr | 48:058ace2aed1d | 369 | #endif |
mjr | 48:058ace2aed1d | 370 | |
mjr | 38:091e511ce8a0 | 371 | #if 0 |
mjr | 40:cc0d9814522b | 372 | // configure the on-board RGB LED as outputs 1,2,3 |
mjr | 53:9b2611964afc | 373 | outPort[0].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(LED1), PortFlagActiveLow); // PTB18 = LED1 = Red LED |
mjr | 53:9b2611964afc | 374 | outPort[1].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(LED2), PortFlagActiveLow); // PTB19 = LED2 = Green LED |
mjr | 53:9b2611964afc | 375 | outPort[2].set(PortTypeGPIOPWM, PINNAME_TO_WIRE(LED3), PortFlagActiveLow); // PTD1 = LED3 = Blue LED |
mjr | 38:091e511ce8a0 | 376 | outPort[3].typ = PortTypeDisabled; |
mjr | 38:091e511ce8a0 | 377 | #endif |
mjr | 35:e959ffba78fd | 378 | } |
mjr | 35:e959ffba78fd | 379 | |
mjr | 35:e959ffba78fd | 380 | // --- USB DEVICE CONFIGURATION --- |
mjr | 35:e959ffba78fd | 381 | |
mjr | 35:e959ffba78fd | 382 | // USB device identification - vendor ID and product ID. For LedLWiz |
mjr | 35:e959ffba78fd | 383 | // emulation, use vendor ID 0xFAFA and product ID 0x00EF + unit#, where |
mjr | 35:e959ffba78fd | 384 | // unit# is the nominal LedWiz unit number from 1 to 16. Alternatively, |
mjr | 35:e959ffba78fd | 385 | // if LedWiz emulation isn't desired or causes any driver conflicts on |
mjr | 35:e959ffba78fd | 386 | // the host, we have a private Pinscape assignment as vendor ID 0x1209 |
mjr | 35:e959ffba78fd | 387 | // and product ID 0xEAEA (registered with http://pid.codes, a registry |
mjr | 35:e959ffba78fd | 388 | // for open-source USB projects). |
mjr | 35:e959ffba78fd | 389 | uint16_t usbVendorID; |
mjr | 35:e959ffba78fd | 390 | uint16_t usbProductID; |
mjr | 35:e959ffba78fd | 391 | |
mjr | 35:e959ffba78fd | 392 | // Pinscape Controller unit number. This is the nominal unit number, |
mjr | 35:e959ffba78fd | 393 | // from 1 to 16. We report this in the status query; DOF uses it to |
mjr | 53:9b2611964afc | 394 | // distinguish among Pinscape units. Note that this doesn't affect |
mjr | 35:e959ffba78fd | 395 | // the LedWiz unit numbering, which is implied by the USB Product ID. |
mjr | 35:e959ffba78fd | 396 | uint8_t psUnitNo; |
mjr | 35:e959ffba78fd | 397 | |
mjr | 35:e959ffba78fd | 398 | // Are joystick reports enabled? Joystick reports can be turned off, to |
mjr | 35:e959ffba78fd | 399 | // use the device as purely an output controller. |
mjr | 35:e959ffba78fd | 400 | char joystickEnabled; |
mjr | 35:e959ffba78fd | 401 | |
mjr | 51:57eb311faafa | 402 | // Timeout for rebooting the KL25Z when the connection is lost. On some |
mjr | 51:57eb311faafa | 403 | // hosts, the mbed USB stack has problems reconnecting after an initial |
mjr | 51:57eb311faafa | 404 | // connection is dropped. As a workaround, we can automatically reboot |
mjr | 51:57eb311faafa | 405 | // the KL25Z when it detects that it's no longer connected, after the |
mjr | 51:57eb311faafa | 406 | // interval set here expires. The timeout is in seconds; setting this |
mjr | 51:57eb311faafa | 407 | // to 0 disables the automatic reboot. |
mjr | 51:57eb311faafa | 408 | uint8_t disconnectRebootTimeout; |
mjr | 35:e959ffba78fd | 409 | |
mjr | 35:e959ffba78fd | 410 | // --- ACCELEROMETER --- |
mjr | 35:e959ffba78fd | 411 | |
mjr | 35:e959ffba78fd | 412 | // accelerometer orientation (ORIENTATION_xxx value) |
mjr | 35:e959ffba78fd | 413 | char orientation; |
mjr | 35:e959ffba78fd | 414 | |
mjr | 35:e959ffba78fd | 415 | |
mjr | 52:8298b2a73eb2 | 416 | // --- EXPANSION BOARDS --- |
mjr | 52:8298b2a73eb2 | 417 | struct |
mjr | 52:8298b2a73eb2 | 418 | { |
mjr | 53:9b2611964afc | 419 | uint8_t typ; // expansion board set type: |
mjr | 53:9b2611964afc | 420 | // 1 -> Pinscape expansion boards |
mjr | 53:9b2611964afc | 421 | uint8_t vsn; // board set interface version |
mjr | 53:9b2611964afc | 422 | uint8_t ext[3]; // board set type-specific extended data |
mjr | 52:8298b2a73eb2 | 423 | |
mjr | 52:8298b2a73eb2 | 424 | } expan; |
mjr | 52:8298b2a73eb2 | 425 | |
mjr | 52:8298b2a73eb2 | 426 | |
mjr | 35:e959ffba78fd | 427 | // --- PLUNGER CONFIGURATION --- |
mjr | 35:e959ffba78fd | 428 | struct |
mjr | 35:e959ffba78fd | 429 | { |
mjr | 35:e959ffba78fd | 430 | // plunger enabled/disabled |
mjr | 35:e959ffba78fd | 431 | char enabled; |
mjr | 33:d832bcab089e | 432 | |
mjr | 35:e959ffba78fd | 433 | // plunger sensor type |
mjr | 35:e959ffba78fd | 434 | char sensorType; |
mjr | 35:e959ffba78fd | 435 | |
mjr | 35:e959ffba78fd | 436 | // Plunger sensor pins. To accommodate a wide range of sensor types, |
mjr | 35:e959ffba78fd | 437 | // we keep a generic list of 4 pin assignments. The use of each pin |
mjr | 35:e959ffba78fd | 438 | // varies by sensor. The lists below are in order of the generic |
mjr | 35:e959ffba78fd | 439 | // pins; NC means that the pin isn't used by the sensor. Each pin's |
mjr | 35:e959ffba78fd | 440 | // GPIO usage is also listed. Certain usages limit which physical |
mjr | 35:e959ffba78fd | 441 | // pins can be assigned (e.g., AnalogIn or PwmOut). |
mjr | 35:e959ffba78fd | 442 | // |
mjr | 35:e959ffba78fd | 443 | // TSL1410R/1412R, serial: SI (DigitalOut), CLK (DigitalOut), AO (AnalogIn), NC |
mjr | 35:e959ffba78fd | 444 | // TSL1410R/1412R, parallel: SI (DigitalOut), CLK (DigitalOut), AO1 (AnalogIn), AO2 (AnalogIn) |
mjr | 35:e959ffba78fd | 445 | // Potentiometer: AO (AnalogIn), NC, NC, NC |
mjr | 35:e959ffba78fd | 446 | // AEDR8300: A (InterruptIn), B (InterruptIn), NC, NC |
mjr | 35:e959ffba78fd | 447 | // AS5304: A (InterruptIn), B (InterruptIn), NC, NC |
mjr | 53:9b2611964afc | 448 | // |
mjr | 53:9b2611964afc | 449 | // Note! These are stored in uint8_t WIRE format, not PinName format. |
mjr | 53:9b2611964afc | 450 | uint8_t sensorPin[4]; |
mjr | 35:e959ffba78fd | 451 | |
mjr | 53:9b2611964afc | 452 | // ZB LAUNCH BALL button setup. |
mjr | 35:e959ffba78fd | 453 | // |
mjr | 35:e959ffba78fd | 454 | // This configures the "ZB Launch Ball" feature in DOF, based on Zeb's (of |
mjr | 35:e959ffba78fd | 455 | // zebsboards.com) scheme for using a mechanical plunger as a Launch button. |
mjr | 35:e959ffba78fd | 456 | // Set the port to 0 to disable the feature. |
mjr | 35:e959ffba78fd | 457 | // |
mjr | 35:e959ffba78fd | 458 | // The port number is an LedWiz port number that we monitor for activation. |
mjr | 53:9b2611964afc | 459 | // This port isn't meant to be connected to a physical device, although it |
mjr | 53:9b2611964afc | 460 | // can be if desired. It's primarily to let the host tell the controller |
mjr | 53:9b2611964afc | 461 | // when the ZB Launch feature is active. The port numbering starts at 1; |
mjr | 53:9b2611964afc | 462 | // set this to zero to disable the feature. |
mjr | 35:e959ffba78fd | 463 | // |
mjr | 53:9b2611964afc | 464 | // The key type and code has the same meaning as for a button mapping. This |
mjr | 53:9b2611964afc | 465 | // sets the key input sent to the PC when the plunger triggers a launch when |
mjr | 53:9b2611964afc | 466 | // the mode is active. For example, set keytype=2 and keycode=0x28 to send |
mjr | 53:9b2611964afc | 467 | // the Enter key (which is the key almost all PC pinball software uses for |
mjr | 53:9b2611964afc | 468 | // plunger and Launch button input). |
mjr | 35:e959ffba78fd | 469 | // |
mjr | 40:cc0d9814522b | 470 | // The "push distance" is the distance, in 1/1000 inch units, for registering a |
mjr | 40:cc0d9814522b | 471 | // push on the plunger as a button push. If the player pushes the plunger |
mjr | 40:cc0d9814522b | 472 | // forward of the rest position by this amount, we'll treat it as pushing the |
mjr | 40:cc0d9814522b | 473 | // button, even if the player didn't pull back the plunger first. This lets |
mjr | 40:cc0d9814522b | 474 | // the player treat the plunger knob as a button for games where it's meaningful |
mjr | 35:e959ffba78fd | 475 | // to hold down the Launch button for specific intervals (e.g., "Championship |
mjr | 35:e959ffba78fd | 476 | // Pub"). |
mjr | 35:e959ffba78fd | 477 | struct |
mjr | 35:e959ffba78fd | 478 | { |
mjr | 53:9b2611964afc | 479 | uint8_t port; |
mjr | 53:9b2611964afc | 480 | uint8_t keytype; |
mjr | 53:9b2611964afc | 481 | uint8_t keycode; |
mjr | 53:9b2611964afc | 482 | uint16_t pushDistance; |
mjr | 35:e959ffba78fd | 483 | |
mjr | 35:e959ffba78fd | 484 | } zbLaunchBall; |
mjr | 35:e959ffba78fd | 485 | |
mjr | 35:e959ffba78fd | 486 | // --- PLUNGER CALIBRATION --- |
mjr | 35:e959ffba78fd | 487 | struct |
mjr | 35:e959ffba78fd | 488 | { |
mjr | 35:e959ffba78fd | 489 | // has the plunger been calibrated? |
mjr | 53:9b2611964afc | 490 | bool calibrated; |
mjr | 35:e959ffba78fd | 491 | |
mjr | 35:e959ffba78fd | 492 | // calibration button switch pin |
mjr | 53:9b2611964afc | 493 | uint8_t btn; |
mjr | 35:e959ffba78fd | 494 | |
mjr | 35:e959ffba78fd | 495 | // calibration button indicator light pin |
mjr | 53:9b2611964afc | 496 | uint8_t led; |
mjr | 35:e959ffba78fd | 497 | |
mjr | 48:058ace2aed1d | 498 | // Plunger calibration min, zero, and max. These are in terms of the |
mjr | 48:058ace2aed1d | 499 | // unsigned 16-bit scale (0x0000..0xffff) that we use for the raw sensor |
mjr | 48:058ace2aed1d | 500 | // readings. |
mjr | 48:058ace2aed1d | 501 | // |
mjr | 48:058ace2aed1d | 502 | // The zero point is the rest position (aka park position), where the |
mjr | 48:058ace2aed1d | 503 | // plunger is in equilibrium between the main spring and the barrel |
mjr | 48:058ace2aed1d | 504 | // spring. In the standard setup, the plunger can travel a small |
mjr | 48:058ace2aed1d | 505 | // distance forward of the rest position, because the barrel spring |
mjr | 48:058ace2aed1d | 506 | // can be compressed a bit. The minimum is the maximum forward point |
mjr | 48:058ace2aed1d | 507 | // where the barrel spring can't be compressed any further. |
mjr | 48:058ace2aed1d | 508 | uint16_t min; |
mjr | 48:058ace2aed1d | 509 | uint16_t zero; |
mjr | 48:058ace2aed1d | 510 | uint16_t max; |
mjr | 52:8298b2a73eb2 | 511 | |
mjr | 52:8298b2a73eb2 | 512 | // Measured release time, in milliseconds. |
mjr | 52:8298b2a73eb2 | 513 | uint8_t tRelease; |
mjr | 35:e959ffba78fd | 514 | |
mjr | 44:b5ac89b9cd5d | 515 | // Reset the plunger calibration |
mjr | 44:b5ac89b9cd5d | 516 | void setDefaults() |
mjr | 35:e959ffba78fd | 517 | { |
mjr | 44:b5ac89b9cd5d | 518 | calibrated = false; // not calibrated |
mjr | 48:058ace2aed1d | 519 | min = 0; // assume we can go all the way forward... |
mjr | 48:058ace2aed1d | 520 | max = 0xffff; // ...and all the way back |
mjr | 48:058ace2aed1d | 521 | zero = max/6; // the rest position is usually around 1/2" back = 1/6 of total travel |
mjr | 52:8298b2a73eb2 | 522 | tRelease = 65; // standard 65ms release time |
mjr | 44:b5ac89b9cd5d | 523 | } |
mjr | 44:b5ac89b9cd5d | 524 | |
mjr | 44:b5ac89b9cd5d | 525 | // Begin calibration. This sets each limit to the worst |
mjr | 44:b5ac89b9cd5d | 526 | // case point - for example, we set the retracted position |
mjr | 44:b5ac89b9cd5d | 527 | // to all the way forward. Each actual reading that comes |
mjr | 44:b5ac89b9cd5d | 528 | // in is then checked against the current limit, and if it's |
mjr | 44:b5ac89b9cd5d | 529 | // outside of the limit, we reset the limit to the new reading. |
mjr | 44:b5ac89b9cd5d | 530 | void begin() |
mjr | 44:b5ac89b9cd5d | 531 | { |
mjr | 48:058ace2aed1d | 532 | min = 0; // we don't calibrate the maximum forward position, so keep this at zero |
mjr | 48:058ace2aed1d | 533 | zero = 0xffff; // set the zero position all the way back |
mjr | 48:058ace2aed1d | 534 | max = 0; // set the retracted position all the way forward |
mjr | 52:8298b2a73eb2 | 535 | tRelease = 65; // revert to a default release time |
mjr | 35:e959ffba78fd | 536 | } |
mjr | 17:ab3cec0c8bf4 | 537 | |
mjr | 35:e959ffba78fd | 538 | } cal; |
mjr | 18:5e890ebd0023 | 539 | |
mjr | 35:e959ffba78fd | 540 | } plunger; |
mjr | 29:582472d0bc57 | 541 | |
mjr | 35:e959ffba78fd | 542 | |
mjr | 35:e959ffba78fd | 543 | // --- TV ON SWITCH --- |
mjr | 35:e959ffba78fd | 544 | // |
mjr | 35:e959ffba78fd | 545 | // To use the TV ON switch feature, the special power sensing circuitry |
mjr | 35:e959ffba78fd | 546 | // implemented on the Expansion Board must be attached (or an equivalent |
mjr | 35:e959ffba78fd | 547 | // circuit, as described in the Build Guide). The circuitry lets us |
mjr | 35:e959ffba78fd | 548 | // detect power state changes on the secondary power supply. |
mjr | 35:e959ffba78fd | 549 | struct |
mjr | 35:e959ffba78fd | 550 | { |
mjr | 35:e959ffba78fd | 551 | // PSU2 power status sense (DigitalIn pin). This pin goes LOW when the |
mjr | 35:e959ffba78fd | 552 | // secondary power supply is turned off, and remains LOW until the LATCH |
mjr | 35:e959ffba78fd | 553 | // pin is raised high AND the secondary PSU is turned on. Once HIGH, |
mjr | 35:e959ffba78fd | 554 | // it remains HIGH as long as the secondary PSU is on. |
mjr | 53:9b2611964afc | 555 | uint8_t statusPin; |
mjr | 35:e959ffba78fd | 556 | |
mjr | 35:e959ffba78fd | 557 | // PSU2 power status latch (DigitalOut pin) |
mjr | 53:9b2611964afc | 558 | uint8_t latchPin; |
mjr | 35:e959ffba78fd | 559 | |
mjr | 35:e959ffba78fd | 560 | // TV ON relay pin (DigitalOut pin). This pin controls the TV switch |
mjr | 35:e959ffba78fd | 561 | // relay. Raising the pin HIGH turns the relay ON (energizes the coil). |
mjr | 53:9b2611964afc | 562 | uint8_t relayPin; |
mjr | 35:e959ffba78fd | 563 | |
mjr | 40:cc0d9814522b | 564 | // TV ON delay time, in 1/100 second units. This is the interval between |
mjr | 40:cc0d9814522b | 565 | // sensing that the secondary power supply has turned on and pulsing the |
mjr | 40:cc0d9814522b | 566 | // TV ON switch relay. |
mjr | 40:cc0d9814522b | 567 | int delayTime; |
mjr | 35:e959ffba78fd | 568 | |
mjr | 35:e959ffba78fd | 569 | } TVON; |
mjr | 35:e959ffba78fd | 570 | |
mjr | 53:9b2611964afc | 571 | // --- Night Mode --- |
mjr | 53:9b2611964afc | 572 | struct |
mjr | 53:9b2611964afc | 573 | { |
mjr | 53:9b2611964afc | 574 | uint8_t btn; // night mode button number (1..MAX_BUTTONS, 0=disabled) |
mjr | 53:9b2611964afc | 575 | uint8_t flags; // flags: |
mjr | 53:9b2611964afc | 576 | // 0x01 = on/off switch (if not set, it's a momentary button) |
mjr | 53:9b2611964afc | 577 | uint8_t port; // indicator output port number (1..MAX_OUT_PORTS, 0=disabled) |
mjr | 53:9b2611964afc | 578 | } nightMode; |
mjr | 53:9b2611964afc | 579 | |
mjr | 29:582472d0bc57 | 580 | |
mjr | 35:e959ffba78fd | 581 | // --- TLC5940NT PWM Controller Chip Setup --- |
mjr | 35:e959ffba78fd | 582 | struct |
mjr | 35:e959ffba78fd | 583 | { |
mjr | 35:e959ffba78fd | 584 | // number of TLC5940NT chips connected in daisy chain |
mjr | 35:e959ffba78fd | 585 | int nchips; |
mjr | 35:e959ffba78fd | 586 | |
mjr | 53:9b2611964afc | 587 | // pin connections (wire pin IDs) |
mjr | 53:9b2611964afc | 588 | uint8_t sin; // Serial data - must connect to SPIO MOSI -> PTC6 or PTD2 |
mjr | 53:9b2611964afc | 589 | uint8_t sclk; // Serial clock - must connect to SPIO SCLK -> PTC5 or PTD1 |
mjr | 35:e959ffba78fd | 590 | // (but don't use PTD1, since it's hard-wired to the on-board blue LED) |
mjr | 53:9b2611964afc | 591 | uint8_t xlat; // XLAT (latch) signal - connect to any GPIO pin |
mjr | 53:9b2611964afc | 592 | uint8_t blank; // BLANK signal - connect to any GPIO pin |
mjr | 53:9b2611964afc | 593 | uint8_t gsclk; // Grayscale clock - must connect to a PWM-out capable pin |
mjr | 29:582472d0bc57 | 594 | |
mjr | 35:e959ffba78fd | 595 | } tlc5940; |
mjr | 35:e959ffba78fd | 596 | |
mjr | 35:e959ffba78fd | 597 | |
mjr | 35:e959ffba78fd | 598 | // --- 74HC595 Shift Register Setup --- |
mjr | 35:e959ffba78fd | 599 | struct |
mjr | 35:e959ffba78fd | 600 | { |
mjr | 35:e959ffba78fd | 601 | // number of 74HC595 chips attached in daisy chain |
mjr | 35:e959ffba78fd | 602 | int nchips; |
mjr | 35:e959ffba78fd | 603 | |
mjr | 35:e959ffba78fd | 604 | // pin connections |
mjr | 53:9b2611964afc | 605 | uint8_t sin; // Serial data - use any GPIO pin |
mjr | 53:9b2611964afc | 606 | uint8_t sclk; // Serial clock - use any GPIO pin |
mjr | 53:9b2611964afc | 607 | uint8_t latch; // Latch - use any GPIO pin |
mjr | 53:9b2611964afc | 608 | uint8_t ena; // Enable signal - use any GPIO pin |
mjr | 35:e959ffba78fd | 609 | |
mjr | 35:e959ffba78fd | 610 | } hc595; |
mjr | 34:6b981a2afab7 | 611 | |
mjr | 25:e22b88bd783a | 612 | |
mjr | 35:e959ffba78fd | 613 | // --- Button Input Setup --- |
mjr | 40:cc0d9814522b | 614 | ButtonCfg button[MAX_BUTTONS] __attribute__((packed)); |
mjr | 17:ab3cec0c8bf4 | 615 | |
mjr | 35:e959ffba78fd | 616 | // --- LedWiz Output Port Setup --- |
mjr | 38:091e511ce8a0 | 617 | LedWizPortCfg outPort[MAX_OUT_PORTS] __attribute__((packed)); // LedWiz & extended output ports |
mjr | 48:058ace2aed1d | 618 | |
mjr | 17:ab3cec0c8bf4 | 619 | }; |
mjr | 17:ab3cec0c8bf4 | 620 | |
mjr | 35:e959ffba78fd | 621 | #endif |