Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

c-periphery

> 编程语言
Open source

A C library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.

1.1K stars0 likes0 views
WebsiteGitHub

About

A C library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.

c-periphery

C Library for Linux Peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial)

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

Examples

GPIO

…

Go to MMIO documentation.

Serial

…

Go to Serial documentation.

Building c-periphery with CMake

Static library

Build c-periphery into a static library:

bash
$ mkdir build
$ cd build
$ cmake ..
$ make

Shared Library

Build c-periphery into a shared library:

bash
$ mkdir build
$ cd build
$ cmake -DBUILD_SHARED_LIBS=ON ..
$ make

Install the shared library and headers:

bash
$ sudo make install

Tests

Build c-periphery tests from the build directory:

bash
$ make tests

Cross-compilation

Set the CC environment variable with the cross-compiler prior to build:

bash
$ export CC=arm-linux-gnueabihf-gcc
$ mkdir build
$ cd build
$ cmake ..
$ make

If additional cross-compiler tools are needed, use a CMAKE_TOOLCHAIN_FILE to fully specify the toolchain parameters:

bash
$ mkdir build
$ cd build
$ cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/arm-linux-gnueabihf.cmake ..
$ make

Building c-periphery with vanilla Make

Static library

Build c-periphery into a static library:

bash
$ make

Tests

Build c-periphery tests:

bash
$ make tests

Cross-compilation

Set the CROSS_COMPILE environment variable with the cross-compiler prefix when building:

bash
$ CROSS_COMPILE=arm-linux-gnueabihf- make

Building c-periphery into another project statically

Include the header files from src/ and link in the periphery.a static library:

bash
$ gcc -I/path/to/periphery/src myprog.c /path/to/periphery/periphery.a -o myprog

Building c-periphery into another project dynamically

If the header files and shared library are installed on the system, simply link with -lperiphery:

bash
$ gcc myprog.c -lperiphery -o myprog

Otherwise, additional include (-I) and library (-L) paths may be required.

Building c-periphery into another project with CMake

Add to project's CMakeLists.txt:

cmake
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)

Documentation

man page style documentation for each interface wrapper is available in docs folder.

Testing

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.

License

c-periphery is MIT licensed. See the included LICENSE file.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言