resyfer opened a new pull request, #18499:
URL: https://github.com/apache/nuttx/pull/18499

   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
   This PR includes support for input and output on all GPIO pins available on 
the RPi 4B, an improvement over the existing single hardcoded GPIO input pin 
and harcoded GPIO output pin.
   
   In the process it also modifies the KConfig in a way that allows the user 
highest degree of customization (as long as allowed) but also does not 
sacrifice maintainability.
   
   Further, this is the first PR in a series of future PRs I'll be doing on 
this board to help provide support for as many features as I can.
   
   ## Impact
   
   You can use any GPIO pin available on the board's headers for input and 
output.
   
   ## Testing
   
   I've tested the output functionality of every pin using a custom blink LED 
application that uses the registered GPIO driver for a pin. I executed it on 
each GPIO port possible in turn, verified both the GPIO registers (by getting 
the value from the GPIO register) and an actual LED connected to the pin(s). 
Further, I ensured no other pins act as an output, so enabling one, due to any 
bug, accidentally enable another.
   
   I've not tested the input yet, as it's the similar and the testing is quite 
manual. However, if needed, I can arrange for testing that as well.
   
   Blink application:
   ```c
   #include <sys/ioctl.h>
   #include <stdio.h>
   #include <fcntl.h>
   #include <nuttx/ioexpander/gpio.h>
   
   void print_all_gpios(void)
   {
        bool val = false;
        int ret = OK;
   
        printf("===========================\n");
   
        for(int i = 0; i <= 27; i++)
                {
                        char dev[30];
   
                        sprintf(dev, "/dev/gpio%d", i);
   
                        int fd = open(dev, O_RDWR);
                        if (fd < 0)
                        {
                                printf("GPIO %d:\tCould not open fd.\n", i);
                                continue;
                        }
   
                        ret = ioctl(fd, GPIOC_READ, (unsigned long)((uintptr_t) 
&val));
                        if (ret != OK)
                                {
                                        printf("GPIO %d:\tBad return (%d)\n", 
i, ret);
                                        ret = OK;
                                }
                        else
                                {
                                        printf("GPIO %d:\t%d\n", i, val);
                                        val = -1;
                                }
   
                        close(fd);
                }
   
        printf("===========================\n");
   }
   
   int main(int argc, char** argv) {
        int ret = OK;
        int fd;
        const char *dev = argv[1];
   
        fd = open(dev, O_RDWR);
        if (predict_false(fd < 0))
                {
                        ret = 1;
                        printf("Could not open %s", dev);
                        goto errout;
                }
   
        for(; ;) {
                ret = ioctl(fd, GPIOC_WRITE, (unsigned long) 1);
                if (predict_false(ret < 0))
                {
                        goto errout_with_fd;
                }
   
                sleep(1);
   
                print_all_gpios();
   
                sleep(1);
   
                ret = ioctl(fd, GPIOC_WRITE, (unsigned long) 0);
                if (predict_false(ret < 0))
                {
                        goto errout_with_fd;
                }
   
                sleep(2);
        }
   
        close(fd);
        return ret;
   
   errout_with_fd:
        close(fd);
   
   errout:
        return ret;
   }
   
   ```


-- 
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]

Reply via email to