A C library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
A C library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
c-periphery is a small C library for GPIO, LED, PWM, SPI, I2C, MMIO, and Serial peripheral I/O interface access in userspace Linux. c-periphery simplifies and consolidates the native Linux APIs to these interfaces. c-periphery is useful in embedded Linux environments (including Raspberry Pi, BeagleBone, etc. platforms) for interfacing with external peripherals. c-periphery is re-entrant, has no dependencies outside the standard C library and Linux, compiles into a static library for easy integration with other projects, and is MIT licensed.
Using Python or Lua? Check out the python-periphery and lua-periphery projects.
Contributed libraries: java-periphery, dart_periphery
……Build c-periphery into a static library:
$ mkdir build
$ cd build
$ cmake ..
$ makeBuild c-periphery into a shared library:
$ mkdir build
$ cd build
$ cmake -DBUILD_SHARED_LIBS=ON ..
$ makeInstall the shared library and headers:
$ sudo make installBuild c-periphery tests from the build directory:
$ make testsSet the CC environment variable with the cross-compiler prior to build:
$ export CC=arm-linux-gnueabihf-gcc
$ mkdir build
$ cd build
$ cmake ..
$ makeIf additional cross-compiler tools are needed, use a CMAKE_TOOLCHAIN_FILE to fully specify the toolchain parameters:
$ mkdir build
$ cd build
$ cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/arm-linux-gnueabihf.cmake ..
$ makeBuild c-periphery into a static library:
$ makeBuild c-periphery tests:
$ make testsSet the CROSS_COMPILE environment variable with the cross-compiler prefix when building:
$ CROSS_COMPILE=arm-linux-gnueabihf- makeInclude the header files from src/ and link in the periphery.a static library:
$ gcc -I/path/to/periphery/src myprog.c /path/to/periphery/periphery.a -o myprogIf the header files and shared library are installed on the system, simply link with -lperiphery:
$ gcc myprog.c -lperiphery -o myprogOtherwise, additional include (-I) and library (-L) paths may be required.
Add to project's CMakeLists.txt:
find_package(periphery REQUIRED)
# If package is installed locally, specify search path explicitly:
# find_package(periphery REQUIRED PATHS )
...
add_executable(YOUR_TARGET src/myprog.c)
target_link_libraries(YOUR_TARGET PRIVATE periphery::periphery)man page style documentation for each interface wrapper is available in docs folder.
The tests located in the tests folder may be run to test the correctness and functionality of c-periphery. Some tests require interactive probing (e.g. with an oscilloscope), the installation of a physical loopback, or the existence of a particular device on a bus. See the usage of each test for more details on the required test setup.
c-periphery is MIT licensed. See the included LICENSE file.
No open issues yet, or sync has not completed.