It's originally based on informations I gathered around the 'net at the time, in particular from http://elinux.org/RPi_GPIO_Code_Samples (which borrowed from http://www.pieter-jan.com/node/15 )
This small set of files is a sort of "foundation", I use them for all my RPi projects that interface to the outside world. In no special order and not exhaustively:
- #Mons2015 LED Screen ElectroSuper
- #Rosace
- #Discrete watchdog
- #SPI Flasher
- #Remote buttons over Ethernet cable
- #ReTest-RPi
- #PixelAvenue
- #micro HTTP server in C
- #Electronics Workshops Resources
- #Simon Says learn Pi and IoT
This file is also used as a basis for my compact #C SPI library for Raspberry Pi (and others, later)
It's pretty well tested now, it was published in 2014 (https://boutique.ed-diamond.com/gnulinux-magazine-hors-series/789-gnulinux-magazine-hs-75.html) but the limits are understood as well.
I published it here so I have a stable repository for this cornerstone software, but also to motivate me to support the newer chips, and eventually port it to other architectures.
In 2014 I added the "parachutes" (atexit() calls) which is mostly OK for development but if you need real reliability, use the #Discrete watchdog system.
In 2017 I finally added support for RPi2 and RPi3.
Bonus: 2 dumb example programs and 3 tiny bash scripts that will save your @$$
Note: Direct access to the GPIO pins (as well as detection script) requires the program to run with root rights, or as setuid root. Compilation usually uses this kind of script:
sudo ./detect_GPIO_BASE.sh
gcc $GPIO_BASE -Wall -o program program.c &&\
sudo chown root program &&\
sudo chmod +s program
I know there are new ways to use GPIOs without root (through /dev/gpiomem) but I'm so used to it that I don't bother, since I run hard real-time SW that need other root goodies...
Logs:
1. How to support the Raspberry Pi 2
2. Damned RPi3 !
3. detect_GPIO_BASE.sh is broken again...
.
Here we go again with the latest shiny new Pi :
// Location of peripheral registers in physical memory
#define PI_01_REG_BASE 0x20000000 // Pi Zero or 1
#define PI_23_REG_BASE 0x3F000000 // Pi 2 or 3
#define PI_4_REG_BASE 0xFE000000 // Pi 4