MCU family Preprocessor checks to determine functionality in a library
I am writing multiple libraries that use either I2C or SPI for communication. I recently discovered that the STM32F4xx family had an interesting "feature" that will take the SPI NSS signal low and keep it low until the SPI module is disabled versus toggling the NSS line based on data transmission when hardware control is specified for the NSS signal. I want the libraries I am writing to be "smarter than the average bear" so a user who has no knowledge of any particular MCU's quirks can easily use the library.
Taking a generic SPI Flash memory module as an example and using the aforementioned STM32F4xx family MCU, is there a "define" specified within the IDE or the HAL's that will allow me to do something similar to the following code snippet? I found something similar to what I am trying to achieve in the system_stm32f4xxx.c file that is auto generated by CubeMX/CubeIDE. I am just looking for a way to cover an entire family of MCU's.
#include "stm32f4xx_hal.h"
#include <stdbool.h>
typedef struct {
// SPI
SPI_HandleTypeDef *_spiHandle;
GPIO_TypeDef *_csBank;
uint16_t _csPin;
bool _usingHW_CS
} FLASH_MEM;
void genericFlashInit(FLASH_MEM *myFlash, SPI_HandleTypeDef *spiHandle,
GPIO_TypeDef *csBank, uint16_t csPin, bool usingHW_CS) {
myFlash->_spiHandle = spiHandle;
myFlash->_csBank = csBank;
myFlash->_csPin = csPin;
#if defined(STM32F4xx)
myFlash->_usingHW_CS = false;
#else
myFlash->_usingHW_CS = usingHW_CS;
#endif
}
