-
Notifications
You must be signed in to change notification settings - Fork 12
/
picoprom.c
122 lines (85 loc) · 1.8 KB
/
picoprom.c
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
#include "picoprom.h"
#include <stdio.h>
#include <tusb.h>
#include "pico/binary_info.h"
#include "pico/stdlib.h"
#include "configs.h"
#include "xmodem.h"
#include "eeprom.h"
static bool setup()
{
bi_decl(bi_program_description("PicoPROM - EEPROM programming tool"));
bool eepromOk = eeprom_init();
stdio_init_all();
while (!tud_cdc_connected()) sleep_ms(100);
printf("\nUSB Serial connected\n");
if (!eepromOk)
{
printf("ERROR: no pin was mapped to Write Enable (ID 15)\n");
return false;
}
init_settings();
return true;
}
static void banner()
{
printf("\n\n");
printf("\n\n");
printf("\n\n");
printf("PicoPROM v0.21 Raspberry Pi Pico DIP-EEPROM programmer\n");
printf(" by George Foot, February 2021\n");
printf(" https://github.com/gfoot/picoprom\n");
}
static bool input_handler(int c)
{
if (c == 13)
{
change_settings();
return true;
}
return false;
}
void loop()
{
printf("\n\n");
printf("\n\n");
printf("\n\n");
banner();
printf("\n\n");
show_settings();
printf("\n\n");
printf("Ready to program - send data now, or press Enter to change settings\n");
printf("\n");
char buffer[65536];
int sizeReceived = xmodem_receive(buffer, sizeof buffer, NULL, input_handler);
if (sizeReceived < 0)
{
xmodem_dumplog();
printf("XMODEM transfer failed\n");
}
if (sizeReceived <= 0)
{
return;
}
printf("\n");
printf("Transfer complete - received %d bytes\n", sizeReceived);
printf("\n");
if (sizeReceived > gConfig.size)
{
printf("Truncating image to %d bytes\n", gConfig.size);
printf("\n");
sizeReceived = gConfig.size;
}
printf("Writing to EEPROM...\n");
eeprom_writeImage(buffer, sizeReceived);
printf("\n");
printf("Done\n");
}
int main()
{
if (!setup())
return -1;
while (true)
loop();
return 0;
}