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: 23
Joined: Wed Feb 25, 2015 9:45 pm
Been thanked: 1 time

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: 13631
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 889 times
Been thanked: 769 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: 23
Joined: Wed Feb 25, 2015 9:45 pm
Been thanked: 1 time

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: 23
Joined: Wed Feb 25, 2015 9:45 pm
Been thanked: 1 time

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 9 times

rolanddixon
Posts: 23
Joined: Wed Feb 25, 2015 9:45 pm
Been thanked: 1 time

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 6 times

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

Re: Allow forward declaration of chibios hal structs

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

Thanks, will apply.

Giovanni


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 1 guest