First Release
Out_PCE/Out_PCE.cpp@1:6c392ebcd4d4, 2013-07-27 (annotated)
- Committer:
- sankichi
- Date:
- Sat Jul 27 14:19:33 2013 +0000
- Revision:
- 1:6c392ebcd4d4
- Parent:
- 0:e1265f6b3565
First release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sankichi | 0:e1265f6b3565 | 1 | #include "NiseKabuto.h" |
sankichi | 0:e1265f6b3565 | 2 | #include "Cfunc_PCEDigital.h" |
sankichi | 0:e1265f6b3565 | 3 | |
sankichi | 0:e1265f6b3565 | 4 | volatile char test = 0; |
sankichi | 0:e1265f6b3565 | 5 | |
sankichi | 0:e1265f6b3565 | 6 | //extern "C" void mbed_reset(); |
sankichi | 0:e1265f6b3565 | 7 | |
sankichi | 0:e1265f6b3565 | 8 | // |
sankichi | 0:e1265f6b3565 | 9 | // Constructor |
sankichi | 0:e1265f6b3565 | 10 | // |
sankichi | 0:e1265f6b3565 | 11 | Out_PCE::Out_PCE( |
sankichi | 0:e1265f6b3565 | 12 | PinName pn_1Y, PinName pn_2Y, PinName pn_3Y, PinName pn_4Y, |
sankichi | 0:e1265f6b3565 | 13 | PinName pn_DSEL, PinName pn_ST, PinName pn_POWDETECT, |
sankichi | 0:e1265f6b3565 | 14 | InputStatus *inputStatus) |
sankichi | 0:e1265f6b3565 | 15 | : _OUT_1Y(pn_1Y), _OUT_2Y(pn_2Y), _OUT_3Y(pn_3Y), _OUT_4Y(pn_4Y), |
sankichi | 0:e1265f6b3565 | 16 | _INTR_DSEL(pn_DSEL), _INTR_ST(pn_ST), _INTR_POWDETECT(pn_POWDETECT) |
sankichi | 0:e1265f6b3565 | 17 | { |
sankichi | 0:e1265f6b3565 | 18 | _InputStatus = inputStatus; |
sankichi | 0:e1265f6b3565 | 19 | |
sankichi | 0:e1265f6b3565 | 20 | // OutputMode Initialize |
sankichi | 0:e1265f6b3565 | 21 | _OutputMode = _InputStatus->InputDeviceType; |
sankichi | 0:e1265f6b3565 | 22 | |
sankichi | 0:e1265f6b3565 | 23 | //printf("_OutputMode: %d(constructor)\r\n",_OutputMode); |
sankichi | 0:e1265f6b3565 | 24 | |
sankichi | 0:e1265f6b3565 | 25 | // InitInterruptPriority(); |
sankichi | 0:e1265f6b3565 | 26 | Initialize(); |
sankichi | 0:e1265f6b3565 | 27 | |
sankichi | 0:e1265f6b3565 | 28 | } |
sankichi | 0:e1265f6b3565 | 29 | |
sankichi | 0:e1265f6b3565 | 30 | // |
sankichi | 0:e1265f6b3565 | 31 | // Initialize |
sankichi | 0:e1265f6b3565 | 32 | // |
sankichi | 0:e1265f6b3565 | 33 | void Out_PCE::Initialize() |
sankichi | 0:e1265f6b3565 | 34 | { |
sankichi | 0:e1265f6b3565 | 35 | |
sankichi | 0:e1265f6b3565 | 36 | // Pin Setting |
sankichi | 0:e1265f6b3565 | 37 | _INTR_ST.mode(PullUp); |
sankichi | 0:e1265f6b3565 | 38 | _INTR_DSEL.mode(PullUp); |
sankichi | 0:e1265f6b3565 | 39 | _INTR_POWDETECT.mode(PullUp); |
sankichi | 0:e1265f6b3565 | 40 | |
sankichi | 0:e1265f6b3565 | 41 | // Class Variable Setting |
sankichi | 0:e1265f6b3565 | 42 | _PhaseCounter = 0; |
sankichi | 0:e1265f6b3565 | 43 | _NowWriting = 0; |
sankichi | 0:e1265f6b3565 | 44 | _DataSelectStatus = 1; |
sankichi | 0:e1265f6b3565 | 45 | _TransferSpeed = TRANSFERSPEED_MAX__MICROSEC; |
sankichi | 0:e1265f6b3565 | 46 | _RapidFireValue = 1; |
sankichi | 0:e1265f6b3565 | 47 | |
sankichi | 0:e1265f6b3565 | 48 | // Reset Interrupt Settings |
sankichi | 0:e1265f6b3565 | 49 | _INTR_ST.fall(NULL); |
sankichi | 0:e1265f6b3565 | 50 | _INTR_ST.rise(NULL); |
sankichi | 0:e1265f6b3565 | 51 | _INTR_DSEL.fall(NULL); |
sankichi | 0:e1265f6b3565 | 52 | _INTR_DSEL.rise(NULL); |
sankichi | 0:e1265f6b3565 | 53 | _PhaseChangeTicker.detach(); |
sankichi | 0:e1265f6b3565 | 54 | _DigitalPadPhase0SetTicker.detach(); |
sankichi | 0:e1265f6b3565 | 55 | _ModeCheckTicker.detach(); |
sankichi | 0:e1265f6b3565 | 56 | |
sankichi | 0:e1265f6b3565 | 57 | // 入力デバイスにより場合わけ |
sankichi | 0:e1265f6b3565 | 58 | _OutputMode = _InputStatus->InputDeviceType; |
sankichi | 0:e1265f6b3565 | 59 | //printf("_OutputMode: %d(init)\r\n",_OutputMode); |
sankichi | 0:e1265f6b3565 | 60 | |
sankichi | 0:e1265f6b3565 | 61 | // ModeCheckTicker Setting |
sankichi | 0:e1265f6b3565 | 62 | _ModeCheckTicker.attach_us(this, &Out_PCE::ModeChecker, MODECHECKPERIOD__MICROSEC); |
sankichi | 0:e1265f6b3565 | 63 | |
sankichi | 0:e1265f6b3565 | 64 | switch(_OutputMode) |
sankichi | 0:e1265f6b3565 | 65 | { |
sankichi | 0:e1265f6b3565 | 66 | // |
sankichi | 0:e1265f6b3565 | 67 | // Input: CyberStick DIGITAL mode |
sankichi | 0:e1265f6b3565 | 68 | // Input: FightingPad 6B |
sankichi | 0:e1265f6b3565 | 69 | // |
sankichi | 0:e1265f6b3565 | 70 | case NiseKabuto::CONFIG_INMODE_CYBERSTICK_DIGITAL: |
sankichi | 0:e1265f6b3565 | 71 | case NiseKabuto::CONFIG_INMODE_MD6B: |
sankichi | 0:e1265f6b3565 | 72 | Cfunc_PCEDigital_Initialize( |
sankichi | 0:e1265f6b3565 | 73 | &_OUT_1Y, |
sankichi | 0:e1265f6b3565 | 74 | &_OUT_2Y, |
sankichi | 0:e1265f6b3565 | 75 | &_OUT_3Y, |
sankichi | 0:e1265f6b3565 | 76 | &_OUT_4Y, |
sankichi | 0:e1265f6b3565 | 77 | &_INTR_DSEL, |
sankichi | 0:e1265f6b3565 | 78 | &_INTR_ST, |
sankichi | 0:e1265f6b3565 | 79 | _PhaseData, |
sankichi | 0:e1265f6b3565 | 80 | &_RapidFireValue, |
sankichi | 0:e1265f6b3565 | 81 | &(_InputStatus->Temp[4]) |
sankichi | 0:e1265f6b3565 | 82 | ); |
sankichi | 0:e1265f6b3565 | 83 | |
sankichi | 0:e1265f6b3565 | 84 | |
sankichi | 0:e1265f6b3565 | 85 | // Ticker Setting |
sankichi | 0:e1265f6b3565 | 86 | _DigitalPadPhase0SetTicker.attach_us( |
sankichi | 0:e1265f6b3565 | 87 | this, |
sankichi | 0:e1265f6b3565 | 88 | &Out_PCE::Digital_TickerMethod, |
sankichi | 0:e1265f6b3565 | 89 | DIGITALPAD_STATERENEWINTERVAL__MICROSEC |
sankichi | 0:e1265f6b3565 | 90 | ); |
sankichi | 0:e1265f6b3565 | 91 | |
sankichi | 0:e1265f6b3565 | 92 | EnableInput(); |
sankichi | 0:e1265f6b3565 | 93 | |
sankichi | 0:e1265f6b3565 | 94 | SetOutputPinsValue(0x00); |
sankichi | 0:e1265f6b3565 | 95 | wait_us(5000); // PCエンジンに気づかせる |
sankichi | 0:e1265f6b3565 | 96 | break; |
sankichi | 0:e1265f6b3565 | 97 | |
sankichi | 0:e1265f6b3565 | 98 | // |
sankichi | 0:e1265f6b3565 | 99 | // Input: CyberStick ANALOG mode |
sankichi | 0:e1265f6b3565 | 100 | // |
sankichi | 0:e1265f6b3565 | 101 | default: |
sankichi | 0:e1265f6b3565 | 102 | case NiseKabuto::CONFIG_INMODE_CYBERSTICK_ANALOG: |
sankichi | 0:e1265f6b3565 | 103 | |
sankichi | 0:e1265f6b3565 | 104 | // Interrupt Setting |
sankichi | 0:e1265f6b3565 | 105 | _INTR_ST.fall(this, &Out_PCE::StrobeFallISR); |
sankichi | 0:e1265f6b3565 | 106 | |
sankichi | 0:e1265f6b3565 | 107 | // Initialize pin status |
sankichi | 0:e1265f6b3565 | 108 | //SetOutputPinsValue(0x0f); // AfterBurner Boot時にRUN押されちゃう |
sankichi | 0:e1265f6b3565 | 109 | SetOutputPinsValue(0x02); // |
sankichi | 0:e1265f6b3565 | 110 | break; |
sankichi | 0:e1265f6b3565 | 111 | |
sankichi | 0:e1265f6b3565 | 112 | } |
sankichi | 0:e1265f6b3565 | 113 | } |
sankichi | 0:e1265f6b3565 | 114 | |
sankichi | 0:e1265f6b3565 | 115 | |
sankichi | 0:e1265f6b3565 | 116 | // |
sankichi | 0:e1265f6b3565 | 117 | // Set Pins |
sankichi | 0:e1265f6b3565 | 118 | // |
sankichi | 0:e1265f6b3565 | 119 | void Out_PCE::SetOutputPinsValue(char dat) |
sankichi | 0:e1265f6b3565 | 120 | { |
sankichi | 0:e1265f6b3565 | 121 | _OUT_1Y = dat & 1; |
sankichi | 0:e1265f6b3565 | 122 | _OUT_2Y = (dat & 2) >> 1; |
sankichi | 0:e1265f6b3565 | 123 | _OUT_3Y = (dat & 4) >> 2; |
sankichi | 0:e1265f6b3565 | 124 | _OUT_4Y = (dat & 8) >> 3; |
sankichi | 0:e1265f6b3565 | 125 | } |
sankichi | 0:e1265f6b3565 | 126 | |
sankichi | 0:e1265f6b3565 | 127 | // |
sankichi | 0:e1265f6b3565 | 128 | // Set Pins2 |
sankichi | 0:e1265f6b3565 | 129 | // |
sankichi | 0:e1265f6b3565 | 130 | void Out_PCE::SetOutputPinsValue2(char dat) |
sankichi | 0:e1265f6b3565 | 131 | { |
sankichi | 0:e1265f6b3565 | 132 | // D0 |
sankichi | 0:e1265f6b3565 | 133 | _OUT_1Y = dat & 1; // D0 |
sankichi | 0:e1265f6b3565 | 134 | // D1 |
sankichi | 0:e1265f6b3565 | 135 | _OUT_2Y = (dat & 8) >> 3; // D3 |
sankichi | 0:e1265f6b3565 | 136 | // D2 |
sankichi | 0:e1265f6b3565 | 137 | _OUT_3Y = (dat & 2) >> 1; // D1 |
sankichi | 0:e1265f6b3565 | 138 | // D3 |
sankichi | 0:e1265f6b3565 | 139 | _OUT_4Y = (dat & 4) >> 2; // D2 |
sankichi | 0:e1265f6b3565 | 140 | } |
sankichi | 0:e1265f6b3565 | 141 | |
sankichi | 0:e1265f6b3565 | 142 | // |
sankichi | 0:e1265f6b3565 | 143 | // ISR for Strobe=L |
sankichi | 0:e1265f6b3565 | 144 | // |
sankichi | 0:e1265f6b3565 | 145 | void Out_PCE::StrobeFallISR(void) |
sankichi | 0:e1265f6b3565 | 146 | { |
sankichi | 0:e1265f6b3565 | 147 | //_PCEActiveCounter++; |
sankichi | 0:e1265f6b3565 | 148 | |
sankichi | 0:e1265f6b3565 | 149 | if( _NowWriting == 0) |
sankichi | 0:e1265f6b3565 | 150 | { |
sankichi | 0:e1265f6b3565 | 151 | _INTR_ST.fall(NULL); |
sankichi | 0:e1265f6b3565 | 152 | |
sankichi | 0:e1265f6b3565 | 153 | |
sankichi | 0:e1265f6b3565 | 154 | |
sankichi | 0:e1265f6b3565 | 155 | // Disableしないと、入力にまれにノイズがのる |
sankichi | 0:e1265f6b3565 | 156 | // Disable/Enable有る場合も無い場合も、しばらくすると入力が受け付けられなくなる |
sankichi | 0:e1265f6b3565 | 157 | // EnableInput()時にInitialize()を実行させるように修正 |
sankichi | 0:e1265f6b3565 | 158 | |
sankichi | 0:e1265f6b3565 | 159 | //wait_us(_TransferSpeed>>1); //AfterBurnerはこれで良かった.OutRun動かないかも? |
sankichi | 0:e1265f6b3565 | 160 | //wait_us(10); //Outrun対策 |
sankichi | 0:e1265f6b3565 | 161 | |
sankichi | 0:e1265f6b3565 | 162 | _NowWriting = 1; |
sankichi | 0:e1265f6b3565 | 163 | |
sankichi | 0:e1265f6b3565 | 164 | // データフェーズごとのデータ用意 |
sankichi | 0:e1265f6b3565 | 165 | int buttons = _InputStatus->Buttons; |
sankichi | 0:e1265f6b3565 | 166 | char ch0 = _InputStatus->Ch0; |
sankichi | 0:e1265f6b3565 | 167 | char ch1 = _InputStatus->Ch1; |
sankichi | 0:e1265f6b3565 | 168 | char ch2 = _InputStatus->Ch2; |
sankichi | 0:e1265f6b3565 | 169 | char ch3 = _InputStatus->Ch3; |
sankichi | 0:e1265f6b3565 | 170 | |
sankichi | 0:e1265f6b3565 | 171 | // DisableInput(); |
sankichi | 0:e1265f6b3565 | 172 | |
sankichi | 0:e1265f6b3565 | 173 | // |A|B|C|D |
sankichi | 0:e1265f6b3565 | 174 | _PhaseData[0] = |
sankichi | 0:e1265f6b3565 | 175 | ( |
sankichi | 0:e1265f6b3565 | 176 | (((buttons) & 0x0200)?1:0)<<3 | // A |
sankichi | 0:e1265f6b3565 | 177 | (((buttons) & 0x0100)?1:0)<<2 | // B |
sankichi | 0:e1265f6b3565 | 178 | (((buttons) & 0x0020)?1:0)<<1 | // C |
sankichi | 0:e1265f6b3565 | 179 | (((buttons) & 0x0010)?1:0) // D |
sankichi | 0:e1265f6b3565 | 180 | ); |
sankichi | 0:e1265f6b3565 | 181 | |
sankichi | 0:e1265f6b3565 | 182 | // |E1|E2|F|G |
sankichi | 0:e1265f6b3565 | 183 | _PhaseData[1] = |
sankichi | 0:e1265f6b3565 | 184 | ( |
sankichi | 0:e1265f6b3565 | 185 | (((buttons) & 0x0008)?1:0)<<3 | // E1 |
sankichi | 0:e1265f6b3565 | 186 | (((buttons) & 0x0004)?1:0)<<2 | // E2 |
sankichi | 0:e1265f6b3565 | 187 | (((buttons) & 0x0002)?1:0)<<1 | // F |
sankichi | 0:e1265f6b3565 | 188 | (((buttons) & 0x0001)?1:0) // G |
sankichi | 0:e1265f6b3565 | 189 | ); |
sankichi | 0:e1265f6b3565 | 190 | |
sankichi | 0:e1265f6b3565 | 191 | // 1H |
sankichi | 0:e1265f6b3565 | 192 | _PhaseData[2] = |
sankichi | 0:e1265f6b3565 | 193 | ( ((ch0)>>4) & 0x0f ); |
sankichi | 0:e1265f6b3565 | 194 | |
sankichi | 0:e1265f6b3565 | 195 | // 2H |
sankichi | 0:e1265f6b3565 | 196 | _PhaseData[3] = |
sankichi | 0:e1265f6b3565 | 197 | ( ((ch1)>>4) & 0x0f ); |
sankichi | 0:e1265f6b3565 | 198 | |
sankichi | 0:e1265f6b3565 | 199 | // 3H |
sankichi | 0:e1265f6b3565 | 200 | _PhaseData[4] = |
sankichi | 0:e1265f6b3565 | 201 | ( ((ch2)>>4) & 0x0f ); |
sankichi | 0:e1265f6b3565 | 202 | |
sankichi | 0:e1265f6b3565 | 203 | // 4H |
sankichi | 0:e1265f6b3565 | 204 | _PhaseData[5] = |
sankichi | 0:e1265f6b3565 | 205 | ( 0x010 ); |
sankichi | 0:e1265f6b3565 | 206 | |
sankichi | 0:e1265f6b3565 | 207 | // 1L |
sankichi | 0:e1265f6b3565 | 208 | _PhaseData[6] = |
sankichi | 0:e1265f6b3565 | 209 | ( ch0 ); |
sankichi | 0:e1265f6b3565 | 210 | |
sankichi | 0:e1265f6b3565 | 211 | // 2L |
sankichi | 0:e1265f6b3565 | 212 | _PhaseData[7] = |
sankichi | 0:e1265f6b3565 | 213 | ( ch1 ); |
sankichi | 0:e1265f6b3565 | 214 | |
sankichi | 0:e1265f6b3565 | 215 | // 3L |
sankichi | 0:e1265f6b3565 | 216 | _PhaseData[8] = |
sankichi | 0:e1265f6b3565 | 217 | ( ch2 ); |
sankichi | 0:e1265f6b3565 | 218 | |
sankichi | 0:e1265f6b3565 | 219 | // 4L |
sankichi | 0:e1265f6b3565 | 220 | _PhaseData[9] = |
sankichi | 0:e1265f6b3565 | 221 | ( 0 ); |
sankichi | 0:e1265f6b3565 | 222 | |
sankichi | 0:e1265f6b3565 | 223 | _PhaseData[10] = |
sankichi | 0:e1265f6b3565 | 224 | // |A|B|A'|B'| |
sankichi | 0:e1265f6b3565 | 225 | ( |
sankichi | 0:e1265f6b3565 | 226 | (((buttons) & 0x0200)?1:0)<<3 | // A |
sankichi | 0:e1265f6b3565 | 227 | (((buttons) & 0x0100)?1:0)<<2 | // B |
sankichi | 0:e1265f6b3565 | 228 | (((buttons) & 0x0080)?1:0)<<1 | // A' |
sankichi | 0:e1265f6b3565 | 229 | (((buttons) & 0x0040)?1:0) // B' |
sankichi | 0:e1265f6b3565 | 230 | ); |
sankichi | 0:e1265f6b3565 | 231 | |
sankichi | 0:e1265f6b3565 | 232 | _PhaseData[11] = (0x0f); |
sankichi | 0:e1265f6b3565 | 233 | |
sankichi | 0:e1265f6b3565 | 234 | // DisableInput(); |
sankichi | 0:e1265f6b3565 | 235 | _PhaseChangeTicker.attach_us(this, &Out_PCE::ChangePhase, _TransferSpeed>>1); |
sankichi | 0:e1265f6b3565 | 236 | } |
sankichi | 0:e1265f6b3565 | 237 | } |
sankichi | 0:e1265f6b3565 | 238 | |
sankichi | 0:e1265f6b3565 | 239 | |
sankichi | 0:e1265f6b3565 | 240 | // |
sankichi | 0:e1265f6b3565 | 241 | // Tickerにより呼ばれる処理 |
sankichi | 0:e1265f6b3565 | 242 | // PhaseCounterを変化 |
sankichi | 0:e1265f6b3565 | 243 | // |
sankichi | 0:e1265f6b3565 | 244 | void Out_PCE::ChangePhase(void) |
sankichi | 0:e1265f6b3565 | 245 | { |
sankichi | 0:e1265f6b3565 | 246 | int loopCounter=0; |
sankichi | 0:e1265f6b3565 | 247 | char state=1; |
sankichi | 0:e1265f6b3565 | 248 | |
sankichi | 0:e1265f6b3565 | 249 | // 一瞬だけ2Yを下げて |
sankichi | 0:e1265f6b3565 | 250 | SetOutputPinsValue( _PhaseCounter&1 ); |
sankichi | 0:e1265f6b3565 | 251 | wait_us(2); //PCEがアナログモードになるwait_us値:10, 5, 3, 2 |
sankichi | 0:e1265f6b3565 | 252 | |
sankichi | 0:e1265f6b3565 | 253 | // すぐデータ変更 |
sankichi | 0:e1265f6b3565 | 254 | SetOutputPinsValue2( _PhaseData[_PhaseCounter] ); |
sankichi | 0:e1265f6b3565 | 255 | |
sankichi | 0:e1265f6b3565 | 256 | // DSELがHになるまで待つ |
sankichi | 0:e1265f6b3565 | 257 | loopCounter=100; |
sankichi | 0:e1265f6b3565 | 258 | while(!(_INTR_DSEL)) |
sankichi | 0:e1265f6b3565 | 259 | { |
sankichi | 0:e1265f6b3565 | 260 | loopCounter--; |
sankichi | 0:e1265f6b3565 | 261 | if(loopCounter<0) |
sankichi | 0:e1265f6b3565 | 262 | { |
sankichi | 0:e1265f6b3565 | 263 | state=0; |
sankichi | 0:e1265f6b3565 | 264 | break; |
sankichi | 0:e1265f6b3565 | 265 | } |
sankichi | 0:e1265f6b3565 | 266 | } |
sankichi | 0:e1265f6b3565 | 267 | |
sankichi | 0:e1265f6b3565 | 268 | if(state) |
sankichi | 0:e1265f6b3565 | 269 | { |
sankichi | 0:e1265f6b3565 | 270 | // DSELがLになるまで待つ |
sankichi | 0:e1265f6b3565 | 271 | loopCounter=100; |
sankichi | 0:e1265f6b3565 | 272 | while(_INTR_DSEL) |
sankichi | 0:e1265f6b3565 | 273 | { |
sankichi | 0:e1265f6b3565 | 274 | loopCounter--; |
sankichi | 0:e1265f6b3565 | 275 | if(loopCounter<0) |
sankichi | 0:e1265f6b3565 | 276 | { |
sankichi | 0:e1265f6b3565 | 277 | state=0; |
sankichi | 0:e1265f6b3565 | 278 | break; |
sankichi | 0:e1265f6b3565 | 279 | } |
sankichi | 0:e1265f6b3565 | 280 | } |
sankichi | 0:e1265f6b3565 | 281 | } |
sankichi | 0:e1265f6b3565 | 282 | |
sankichi | 0:e1265f6b3565 | 283 | if(state) |
sankichi | 0:e1265f6b3565 | 284 | { |
sankichi | 0:e1265f6b3565 | 285 | |
sankichi | 0:e1265f6b3565 | 286 | // その後、Ack出力に戻す |
sankichi | 0:e1265f6b3565 | 287 | SetOutputPinsValue( _PhaseCounter&1 | 0x02); |
sankichi | 0:e1265f6b3565 | 288 | |
sankichi | 0:e1265f6b3565 | 289 | _PhaseCounter++; |
sankichi | 0:e1265f6b3565 | 290 | |
sankichi | 0:e1265f6b3565 | 291 | //if(_PhaseCounter==12) |
sankichi | 0:e1265f6b3565 | 292 | if(_PhaseCounter>=11) |
sankichi | 0:e1265f6b3565 | 293 | { |
sankichi | 0:e1265f6b3565 | 294 | _PhaseCounter = 0; |
sankichi | 0:e1265f6b3565 | 295 | _PhaseChangeTicker.detach(); |
sankichi | 0:e1265f6b3565 | 296 | SetOutputPinsValue(0x02); |
sankichi | 0:e1265f6b3565 | 297 | _NowWriting = 0; |
sankichi | 0:e1265f6b3565 | 298 | // EnableInput(); |
sankichi | 0:e1265f6b3565 | 299 | _INTR_ST.fall(this, &Out_PCE::StrobeFallISR); |
sankichi | 0:e1265f6b3565 | 300 | } |
sankichi | 0:e1265f6b3565 | 301 | } |
sankichi | 0:e1265f6b3565 | 302 | else |
sankichi | 0:e1265f6b3565 | 303 | { |
sankichi | 0:e1265f6b3565 | 304 | _PhaseCounter = 0; |
sankichi | 0:e1265f6b3565 | 305 | _PhaseChangeTicker.detach(); |
sankichi | 0:e1265f6b3565 | 306 | SetOutputPinsValue(0x02); |
sankichi | 0:e1265f6b3565 | 307 | _NowWriting = 0; |
sankichi | 0:e1265f6b3565 | 308 | // EnableInput(); |
sankichi | 0:e1265f6b3565 | 309 | _INTR_ST.fall(this, &Out_PCE::StrobeFallISR); |
sankichi | 0:e1265f6b3565 | 310 | } |
sankichi | 0:e1265f6b3565 | 311 | |
sankichi | 0:e1265f6b3565 | 312 | } |
sankichi | 0:e1265f6b3565 | 313 | |
sankichi | 0:e1265f6b3565 | 314 | |
sankichi | 0:e1265f6b3565 | 315 | |
sankichi | 0:e1265f6b3565 | 316 | // |
sankichi | 0:e1265f6b3565 | 317 | // Ticker method for digital pad output |
sankichi | 0:e1265f6b3565 | 318 | // |
sankichi | 0:e1265f6b3565 | 319 | // 1. 全phase用のデータを集め、クラス変数に保存 |
sankichi | 0:e1265f6b3565 | 320 | // 2. Phase0データを出力する |
sankichi | 0:e1265f6b3565 | 321 | void Out_PCE::Digital_TickerMethod(void) |
sankichi | 0:e1265f6b3565 | 322 | { |
sankichi | 0:e1265f6b3565 | 323 | // デバッグ用:この関数が呼ばれるたび+1される |
sankichi | 0:e1265f6b3565 | 324 | (_InputStatus->Temp[2])++; |
sankichi | 0:e1265f6b3565 | 325 | |
sankichi | 0:e1265f6b3565 | 326 | //printf("I\r\n"); // これがあるとhungup起きない?(1) |
sankichi | 0:e1265f6b3565 | 327 | // _InputStatus->Temp[0] = 1; |
sankichi | 0:e1265f6b3565 | 328 | // wait_us(14000); |
sankichi | 0:e1265f6b3565 | 329 | |
sankichi | 0:e1265f6b3565 | 330 | volatile int idx; |
sankichi | 0:e1265f6b3565 | 331 | |
sankichi | 0:e1265f6b3565 | 332 | // データフェーズごとのデータ用意 |
sankichi | 0:e1265f6b3565 | 333 | __disable_irq(); |
sankichi | 0:e1265f6b3565 | 334 | volatile int buttons = _InputStatus->Buttons; |
sankichi | 0:e1265f6b3565 | 335 | volatile char type = _InputStatus->InputDeviceType; |
sankichi | 0:e1265f6b3565 | 336 | __enable_irq(); |
sankichi | 0:e1265f6b3565 | 337 | |
sankichi | 0:e1265f6b3565 | 338 | volatile int val_1a=0x0f; |
sankichi | 0:e1265f6b3565 | 339 | volatile int val_1b=0x0f; |
sankichi | 0:e1265f6b3565 | 340 | volatile int trgState_I = 1; |
sankichi | 0:e1265f6b3565 | 341 | volatile int trgState_II = 1; |
sankichi | 0:e1265f6b3565 | 342 | |
sankichi | 0:e1265f6b3565 | 343 | if( type == NiseKabuto::CONFIG_INMODE_CYBERSTICK_DIGITAL) |
sankichi | 0:e1265f6b3565 | 344 | { |
sankichi | 0:e1265f6b3565 | 345 | // 入力デバイス=サイバースティック/カブトガニ デジタルモード |
sankichi | 0:e1265f6b3565 | 346 | |
sankichi | 0:e1265f6b3565 | 347 | // 4Y 3Y 2Y 1Y |
sankichi | 0:e1265f6b3565 | 348 | // L D R U |
sankichi | 0:e1265f6b3565 | 349 | val_1a = |
sankichi | 0:e1265f6b3565 | 350 | ( |
sankichi | 0:e1265f6b3565 | 351 | ((buttons & 0x0800) ? 0x08 : 0) | // L |
sankichi | 0:e1265f6b3565 | 352 | ((buttons & 0x1000) ? 0x04 : 0) | // D |
sankichi | 0:e1265f6b3565 | 353 | ((buttons & 0x0400) ? 0x02 : 0) | // R |
sankichi | 0:e1265f6b3565 | 354 | ((buttons & 0x2000) ? 0x01 : 0) // U |
sankichi | 0:e1265f6b3565 | 355 | ); |
sankichi | 0:e1265f6b3565 | 356 | |
sankichi | 0:e1265f6b3565 | 357 | // 4Y 3Y 2Y 1Y |
sankichi | 0:e1265f6b3565 | 358 | // |Run|Sel|II|I |
sankichi | 0:e1265f6b3565 | 359 | val_1b = |
sankichi | 0:e1265f6b3565 | 360 | ( |
sankichi | 0:e1265f6b3565 | 361 | ((buttons & 0x0002) ? 0x08 : 0)&((buttons & 0x0010) ? 0x08 : 0) | // F(Start) & D |
sankichi | 0:e1265f6b3565 | 362 | ((buttons & 0x0001) ? 0x04 : 0)&((buttons & 0x0020) ? 0x04 : 0) | // G(Sel,Mode) & C |
sankichi | 0:e1265f6b3565 | 363 | ((buttons & 0x0100) ? 0x02 : 0) | // B |
sankichi | 0:e1265f6b3565 | 364 | ((buttons & 0x0200) ? 0x01 : 0) // A |
sankichi | 0:e1265f6b3565 | 365 | ); |
sankichi | 0:e1265f6b3565 | 366 | |
sankichi | 0:e1265f6b3565 | 367 | } |
sankichi | 0:e1265f6b3565 | 368 | else if (type == NiseKabuto::CONFIG_INMODE_MD6B) |
sankichi | 0:e1265f6b3565 | 369 | { |
sankichi | 0:e1265f6b3565 | 370 | // 入力デバイス=6B |
sankichi | 0:e1265f6b3565 | 371 | |
sankichi | 0:e1265f6b3565 | 372 | if( !(buttons & 0x020000) ) //Y |
sankichi | 0:e1265f6b3565 | 373 | { |
sankichi | 0:e1265f6b3565 | 374 | trgState_II = ((_RapidFireValue) ? 0x02 : 0); |
sankichi | 0:e1265f6b3565 | 375 | } |
sankichi | 0:e1265f6b3565 | 376 | else |
sankichi | 0:e1265f6b3565 | 377 | { |
sankichi | 0:e1265f6b3565 | 378 | trgState_II = ((buttons & 0x0100) ? 0x02 : 0); // B |
sankichi | 0:e1265f6b3565 | 379 | } |
sankichi | 0:e1265f6b3565 | 380 | if( !(buttons & 0x010000) ) //Z |
sankichi | 0:e1265f6b3565 | 381 | { |
sankichi | 0:e1265f6b3565 | 382 | trgState_I = ((_RapidFireValue) ? 0x01 : 0); |
sankichi | 0:e1265f6b3565 | 383 | } |
sankichi | 0:e1265f6b3565 | 384 | else |
sankichi | 0:e1265f6b3565 | 385 | { |
sankichi | 0:e1265f6b3565 | 386 | trgState_I = ((buttons & 0x0020) ? 0x01 : 0); // C |
sankichi | 0:e1265f6b3565 | 387 | } |
sankichi | 0:e1265f6b3565 | 388 | |
sankichi | 0:e1265f6b3565 | 389 | // 4Y 3Y 2Y 1Y |
sankichi | 0:e1265f6b3565 | 390 | // L D R U |
sankichi | 0:e1265f6b3565 | 391 | val_1a = |
sankichi | 0:e1265f6b3565 | 392 | ( |
sankichi | 0:e1265f6b3565 | 393 | ((buttons & 0x0800) ? 0x08 : 0) | // L |
sankichi | 0:e1265f6b3565 | 394 | ((buttons & 0x1000) ? 0x04 : 0) | // D |
sankichi | 0:e1265f6b3565 | 395 | ((buttons & 0x0400) ? 0x02 : 0) | // R |
sankichi | 0:e1265f6b3565 | 396 | ((buttons & 0x2000) ? 0x01 : 0) // U |
sankichi | 0:e1265f6b3565 | 397 | ); |
sankichi | 0:e1265f6b3565 | 398 | |
sankichi | 0:e1265f6b3565 | 399 | // 4Y 3Y 2Y 1Y |
sankichi | 0:e1265f6b3565 | 400 | // |Run|Sel|II|I |
sankichi | 0:e1265f6b3565 | 401 | val_1b = |
sankichi | 0:e1265f6b3565 | 402 | ( |
sankichi | 0:e1265f6b3565 | 403 | ((buttons & 0x0002) ? 0x08 : 0) | // F(Start) |
sankichi | 0:e1265f6b3565 | 404 | ((buttons & 0x0001) ? 0x04 : 0) | // G(Sel,Mode) |
sankichi | 0:e1265f6b3565 | 405 | trgState_II | |
sankichi | 0:e1265f6b3565 | 406 | trgState_I |
sankichi | 0:e1265f6b3565 | 407 | ); |
sankichi | 0:e1265f6b3565 | 408 | |
sankichi | 0:e1265f6b3565 | 409 | |
sankichi | 0:e1265f6b3565 | 410 | } |
sankichi | 0:e1265f6b3565 | 411 | |
sankichi | 0:e1265f6b3565 | 412 | __disable_irq(); |
sankichi | 0:e1265f6b3565 | 413 | for(idx=0; idx<12; idx+=2) |
sankichi | 0:e1265f6b3565 | 414 | { |
sankichi | 0:e1265f6b3565 | 415 | //printf("idx:%d\r\n",idx); |
sankichi | 0:e1265f6b3565 | 416 | _PhaseData[idx ] = val_1a; |
sankichi | 0:e1265f6b3565 | 417 | _PhaseData[idx+1] = val_1b; |
sankichi | 0:e1265f6b3565 | 418 | } |
sankichi | 0:e1265f6b3565 | 419 | __enable_irq(); |
sankichi | 0:e1265f6b3565 | 420 | |
sankichi | 0:e1265f6b3565 | 421 | |
sankichi | 0:e1265f6b3565 | 422 | // //phase0データをset |
sankichi | 0:e1265f6b3565 | 423 | // Digital_SetDataOfPhase(0); |
sankichi | 0:e1265f6b3565 | 424 | |
sankichi | 0:e1265f6b3565 | 425 | |
sankichi | 0:e1265f6b3565 | 426 | //printf("O\r\n"); // これがあるとhungup起きない?(2) |
sankichi | 0:e1265f6b3565 | 427 | // _InputStatus->Temp[0] = 0; |
sankichi | 0:e1265f6b3565 | 428 | // wait_us(14000); |
sankichi | 0:e1265f6b3565 | 429 | |
sankichi | 0:e1265f6b3565 | 430 | } |
sankichi | 0:e1265f6b3565 | 431 | |
sankichi | 0:e1265f6b3565 | 432 | |
sankichi | 0:e1265f6b3565 | 433 | void Out_PCE::Digital_SetDataOfPhase(char phaseCounter) |
sankichi | 0:e1265f6b3565 | 434 | { |
sankichi | 0:e1265f6b3565 | 435 | if( phaseCounter < 10 ) |
sankichi | 0:e1265f6b3565 | 436 | { |
sankichi | 0:e1265f6b3565 | 437 | SetOutputPinsValue(_PhaseData[phaseCounter]); |
sankichi | 0:e1265f6b3565 | 438 | } |
sankichi | 0:e1265f6b3565 | 439 | else |
sankichi | 0:e1265f6b3565 | 440 | { |
sankichi | 0:e1265f6b3565 | 441 | SetOutputPinsValue(0x0f); |
sankichi | 0:e1265f6b3565 | 442 | } |
sankichi | 0:e1265f6b3565 | 443 | |
sankichi | 0:e1265f6b3565 | 444 | } |
sankichi | 0:e1265f6b3565 | 445 | |
sankichi | 0:e1265f6b3565 | 446 | void Out_PCE::ModeChecker(void) |
sankichi | 0:e1265f6b3565 | 447 | { |
sankichi | 0:e1265f6b3565 | 448 | // デバッグ用:この関数が呼ばれるたび+1される |
sankichi | 0:e1265f6b3565 | 449 | (_InputStatus->Temp[5])++; |
sankichi | 0:e1265f6b3565 | 450 | |
sankichi | 0:e1265f6b3565 | 451 | __disable_irq(); |
sankichi | 0:e1265f6b3565 | 452 | char curOutMode = _InputStatus->InputDeviceType; |
sankichi | 0:e1265f6b3565 | 453 | __enable_irq(); |
sankichi | 0:e1265f6b3565 | 454 | |
sankichi | 0:e1265f6b3565 | 455 | // Analog/Digital切り替え判定 |
sankichi | 0:e1265f6b3565 | 456 | if(_OutputMode != curOutMode) |
sankichi | 0:e1265f6b3565 | 457 | { |
sankichi | 0:e1265f6b3565 | 458 | _OutputMode = curOutMode; |
sankichi | 0:e1265f6b3565 | 459 | // printf("InputDeviceType changed. Calling Initialize().\r\n"); |
sankichi | 0:e1265f6b3565 | 460 | Initialize(); |
sankichi | 0:e1265f6b3565 | 461 | } |
sankichi | 0:e1265f6b3565 | 462 | } |
sankichi | 0:e1265f6b3565 | 463 | |
sankichi | 0:e1265f6b3565 | 464 | |
sankichi | 0:e1265f6b3565 | 465 | |
sankichi | 0:e1265f6b3565 | 466 | void Out_PCE::SetupInputControll(void (*startInputFunction)(void), void (*stopInputFunction)(void)) |
sankichi | 0:e1265f6b3565 | 467 | { |
sankichi | 0:e1265f6b3565 | 468 | StartInputFunction = startInputFunction; |
sankichi | 0:e1265f6b3565 | 469 | StopInputFunction = stopInputFunction; |
sankichi | 0:e1265f6b3565 | 470 | } |
sankichi | 0:e1265f6b3565 | 471 | |
sankichi | 0:e1265f6b3565 | 472 | void Out_PCE::EnableInput(void) |
sankichi | 0:e1265f6b3565 | 473 | { |
sankichi | 0:e1265f6b3565 | 474 | //printf("Out_PCE::EnableInput() called!!"); |
sankichi | 0:e1265f6b3565 | 475 | if(_InputInstance && StartInputMethod) |
sankichi | 0:e1265f6b3565 | 476 | { |
sankichi | 0:e1265f6b3565 | 477 | (_InputInstance->*StartInputMethod)(); |
sankichi | 0:e1265f6b3565 | 478 | } |
sankichi | 0:e1265f6b3565 | 479 | else if(StartInputFunction) |
sankichi | 0:e1265f6b3565 | 480 | { |
sankichi | 0:e1265f6b3565 | 481 | StartInputFunction(); |
sankichi | 0:e1265f6b3565 | 482 | } |
sankichi | 0:e1265f6b3565 | 483 | } |
sankichi | 0:e1265f6b3565 | 484 | |
sankichi | 0:e1265f6b3565 | 485 | void Out_PCE::DisableInput(void) |
sankichi | 0:e1265f6b3565 | 486 | { |
sankichi | 0:e1265f6b3565 | 487 | //printf("Out_PCE::DisableInput() called!!"); |
sankichi | 0:e1265f6b3565 | 488 | |
sankichi | 0:e1265f6b3565 | 489 | if(_InputInstance && StopInputMethod) |
sankichi | 0:e1265f6b3565 | 490 | { |
sankichi | 0:e1265f6b3565 | 491 | (_InputInstance->*StopInputMethod)(); |
sankichi | 0:e1265f6b3565 | 492 | } |
sankichi | 0:e1265f6b3565 | 493 | else if(StopInputFunction) |
sankichi | 0:e1265f6b3565 | 494 | { |
sankichi | 0:e1265f6b3565 | 495 | StopInputFunction(); |
sankichi | 0:e1265f6b3565 | 496 | } |
sankichi | 0:e1265f6b3565 | 497 | } |
sankichi | 0:e1265f6b3565 | 498 | |
sankichi | 0:e1265f6b3565 | 499 | |
sankichi | 0:e1265f6b3565 | 500 |