RPiGpio - Simplifies raspberry pi gpio access
RPiOperant - Example client program demonstrating capabilities
Author: Jesse McClure, Copyright 2014 License: GPLv3 / CC-BY-SA
The RPiGpio program must be run as root - this can be accomplished by launching from init at boot. A systemd service file is included for distros which use systemd (e.g., ArchlinuxARM).
RPiGpio creates to user-accessible fifo pipes in /tmp, one for send messages to RPiGpio to change pin settings (change outputs) and the other for receiving events from RPiGpio (inputs).
Interaction with these fifos can be handled by using the constants and inline functions defined in RPiGpio.h (for compiled client programs) or RPiGPio.sh (for shell script clients - this is not yet tested and may not currently work as RPiGpio requires a process have the event fifo open for reading before it proceeds). RPiOperant provides an example of a compiled client for song-preference test for songbirds using RPiGpio.c.
The constants, macros, and functions available are as follows:
- RPiPinMask
- bitwise *and* with a message to get a pin fit-field that the message applies to.
- RPiMsgMask
- bitwise *and* with a message to get the message type. Note that this is not likely of use for client programs.
- RPiMsgSetOff
- bitwise *or* with your message to turn off outputs
- RPiMsgSetOn
- bitwise *or* with your message to turn on outputs
- RPiMsgQueryState
- bitwise *or* with your message to query the state of all pins
- RPiMsgInit
- must be the first message sent when a client program starts. Bitwise *or* any pin numbers that are to be used as inputs, otherwise all pins default to being outputs.
- RPiMsgStop
- send this message before shutting down a client program.
NOTE: descriptions for the following coming soon
RPiEventMask RPiEventError RPiEventChange RPiEventState RPiEventUnused
RPiDetailMask RPiExported RPiDirection RPiFatalError
RPiPin(x)
open_gpio(); void close_gpio();
int check_event(int sec, int usec); flush_events();
void send_msg(int msg);
Client programs should do the following:
- call open_gpio (compiled clients only)
- call send_msg passing a RPiMsgInit message bitwise-or'ed with an RPiPin(pin) for every pin to be used as an input.
- The following may be used as needed:
- Send message:
- RPiMsgStateOn/Off bitwise-or'ed with any RPiPin(num) you wish to turn on/off. Multiple output pins can be specified.
- RPiMsgQueryState to trigger a response with the state of ever pin.
- Handle events:
- call check_event with a limit of seconds and/or useconds which will be used as the timeout value for a select() read. The return value will be an integer bitfield specifying an event or error message.
- call flush_events to discard any messages currently in the queue. (not implemented in RPiGpio.sh yet)
- Send message:
- call send_msg with a RPiMsgStop message
- call close_gpio (compiled clients only)