Skip to content

Commit f1d2a96

Browse files
committed
auto-program cycle for Pico on Mac. added -showPath option to serial2xsbug
1 parent 7e11db6 commit f1d2a96

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

build/devices/pico/config/programmingMode

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ VENDOR_ID=$1
44
PRODUCT_ID=$2
55
VOLUME_NAME=$3
66

7-
if [[ ! -d $VOLUME_NAME ]]
7+
if [[ ! -d ${VOLUME_NAME} ]]
88
then
9-
serial2xsbug ${VENDOR_ID}:${PRODUCT_ID} 921600 8N1 -programming
9+
DEVICE_NAME=`serial2xsbug ${VENDOR_ID}:${PRODUCT_ID} -showPath`
10+
if [[ "timeout" != "${DEVICE_NAME}" ]]
11+
then
12+
serial2xsbug ${VENDOR_ID}:${PRODUCT_ID} 921600 8N1 -programming
13+
else
14+
echo -n "Hold the BOOTSEL button and power-cycle the device."
15+
fi
1016
echo -n "Waiting for ${VOLUME_NAME}."
11-
while [ ! -d "${VOLUME_NAME}" ]; do
17+
while [[ ! -d "${VOLUME_NAME}" ]]; do
1218
echo -n "."
1319
sleep 1
1420
done

tools/serial2xsbug/serial2xsbug.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,26 @@ static char* gExceptionList[33] = {
9999
int fxArguments(txSerialTool self, int argc, char* argv[])
100100
{
101101
int argi;
102-
if (argc < 4) {
102+
if (argc < 3) {
103103
fprintf(stderr, "### serial2xsbug <port name> <baud rate> <data bits><parity><stop bits>\n");
104+
fprintf(stderr, "### serial2xsbug <vid:pid> -showPath [-timeout <ms>]\n");
104105
return 1;
105106
}
106107
memset(self, 0, sizeof(txSerialToolRecord));
107108
self->path = argv[1];
108-
self->baud = atoi(argv[2]);
109-
self->data = argv[3][0] - '0';
110-
self->parity = argv[3][1];
111-
self->stop = argv[3][2] - '0';
109+
if (argc > 2) {
110+
self->baud = atoi(argv[2]);
111+
if (argc > 3) {
112+
self->data = argv[3][0] - '0';
113+
self->parity = argv[3][1];
114+
self->stop = argv[3][2] - '0';
115+
}
116+
}
112117
self->host = "localhost";
113118
self->port = 5002;
114119
self->restartOnConnect = 1;
120+
self->showPath = 0;
121+
self->timeout = 5000; // for showpath
115122

116123
if (9 == strlen(self->path) && (':' == self->path[4])) {
117124
self->vendorID = (mapHex(self->path[0]) << 12) | (mapHex(self->path[1]) << 8) | (mapHex(self->path[2]) << 4) | mapHex(self->path[3]);
@@ -122,8 +129,16 @@ int fxArguments(txSerialTool self, int argc, char* argv[])
122129
TOOLS_BIN = NULL;
123130
elfPath = NULL;
124131
gCmd = NULL;
125-
for (argi = 4; argi < argc; argi++) {
126-
if (!strcmp(argv[argi], "-elf") && ((argi + 1) < argc)) {
132+
133+
for (argi = 2; argi < argc; argi++) {
134+
if (argv[argi][0] != '-')
135+
continue;
136+
if (!strcmp(argv[argi], "-showPath"))
137+
self->showPath = 1;
138+
else if (!strcmp(argv[argi], "-timeout") && ((argi + 1) < argc)) {
139+
self->timeout = atoi(argv[++argi]);
140+
}
141+
else if (!strcmp(argv[argi], "-elf") && ((argi + 1) < argc)) {
127142
elfPath = argv[++argi];
128143
}
129144
else if (!strcmp(argv[argi], "-bin") && ((argi + 1) < argc)) {

tools/serial2xsbug/serial2xsbug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ struct txSerialToolStruct {
158158
int dtr;
159159
int programming;
160160
int restartOnConnect;
161+
int showPath;
162+
int timeout;
161163
txSerialMachine firstMachine;
162164
txSerialMachine currentMachine;
163165
int index;

tools/serial2xsbug/serial2xsbug_mac.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void fxRegisterSerial(void *refcon, io_iterator_t iterator)
278278
if (productRef)
279279
CFNumberGetValue(productRef , kCFNumberIntType, &productID);
280280

281-
fprintf(stderr, "checking productID %04x:%04x\n", vendorID, productID);
281+
//fprintf(stderr, "checking productID %04x:%04x\n", vendorID, productID);
282282
match = (!self->productID || (productID == self->productID)) &&
283283
(!self->vendorID || (vendorID == self->vendorID));
284284

@@ -292,8 +292,15 @@ fprintf(stderr, "checking productID %04x:%04x\n", vendorID, productID);
292292
if (!strcmp(self->path, "") && match) {
293293
self->path = malloc(strlen(description->path) + 1);
294294
strcpy(self->path, description->path);
295-
fprintf(stderr, "product/vendor match: %s\n", description->path);
296-
fxOpenSerial(self);
295+
296+
if (self->showPath) {
297+
fprintf(stderr, "%s\n", description->path);
298+
exit(0);
299+
}
300+
else {
301+
fprintf(stderr, "product/vendor match: %s\n", description->path);
302+
fxOpenSerial(self);
303+
}
297304
}
298305
else
299306
if (!strcmp(self->path, description->path)
@@ -358,6 +365,12 @@ static void fxSignalHandler(int s) {
358365
exit(1);
359366
}
360367

368+
static void timeoutHandler(CFRunLoopTimerRef cfTimer, void *info)
369+
{
370+
printf("timeout\n");
371+
exit(1);
372+
}
373+
361374
int main(int argc, char* argv[])
362375
{
363376
txSerialToolRecord tool;
@@ -372,9 +385,16 @@ int main(int argc, char* argv[])
372385
IOServiceAddMatchingNotification(self->notificationPort, kIOPublishNotification, matchingDict, fxRegisterSerial, self, &self->ioIterator);
373386
fxRegisterSerial(self, self->ioIterator);
374387

375-
signal(SIGINT, fxSignalHandler);
388+
if (self->showPath) {
389+
CFRunLoopTimerRef cfTimer;
390+
CFRunLoopTimerContext context = {0};
376391

377-
CFRunLoopRun();
392+
cfTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + (self->timeout / 1000.0), 0, 0, 0, timeoutHandler, &context);
393+
CFRunLoopAddTimer(CFRunLoopGetCurrent(), cfTimer, kCFRunLoopCommonModes);
394+
}
378395

379-
return result;
380-
}
396+
signal(SIGINT, fxSignalHandler);
397+
398+
CFRunLoopRun();
399+
400+
}

0 commit comments

Comments
 (0)