Skip to content
Snippets Groups Projects
Commit 9b6ad688 authored by CNLohr's avatar CNLohr
Browse files

Fix windows build.

parent 68cab02c
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,7 @@ int ArdulinkWriteReg32(void * dev, uint8_t reg_7_bit, uint32_t command)
if (serial_dev_read(&((ardulink_ctx_t*)dev)->serial, buf, 1) == -1)
return -errno;
return buf[0] == '+' ? 0 : -EPROTO;
return buf[0] == '+' ? 0 : -71; // EPROTO
}
int ArdulinkReadReg32(void * dev, uint8_t reg_7_bit, uint32_t * commandresp)
......@@ -78,9 +78,9 @@ int ArdulinkControl3v3(void * dev, int power_on) {
return -errno;
if (c != '+')
return -EPROTO;
return -71; // EPROTO
usleep(20000);
MCF.DelayUS(dev, 20000);
return 0;
}
......@@ -97,11 +97,26 @@ int ArdulinkExit(void * dev)
return 0;
}
int ArdulinkSetupInterface( void * dev )
{
char first;
// Let the bootloader do its thing.
MCF.DelayUS(dev, 3UL*1000UL*1000UL);
if (serial_dev_read(&((ardulink_ctx_t*)dev)->serial, &first, 1) == -1) {
perror("read");
return -1;
}
if (first != '!') {
fprintf(stderr, "Ardulink: not the sync character.\n");
return -1;
}
}
void * TryInit_Ardulink(const init_hints_t* hints)
{
ardulink_ctx_t *ctx;
char first;
if (!(ctx = calloc(sizeof(ardulink_ctx_t), 1))) {
perror("calloc");
......@@ -143,19 +158,6 @@ void * TryInit_Ardulink(const init_hints_t* hints)
return NULL;
}
// Let the bootloader do its thing.
usleep(3UL*1000UL*1000UL);
if (serial_dev_read(&ctx->serial, &first, 1) == -1) {
perror("read");
return NULL;
}
if (first != '!') {
fprintf(stderr, "Ardulink: not the sync character.\n");
return NULL;
}
fprintf(stderr, "Ardulink: synced.\n");
MCF.WriteReg32 = ArdulinkWriteReg32;
......@@ -164,6 +166,7 @@ void * TryInit_Ardulink(const init_hints_t* hints)
MCF.Control3v3 = ArdulinkControl3v3;
MCF.DelayUS = ArdulinkDelayUS;
MCF.Exit = ArdulinkExit;
MCF.SetupInterface = ArdulinkSetupInterface;
return ctx;
}
......@@ -71,37 +71,30 @@ void * MiniCHLinkInitAsDLL( struct MiniChlinkFunctions ** MCFO, const init_hints
return dev;
}
void parse_possible_init_hints(int argc, char **argv, init_hints_t *hints)
{
if (!hints)
return;
int c;
opterr = 0;
/* we're only interested in the value for the COM port, given in a -c parameter */
/* the '-' is really important so that getopt does not permutate the argv array and messes up parsing later */
while ((c = getopt(argc, argv, "-c:")) != -1)
{
switch (c)
{
case 'c':
// we can use the pointer as-is because it points in our
// argv array and that is stable.
hints->serial_port = optarg;
break;
}
}
}
#if !defined( MINICHLINK_AS_LIBRARY ) && !defined( MINICHLINK_IMPORT )
int main( int argc, char ** argv )
{
int i;
if( argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h' )
{
goto help;
}
init_hints_t hints;
memset(&hints, 0, sizeof(hints));
parse_possible_init_hints(argc, argv, &hints);
// Scan for possible hints.
for( i = 0; i < argc; i++ )
{
char * v = argv[i];
if( strncmp( v, "-c", 2 ) == 0 )
{
i++;
if( i < argc )
hints.serial_port = argv[i];
}
}
void * dev = MiniCHLinkInitAsDLL( 0, &hints );
if( !dev )
{
......
No preview for this file type
......@@ -9,6 +9,7 @@
#define IS_WINDOWS
#define DEFAULT_SERIAL_NAME "\\\\.\\COM3"
#else
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
......@@ -17,7 +18,6 @@
#endif
/* these are available on all platforms */
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
typedef struct {
......
tcc minichlink.c pgm-esp32s2-ch32xx.c pgm-wch-linke.c minichgdb.c nhc-link042.c -DWIN32 -lws2_32 -lsetupapi libusb-1.0.dll
tcc minichlink.c pgm-esp32s2-ch32xx.c serial_dev.c ardulink.c pgm-b003fun.c pgm-wch-linke.c minichgdb.c nhc-link042.c -DWIN32 -lws2_32 -lsetupapi libusb-1.0.dll
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment