filex icon indicating copy to clipboard operation
filex copied to clipboard

Adding peripheral handle to the filex::FX_MEDIA class

Open nkrishit opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. When working with Filex and making custom driver, for instance, SD card using SPI, I need to extern the hspiX from the main.c to implement the driver. This approach ends up forcing me to have only one instance of this custom driver.

Describe the solution you'd like By having the handle inside the FX_MEDIA class preferably as a (void *) type, I would be able to typecast it into my desired peripheral Handle, be it SDMMC, SPI, I2C or anything else and have multiple instances of the same driver to define different devices all connect via the same custom peripheral.

Describe alternatives you've considered Alternatively expanding the available base options would be great. But the work involved might be non-trivial as opposed to the above change

Additional context Add any other context or screenshots about the feature request here.

nkrishit avatar Aug 16 '24 20:08 nkrishit

I am not one of the contributors to this repo, but I have dealt with a similar situation, and would like to share my solution (in case it helps).

I dealt with it by creating a custom struct for that driver (which you can obviously apply to multiple drivers), which contains a pointer to the handle, along with a variety of other characteristics of the media. Another parameter might be an enum that described what type of peripheral you're using.

I initialize the struct, then pass a pointer to it into the fx_media_open, via the "VOID *driver_info_ptr" variable, which ends up as the "VOID *fx_media_driver_info;" parameter of the "FX_MEDIA" struct. You can then read the various parameters of your struct to determine how the driver should act.

nflandin avatar Aug 26 '24 20:08 nflandin