OpenBSD: GPIO with the I2C device PCF8574(A)
#1
Currently the ROCK64 GPIO cannot used in userland. (I currently working on it.)

So I have written a driver for the good old PCF8574 from NXP.
You can find the driver on my Github page:

Additional drivers for OpenBSD

To use the PCF8574, add this to the device trees (Example):

Code:
/dts-v1/;
/include/ "rk3328-rock64.dts"

&i2c0 {
   status = "okay";

   pcf8574: gpio@20 {
       compatible = "nxp,pcf8574";
       status = "okay";
       reg = <0x20>;
       #gpio-cells = <2>;
       gpio-controller;
   };
};

Configuration of the Kernel (add the following):

Code:
pcfgpio*    at iic?
gpio*       at pcfgpio?

Compile the kernel.

dmesg output from my driver:

Code:
pcfgpio0 at iic0 addr 0x20
gpio0 at pcfgpio0: 8 pins



Use the driver with gpioctl:

Code:
$ gpioctl /dev/gpio0 0 on
Turns pin 0 to on.



Use the driver with ioctls (simple running light example):

Code:
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/gpio.h>
#include <sys/ioctl.h>

int main(int argc, char *argv[])
{
   int i, fd;
   int ret;
   struct gpio_info ginfo;
   struct gpio_pin_op gop;
   
   if (argc < 2) {
       printf("usage: gpio [DEV]\n");
       return 1;
   }

   fd = open(argv[1], O_RDWR);

   if (fd == -1) {
       printf("error: couldn't open file (%s)\n", strerror(errno));
       return 1;
   }

   ret = ioctl(fd, GPIOINFO, &ginfo);

   if (ret == -1) {
       printf("error: ioctl GPIOINFO failed (%s)\n", strerror(errno));
       close(fd);
       return 1;
   }

   printf("gpio: Number of pins: %d\n", ginfo.gpio_npins);

   while (1) {
       for (i = 0; i < ginfo.gpio_npins; i++) {
           gop.gp_pin = i;
           gop.gp_value = GPIO_PIN_HIGH;
           ret = ioctl(fd, GPIOPINWRITE, &gop);

           if (ret == -1) {
               printf("error: ioctl GPIOPINWRITE failed (%s)\n", strerror(errno));
               close(fd);
               return 1;
           }

           sleep(1);
           gop.gp_value = GPIO_PIN_LOW;
           ret = ioctl(fd, GPIOPINWRITE, &gop);

           if (ret == -1) {
               printf("error: ioctl GPIOPINWRITE failed (%s)\n", strerror(errno));
               close(fd);
               return 1;
           }
       }
   }

   close(fd);
   return 0;
}
  Reply


Messages In This Thread
OpenBSD: GPIO with the I2C device PCF8574(A) - by krjdev - 08-09-2018, 06:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tutorial: Install OpenBSD on ROCK64 media board krjdev 31 49,670 04-29-2023, 04:32 AM
Last Post: newestssd
  OpenBSD 6.7 microSD card image krjdev 4 9,917 05-31-2020, 12:46 PM
Last Post: krjdev
  Rock64 ethernet not working during install OpenBSD Enig123 4 7,840 05-25-2020, 02:29 PM
Last Post: Enig123
  AMENDED: OpenBSD, GigE Adapters/Chipsets, and ROCK64 STEREO AUDIO DAC ADD-ON BOARD jovval 1 4,764 08-07-2018, 02:44 AM
Last Post: krjdev

Forum Jump:


Users browsing this thread: 1 Guest(s)