Originally Posted by
mr_monster
Actually it does not matter what SPI is... The structure type is SPI_HandleTypeDef and it is defined in a header which indeed has public privileges. The thing is that I need to use the specific instance that is created in main, which I showed before, declared as private. I somehow need to be able to point at it. I guess an option would be to create a copy of the structure but since all structure manipulation is taken care of by the SPI library I can't be sure that my copy is up to date and I don't want to modify the SPI library or write a function that would be called repeatedly to compare my copy structure with the original one.
I kinda lost you!
Since SPI_HandleTypeDef is a public type, which you instantiate in your main.c file, what stops you from passing a pointer to that instant as an argument to a function of your own library? Your library function gets access directly to that particular instance of SPI_HandleTypeDef.
Code:
// main.c
#include "spi.h"
#include "mylib.h"
...
int main( void )
{
SPI_HandleTypeDef hspi3;
mylib_foo( &hspi3, ... );
...
}
Code:
// mylib.h
...
#include "spi.h"
...
whatever mylib_foo( SPI_HandleTypeDef *, ... );
...
Code:
// mylib.c
#include "spi.h"
...
whatever mylib_foo( SPI_HandleTyleDef *handle, ... )
{
...
return whatever;
}