-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAqUartProtocol.h
152 lines (132 loc) · 4.17 KB
/
AqUartProtocol.h
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
150
151
152
#pragma once
#include "Common.h"
#include "VFS.h"
#define MAX_FDS (10)
#define MAX_DDS (10)
enum GameCtrlBtnIdx {
GCB_A_IDX = 0,
GCB_B_IDX = 1,
GCB_X_IDX = 2,
GCB_Y_IDX = 3,
GCB_VIEW_IDX = 4,
GCB_GUIDE_IDX = 5,
GCB_MENU_IDX = 6,
GCB_LS_IDX = 7,
GCB_RS_IDX = 8,
GCB_LB_IDX = 9,
GCB_RB_IDX = 10,
GCB_DPAD_UP_IDX = 11,
GCB_DPAD_DOWN_IDX = 12,
GCB_DPAD_LEFT_IDX = 13,
GCB_DPAD_RIGHT_IDX = 14,
GCB_SHARE_IDX = 15,
GCB_A = (1 << GCB_A_IDX),
GCB_B = (1 << GCB_B_IDX),
GCB_X = (1 << GCB_X_IDX),
GCB_Y = (1 << GCB_Y_IDX),
GCB_VIEW = (1 << GCB_VIEW_IDX),
GCB_GUIDE = (1 << GCB_GUIDE_IDX),
GCB_MENU = (1 << GCB_MENU_IDX),
GCB_LS = (1 << GCB_LS_IDX),
GCB_RS = (1 << GCB_RS_IDX),
GCB_LB = (1 << GCB_LB_IDX),
GCB_RB = (1 << GCB_RB_IDX),
GCB_DPAD_UP = (1 << GCB_DPAD_UP_IDX),
GCB_DPAD_DOWN = (1 << GCB_DPAD_DOWN_IDX),
GCB_DPAD_LEFT = (1 << GCB_DPAD_LEFT_IDX),
GCB_DPAD_RIGHT = (1 << GCB_DPAD_RIGHT_IDX),
GCB_SHARE = (1 << GCB_SHARE_IDX),
};
class AqUartProtocol {
AqUartProtocol();
public:
static AqUartProtocol &instance();
void init();
void writeCtrl(uint8_t data);
void writeData(uint8_t data);
uint8_t readCtrl();
uint8_t readData();
struct FileInfo {
uint8_t flags;
std::string name;
unsigned offset;
};
std::map<uint8_t, FileInfo> fi;
struct DirInfo {
std::string name;
unsigned offset;
};
std::map<uint8_t, DirInfo> di;
private:
int txFifoRead();
void txFifoWrite(uint8_t data);
void txFifoWrite(const void *buf, size_t length);
void splitPath(const std::string &path, std::vector<std::string> &result);
std::string resolvePath(std::string path, VFS **vfs, std::string *wildCard = nullptr);
void closeAllDescriptors();
void receivedByte(uint8_t data);
void cmdReset();
void cmdVersion();
void cmdGetDateTime(uint8_t type);
void cmdKeyMode(uint8_t mode);
void cmdGetMouse();
void cmdGetGameCtrl(uint8_t idx);
void cmdOpen(uint8_t flags, const char *pathArg);
void cmdClose(uint8_t fd);
void cmdRead(uint8_t fd, uint16_t size);
void cmdReadLine(uint8_t fd, uint16_t size);
void cmdWrite(uint8_t fd, uint16_t size, const void *data);
void cmdSeek(uint8_t fd, uint32_t offset);
void cmdTell(uint8_t fd);
void cmdOpenDirExt(const char *pathArg, uint8_t flags, uint16_t skip_count);
void cmdCloseDir(uint8_t dd);
void cmdReadDir(uint8_t dd);
void cmdDelete(const char *pathArg);
void cmdRename(const char *oldArg, const char *newArg);
void cmdMkDir(const char *pathArg);
void cmdChDir(const char *pathArg);
void cmdStat(const char *pathArg);
void cmdGetCwd();
void cmdCloseAll();
void cmdLoadFpga(const char *pathArg);
std::string currentPath;
uint8_t rxBuf[16 + 0x10000];
unsigned rxBufIdx;
VFS *fdVfs[MAX_FDS];
uint8_t fds[MAX_FDS];
DirEnumCtx deCtxs[MAX_DDS];
int deIdx[MAX_DDS];
const char *newPath;
uint8_t txBuf[0x10000 + 16];
unsigned txBufWrIdx;
unsigned txBufRdIdx;
unsigned txBufCnt;
bool mousePresent = false;
float mouseX = 0;
float mouseY = 0;
uint8_t mouseButtons = 0;
int mouseWheel = 0;
public:
bool gameCtrlPresent = false;
int8_t gameCtrlLX = 0;
int8_t gameCtrlLY = 0;
int8_t gameCtrlRX = 0;
int8_t gameCtrlRY = 0;
uint8_t gameCtrlLT = 0;
uint8_t gameCtrlRT = 0;
uint16_t gameCtrlButtons = 0;
void gameCtrlReset(bool present) {
gameCtrlPresent = present;
gameCtrlLX = 0;
gameCtrlLY = 0;
gameCtrlRX = 0;
gameCtrlRY = 0;
gameCtrlLT = 0;
gameCtrlRT = 0;
gameCtrlButtons = 0;
gameCtrlUpdated();
}
void gameCtrlUpdated();
private:
friend class UI;
};