Allow forward declaration of chibios hal structs Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

Allow forward declaration of chibios hal structs  Topic is solved

Postby rolanddixon » Tue Jun 22, 2021 10:33 am

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++.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Allow forward declaration of chibios hal structs

Postby Giovanni » Tue Jun 22, 2021 11:19 am

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

rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Allow forward declaration of chibios hal structs

Postby rolanddixon » Wed Jun 23, 2021 9:18 am

Ok, yes. I'll submit one patch at a time per driver if that is OK with you.

Roland

rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Allow forward declaration of chibios hal structs

Postby rolanddixon » Wed Jun 23, 2021 11:15 am

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.
Attachments
hal_serial_patch.diff.zip
(8.96 KiB) Downloaded 130 times

rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Allow forward declaration of chibios hal structs

Postby rolanddixon » Wed Jun 23, 2021 3:34 pm

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.
Attachments
hal_typedef_patches.zip
(3.28 KiB) Downloaded 128 times

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Allow forward declaration of chibios hal structs

Postby Giovanni » Wed Jun 23, 2021 5:43 pm

Thanks, will apply.

Giovanni

rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Allow forward declaration of chibios hal structs

Postby rolanddixon » Tue Oct 26, 2021 2:59 pm

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.
Attachments
i2c_driver_patch.diff.zip
(1.43 KiB) Downloaded 110 times

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Allow forward declaration of chibios hal structs

Postby Giovanni » Tue Oct 26, 2021 6:50 pm

Hi,

Thanks, will try it tomorrow.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Allow forward declaration of chibios hal structs

Postby Giovanni » Sun Oct 31, 2021 7:34 am

Thanks, patch applied.

Giovanni


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 8 guests