Unlike several other callbacks the UART are missing an argument. Having that is VERY VERY handy for a bunch of use cases.
I couldn't find any thread requesting this, but I would be surprised if I was the first suggesting this.
Please consider this suggestion for a future improvement or link to an already existing suggestion!
Argument to PAL UART callbacks Topic is solved
-
- Posts: 91
- Joined: Sat Feb 18, 2017 11:50 am
- Has thanked: 43 times
- Been thanked: 23 times
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Location: Munich (Germany)
- Has thanked: 83 times
- Been thanked: 67 times
- Contact:
Re: Argument to PAL UART callbacks
HI,
Moved in a more proper section.
Anyway we are talking of PAL or UART? Can you explain with a code example what you are talking about?
Moved in a more proper section.
Anyway we are talking of PAL or UART? Can you explain with a code example what you are talking about?
Ciao,
RM
RM
-
- Posts: 91
- Joined: Sat Feb 18, 2017 11:50 am
- Has thanked: 43 times
- Been thanked: 23 times
Re: Argument to PAL UART callbacks
Hi,
Thanks for the prompt reply!
Here's an example of a callback that has args: palSetLineCallback
You have the line, the callback AND an argument that you can pass whatever is convinient for your code AT the event handler.
On the other hand UARTConfig has several callbacks for Tx, Rx, etc (uartcb_t) but that declaration only accepts the UARTDriver as argument. If it could accept a void arg as the above, it would be awesome because one could use that in the event handler (if needed, of course).
As we are at it, this is valid for any other driver callback that does not support args, btw.
Hope I've explained myself a little better now!
Thanks for the prompt reply!
Here's an example of a callback that has args: palSetLineCallback
You have the line, the callback AND an argument that you can pass whatever is convinient for your code AT the event handler.
On the other hand UARTConfig has several callbacks for Tx, Rx, etc (uartcb_t) but that declaration only accepts the UARTDriver as argument. If it could accept a void arg as the above, it would be awesome because one could use that in the event handler (if needed, of course).
As we are at it, this is valid for any other driver callback that does not support args, btw.
Hope I've explained myself a little better now!
Re: Argument to PAL UART callbacks
I haven't looked at all drivers, but it seems like a pretty common pattern in ChibiOS HAL.
At least for the UART driver it exists.
https://github.com/ChibiOS/ChibiOS/blob ... lld.h#L550
If you add the following to your halconf you can include any additional fields in the UARTDriver structure that you need.
Since the callbacks get a pointer to the UARTDriver structure you can access them like so:
At least for the UART driver it exists.
https://github.com/ChibiOS/ChibiOS/blob ... lld.h#L550
If you add the following to your halconf you can include any additional fields in the UARTDriver structure that you need.
Code: Select all
#define UART_DRIVER_EXT_FIELDS \
void *mycontext; \
int myotherthing;
Since the callbacks get a pointer to the UARTDriver structure you can access them like so:
Code: Select all
void txend1_cb(UARTDriver *uartp) {
MyContextType *ctx = (MyContextType*)uartp->mycontext;
doSomething(ctx, ...);
}
-
- Posts: 91
- Joined: Sat Feb 18, 2017 11:50 am
- Has thanked: 43 times
- Been thanked: 23 times
Re: Argument to PAL UART callbacks
That looks promising. Thanks for the tip!
My suggestion with arguments was to make it kind of in line with other drivers callbacks.
It should do its purpose with any of those alternatives.
My suggestion with arguments was to make it kind of in line with other drivers callbacks.
It should do its purpose with any of those alternatives.
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Argument to PAL UART callbacks
Hi,
HAL callbacks do not have parameters, this is true for all driver except PAL (see below), this is not necessary because you can extend the driver structure as suggested by apmorton.
The PAL driver has arguments because it is a special case, it does not have an object that can be extended.
Giovanni
HAL callbacks do not have parameters, this is true for all driver except PAL (see below), this is not necessary because you can extend the driver structure as suggested by apmorton.
The PAL driver has arguments because it is a special case, it does not have an object that can be extended.
Giovanni
Return to “Small Change Requests”
Who is online
Users browsing this forum: No registered users and 4 guests