-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduino_OS.ino
More file actions
234 lines (196 loc) · 4.72 KB
/
Arduino_OS.ino
File metadata and controls
234 lines (196 loc) · 4.72 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*imports*/
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <SoftwareSerial.h>
/*===== user defined stuf ======*/
#define GPU_ADRR 0x27 // the gpu/lcd communication addr
#define RX 2 // COM port for ESP-01
#define TX 3 // ...
/*===== display Resolution =====*/
#define LCD // LCD | OLED
#ifdef LCD
#define MAX_X 16 // LCD resolution
#define MAX_Y 2
#endif
#ifdef OLED
#define MAX_X 128 // OLED resolution
#define MAX_Y 64
#endif
/*====== system defined stuf ======*/
// Rotatory encoder input config
#define CLK 8
#define DT 9
#define select 10
// Disk config
#define lbaMAX 2047 // max stable address for the disk
// other things
#define endBit 254
#define devPIN 7
// global objs / variables
LiquidCrystal_I2C lcd(GPU_ADRR, 16, 2);
SoftwareSerial esp(RX, TX);
unsigned int opt = 1;
byte lastStateCLK, currentStateCLK;
bool devmode = false;
const char* const commands_inter[] = {"mova", "movb", "movc", "movd", "jmp", "je", "jne", "add", "sub", "stc", "clc", "jc", "jnc", "int", "hlt", "exit"};
const char* const page[] = {NULL,
"LED on", "LED off",
"Program disk", "Read disk",
"Shutdown", "Run disk",
"Get temps[NET]", "Write RAW",
"sus"
}; // 15 chars MAX | add label for your application
// byte disk_buffer[512];
const byte backslash[] = {
B00000,
B10000,
B01000,
B00100,
B00010,
B00001,
B00000,
B00000
};
/*mova = 1
movb = 2
movc = 3
movd = 4
int = 5
jmp = 6
je = 7
jne = 8
add = 9
sub = 10
stc = 11
clc = 12
jc = 13
jnc = 14
fend = 254
hlt = 255*/
#define commandMAX ((sizeof(commands_inter)/sizeof(char*)) - 1)
#define optMAX ((sizeof(page)/sizeof(char*)) - 1)
/* ==================== FUNCTION WRAPPER ==================== */
#define commands_MAX sizeof(commands) / sizeof(commands[0])
typedef void (*function_pointer)();
typedef struct {
function_pointer run;
char* name;
} function_container;
void cmd_LED_ON(){
digitalWrite(LED_BUILTIN, HIGH);
}
void cmd_LED_OFF(){
digitalWrite(LED_BUILTIN, LOW);
}
void cmd_program_disk(){
programEEPROM();
}
void cmd_read_disk(){
readEEPROM();
}
void cmd_shutdown(){
lcd.clear();
lcd.home();
lcd.print(F("Shutting"));
lcd.setCursor(0, 1);
lcd.print(F("down..."));
lcd.noBacklight();
lcd.noDisplay();
Serial.end();
esp.end();
cli(); // clear interupts
while (true); // halt; loop forever...
}
void cmd_run_disk(){
inter();
}
void cmd_get_temps(){
lcd.clear();
lcd.home();
lcd.print(getNet(F("PING")));
delay(3500);
updatePAGE();
}
void cmd_write_raw(){
writeRAW_EEPROM();
}
// This need not be in order
const function_container commands[] = {
{cmd_LED_ON, "LED on"},
{cmd_LED_OFF, "LED off"},
{cmd_program_disk, "Program disk"},
{cmd_read_disk, "Read disk"},
{cmd_shutdown, "Shutdown"},
{cmd_run_disk, "Run disk"},
{cmd_get_temps, "Get temps[NET]"},
{cmd_write_raw, "Write RAW"}
};
/* ==================== MAIN ==================== */
void setup() {
pinMode(devPIN, INPUT_PULLUP);
Wire.begin();
lcd.init();
lcd.createChar(byte(0), backslash);
lcd.backlight();
if(!digitalRead(devPIN)){
Serial.begin(9600);
lcd.home();
lcd.print(F("Enable DEV mode?"));
lcd.setCursor(0, 1);
lcd.print(F("YES/NO (Serial)"));
while(true){
if(Serial.available()){
String input = Serial.readStringUntil('\n');
if(input == "YES"){
devmode = true;
} else{
Serial.end();
}
break;
}
}
}
lcd.clear();
lcd.home();
lcd.print(F("Booting..."));
esp.begin(115200);
pinMode(CLK, INPUT);
pinMode(DT, INPUT);
pinMode(select, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
lcd.clear();
updatePAGE();
lastStateCLK = digitalRead(CLK);
}
// main loop for the kernel
void loop(){
currentStateCLK = digitalRead(CLK);
if(lastStateCLK != currentStateCLK){
if(digitalRead(DT) != currentStateCLK && opt < optMAX){
opt++;
updatePAGE();
} else if(digitalRead(DT) == currentStateCLK && opt > 1){
opt--;
updatePAGE();
}
lastStateCLK = digitalRead(CLK);
}
// cmd executer
if(!digitalRead(select)){
bool found = false;
for(unsigned int i = 0; i < commands_MAX; i++){
if(!strcmp(commands[i].name, page[opt])){
commands[i].run();
found = true;
break;
}
}
if(!found){
lcd.clear();
lcd.home();
lcd.print(F("CMD not assigned"));
delay(1500);
updatePAGE();
}
}
}