linguini1 commented on code in PR #18951:
URL: https://github.com/apache/nuttx/pull/18951#discussion_r3295227555
##########
Documentation/platforms/sim/sim_ft2232h_gpio.rst:
##########
@@ -0,0 +1,218 @@
+=======================================
+Sim FT2232 GPIO Driver (Using libftdi1)
+=======================================
+
+Overview
+========
+
+The NuttX simulation (sim) already has a GPIO Chip driver that provides a
mechanism use GPIO to control external devices. However that solution depends
on having a driver to Linux side and that adds more overhead.
+
+This FT2232H driver allows a direct use of libftdi1 to control up to 8 GPIOs.
+
+This driver is particularly useful for:
+
+- Testing GPIO-based applications in a simulated environment with real hardware
+- Interfacing with USB-to-GPIO adapters from NuttX simulation
+- Developing and debugging GPIO drivers without dedicated embedded hardware
+
+Host Prepare
+============
+
+Preparation required on the host side:
+
+- Hardware module required: FT2232H module like the CJMCU-2232HL module
+- A udev rule on Linux side to avoid using the FT2232H as USB/Serial:
+
+.. code-block:: console
+
+ $ cat /etc/udev/rules.d/99-ft2232h-d2xx.rules
+ ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ATTRS{product}=="FTDI
Device", MODE="0666"
+
+- The libftdi1-dev installed on your system.
+
+Architecture
+============
+
+The driver consists of two layers:
+
+1. **NuttX Layer** (``sim_ft2232h_ioexpander.c``): Implements the NuttX
``ioexpander_dev_s``
+ interface, providing standard GPIO operations to upper-layer NuttX drivers.
+
+2. **Host Layer** (``sim_ft2232h.c``): Interfaces directly with libftdio1 to
initialize and to provide the functions to control the GPIOs.
+
+::
+
+ +---------------------+
+ | NuttX Application |
+ +---------------------+
+ |
+ v
+ +---------------------+
+ | GPIO Lower Half |
+ | (gpio_lower_half) |
+ +---------------------+
+ |
+ v
+ +---------------------+
+ | sim_ft2232h_ioex...c| <-- NuttX ioexpander interface
+ | (ioexpander_dev_s) |
+ +---------------------+
+ |
+ v
+ +---------------------+
+ | sim_ft2232h.c | <-- Linux host GPIO interface
+ | (host interface) |
+ +---------------------+
+ |
+ v
+ +---------------------+
+ | libftdi1 | <-- Linux library to control FT2232H
+ +---------------------+
+
+Header Files
+============
+
+- ``arch/sim/src/sim/sim_ft2232h_ioexpander.h``: Host GPIO chip interface
definitions and function prototypes.
+
+- ``include/nuttx/ioexpander/ioexpander.h``: Standard NuttX IO expander
interface.
+
+- ``include/nuttx/ioexpander/gpio.h``: NuttX GPIO interface definitions.
+
+Configuration Options
+=====================
+
+The following configuration options are relevant to this driver:
+
+- ``CONFIG_SIM_FT2232H``: Enable the FT2232H driver support.
+- ``CONFIG_SIM_FT2232H_GPIO``: Enable the sim GPIO chip driver.
+
+Supported Operations
+====================
+
+The driver supports the following GPIO operations:
+
+Direction Control
+-----------------
+
+.. code-block:: c
+
+ int sim_ft2232h_gpio_direction(struct ioexpander_dev_s *dev,
+ uint8_t pin, int direction);
+
+Set GPIO pin direction. Supported directions:
+
+- ``IOEXPANDER_DIRECTION_IN``: Configure as input
+- ``IOEXPANDER_DIRECTION_OUT``: Configure as output
+- ``IOEXPANDER_DIRECTION_OUT_OPENDRAIN``: Configure as open-drain output
+
+Read/Write Pin
+--------------
+
+.. code-block:: c
+
+ int sim_ft2232h_gpio_readpin(struct ioexpander_dev_s *dev, uint8_t pin,
+ bool *value);
+ int sim_ft2232h_gpio_writepin(struct ioexpander_dev_s *dev, uint8_t pin,
+ bool value);
+
+Read or write the value of a GPIO pin.
+
+Host Layer API
+==============
+
+The host layer (``sim_ft2232h.c``) provides the following functions:
+
+.. code-block:: c
+
+ /* Allocate and initialize a host GPIO chip device */
+ struct host_ft2232h_gpio_dev *host_ft2232h_gpio_alloc(const char *filename);
+
+ /* Free a host GPIO chip device */
+ void host_ft2232h_gpio_free(struct host_ft2232h_gpio_dev *dev);
+
+ /* Set GPIO pin direction */
+ int host_ft2232h_gpio_direction(struct host_ft2232h_gpio_dev *dev,
+ uint8_t pin, bool input);
+
+ /* Read GPIO pin value */
+ int host_ft2232h_gpio_readpin(struct host_ft2232h_gpio_dev *dev,
+ uint8_t pin, bool *value);
+
+ /* Write GPIO pin value */
+ int host_ft2232h_gpio_writepin(struct host_ft2232h_gpio_dev *dev,
+ uint8_t pin, bool value);
+
+ /* Request GPIO interrupt */
+ int host_ft2232h_gpio_irq_request(struct host_ft2232h_gpio_dev *dev,
+ uint8_t pin, uint16_t cfgset);
+
+ /* Check if GPIO interrupt is active */
+ bool host_ft2232h_gpio_irq_active(struct host_ft2232h_gpio_dev *dev,
uint8_t pin);
+
+ /* Get GPIO line information */
+ int host_ft2232h_gpio_get_line(struct host_ft2232h_gpio_dev *priv,
+ uint8_t pin, bool *input);
+
+Linux Kernel Version Requirements
+=================================
+
+The driver uses Linux GPIO v2 ABI, which requires:
+
+- **Linux kernel >= 6.8.0**: Full functionality with GPIO v2 API support.
+- **Linux kernel < 6.8.0**: The driver compiles but provides stub
implementations
+ that return 0 or NULL.
+
+Usage Example
+=============
+
+Initialization
+--------------
+
+Application Usage
+-----------------
+
+After initialization, GPIO pins can be accessed through standard NuttX GPIO
interface:
+
+.. code-block:: c
+
+ #include <fcntl.h>
+ #include <sys/ioctl.h>
+ #include <nuttx/ioexpander/gpio.h>
+
+ int main(void)
+ {
+ int fd;
+ bool value;
+
+ /* Open GPIO device */
+ fd = open("/dev/gpio20", O_RD);
+ if (fd < 0)
+ {
+ return -1;
+ }
+
+ /* Read GPIO value */
+ ioctl(fd, GPIOC_READ, &value);
+ printf("GPIO value: %d\n", value);
+
+ close(fd);
+ return 0;
+ }
+
+Files
+=====
+
+- ``arch/sim/src/sim/sim_ft2232h_ioexpander.c``: NuttX IO expander
implementation
+- ``arch/sim/src/sim/posix/sim_ft2232h.c``: Linux host GPIO interface
+- ``arch/sim/src/sim/sim_ft2232h_ioxpander.h``: Host GPIO chip header file
Review Comment:
Probably don't need to mention this.
##########
Documentation/platforms/sim/sim_ft2232h_gpio.rst:
##########
@@ -0,0 +1,218 @@
+=======================================
+Sim FT2232 GPIO Driver (Using libftdi1)
+=======================================
+
+Overview
+========
+
+The NuttX simulation (sim) already has a GPIO Chip driver that provides a
mechanism use GPIO to control external devices. However that solution depends
on having a driver to Linux side and that adds more overhead.
+
+This FT2232H driver allows a direct use of libftdi1 to control up to 8 GPIOs.
+
+This driver is particularly useful for:
+
+- Testing GPIO-based applications in a simulated environment with real hardware
+- Interfacing with USB-to-GPIO adapters from NuttX simulation
+- Developing and debugging GPIO drivers without dedicated embedded hardware
+
+Host Prepare
+============
+
+Preparation required on the host side:
+
+- Hardware module required: FT2232H module like the CJMCU-2232HL module
+- A udev rule on Linux side to avoid using the FT2232H as USB/Serial:
+
+.. code-block:: console
+
+ $ cat /etc/udev/rules.d/99-ft2232h-d2xx.rules
+ ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ATTRS{product}=="FTDI
Device", MODE="0666"
+
+- The libftdi1-dev installed on your system.
+
+Architecture
+============
+
+The driver consists of two layers:
+
+1. **NuttX Layer** (``sim_ft2232h_ioexpander.c``): Implements the NuttX
``ioexpander_dev_s``
+ interface, providing standard GPIO operations to upper-layer NuttX drivers.
+
+2. **Host Layer** (``sim_ft2232h.c``): Interfaces directly with libftdio1 to
initialize and to provide the functions to control the GPIOs.
+
+::
+
+ +---------------------+
+ | NuttX Application |
+ +---------------------+
+ |
+ v
+ +---------------------+
+ | GPIO Lower Half |
+ | (gpio_lower_half) |
+ +---------------------+
+ |
+ v
+ +---------------------+
+ | sim_ft2232h_ioex...c| <-- NuttX ioexpander interface
+ | (ioexpander_dev_s) |
+ +---------------------+
+ |
+ v
+ +---------------------+
+ | sim_ft2232h.c | <-- Linux host GPIO interface
+ | (host interface) |
+ +---------------------+
+ |
+ v
+ +---------------------+
+ | libftdi1 | <-- Linux library to control FT2232H
+ +---------------------+
Review Comment:
You can use the plantuml plugin instead!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]