mirror of
https://github.com/MickGyver/DaemonBite-Retro-Controllers-USB
synced 2024-11-24 18:22:17 -05:00
Probably fixed the "going-to-sleep" bug for the SNES adapter
This commit is contained in:
parent
8afc5eb909
commit
3034c3bcf6
@ -30,7 +30,10 @@ const char *gp_serial = "NES/SNES to USB";
|
||||
#define GAMEPAD_COUNT 2 // NOTE: No more than TWO gamepads are possible at the moment due to a USB HID issue.
|
||||
#define GAMEPAD_COUNT_MAX 4 // NOTE: For some reason, can't have more than two gamepads without serial breaking. Can someone figure out why?
|
||||
// (It has something to do with how Arduino handles HID devices)
|
||||
#define BUTTON_READ_DELAY 300 // Button read delay in µs
|
||||
#define BUTTON_READ_DELAY 30 // Delay between button reads in µs
|
||||
#define MICROS_LATCH 12 // 12µs according to specs (8 seems to work fine)
|
||||
#define MICROS_CLOCK 6 // 6µs according to specs (4 seems to work fine)
|
||||
#define MICROS_PAUSE 6 // 6µs according to specs (4 seems to work fine)
|
||||
|
||||
#define UP 0x01
|
||||
#define DOWN 0x02
|
||||
@ -67,8 +70,7 @@ uint8_t gp = 0;
|
||||
uint8_t buttonCount = 32;
|
||||
|
||||
// Timing
|
||||
long microsNow = 0;
|
||||
long microsButtons = 0;
|
||||
uint32_t microsButtons = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -81,13 +83,10 @@ void setup()
|
||||
PORTF |= B11110000; // enable internal pull-ups
|
||||
}
|
||||
|
||||
void loop()
|
||||
void loop() { while(1)
|
||||
{
|
||||
// Get current time
|
||||
microsNow = micros();
|
||||
|
||||
// See if enough time has passed since last button read
|
||||
if(microsNow > microsButtons+BUTTON_READ_DELAY)
|
||||
if(micros() - microsButtons > BUTTON_READ_DELAY)
|
||||
{
|
||||
// Pulse latch
|
||||
sendLatch();
|
||||
@ -113,9 +112,6 @@ void loop()
|
||||
buttons[gp] &= 0xFFF;
|
||||
}
|
||||
|
||||
microsButtons = microsNow+100;
|
||||
}
|
||||
|
||||
for(gp=0; gp<GAMEPAD_COUNT; gp++)
|
||||
{
|
||||
// Has any buttons changed state?
|
||||
@ -128,22 +124,25 @@ void loop()
|
||||
Gamepad[gp].send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
microsButtons = micros();
|
||||
}
|
||||
}}
|
||||
|
||||
void sendLatch()
|
||||
{
|
||||
// Send a latch pulse to (S)NES controller(s)
|
||||
PORTD |= B00000010; // Set HIGH
|
||||
delayMicroseconds(12);
|
||||
delayMicroseconds(MICROS_LATCH);
|
||||
PORTD &= ~B00000010; // Set LOW
|
||||
delayMicroseconds(6);
|
||||
delayMicroseconds(MICROS_PAUSE);
|
||||
}
|
||||
|
||||
void sendClock()
|
||||
{
|
||||
// Send a clock pulse to (S)NES controller(s)
|
||||
PORTD |= B10000001; // Set HIGH
|
||||
delayMicroseconds(6);
|
||||
delayMicroseconds(MICROS_CLOCK);
|
||||
PORTD &= ~B10000001; // Set LOW
|
||||
delayMicroseconds(6);
|
||||
delayMicroseconds(MICROS_PAUSE);
|
||||
}
|
||||
|
@ -24,8 +24,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Gamepad.h"
|
||||
|
||||
static const uint8_t _hidReportDescriptor[] PROGMEM = {
|
||||
|
Loading…
Reference in New Issue
Block a user