-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnanoprom.cpp
97 lines (72 loc) · 1.69 KB
/
nanoprom.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
#include <Arduino.h>
#include <stdio.h>
#include "configs.h"
#include "xmodem.h"
#include "eeprom.h"
#include "serprintf.h"
void setup()
{
/* Initialize the eeprom module first, so we don't accidentally write garbage to it */
eeprom_init();
Serial.begin(115200);
while (!Serial.available()) {
printf(F("Press a key to begin\n"));
delay(1000);
}
while (Serial.available()) Serial.read();
init_settings();
}
static void banner()
{
printf(F("\n\n"));
printf(F("\n\n"));
printf(F("\n\n"));
printf(F("NanoPROM v0.1 Arduino Nano DIP-EEPROM programmer\n"));
printf(F(" by George Foot, March 2021\n"));
printf(F(" https://github.com/gfoot/nanoprom\n"));
}
static bool input_handler(int c)
{
if (c == 13)
{
change_settings();
return true;
}
return false;
}
static bool gWriteStarted = false;
static bool data_handler(const uint8_t* buffer, size_t size)
{
if (!gWriteStarted)
{
gWriteStarted = true;
eeprom_writeImageBegin();
}
return eeprom_writeImageBlock(buffer, size);
}
void loop()
{
serprintf(F("\n\n"));
serprintf(F("\n\n"));
serprintf(F("\n\n"));
banner();
serprintf(F("\n\n"));
show_settings();
serprintf(F("\n\n"));
printf(F("Ready to program - send data now, or press Enter to change settings\n"));
printf(F("\n"));
gWriteStarted = false;
int32_t sizeReceived = xmodem_receive(NULL, input_handler, data_handler);
if (sizeReceived < 0)
{
xmodem_dumplog();
printf(F("XMODEM transfer failed\n"));
}
if (sizeReceived <= 0)
{
return;
}
printf(F("\n"));
printf(F("Transfer complete - %ld bytes written to EEPROM\n"), sizeReceived);
printf(F("\n"));
}