I am trying to write a peripheral driver for one chip I am using on STM32. To make the driver general for all chips I will possibly use in the future, I am trying to separate the platform-specific code and the code dedicated for the chip. I am wondering is there a discipline that I can follow?
Currently, I am thinking about 2 possibilities:
Use weak functions to separate. The chip driver will rely on several weak functions, and the user provides functions to override the weak functions.
Use an initialization structure, which contains several function pointers that point to the hardware-specific functions. And the driver will use these functions provided during the initialization process.
But I cannot foresee what are the pros and cons.