lupyuen edited a comment on issue #5810:
URL: 
https://github.com/apache/incubator-nuttx/issues/5810#issuecomment-1077001344


   ST7789 Driver runs in Kernel Space so I don't think it can access 
`/dev/gpio*`?
   
   There is a generic LCD Driver that wraps up the ST7789 Driver as `/dev/lcd*`:
   
   
https://github.com/lupyuen/incubator-nuttx/blob/st7789/drivers/lcd/lcd_dev.c#L342-L343
   
   I suppose LVGL runs in User Mode to access `/dev/lcd*`? I'm still 
deciphering the code: 
[lvgldemo.c](https://github.com/lupyuen/incubator-nuttx-apps/blob/st7789/examples/lvgldemo/lvgldemo.c)
   
   UPDATES: Yes LVGL indeed runs in User Mode to access `/dev/lcd0`. See 
[lcddev.c](https://github.com/lupyuen/incubator-nuttx-apps/blob/st7789/examples/lvgldemo/lcddev.c#L48-L51)
   
   There's another GPIO quirk inside the SPI Driver for ESP32: To control the 
ST7789 Data/Command Pin, the SPI Driver flips the MISO Pin as though it was a 
GPIO: 
[esp32c3_board_spi.c](https://github.com/lupyuen/incubator-nuttx/blob/st7789/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_board_spi.c#L64-L84)
   
   ```c
   int esp32c3_spi2_cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool 
cmd) {
         ...
         /*  This is the Data/Command control pad which determines whether the
          *  data bits are data or a command.
          */
         esp32c3_gpiowrite(CONFIG_ESP32C3_SPI2_MISOPIN, !cmd);
   ```
   
   To implement this on BL602 I'm trying to reconfigure MISO as GPIO on the 
fly: 
[bl602_spi.c](https://github.com/lupyuen/incubator-nuttx/blob/st7789/arch/risc-v/src/bl602/bl602_spi.c#L709-L735)
   
   ```c
   static int bl602_spi_cmddata(struct spi_dev_s *dev, uint32_t devid, bool 
cmd) {
     //  MISO is now configured as SPI Pin. We reconfigure MISO as GPIO Pin.
     gpio_pinset_t gpio = 
       (BOARD_SPI_MISO & GPIO_PIN_MASK)  //  Get the pin number
       | GPIO_OUTPUT | GPIO_PULLUP | GPIO_FUNC_SWGPIO;  //  Change to GPIO 
Output
     int ret = bl602_configgpio(gpio);
     ...
     //  Set MISO to High (data) or Low (command)
     bl602_gpiowrite(gpio, !cmd);
   
     //  After this the caller will transmit data or command.
     //  Then bl602_spi_select() will revert MISO back from GPIO to SPI Pin.
     //  We must revert because the SPI Bus may be used by other drivers.
     return OK;
   }
   ```
   
   I'm now testing this with a Logic Analyser. I'm hitting another problem with 
SPI Receive Timeout but I'll explain later: 
   
   https://github.com/lupyuen/incubator-nuttx/pull/39/files
   
   UPDATE: The fix for SPI Receive Timeout is here: 
https://github.com/lupyuen/incubator-nuttx/pull/42


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to