Implement get_controller_type

This commit is contained in:
Raphael Assenat 2015-10-31 01:39:24 -04:00
parent 92aa261e4e
commit 5ff36596bb
4 changed files with 20 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#include "bootloader.h" #include "bootloader.h"
#include "gcn64_protocol.h" #include "gcn64_protocol.h"
#include "version.h" #include "version.h"
#include "main.h"
// dataHidReport is 40 bytes. // dataHidReport is 40 bytes.
#define CMDBUF_SIZE 41 #define CMDBUF_SIZE 41
@ -106,7 +107,13 @@ static void hiddata_processCommandBuffer(void)
break; break;
case RQ_GCN64_GET_SIGNATURE: case RQ_GCN64_GET_SIGNATURE:
strcpy_P((char*)(cmdbuf + 1), g_signature); strcpy_P((char*)(cmdbuf + 1), g_signature);
cmdbuf_len = 1 + strlen_P(g_version) + 1; cmdbuf_len = 1 + strlen_P(g_signature) + 1;
break;
case RQ_GCN64_GET_CONTROLLER_TYPE:
// CMD : RQ, CHN
// Answer: RQ, CHN, TYPE
cmdbuf[2] = current_pad_type;
cmdbuf_len = 3;
break; break;
} }

9
main.c
View File

@ -5,6 +5,7 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <util/delay.h> #include <util/delay.h>
#include "main.h"
#include "util.h" #include "util.h"
#include "usart1.h" #include "usart1.h"
#include "usb.h" #include "usb.h"
@ -209,13 +210,13 @@ void hwinit(void)
#define NUM_PAD_TYPES 2 #define NUM_PAD_TYPES 2
unsigned char current_pad_type = CONTROLLER_IS_ABSENT;
Gamepad *detectPad(void) Gamepad *detectPad(void)
{ {
char type; current_pad_type = gcn64_detectController();
type = gcn64_detectController(); switch (current_pad_type)
switch (type)
{ {
case CONTROLLER_IS_ABSENT: case CONTROLLER_IS_ABSENT:
case CONTROLLER_IS_UNKNOWN: case CONTROLLER_IS_UNKNOWN:

6
main.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef _main_h__
#define _main_h__
extern unsigned char current_pad_type;
#endif // _main_h__

View File

@ -7,6 +7,7 @@
#define RQ_GCN64_SUSPEND_POLLING 0x03 #define RQ_GCN64_SUSPEND_POLLING 0x03
#define RQ_GCN64_GET_VERSION 0x04 #define RQ_GCN64_GET_VERSION 0x04
#define RQ_GCN64_GET_SIGNATURE 0x05 #define RQ_GCN64_GET_SIGNATURE 0x05
#define RQ_GCN64_GET_CONTROLLER_TYPE 0x06
#define RQ_GCN64_RAW_SI_COMMAND 0x80 #define RQ_GCN64_RAW_SI_COMMAND 0x80
#define RQ_GCN64_JUMP_TO_BOOTLOADER 0xFF #define RQ_GCN64_JUMP_TO_BOOTLOADER 0xFF