PIO

The PIO module gives access to the pins including reading, writing, and configuring the direction register. The PIO module does not allow the pin to be configured for another function (such as UART TX).

The following is an example of how to use the PIO in an OS environment:

#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <dev/pio.h>

int pio_example(){
     int fd;
     pio_attr_t attr;
     pio_action_t action;

     fd = open("/dev/pio0", O_RDWR);
     if ( fd < 0 ){
          printf("Error opening peripheral (%d)\n", errno);
     } else {

     attr.output = (1<<1)|(1<<0);
     attr.input = 0;
     //this will configure pins 0 and 1 of PIO Port 0 as outputs
     if ( ioctl(fd, I_PIO_SETATTR, &attr) < 0 ){
          printf("Failed to configure peripheral pins (%d)\n", errno);
     }

     //this will set pin 0 of PIO Port 0
     if ( ioctl(fd, I_PIO_SETMASK, (void*)((1<<0))) ){
          printf("Failed to set pin (%d)\n", errno);
     }

     //this will clear pin 1 of PIO 0
     if ( ioctl(fd, I_PIO_CLRMASK, (void*)((1<<1))) ){
          printf("Failed to clear pin (%d)\n", errno);
     }

     }
     close(fd);
     return 0;
}

Details

define PIO_VERSION

define PIO_IOC_IDENT_CHAR

define I_PIO_GETVERSION

define I_PIO_GETINFO

define I_PIO_SETATTR

define I_PIO_SETACTION

define I_PIO_SETMASK

This request sets the pins that are sets in the mask. The ctl argument is the mask. The following code sets bits 0 to 4 on port 4:

pio_fd = open("/dev/pio4", O_RDWR");
ioctl(pio_fd, I_PIO_SETMASK, 0x0F);

define I_PIO_SET_MASK

define I_PIO_CLRMASK

This request clears the pins that are set in the mask. The ctl argument is the mask. This request works like I_PIO_SETMASK but instead of setting pins, they are cleared.

Example:

ioctl(pio_fd, I_PIO_CLRMASK, 0x0F);

define I_PIO_CLR_MASK

define I_PIO_GET

This request sets the action to take when an event occurs on a PIO port. The ctl argument should be of the form void (*callback)(int) where the “int” argument will have a bit set for each pin that has a pending event.

Example:

  • cpp uint32_t value; ioctl(pio_fd, I_PIO_GET, &value);

define I_PIO_SET

This request sets the action to take when an event occurs on a PIO port. The ctl argument should be of the form void (*callback)(int) where the “int” argument will have a bit set for each pin that has a pending event.

Example:

  • cpp uint32_t value; ioctl(pio_fd, I_PIO_SET, value);

define I_PIO_TOTAL

enum pio_flag_t
  • PIO_FLAG_SET_INPUT Configure the pin as an input
  • PIO_FLAG_SET_OUTPUT Configure the pin as an output
  • PIO_FLAG_IS_PULLUP Use the built-in pullup
  • PIO_FLAG_IS_PULLDOWN Use the built-in pull-down
  • PIO_FLAG_IS_REPEATER Use the built-in repeater function
  • PIO_FLAG_IS_FLOAT Leave the pin floating
  • PIO_FLAG_IS_SPEED_LOW Max speed 2Mhz (stm32f only)
  • PIO_FLAG_IS_SPEED_MEDIUM Add fast mode slew rate
  • PIO_FLAG_IS_SPEED_HIGH Max speed 10Mhz (stm32f only)
  • PIO_FLAG_IS_SPEED_BLAZING Max speed 50Mhz (stm32f only)
  • PIO_FLAG_IS_OPENDRAIN Configure as open drain
  • PIO_FLAG_IS_HYSTERESIS Enable hysteresis on pin
  • PIO_FLAG_IS_DIRONLY Only set input/output (ignore other settings)
  • PIO_FLAG_IS_ANALOG Use an analog rather than digital input
  • PIO_FLAG_IS_INVERT Invert the logic on the pin
  • PIO_FLAG_IS_FILTER Filter noise on pin
  • PIO_FLAG_SET Set the bits in the mask
  • PIO_FLAG_CLEAR Clear the bits in the mask
  • PIO_FLAG_ASSIGN Assign the pinmask value to the port

struct::pio_info_t

u32 o_flags

u32 o_events

u32 resd

struct::pio_attr_t

u32 o_flags

u32 o_pinmask

u32 resd

X

Thanks for Coming!

Subscribe to news and updates