Gentlemen,
The typical pin configuration of a SPI pin (in this example, the CLK pin) is:
GPIOPinTypeSSI(SSI_GYROS_CLK_PORT,SSI_GYROS_CLK_PIN); GPIOPinConfigure(GPIO_PA2_SSI0CLK);
I would like to have a fixed external function to let me to initialize a given SPI peripheral from my main application.
Simplifying for the CLK pin, the idea would be:
SPISensorHWInit(int32_t SSIBase, int32_t sensorClockPort, int_32_t sensorClockPin) // Plus the ports and pins of the other MISO/MOSI/CS GPIO's { // First, execute the SSI Peripheral Configuration
// Then each of the pins, for example:
GPIOPinTypeSSI(sensorClockBase,sensorClockPin); GPIOPinConfigure(SOMETHING); // This is tricky... }
I see two possible ways regarding the SOMETHING parameter:
1) To pass the original GPIOPinConfigure GPIO_PA2_SSI0CLK argument inside the "packing" function, adding yet one more argument to the already long list
or
2) To kind of reconstruct the said parameter inside the function, if the fact that we are dealing with SSI peripheral and we know the SSI base are enough for that.
I looked into the GPIOPinConfigure code, and it is not that easy to read. In the end we want to write a register:
HWREG(ui32Base + GPIO_O_PCTL) = ((HWREG(ui32Base + GPIO_O_PCTL) & ~(0xf << ui32Shift)) | ((ui32PinConfig & 0xf) << ui32Shift));
Question is: can we determine the Base, Shift and remaining PinConfig from the know figures SSI base and pin? What are the "magic" rules?
Regards
Bruno