2022-11-11 11:40 AM
2022-11-11 11:41 AM
I guess I was thinking that was for the title...
This is more of a code related question.
So st likes to dump the auto generated code.
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
ADC_HandleTypeDef hadc2;
etc..
I want to expose them to a struct and was planning to just make pointers.
typedef struct
{
void *pADC1;
void *pADC2;
} peripheral_Pointers;
then in the main I can
peripheral_Pointers *peripheral;
peripheral->pADC1 = hadc1;
peripheral->pADC2 = hadc2;
the thinking here is that my struct now has access to them. but I guess you can not just make a generic pointer to them because they are typedef structs of ADC_HandleTypeD.
Is there some way to cast as a generic pointer?
2022-11-11 11:53 AM
or do I just need this
peripheral->pADC1 = &hadc1;
peripheral->pADC2 = &hadc2;
2022-11-11 12:35 PM
Assuming you want a void pointer in the typedef then you have to cast the struct member when you reference it:
(ADC_HandleTypeDef *) (peripheral->pADC1) = &hadc1;
or, in the typedef if you don't require a void (better way):
typedef struct
{
ADC_HandleTypeDef* pADC1;
ADC_HandleTypeDef* pADC2;
} peripheral_Pointers;
That way you maintain type consistency with pointers.
2022-11-11 01:50 PM
Implicitly converting from (ADC_HandleTypeDef *) to (void *) is fine. Converting the other way requires a cast. In this case it seems like the best option is to make them the correct pointer type in the struct.