mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-04-27 23:29:01 -07:00
Fix for 1.5.8
This commit is contained in:
parent
c9c6354e5e
commit
48053b678c
@ -5,7 +5,7 @@
|
|||||||
* Modified for Digispark by Digistump
|
* Modified for Digispark by Digistump
|
||||||
* And now modified by Sean Murphy (duckythescientist) from a keyboard device to a joystick device
|
* And now modified by Sean Murphy (duckythescientist) from a keyboard device to a joystick device
|
||||||
* And now modified by Bluebie to have better code style, not ruin system timers, and have delay() function
|
* And now modified by Bluebie to have better code style, not ruin system timers, and have delay() function
|
||||||
* Most of the credit for the joystick code should go to Raphaël Assénat
|
* Most of the credit for the joystick code should go to Raphaël Assénat
|
||||||
*/
|
*/
|
||||||
#ifndef __DigiJoystick_h__
|
#ifndef __DigiJoystick_h__
|
||||||
#define __DigiJoystick_h__
|
#define __DigiJoystick_h__
|
||||||
@ -26,12 +26,10 @@
|
|||||||
#include "oddebug.h"
|
#include "oddebug.h"
|
||||||
#include "usbconfig.h"
|
#include "usbconfig.h"
|
||||||
|
|
||||||
static uchar *rt_usbHidReportDescriptor=NULL;
|
const static uchar *rt_usbHidReportDescriptor=NULL;
|
||||||
static uchar rt_usbHidReportDescriptorSize=0;
|
static uchar rt_usbHidReportDescriptorSize=0;
|
||||||
static uchar *rt_usbDeviceDescriptor=NULL;
|
const static uchar *rt_usbDeviceDescriptor=NULL;
|
||||||
static uchar rt_usbDeviceDescriptorSize=0;
|
static uchar rt_usbDeviceDescriptorSize=0;
|
||||||
byte buttonLowByte = 0;
|
|
||||||
byte buttonHighByte = 0;
|
|
||||||
|
|
||||||
// TODO: Work around Arduino 12 issues better.
|
// TODO: Work around Arduino 12 issues better.
|
||||||
//#include <WConstants.h>
|
//#include <WConstants.h>
|
||||||
@ -53,9 +51,9 @@ static unsigned char must_report = 0;
|
|||||||
static unsigned char idle_rate = DIGIJOYSTICK_DEFAULT_REPORT_INTERVAL / 4; // in units of 4ms
|
static unsigned char idle_rate = DIGIJOYSTICK_DEFAULT_REPORT_INTERVAL / 4; // in units of 4ms
|
||||||
// new minimum report frequency system:
|
// new minimum report frequency system:
|
||||||
static unsigned long last_report_time = 0;
|
static unsigned long last_report_time = 0;
|
||||||
char usb_hasCommed = 0;
|
|
||||||
|
|
||||||
unsigned char gcn64_usbHidReportDescriptor[] PROGMEM = {
|
|
||||||
|
const unsigned char gcn64_usbHidReportDescriptor[] PROGMEM = {
|
||||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
0x09, 0x05, // USAGE (Gamepad)
|
0x09, 0x05, // USAGE (Gamepad)
|
||||||
0xa1, 0x01, // COLLECTION (Application)
|
0xa1, 0x01, // COLLECTION (Application)
|
||||||
@ -93,7 +91,7 @@ unsigned char gcn64_usbHidReportDescriptor[] PROGMEM = {
|
|||||||
|
|
||||||
#define USBDESCR_DEVICE 1
|
#define USBDESCR_DEVICE 1
|
||||||
|
|
||||||
unsigned char usbDescrDevice[] PROGMEM = { /* USB device descriptor */
|
const unsigned char usbDescrDevice[] PROGMEM = { /* USB device descriptor */
|
||||||
18, /* sizeof(usbDescrDevice): length of descriptor in bytes */
|
18, /* sizeof(usbDescrDevice): length of descriptor in bytes */
|
||||||
USBDESCR_DEVICE, /* descriptor type */
|
USBDESCR_DEVICE, /* descriptor type */
|
||||||
0x01, 0x01, /* USB version supported */
|
0x01, 0x01, /* USB version supported */
|
||||||
@ -137,18 +135,11 @@ int getGamepadReport(unsigned char *dstbuf) {
|
|||||||
return GCN64_REPORT_SIZE;
|
return GCN64_REPORT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DigiJoystickDevice {
|
class DigiJoystickDevice {
|
||||||
public:
|
public:
|
||||||
DigiJoystickDevice () {
|
DigiJoystickDevice () {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void begin(){
|
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
PORTB &= ~(_BV(USB_CFG_DMINUS_BIT) | _BV(USB_CFG_DPLUS_BIT));
|
|
||||||
usbDeviceDisconnect();
|
usbDeviceDisconnect();
|
||||||
_delay_ms(250);
|
_delay_ms(250);
|
||||||
usbDeviceConnect();
|
usbDeviceConnect();
|
||||||
@ -163,21 +154,6 @@ class DigiJoystickDevice {
|
|||||||
sei();
|
sei();
|
||||||
|
|
||||||
last_report_time = millis();
|
last_report_time = millis();
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
char isConnected()
|
|
||||||
{
|
|
||||||
return usb_hasCommed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void refresh() {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void poll() {
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
@ -263,18 +239,6 @@ class DigiJoystickDevice {
|
|||||||
void setSLIDER(char value) {
|
void setSLIDER(char value) {
|
||||||
setSLIDER(*(reinterpret_cast<byte *>(&value)));
|
setSLIDER(*(reinterpret_cast<byte *>(&value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setButton(unsigned char button, unsigned char state) {
|
|
||||||
if(button<8){
|
|
||||||
bitWrite(buttonLowByte, button, state);
|
|
||||||
setButtons(buttonByte, (byte) 0);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
button = button - 8;
|
|
||||||
bitWrite(buttonHighByte, button, state);
|
|
||||||
setButtons((byte) 0, buttonByte);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setButtons(unsigned char low, unsigned char high) {
|
void setButtons(unsigned char low, unsigned char high) {
|
||||||
last_built_report[6] = low;
|
last_built_report[6] = low;
|
||||||
@ -308,7 +272,6 @@ extern "C"{
|
|||||||
// USB_PUBLIC uchar usbFunctionSetup
|
// USB_PUBLIC uchar usbFunctionSetup
|
||||||
|
|
||||||
uchar usbFunctionSetup(uchar data[8]) {
|
uchar usbFunctionSetup(uchar data[8]) {
|
||||||
usb_hasCommed = 1;
|
|
||||||
usbRequest_t *rq = (usbRequest_t *)data;
|
usbRequest_t *rq = (usbRequest_t *)data;
|
||||||
|
|
||||||
usbMsgPtr = reportBuffer;
|
usbMsgPtr = reportBuffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user