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.
Post Reply
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

Post 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++.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Allow forward declaration of chibios hal structs

Post 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
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

Post by rolanddixon »

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

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

Post 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.
Attachments
hal_typedef_patches.zip
(3.28 KiB) Downloaded 506 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Allow forward declaration of chibios hal structs

Post by Giovanni »

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

Post 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.
Attachments
i2c_driver_patch.diff.zip
(1.43 KiB) Downloaded 566 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Allow forward declaration of chibios hal structs

Post by Giovanni »

Hi,

Thanks, will try it tomorrow.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Allow forward declaration of chibios hal structs

Post by Giovanni »

Thanks, patch applied.

Giovanni
Post Reply