@@ -8,7 +8,7 @@ static const uint32_t bitReceiveCycles = cyclesPerUS * 4;
88static const uint32_t halfBitReceiveCycles = cyclesPerUS * 2 ;
99
1010GameCubeController::GameCubeController (unsigned p) {
11- setPortData (&port, p );
11+ setPortData (&port, p);
1212}
1313
1414bool GameCubeController::begin () {
@@ -25,13 +25,13 @@ void GameCubeController::sendBits(uint32_t data, uint8_t bits) {
2525 DWT->CYCCNT = 0 ;
2626 uint32_t timerEnd = DWT->CYCCNT ;
2727 do {
28- * port.port &= ~ port.mask ;
28+ gpio_write_bit ( port.device , port.pinNumber , 0 ) ;
2929 if (0x80000000ul & data)
3030 timerEnd += quarterBitSendingCycles;
3131 else
3232 timerEnd += 3 * quarterBitSendingCycles;
3333 while (DWT->CYCCNT < timerEnd) ;
34- * port.port |= port.mask ;
34+ gpio_write_bit ( port.device , port.pinNumber , 1 ) ;
3535 if (0x80000000ul & data)
3636 timerEnd += 3 * quarterBitSendingCycles;
3737 else
@@ -52,10 +52,12 @@ bool GameCubeController::receiveBits(void* data0, uint32_t bits) {
5252
5353 *data = 0 ;
5454 do {
55- if (!(*port.port & port.mask )) {
55+ if (!gpio_read_bit (port.device , port.pinNumber )) {
56+
5657 DWT->CYCCNT = 0 ;
5758 while (DWT->CYCCNT < halfBitReceiveCycles - 2 ) ;
58- if (*port.port & port.mask ) {
59+ if (gpio_read_bit (port.device , port.pinNumber )) {
60+
5961 *data |= bitmap;
6062 }
6163 bitmap >>= 1 ;
@@ -66,7 +68,7 @@ bool GameCubeController::receiveBits(void* data0, uint32_t bits) {
6668 if (bits)
6769 *data = 0 ;
6870 }
69- while (0 == (* port.port & port.mask ) && --timeout) ;
71+ while (! gpio_read_bit ( port.device , port.pinNumber ) && --timeout) ;
7072 if (timeout == 0 ) {
7173 break ;
7274 }
@@ -83,12 +85,12 @@ bool GameCubeController::readWithRumble(GameControllerData_t* data, bool rumble)
8385 nvic_globalirq_enable ();
8486 delayMicroseconds (400 );
8587 fails = 0 ;
86- }
88+ }
8789 nvic_globalirq_disable ();
8890 sendBits (rumble ? 0b0100000000000011000000011l : 0b0100000000000011000000001l , 25 );
8991 bool success = receiveBits (&gcData, 64 );
9092 nvic_globalirq_enable ();
91- if (success && 0 == (data-> buttons & 0x80 ) && (data-> buttons & 0x8000 ) ) {
93+ if (success && 0 == (gcData. buttons & 0x80 ) && (gcData. buttons & 0x8000 ) ) {
9294 data->device = CONTROLLER_GAMECUBE;
9395 data->buttons = gcData.buttons ;
9496 data->joystickX = rescale (gcData.joystickX );
0 commit comments