-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide serialadapter entity in avrdude.conf #1497
Conversation
Thanks for the PR @stefanrueger! This approach looks much less complicated than mine, and I agree that the small tradeoffs is weighed up by the fact that the code is easier to understand, and we can utilize the developer options.
Inheritance is really neat. And I'm absolutely fine with
I didn't think of this. Neat!
IMO there is no doubt. We should continue working on this rather than my branch! |
@stefanrueger where do we continue from here? From what I can read from the code, what's missing now is the libserialport part, where it's given a USB vid, pid, and an optional serial number, and a COM port number/dev path is returned. The libserialport example code I wrote earlier this summer contains the essence of what we want to use the libserialport library for. What the example currently doesn't support is |
@MCUdude Would it be OK if you built what's needed from here? Add your name as author to |
Perhaps we can do some basic regression testing against this PR, and then merge it as it is? I prefer to have it merged into main before continuing the work, to make my git life easier. |
OK. I'll add documentation for |
Well, yes, I think viewing a serialadapter as just another programmer is mildly confusing. What convinces is the quality of the patch though :), in particular all the documentation updates. |
There are a number of existing programmers, eg, ft232r, ft232h, ft2232h etc that you might want as serial adapters and that already have all the relevant info... There will be other programmers that are not serial adapters (by any stretch of imagination) but then allowing them is no harm as it really means I have usbvid and usbpid and want to be looked up as serial interface. |
@MCUdude @dl8dtl There is also the possibility to add either sth like |
That sounds like a good idea. Then one can look at the programmers in avrdude.conf and figure out that this |
@MCUdude Which programmers should this PR also treat as generic serial adapter? I assume However, the derived Note there is no entity called |
How about only the parent programmer, with a few exceptions? Then we don't fill the list with lots of serial adapter names that do the exact same thing. The ft245 isn't a USB to serial chip, but rather a USB to parallel chip. So I'll argue that we should add
|
I tried adding the following code to main.c, just to see if I could make it print out the information from avrdude.conf. For some reason it segfaults if -P isn't const char *seradapter;
SERIALADAPTER *ser = locate_programmer_set(programmers, port, &seradapter);
if (is_serialadapter(ser))
msg_info("port id: %s, vid: 0x%04x, pid: 0x%04x\n", (const char *)ldata(lfirst(ser->id)), ser->usbvid, *(int *)ldata(lfirst(ser->usbpid)));
else if (is_programmer(ser))
msg_error("programmer incorrectly specified using -P %s\n", port);
else if (port && !seradapter)
msg_info("Port %s specified\n", port); But why does the above code fail when I use something else than EDIT: I can make it not segfault by guarding against const char *seradapter;
SERIALADAPTER *ser = locate_programmer_set(programmers, port, &seradapter);
if (ser && is_serialadapter(ser))
msg_info("port id: %s, vid: 0x%04x, pid: 0x%04x\n", (const char *)ldata(lfirst(ser->id)), ser->usbvid, *(int *)ldata(lfirst(ser->usbpid)));
else if (ser && is_programmer(ser))
msg_error("programmer incorrectly specified using -P %s\n", port);
else if (port)
msg_info("Port %s specified\n", port); |
It's a philosophical question of whether the caller or callee is supposed to check against NULL. Before using a function it's best to read its man page or, failing that, the function itself.
Try passing NULL to strlen(), str_eq(), fprintf(), ... and watch the world explode. More often than not, C-functions assume it's the caller who does the checking. Makes sense, too. You open a file once and then use the file pointer one million times to print something. So, it's expected that the caller checks once after opening and not burden the callee 1 million times with unnecessary checks against NULL. But yes, is_programmer() and is_serialadapter() could be hardened against NULL. |
OK, implemented
|
Excellent! I think this PR is ready to be merged then |
OK, all done. @MCUdude You will need to add libserialport detection for |
This work-in-progress PR provides a
serialadapter
entity inavrdude.conf.in
as a specific programmer, namely one that only defines USB parameters. In contrast to the ser-auto branch this PR intends toserialadapter
entities, eg, you can have in your~/.avrduderc
file sth likeft232r
programmer is also a serial adapterusbpid
as a list instead of a single valueserialadapter.c
of the ser-auto branch superfluous asserialadapter
is a programmer, so the original programmer functions will do the jobserialadapter
entities with developer options-c*/s
This PR also provides a
SERIALADAPTER
structure: actually, behind the scenes, it is the same asPROGRAMMER
, but this will allow writing self-documenting code.For the time being, this PR utilises the
baudrate
component ofPROGRAMMER
asdefault_baud
but it would be vvv simple to have bothbaudrate
anddefault_baud
if needed. Here is a code example of how this PR can be utilised to retrieve a particular serial adapter (or programmer with USB definitions) from the config files:@MCUdude: Please check out this PR and see whether this is useful for what you try to achieve. I suspect @dl8dtl has reservations about viewing a serial adapter as a special unfinished programmer entry, but I am hoping that the simplicity of this PR will be somewhat persuasive.
It's possible to carry on with the ser-auto branch but adding above functionality will cost quite some work, in particular, the developer options that print AVRDUDE's understanding of its internal entities.