A GPIO pin always contains info of a GPIO port(GPIO_PORTA_BASE), and a GPIO Pin(GPIO_PIN_0).
A GPIO shortpin in cox is a macro contained port, pin information in one body. PA0, A indicates GPIO_PortA_BASE, 0 indicates GPIO_PIN_0.
Use the shortpin to read/write:
Use the shortpin AFIO operation:
Use the shortpin in a device driver:
#define SPI_FLASH_PIN_CS PC2 xGPIOSPinWrite(SPI_FLASH_PIN_CS, 0);
There is also APIs to get the Port, Pin:
CoX unified defines the interruption of peripherals Compatible with a variety of MCUs using a callback function with an event ID.
Users should use the Event ID, not the interrupt flags in the MCU peripherals.
Users should also use the callback function instead of the interrupt Handler function defined in the vector table.
Step of Using the interrupt feature:
1. First of all, you should set the system clock using XSysCtlClockSet().
2. If you use a peripheral such as SPI, you should enable the SPI clock and some GPIO clock before calling any SPI APIs.
xSysCtlPeripheralEnable(xSYSCTL_PERIPH_SPI0); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(FLASH_PIN_SPI_CLK)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(FLASH_PIN_SPI_CS)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(FLASH_PIN_SPI_MISO)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(FLASH_PIN_SPI_MOSI));
3. Then you should config the SPI IO.
xSPinTypeSPI(SPI2CLK, FLASH_PIN_SPI_CLK); xSPinTypeSPI(SPI2MISO, FLASH_PIN_SPI_MISO); xSPinTypeSPI(SPI2MOSI, FLASH_PIN_SPI_MOSI);
4. You can enable and initialize the SPI.
xSPIEnable(FLASH_PIN_SPI_PORT); xSPIConfigSet(FLASH_PIN_SPI_PORT, ulSpiClock, xSPI_MOTO_FORMAT_MODE_0 | xSPI_MODE_MASTER | xSPI_MSB_FIRST | xSPI_DATA_WIDTH8);
5. You can use SPI to communicate with a device.
Code based on CoX is convenient to port, but you can do more to make the code more portable.
For example: When using CoX SPI to write a SPI flash driver, we redefine the SPI base and shortpins. And then when need porting the code to other paltforms, We only need to change this defines.
// // Define SPIx as a port connecting W25Xxx which can be configured // #define FLASH_PIN_SPI_CLK PD1 #define FLASH_PIN_SPI_MISO PD2 #define FLASH_PIN_SPI_MOSI PD3 #define FLASH_PIN_SPI_PORT SPI2_BASE // // Configure GPIOC.0 as chip Select // #define FLASH_PIN_SPI_CS PD0
The presentment is using the doxygen standard.
If you encounter any problems in the porting period, please contact us.