-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathmain.cpp
executable file
·149 lines (126 loc) · 3.08 KB
/
main.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <library.h>
#include <stm32f10x.h>
// based on https://github.com/pellepl/arcadehid.git
// todo: cleanup code
typedef void (*THandler)(void);
extern "C"
{
void _Initialize(void* pDeviceInfo, void* pDevice, void* pDeviceProperty, void* pUserStandardRequests,
THandler arrHandlerIn[], THandler arrHandlerOut[], THandler callbacks[], THandler pLeaveLowPowerMode)
{
BIOS::USB::Initialize(pDeviceInfo, pDevice, pDeviceProperty, pUserStandardRequests, arrHandlerIn, arrHandlerOut, callbacks, pLeaveLowPowerMode);
}
void InitializeFinish(int imr_msk)
{
BIOS::USB::InitializeFinish(imr_msk);
}
}
extern "C" {
#include "usb/common.h"
char dbgPushBuf[256];
void dbgPrint(const char* msg)
{
strcat(dbgPushBuf, msg);
}
}
bool demo = false;
extern "C" void InitUsb();
using namespace BIOS;
#ifdef _ARM
__attribute__((__section__(".entry")))
#endif
int _main(void)
{
static usb_kb_report kb_report{0};
static usb_mouse_report mouse_report{0};
USB_ARC_set_kb_callback([](){});
USB_ARC_set_mouse_callback([](){});
USB_ARC_set_joystick_callback([](usb_joystick joy){});
USB::Enable();
InitUsb();
BIOS::DBG::Print("USB HID ready,\nuse encoders to control cursor.\n");
KEY::EKey key;
while ((key = KEY::GetKey()) != KEY::Escape)
{
if (strlen(dbgPushBuf) > 0)
{
BIOS::DBG::Print(dbgPushBuf);
strcpy(dbgPushBuf, "");
}
if (key == KEY::Left)
{
mouse_report.dx = -10;
USB_ARC_MOUSE_tx(&mouse_report);
}
else if (key == KEY::Right)
{
mouse_report.dx = +10;
USB_ARC_MOUSE_tx(&mouse_report);
}
else if (key == KEY::Up)
{
mouse_report.dy = -10;
USB_ARC_MOUSE_tx(&mouse_report);
}
else if (key == KEY::Down)
{
mouse_report.dy = +10;
USB_ARC_MOUSE_tx(&mouse_report);
}
else if (key == KEY::F1)
{
mouse_report.modifiers = 1<<0;
USB_ARC_MOUSE_tx(&mouse_report);
}
else
{
mouse_report.modifiers = 0;
mouse_report.dx = 0;
mouse_report.dy = 0;
}
if (key == KEY::F3)
{
kb_report.modifiers = KB_MOD_NONE;
kb_report.keymap[0] = KC_G;
USB_ARC_KB_tx(&kb_report);
kb_report.keymap[0] = KC_A;
USB_ARC_KB_tx(&kb_report);
kb_report.keymap[0] = KC_B;
USB_ARC_KB_tx(&kb_report);
kb_report.keymap[0] = KC_O;
USB_ARC_KB_tx(&kb_report);
kb_report.keymap[0] = 0;
USB_ARC_KB_tx(&kb_report);
} else
{
kb_report.modifiers = KB_MOD_NONE;
kb_report.keymap[0] = 0;
}
if (key == KEY::F4)
{
demo = !demo;
}
if (demo)
{
EVERY(200)
{
static int phase = 0;
mouse_report.dx = 0;
mouse_report.dy = 0;
if (phase < 10)
mouse_report.dx = 10;
else if (phase < 20)
mouse_report.dy = 10;
else if (phase < 30)
mouse_report.dx = -10;
else if (phase < 40)
mouse_report.dy = -10;
USB_ARC_MOUSE_tx(&mouse_report);
if (++phase >= 40)
phase = 0;
}
}
}
BIOS::USB::InitializeMass();
return 0;
}