[Nov 13] Slackware Aarch64 Miniroot & XFCE (20181101) / NextCloudPi (11-04-18) / Armbian Debian Stretch Desktop & Armbian Ubuntu Bionic (5.65) - Rock64 |[Nov 12] Q4OS ( 2.4-r5) - 1080P Pinebook / Pinebook |[Nov 09] KDE Neon ( 20181104-1500) - 1080P Pinebook / Pinebook /Arch Linux (20181104) - Pinebook |[Nov 09]Arch Linux (20181104) /Armbian - Xenial (5.56) - PineA64-LTS / SOPINE |[Nov 09]Armbian (5.65) /Arch Linux (20181104) /motionEyeOS (20180627) - PINE A64(+) |[Nov 02] Volumio ( 2.462-2018-09-29) - Rock64 |[Oct 23] AOSC with Mate Desktop [20181016] - Pinebook / Q4OS (2.6-r3) - Pinebook

Project Inspiration | Get Started | IRC Logs | Forum Rules/Policy


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: [email protected] {
       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


Possibly Related Threads...
Thread Author Replies Views Last Post
  Tutorial: Install OpenBSD on ROCK64 media board krjdev 16 2,397 09-13-2018, 03:16 PM
Last Post: OpenBSDQuestion
  AMENDED: OpenBSD, GigE Adapters/Chipsets, and ROCK64 STEREO AUDIO DAC ADD-ON BOARD jovval 1 145 08-07-2018, 02:44 AM
Last Post: krjdev

Forum Jump:


Users browsing this thread: 1 Guest(s)