-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUSB.cpp
More file actions
57 lines (48 loc) · 2.21 KB
/
Copy pathUSB.cpp
File metadata and controls
57 lines (48 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "USB.h"
using LogUsb = Tiny::TILogTarget<TinyCon::UsbLogLevel>;
#if !NO_USB
void TinyCon::USBController::UsbHidReportReceived(uint8_t reportId, hid_report_type_t report, const uint8_t* data, uint16_t length)
{ ReportReceived(reportId, report, data, length); }
uint16_t TinyCon::USBController::UsbHidReportRequested(uint8_t reportId, hid_report_type_t report, uint8_t* data, uint16_t length)
{ return ReportRequested(reportId, report, data, length); }
std::function<void(uint8_t, hid_report_type_t, const uint8_t*, uint16_t)> TinyCon::USBController::ReportReceived =
[](uint8_t reportId, hid_report_type_t report, const uint8_t* data, uint16_t length) {};
std::function<uint16_t(uint8_t, hid_report_type_t, uint8_t*, uint16_t)> TinyCon::USBController::ReportRequested =
[](uint8_t reportId, hid_report_type_t report, uint8_t* data, uint16_t length) { return 0; };
void TinyCon::USBController::Init()
{
LogUsb::Info("USB Init", Tiny::TIEndl);
Gamepad.setPollInterval(10);
Gamepad.setStringDescriptor("Game Controller");
Gamepad.setReportDescriptor(HidDescriptor, sizeof(HidDescriptor));
ReportReceived = [this](uint8_t reportId, hid_report_type_t report, const uint8_t* data, uint16_t length)
{
if (Processor.GetUSBEnabled() && reportId == USBController::ReportCommand && length >= 1)
Processor.ProcessCommand({data, length});
};
Gamepad.setReportCallback(UsbHidReportRequested, UsbHidReportReceived);
Gamepad.begin();
}
void TinyCon::USBController::Update()
{
LogUsb::Debug("USB: ");
if (!Processor.GetUSBEnabled() || !Active)
{
if (!Processor.GetUSBEnabled()) LogUsb::Debug("Disabled");
else LogUsb::Debug("Inactive");
Active = false;
Connected = false;
}
else if ((Connected = TinyUSBDevice.mounted() && Gamepad.ready()))
{
LogUsb::Debug("Controller");
auto report = Controller.MakeHidReport();
Gamepad.sendReport(ReportGamepad, &report, sizeof(report));
LogUsb::Debug(", MPU");
uint8_t data[MpuReportSize];
auto size = Controller.MakeMpuBuffer({data, 42});
Gamepad.sendReport(ReportMpu, data, size);
}
LogUsb::Info(Tiny::TIEndl);
}
#endif