Repository navigation
Expand file tree
/
Copy pathNINA-Arduino.ino
More file actions
95 lines (70 loc) · 1.92 KB
/
Copy pathNINA-Arduino.ino
File metadata and controls
95 lines (70 loc) · 1.92 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
#include <WiFi.h>
#include "SPIS.h"
#include "CommandHandler.h"
#define SPI_BUFFER_LEN SPI_MAX_DMA_LEN
uint8_t* commandBuffer;
uint8_t* responseBuffer;
void setupWiFi();
int debug = 0;
void setDebug(int d) {
debug = d;
if (debug) {
Serial.begin(115200);
Serial.println("Start");
} else {
Serial.end();
}
}
void setup() {
setDebug(debug);
setupWiFi();
}
// unsigned long getTime() {
// int ret = 0;
// do {
// ret = WiFi.getTime();
// } while (ret == 0);
// return ret;
// }
void setupWiFi() {
SPIS.begin();
// TODO: Not implemented. Used for OTA update, but I have disabled it as it caused compiler issues.
// esp_vfs_spiffs_conf_t conf = {
// .base_path = "/fs",
// .partition_label = "storage",
// .max_files = 20,
// .format_if_mount_failed = true
// };
// esp_err_t ret = esp_vfs_spiffs_register(&conf);
commandBuffer = (uint8_t*)heap_caps_malloc(SPI_BUFFER_LEN, MALLOC_CAP_DMA);
responseBuffer = (uint8_t*)heap_caps_malloc(SPI_BUFFER_LEN, MALLOC_CAP_DMA);
CommandHandler.begin();
}
void loop() {
// wait for a command
memset(commandBuffer, 0x00, SPI_BUFFER_LEN);
int commandLength = SPIS.transfer(NULL, commandBuffer, SPI_BUFFER_LEN);
if (debug)
Serial.println(commandLength);
if (commandLength == 0) {
return;
}
if (debug) {
Serial.println("COMMAND");
for (int i=0; i<commandLength; i++) {
Serial.printf("0x%x ", commandBuffer[i]);
}
Serial.println();
}
// process
memset(responseBuffer, 0x00, SPI_BUFFER_LEN);
int responseLength = CommandHandler.handle(commandBuffer, responseBuffer);
SPIS.transfer(responseBuffer, NULL, responseLength);
if (debug) {
Serial.println("RESPONSE");
for (int i=0; i<responseLength; i++) {
Serial.printf("0x%x ", responseBuffer[i]);
}
Serial.println();
}
}