Tool/software: TI-RTOS
Hi E2E.
I've earlier asked a question about static configuration of GPIOs, and the answer I got from that question led me to another question: how to configure the GPIOs dynamically, the "smoothiest" way.
In many of the examples for the CC2640R2-Launchpad, i.e. the gpiointerrupt-example, the GPIOs for the 2 on-board buttons and LEDs are set dynamic very simple, as shown underneath:
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
/* Call driver init functions */
GPIO_init();
/* Configure the LED and button pins */
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(Board_GPIO_LED1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(Board_GPIO_BUTTON0, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
GPIO_setConfig(Board_GPIO_BUTTON1, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
/* install Button callback */
GPIO_setCallback(Board_GPIO_BUTTON0, gpioButtonFxn0);
GPIO_setCallback(Board_GPIO_BUTTON1, gpioButtonFxn1);
/* Enable interrupts */
GPIO_enableInt(Board_GPIO_BUTTON0);
GPIO_enableInt(Board_GPIO_BUTTON1);
return (NULL);
}
This is only possible because those GPIOs have been implemented to be generic in the Board.h-file and the CC2640R2_LAUNCHXL.h-file, as shown underneath:
// Board.h definitions: #define Board_GPIO_BUTTON0 CC2640R2_LAUNCHXL_GPIO_S1 #define Board_GPIO_BUTTON1 CC2640R2_LAUNCHXL_GPIO_S2 #define Board_GPIO_BTN1 CC2640R2_LAUNCHXL_GPIO_S1 #define Board_GPIO_BTN2 CC2640R2_LAUNCHXL_GPIO_S2 #define Board_GPIO_LED0 CC2640R2_LAUNCHXL_GPIO_LED_RED #define Board_GPIO_LED1 CC2640R2_LAUNCHXL_GPIO_LED_GREEN #define Board_GPIO_LED2 CC2640R2_LAUNCHXL_GPIO_LED_RED #define Board_GPIO_RLED CC2640R2_LAUNCHXL_GPIO_LED_RED #define Board_GPIO_GLED CC2640R2_LAUNCHXL_GPIO_LED_GREEN #define Board_GPIO_LED_ON CC2640R2_LAUNCHXL_GPIO_LED_ON #define Board_GPIO_LED_OFF CC2640R2_LAUNCHXL_GPIO_LED_OFF #define Board_GPIO_TMP116_EN CC2640R2_LAUNCHXL_GPIO_TMP116_EN
/*!
* @def CC2640R2_LAUNCHXL_GPIOName
* @brief Enum of GPIO names
*/
typedef enum CC2640R2_LAUNCHXL_GPIOName {
CC2640R2_LAUNCHXL_GPIO_S1 = 0,
CC2640R2_LAUNCHXL_GPIO_S2,
CC2640R2_LAUNCHXL_SPI_MASTER_READY,
CC2640R2_LAUNCHXL_SPI_SLAVE_READY,
CC2640R2_LAUNCHXL_GPIO_LED_GREEN,
CC2640R2_LAUNCHXL_GPIO_LED_RED,
CC2640R2_LAUNCHXL_GPIO_TMP116_EN,
CC2640R2_LAUNCHXL_GPIO_SPI_FLASH_CS,
CC2640R2_LAUNCHXL_SDSPI_CS,
CC2640R2_LAUNCHXL_GPIO_LCD_CS,
CC2640R2_LAUNCHXL_GPIO_LCD_POWER,
CC2640R2_LAUNCHXL_GPIO_LCD_ENABLE,
CC2640R2_LAUNCHXL_GPIOCOUNT
} CC2640R2_LAUNCHXL_GPIOName;
I think it is a strange way to use a driver, if I have to modify these .h-files to be able to use the GPIO-driver, and I'd like to know whether there is another, more straight forward way to configure GPIOs generic, that hasn't already been implemented in these .h-files - for example the DIO22-pin. As it is by now, I'm doing it as shown underneath, with the DIO implemented in both of the .h-files:
// Board.h definitions #define Board_GPIO_SPI_nDRDY CC2640R2_LAUNCHXL_GPIO_DIO22 // Added by PWN #define Board_GPIO_DIO22 CC2640R2_LAUNCHXL_GPIO_DIO22 // Added by PWN #define Board_GPIO_BUTTON0 CC2640R2_LAUNCHXL_GPIO_S1 #define Board_GPIO_BUTTON1 CC2640R2_LAUNCHXL_GPIO_S2 #define Board_GPIO_BTN1 CC2640R2_LAUNCHXL_GPIO_S1 #define Board_GPIO_BTN2 CC2640R2_LAUNCHXL_GPIO_S2 #define Board_GPIO_LED0 CC2640R2_LAUNCHXL_GPIO_LED_RED #define Board_GPIO_LED1 CC2640R2_LAUNCHXL_GPIO_LED_GREEN #define Board_GPIO_LED2 CC2640R2_LAUNCHXL_GPIO_LED_RED #define Board_GPIO_RLED CC2640R2_LAUNCHXL_GPIO_LED_RED #define Board_GPIO_GLED CC2640R2_LAUNCHXL_GPIO_LED_GREEN #define Board_GPIO_LED_ON CC2640R2_LAUNCHXL_GPIO_LED_ON #define Board_GPIO_LED_OFF CC2640R2_LAUNCHXL_GPIO_LED_OFF #define Board_GPIO_TMP116_EN CC2640R2_LAUNCHXL_GPIO_TMP116_EN
/*!
* @def CC2640R2_LAUNCHXL_GPIOName
* @brief Enum of GPIO names
*/
typedef enum CC2640R2_LAUNCHXL_GPIOName {
CC2640R2_LAUNCHXL_GPIO_DIO22 = 0, // Added by PWN
CC2640R2_LAUNCHXL_GPIO_S1,
CC2640R2_LAUNCHXL_GPIO_S2,
CC2640R2_LAUNCHXL_SPI_MASTER_READY,
CC2640R2_LAUNCHXL_SPI_SLAVE_READY,
CC2640R2_LAUNCHXL_GPIO_LED_GREEN,
CC2640R2_LAUNCHXL_GPIO_LED_RED,
CC2640R2_LAUNCHXL_GPIO_TMP116_EN,
CC2640R2_LAUNCHXL_GPIO_SPI_FLASH_CS,
CC2640R2_LAUNCHXL_SDSPI_CS,
CC2640R2_LAUNCHXL_GPIO_LCD_CS,
CC2640R2_LAUNCHXL_GPIO_LCD_POWER,
CC2640R2_LAUNCHXL_GPIO_LCD_ENABLE,
CC2640R2_LAUNCHXL_GPIOCOUNT
} CC2640R2_LAUNCHXL_GPIOName;
With this it's possible to implement the DIO22 to the GPIO-driver, by applying the DIO22 to the gpioPin table and the gpioCallback table in the CC2640R2_LAUNCHXL.c-file, as shown below:
/*
* Array of Pin configurations
* NOTE: The order of the pin configurations must coincide with what was
* defined in CC2640R2_LAUNCHXL.h
* NOTE: Pins not used for interrupts should be placed at the end of the
* array. Callback entries can be omitted from callbacks array to
* reduce memory usage.
*/
GPIO_PinConfig gpioPinConfigs[] = {
/* Input pins */
GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* SPI - nDRDY (added by PWN) */
GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 1 */
GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 2 */
GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
/* Output pins */
GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */
GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */
GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG, /* TMP116_EN */
/* SPI Flash CSN */
GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG,
/* SD CS */
GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,
/* Sharp Display - GPIO configurations will be done in the Display files */
GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */
GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* LCD power control */
GPIOCC26XX_DIO_23 | GPIO_DO_NOT_CONFIG, /*LCD enable */
};
/*
* Array of callback function pointers
* NOTE: The order of the pin configurations must coincide with what was
* defined in CC2640R2_LAUNCH.h
* NOTE: Pins not used for interrupts can be omitted from callbacks array to
* reduce memory usage (if placed at end of gpioPinConfigs array).
*/
GPIO_CallbackFxn gpioCallbackFunctions[] = {
NULL, /* SPI - nDRDY (added by PWN) */
NULL, /* Button 1 */
NULL, /* Button 2 */
NULL, /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
NULL, /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
};
With these modifications, its possible to configure the DIO22 generic, as shown below:
/* Configure the L_button pin and the SPI_nDRDY pin */
GPIO_setConfig(Board_GPIO_BUTTON0, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
GPIO_setConfig(Board_GPIO_SPI_nDRDY, GPIO_CFG_INPUT | GPIO_CFG_IN_INT_FALLING);
/* install L_button callback and SPI_nDRDY callback */
GPIO_setCallback(Board_GPIO_BUTTON0, btnL_intFxn);
GPIO_setCallback(Board_GPIO_SPI_nDRDY, btnR_intFxn);
/* Enable interrupts */
GPIO_enableInt(Board_GPIO_BUTTON0);
GPIO_enableInt(Board_GPIO_SPI_nDRDY);
But as you see, I have to modify the generic code 4 places, and it seems very strange to me, that it's needed to use the GPIO-driver for non-implementet GPIOs.
I've tried to look this up on this and other forums, and the GPIO-driver manuals, but with no luck.
Kind regards,
Peter