int board_tsc_setup(int minor) { FAR struct spi_dev_s *dev; static bool initialized = false; int ret; idbg("minor %d\n", minor); DEBUGASSERT(minor == 0); /* Have we already initialized? Since we never uninitialize we must prevent * multiple initializations. This is necessary, for example, when the * touchscreen example is used as a built-in application in NSH and can be * called numerous time. It will attempt to initialize each time. */ if (!initialized) { /* Configure and enable the XPT2046 interrupt pin as an input */ (void)sam_configgpio(GPIO_TSC_IRQ); /* Configure the PIO interrupt */ sam_gpioirq(SAM_TSC_IRQ); /* Get an instance of the SPI interface for the touchscreen chip select */ dev = sam_tsc_spiinitialize(); if (!dev) { idbg("Failed to initialize bit bang SPI\n"); return -ENODEV; } /* Initialize and register the SPI touschscreen device */ ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR); if (ret < 0) { idbg("Failed to register touchscreen device\n"); /* up_spiuninitialize(dev); */ return -ENODEV; } /* Now we are initialized */ initialized = true; } return OK; }
int arch_tcinitialize(int minor) { FAR struct spi_dev_s *dev; int ret; idbg("minor %d\n", minor); DEBUGASSERT(minor == 0); /* Configure and enable the ADS7843E interrupt pin as an input */ (void)sam_configgpio(GPIO_TCS_BUSY); (void)sam_configgpio(GPIO_TCS_IRQ); /* Configure the PIO interrupt */ sam_gpioirq(GPIO_TCS_IRQ); /* Get an instance of the SPI interface for the touchscreen chip select */ dev = up_spiinitialize(TSC_CSNUM); if (!dev) { idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM); return -ENODEV; } /* Initialize and register the SPI touschscreen device */ ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR); if (ret < 0) { idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM); /* up_spiuninitialize(dev); */ return -ENODEV; } return OK; }