Initial commit, proof-of-concept on Amiga
This commit is contained in:
commit
9392e95b0b
175
YAOCMouse.ino
Normal file
175
YAOCMouse.ino
Normal file
@ -0,0 +1,175 @@
|
||||
// Drivers
|
||||
#include <SPI.h>
|
||||
|
||||
// SPI USB
|
||||
#include <hidboot.h>
|
||||
|
||||
|
||||
class MouseRptParser : public MouseReportParser
|
||||
{
|
||||
protected:
|
||||
void OnMouseMove (MOUSEINFO *mi);
|
||||
void OnRightButtonUp (MOUSEINFO *mi);
|
||||
void OnRightButtonDown (MOUSEINFO *mi);
|
||||
void OnLeftButtonDown (MOUSEINFO *mi);
|
||||
void OnLeftButtonUp (MOUSEINFO *mi);
|
||||
void OnMiddleButtonDown (MOUSEINFO *mi);
|
||||
};
|
||||
|
||||
|
||||
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
digitalWrite(16, LOW);
|
||||
};
|
||||
|
||||
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
|
||||
{
|
||||
digitalWrite(16, HIGH);
|
||||
};
|
||||
|
||||
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
byte mouseStates[4][2] = {
|
||||
{0, 0},
|
||||
{0, 1},
|
||||
{1, 1},
|
||||
{1, 0}
|
||||
};
|
||||
|
||||
bool mouseYworking = false;
|
||||
int mouseYTableIndex = 0;
|
||||
void amigaYpulse(int8_t count) {
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
if (mouseYworking)
|
||||
return;
|
||||
|
||||
mouseYworking = true;
|
||||
byte mapped = map(abs(count), 0, 127, 1, 63);
|
||||
for (byte i = 0; i < mapped; i++)
|
||||
{
|
||||
if (count < 0) {
|
||||
mouseYTableIndex++;
|
||||
|
||||
if (mouseYTableIndex > 3) {
|
||||
mouseYTableIndex = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
mouseYTableIndex--;
|
||||
|
||||
if (mouseYTableIndex == -1) {
|
||||
mouseYTableIndex = 3;
|
||||
}
|
||||
}
|
||||
|
||||
digitalWrite(13, mouseStates[mouseYTableIndex][0]);
|
||||
digitalWrite(14, mouseStates[mouseYTableIndex][1]);
|
||||
delayMicroseconds(70);
|
||||
}
|
||||
|
||||
mouseYworking = false;
|
||||
}
|
||||
|
||||
int mouseXTableIndex = 0;
|
||||
void amigaXpulse(int8_t count) {
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
for (byte i = 0; i < map(abs(count), 0, 127, 1, 63); i++)
|
||||
{
|
||||
if (count < 0) {
|
||||
mouseXTableIndex++;
|
||||
|
||||
if (mouseXTableIndex > 3) {
|
||||
mouseXTableIndex = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
mouseXTableIndex--;
|
||||
|
||||
if (mouseXTableIndex == -1) {
|
||||
mouseXTableIndex = 3;
|
||||
}
|
||||
}
|
||||
|
||||
digitalWrite(15, mouseStates[mouseXTableIndex][0]);
|
||||
digitalWrite(12, mouseStates[mouseXTableIndex][1]);
|
||||
delayMicroseconds(70);
|
||||
}
|
||||
}
|
||||
|
||||
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
|
||||
{
|
||||
amigaYpulse(mi->dY);
|
||||
amigaXpulse(mi->dX);
|
||||
};
|
||||
|
||||
|
||||
// This is only for single USB device (without HUB)
|
||||
// In this example we support keyboard or mouse
|
||||
USB Usb;
|
||||
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);
|
||||
|
||||
MouseRptParser PrsMouse;
|
||||
|
||||
void setupAmigaMouse() {
|
||||
pinMode(14, OUTPUT); //Y
|
||||
pinMode(13, OUTPUT); //QY
|
||||
|
||||
pinMode(15, OUTPUT); //X
|
||||
pinMode(12, OUTPUT); //QX
|
||||
|
||||
pinMode(16, OUTPUT); //Button L
|
||||
|
||||
digitalWrite(14, LOW);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
digitalWrite(15, LOW);
|
||||
digitalWrite(12, LOW);
|
||||
|
||||
digitalWrite(16, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.println("INIT");
|
||||
|
||||
Serial.print("USB init...");
|
||||
SPI.begin(32, 35, 33, 5);
|
||||
|
||||
if (Usb.Init() == -1) {
|
||||
Serial.println("WARN: Usb init failed.");
|
||||
}
|
||||
else {
|
||||
Serial.println(" DONE");
|
||||
}
|
||||
|
||||
setupAmigaMouse();
|
||||
|
||||
HidMouse.SetReportParser(0, &PrsMouse);
|
||||
|
||||
Serial.print("Interupts init...");
|
||||
|
||||
Serial.println("Ready to rock and roll...");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Usb.Task();
|
||||
}
|
Loading…
Reference in New Issue
Block a user