Page 1 of 1

Allow forward declaration of chibios hal structs

Posted: Tue Jun 22, 2021 10:33 am
by rolanddixon
Hi All,

This is a fairly simple request and I do not mind submitting a patch for it but I thought I would ask as it could be against a previous design decision.

I will use the SerialConfig as an example. Currently the structure is defined as:

Code: Select all

typedef struct
{
   uint32_t speed;
   ...
} SerialConfig;


This has the adverse effect that it cannot be forward declared. Instead the struct could look like the following:

Code: Select all

typedef struct _SerialConfig
{
   uint32_t speed;
   ...
} SerialConfig;


This would allow for forward declaration as:

Code: Select all

typedef struct _SerialConfig SerialConfig;


As far as I can tell, it would only be the definitions that need updating and the actual source code will remain the same.

This is useful when implementing pimpl and factory type patterns in C++.

Re: Allow forward declaration of chibios hal structs

Posted: Tue Jun 22, 2021 11:19 am
by Giovanni
Hi,

This is already done for some (newer) drivers, see hal_sio.h for example. If you are going to propose a patch please follow comment and naming patterns as seen in that file.

Giovanni

Re: Allow forward declaration of chibios hal structs

Posted: Wed Jun 23, 2021 9:18 am
by rolanddixon
Ok, yes. I'll submit one patch at a time per driver if that is OK with you.

Roland

Re: Allow forward declaration of chibios hal structs

Posted: Wed Jun 23, 2021 11:15 am
by rolanddixon
Here is the first hal_serial patch. I have applied it and built all code in "testhal". All the arm based code compiles file. Some of the AVR based code fails but not due to the changes I made. I probably have a mismatch of version of the avr-gcc compiler.

I have zipped the patch along with the build log text file.

I used "git diff --no-prefix" to generate the patch which can be appled with "patch -p0 << /path/to/patch/patch.diff" in the root of the repo.

Re: Allow forward declaration of chibios hal structs

Posted: Wed Jun 23, 2021 3:34 pm
by rolanddixon
Here are the can, uart and serial patches.
These are the peripherals that I am using at the moment. I will upload the other when I use the peripherals which won't be for a while.

Re: Allow forward declaration of chibios hal structs

Posted: Wed Jun 23, 2021 5:43 pm
by Giovanni
Thanks, will apply.

Giovanni

Re: Allow forward declaration of chibios hal structs

Posted: Tue Oct 26, 2021 2:59 pm
by rolanddixon
Hi Giovanni,

It has been a while but here is a patch for the i2c driver and config typedefs (hal_i2c_config and hal_i2c_driver).

I have tested the builds for the STM32 testhal projects.

Re: Allow forward declaration of chibios hal structs

Posted: Tue Oct 26, 2021 6:50 pm
by Giovanni
Hi,

Thanks, will try it tomorrow.

Giovanni

Re: Allow forward declaration of chibios hal structs

Posted: Sun Oct 31, 2021 7:34 am
by Giovanni
Thanks, patch applied.

Giovanni