/* gc_n64_usb : Gamecube or N64 controller to USB firmware Copyright (C) 2007-2015 Raphael Assenat This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include "gcn64_protocol.h" #include "gcn64txrx.h" #undef FORCE_KEYBOARD /******** IO port definitions and options **************/ #ifndef STK525 #define GCN64_DATA_PORT PORTD #define GCN64_DATA_DDR DDRD #define GCN64_DATA_PIN PIND #define GCN64_DATA_BIT (1<<0) #define GCN64_BIT_NUM_S "0" // for asm #else #define GCN64_DATA_PORT PORTA #define GCN64_DATA_DDR DDRA #define GCN64_DATA_PIN PINA #define GCN64_DATA_BIT (1<<0) #define GCN64_BIT_NUM_S "0" // for asm #endif #define DISABLE_INTS_DURING_COMM void gcn64protocol_hwinit(void) { // data as input GCN64_DATA_DDR &= ~(GCN64_DATA_BIT); // keep data low. By toggling the direction, we make the // pin act as an open-drain output. GCN64_DATA_PORT &= ~GCN64_DATA_BIT; /* debug bit PORTB4 (MISO) */ DDRB |= 0x10; PORTB &= ~0x10; } /** * \brief Send n data bytes + stop bit, wait for answer. * \return The number of bytes received, 0 on timeout/error. * * The result is in gcn64_workbuf. */ unsigned char gcn64_transaction(const unsigned char *tx, int tx_len, unsigned char *rx, unsigned char rx_max) { int count; unsigned char sreg = SREG; //int i; #ifdef DISABLE_INTS_DURING_COMM cli(); #endif gcn64_sendBytes(tx, tx_len); count = gcn64_receiveBytes(rx, rx_max); SREG = sreg; #if 0 printf("Count: %d { ", count); for (i=0; i> 8) & 0x0F) { case 0x05: return CONTROLLER_IS_N64; case 0x09: // normal controllers case 0x0b: // Never saw this one, but it is mentionned above. return CONTROLLER_IS_GC; case 0x08: if (id == 0x0820) { // Ascii keyboard return CONTROLLER_IS_GC_KEYBOARD; } // wavebird, controller off. return CONTROLLER_IS_GC; default: return CONTROLLER_IS_UNKNOWN; } return 0; }