GithubHelp home page GithubHelp logo

vsergeev / c-periphery Goto Github PK

View Code? Open in Web Editor NEW
680.0 680.0 212.0 255 KB

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

License: MIT License

Makefile 0.85% C 97.88% CMake 1.28%

c-periphery's Introduction

Primary

  • luaradio - Lightweight, embeddable software-defined radio framework built on LuaJIT
  • zigradio - Lightweight software-defined radio framework built with Zig
  • python-periphery - Pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux
  • lua-periphery - Lua library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux
  • c-periphery - C library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux
  • u-msgpack-python - Portable, lightweight MessagePack serializer and deserializer written in pure Python
  • briefsky - Weather frontend to a variety of weather providers

Software

  • snake.ts - Simple console snake implementation written in TypeScript
  • evolve110 - Rule 110 implementation on the Ethereum blockchain written in Solidity/JavaScript
  • rigexpert-tool - Tool to dump impedance sweeps from RigExpert antenna analyzers written in Python
  • ssterm - Simple console-based serial port terminal written in Python
  • ntgbtminer - No thrills getblocktemplate Bitcoin miner written in Python
  • btckeygenie - Standalone Bitcoin keypair/address generator written in Go
  • template110 - Rule 110 implemented with templates and std::array written in C++11
  • tinytaptunnel - a point-to-point layer 2 tap interface tunnel over UDP/IP written in Go
  • audioprism - Spectrogram tool for PulseAudio and WAV files written in C++11
  • arm-bmw-sw - ARM Bare Metal Widget (arm-bmw) software written in C
  • minifortune - Minimal fortune-mod clone written in C

Hardware/RTL

  • teatimer - Simple kitchen timer implemented in digital logic on a Lattice MachXO2 CPLD
  • arm-bmw-hw - ARM Bare Metal Widget (arm-bmw) hardware
  • wclock - LED Word Clock
  • v8cpu - Simple multi-cycle von Neumann architecture 8-bit CPU in under 500 lines of Verilog
  • wireless-triac - Wireless ZigBee/XBee Controlled TRIAC
  • wireless-power-meter - Wireless ZigBee/XBee V-I Power Meter

3D Models

Presentations

Miscellaneous

  • radio-decoders - Miscellaneous radio demodulator/decoder experiments
  • gardend-lua - Modular, discrete-time control daemon for a hydroponic garden written in Lua
  • yatumblr-backup - Yet another tumblr backup script

Archived

  • libGIS - Library for creating/reading/writing Atmel Generic, Intel HEX8, and Motorola S-Record files
  • libGISdotnet - Port of libGIS to .NET
  • vavrdisasm - 8-bit Atmel AVR disassembler
  • vpicdisasm - Microchip PIC disassembler
  • 0xtrades.info - Real-time trade viewer for the 0x protocol
  • mbed-cmsis - Guide for building your own CMSIS Code for the mbed
  • cmsis-templates - CMSIS v3.20 Bootstrapping Templates for GNU ARM Tools
  • qrd - Simple QR Code decoder for educational purposes

c-periphery's People

Contributors

ffontaine avatar jhlimatplk avatar jorisoffouga avatar oficsu avatar remdzi avatar rjbarnet avatar tpetazzoni avatar vsergeev avatar wangqiang1588 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c-periphery's Issues

Update GPIO code?

I noticed this while browsing the gpio.h source. You use it here

struct gpioevent_data event_data = {0};

/**
 * struct gpioevent_data - The actual event being pushed to userspace
 * @timestamp: best estimate of time of event occurrence, in nanoseconds
 * @id: event identifier
 *
 * Note: This struct is part of ABI v1 and is deprecated.
 * Use &struct gpio_v2_line_event instead.
 */
struct gpioevent_data {
	__u64 timestamp;
	__u32 id;
};

Info in documentation

I need to know wether this Library depends on RT_PREEMPT.
Couldn't find anything in the docs.

PWM functions are hardware PWM ?

Hi,

In this wonderful library, do pwm functions support only hardware pwm ?
I read the pwm.c source code. In the code, we can use pwm_open and that function opens /sys/class/pwm/pwmchipN/export.

So, I think that this library supports hardware pwm.
Is this correct understanding ?
In the Linux kernel, opening /sys/class/pwm/pwmchipN/ directory is default method to control pwm device ?

Unknown CMake command "check_source_compiles" on Debian Bullseye

Hi all,

I'm trying to build this source on a debian bullseye machine without success.
I'm facing the following CMake issue:

CMake Error at src/c-periphery/CMakeLists.txt:12 (check_source_compiles): Unknown CMake command "check_source_compiles".

If I'm not mistaken, this command was only introduced in CMake version 3.19, where Debian bullseye ships with 3.18.4 by default.
Any suggestions on how to go about this? (preferrably without utilizing bullseye-backports version of CMake?)

Thank in advance!
Thierry
Also, the cmake_minimum_required version is currently set at 2.6, which should be upped I think?

SPI R/W REG

Hello,

I am working on a module that use the SPI communication
I should write/read in/from specific registers of this module
My question Is there any example of this issue using this python package ?

Thank you.

Best regards,

test_gpio gpio_set_bias(gpio, GPIO_BIAS_PULL_UP) fails

On a RPi 3B+ with Linux raspberrypi 5.10.17-v7+ #1403 SMP Mon Feb 22 11:29:51 GMT 2021 armv7l GNU/Linux

 ./test_gpio /dev/gpiochip0 17 27
[ OK ]  /home/pi/c-periphery/tests/test_gpio.c test_open_config_close():151  edge == GPIO_EDGE_NONE
 [FAIL]  /home/pi/c-periphery/tests/test_gpio.c test_open_config_close():154  gpio_set_bias(gpio, GPIO_BIAS_PULL_UP) == 0

Fails also for su, not cable connection at this point of the test.
Any idea?

Any plans to expand to add network support?

First off, thank you very much for this library @vsergeev. It is very clean, easy to understand, and easy to use (and actually documented). I don't know of any other C library that supports these basic functions. I know this is called c-periphery for a reason, but are there any plans to add network functions to this (i.e. TCP/UDP, socket open, send, recv, etc.)? I think it could be very useful as you usually need a much larger library (i.e. Qt, Boost.Asio, etc.) to do this reliably.

I could look into a pull request in the future as time allows ... but didn't know if you wanted to merge in such changes. Thanks.

Portage error: make: *** No rule to make target 'install'. Stop.

I want to package c-periphery for Gentoo, but I am getting an error that an installation target doesn't exit.

>>> Emerging (1 of 1) sys-libs/c-periphery-9999::testing
 * sys-libs/c-periphery will not be compiled with PGO.
>>> Unpacking source...
 * Repository id: vsergeev_c-periphery.git
 * To override fetched repository properties, use:
 *   EGIT_OVERRIDE_REPO_VSERGEEV_C_PERIPHERY
 *   EGIT_OVERRIDE_BRANCH_VSERGEEV_C_PERIPHERY
 *   EGIT_OVERRIDE_COMMIT_VSERGEEV_C_PERIPHERY
 *   EGIT_OVERRIDE_COMMIT_DATE_VSERGEEV_C_PERIPHERY
 * 
 * Fetching https://github.com/vsergeev/c-periphery.git ...
git fetch https://github.com/vsergeev/c-periphery.git +HEAD:refs/git-r3/HEAD
git symbolic-ref refs/git-r3/sys-libs/c-periphery/0/__main__ refs/git-r3/HEAD
 * Checking out https://github.com/vsergeev/c-periphery.git to /mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/work/c-periphery-9999 ...
git checkout --quiet refs/git-r3/HEAD
GIT update -->
   repository:               https://github.com/vsergeev/c-periphery.git
   at the commit:            2379567960b9f72ccfb8f9db7271092612e89bdf
>>> Source unpacked in /mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/work
>>> Preparing source in /mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/work/c-periphery-9999 ...
>>> Source prepared.
>>> Configuring source in /mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/work/c-periphery-9999 ...
>>> Source configured.
>>> Compiling source in /mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/work/c-periphery-9999 ...
make -j3 -l2 
mkdir obj
cc -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation  -fPIC -DPERIPHERY_VERSION_COMMIT=\"v2.3.1-1-g2379567\" -DPERIPHERY_GPIO_CDEV_SUPPORT=1 -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--trace -Wl,-z,relro -Wl,-z,now -Wl,--stats -Wl,--print-map -Wl,--hash-style=gnu -Wl,--enable-new-dtags -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -c src/gpio.c -o obj/gpio.o
cc -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation  -fPIC -DPERIPHERY_VERSION_COMMIT=\"v2.3.1-1-g2379567\" -DPERIPHERY_GPIO_CDEV_SUPPORT=1 -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--trace -Wl,-z,relro -Wl,-z,now -Wl,--stats -Wl,--print-map -Wl,--hash-style=gnu -Wl,--enable-new-dtags -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -c src/pwm.c -o obj/pwm.o
cc -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation  -fPIC -DPERIPHERY_VERSION_COMMIT=\"v2.3.1-1-g2379567\" -DPERIPHERY_GPIO_CDEV_SUPPORT=1 -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--trace -Wl,-z,relro -Wl,-z,now -Wl,--stats -Wl,--print-map -Wl,--hash-style=gnu -Wl,--enable-new-dtags -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -c src/spi.c -o obj/spi.o
cc -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation  -fPIC -DPERIPHERY_VERSION_COMMIT=\"v2.3.1-1-g2379567\" -DPERIPHERY_GPIO_CDEV_SUPPORT=1 -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--trace -Wl,-z,relro -Wl,-z,now -Wl,--stats -Wl,--print-map -Wl,--hash-style=gnu -Wl,--enable-new-dtags -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -c src/i2c.c -o obj/i2c.o
cc -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation  -fPIC -DPERIPHERY_VERSION_COMMIT=\"v2.3.1-1-g2379567\" -DPERIPHERY_GPIO_CDEV_SUPPORT=1 -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--trace -Wl,-z,relro -Wl,-z,now -Wl,--stats -Wl,--print-map -Wl,--hash-style=gnu -Wl,--enable-new-dtags -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -c src/mmio.c -o obj/mmio.o
cc -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation  -fPIC -DPERIPHERY_VERSION_COMMIT=\"v2.3.1-1-g2379567\" -DPERIPHERY_GPIO_CDEV_SUPPORT=1 -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--trace -Wl,-z,relro -Wl,-z,now -Wl,--stats -Wl,--print-map -Wl,--hash-style=gnu -Wl,--enable-new-dtags -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -c src/serial.c -o obj/serial.o
cc -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation  -fPIC -DPERIPHERY_VERSION_COMMIT=\"v2.3.1-1-g2379567\" -DPERIPHERY_GPIO_CDEV_SUPPORT=1 -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--trace -Wl,-z,relro -Wl,-z,now -Wl,--stats -Wl,--print-map -Wl,--hash-style=gnu -Wl,--enable-new-dtags -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -c src/version.c -o obj/version.o
cc -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation  -fPIC -DPERIPHERY_VERSION_COMMIT=\"v2.3.1-1-g2379567\" -DPERIPHERY_GPIO_CDEV_SUPPORT=1 -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--trace -Wl,-z,relro -Wl,-z,now -Wl,--stats -Wl,--print-map -Wl,--hash-style=gnu -Wl,--enable-new-dtags -march=native -mprefer-avx128 -mvzeroupper  -frecord-gcc-switches -mno-tbm  -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register  -flto -flto-report -fuse-linker-plugin  -pipe -O2 -c src/led.c -o obj/led.o
ar rcs periphery.a obj/gpio.o obj/led.o obj/pwm.o obj/spi.o obj/i2c.o obj/mmio.o obj/serial.o obj/version.o
>>> Source compiled.
>>> Test phase [not enabled]: sys-libs/c-periphery-9999

>>> Install sys-libs/c-periphery-9999 into /mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/image
make -j3 -l2 DESTDIR=/mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/image install 
make: *** No rule to make target 'install'.  Stop.
 * ERROR: sys-libs/c-periphery-9999::testing failed (install phase):
 *   emake failed
 * 
 * If you need support, post the output of `emerge --info '=sys-libs/c-periphery-9999::testing'`,
 * the complete build log and the output of `emerge -pqv '=sys-libs/c-periphery-9999::testing'`.
 * The complete build log is located at '/var/log/portage/sys-libs:c-periphery-9999:20220611-143939.log'.
 * For convenience, a symlink to the build log is located at '/mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/temp/build.log'.
 * The ebuild environment file is located at '/mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/temp/environment'.
 * Working directory: '/mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/work/c-periphery-9999'
 * S: '/mnt/Volume_3/Gentoo/temp/portage/sys-libs/c-periphery-9999/work/c-periphery-9999'

I am confused since there is an install command in CMakeLists.txt here.[1] What am I missing here?

Thank you for your time.

[1] https://github.com/vsergeev/c-periphery/blob/v2.3.1/CMakeLists.txt#L52

spi.c Error message builder is buggy

Hey all,

I've seen some overflows and other corruption on the SPI error message builder. I've edited it to be the following with much more success. Though, I will admit the initial sizeof(errmsg) at 96 bytes seemed concerning but doing the math between the exact separators and extra strings, 96 bytes is spot on. I didn't track down the corruption I was seeing but replacing the function with the one below works well. I didn't want to do a merge request as I'm sure this edit is opinionated.

static int _spi_error(struct spi_handle *spi, int code, int c_errno, const char *fmt, ...) {
    va_list ap;

    char sep[] = ": ";

    // split buffer access arbitrarily, why not in half?
    char temp1[sizeof(spi->error.errmsg) / 2] = {0};
    char temp2[sizeof(spi->error.errmsg) / 2 - sizeof(sep) - 1] = {0}; // -1 for null terminator

    spi->error.c_errno = c_errno;

    va_start(ap, fmt);
    vsnprintf(temp1, sizeof(temp1), fmt, ap);
    va_end(ap);

    /* Tack on strerror() and errno */
    if (c_errno) {
        // - The most we can do is sizeof(temp2) to not guarantee truncation
        // - The tool `errno` only reports a max used string of 49 bytes:
        //     errno -ls | xargs -L1  | cut -d' ' -f3- | awk '{print length}' | sort -n | tail -1
        // - snprintf will truncate anyway
        // - Put the [errno %d] hint first as any truncation will not remove valuable information
        // - 10 bytes for the extra information, this will be fragile if someone changes the extra
        //     strings, but the compiler warnings will let you know.
        char temp3[sizeof(temp2) - 10] = {0};
        snprintf(temp2, sizeof(temp2), "[errno %d] %s", c_errno, strerror_r(c_errno, temp3, sizeof(temp3)));
    }

    snprintf(spi->error.errmsg, sizeof(spi->error.errmsg),
             "%s%s%s", temp1, sep, temp2);

    return code;
}

GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME missing for Debian 11 x86/x86_64

Version 2.4.1 - no problem to build for Armbian/PI-OS.

Install the headers for the cmake tests
apt install linux-headers-$(uname -r)

Debian 11 runs into following problem.

oot@debian64:/home/pezi/c-periphery/build# cmake ..
-- The C compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for GPIO_V2_LINES_MAX
-- Looking for GPIO_V2_LINES_MAX - found
-- Looking for GPIO_GET_LINEEVENT_IOCTL
-- Looking for GPIO_GET_LINEEVENT_IOCTL - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pezi/c-periphery/build
root@debian64:/home/pezi/c-periphery/build# make
Scanning dependencies of target periphery
[  3%] Building C object CMakeFiles/periphery.dir/src/gpio.c.o
[  7%] Building C object CMakeFiles/periphery.dir/src/gpio_cdev_v1.c.o
[ 10%] Building C object CMakeFiles/periphery.dir/src/gpio_cdev_v2.c.o
/home/pezi/c-periphery/src/gpio_cdev_v2.c: In function ‘_gpio_cdev_reopen’:
/home/pezi/c-periphery/src/gpio_cdev_v2.c:66:45: error: ‘GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME’ undeclared (first use in this function)
   66 |         flags |= (edge != GPIO_EDGE_NONE) ? c : 0;
      |                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

serial_set_parity(serial, PARITY_ODD) fails on RaspiPi3 B+

Running the serial test on a RaspiPi3 B+ fails

pi@raspberrypi:~/c-periphery/build $ ./test_serial /dev/serial0
..
[ OK ]  /home/pi/c-periphery/tests/test_serial.c test_open_config_close():92  serial_set_parity(serial, PARITY_ODD) == 0
 [ OK ]  /home/pi/c-periphery/tests/test_serial.c test_open_config_close():93  serial_get_parity(serial, &parity) == 0
 [FAIL]  /home/pi/c-periphery/tests/test_serial.c test_open_config_close():94  parity == PARITY_ODD
test_serial: /home/pi/c-periphery/tests/test_serial.c:94: test_open_config_close: Assertion `r' failed.

serial_set_parity() doesn't change the parity to PARITY_ODD

Serial description: Serial (fd=9, baudrate=9600, databits=7, parity=none, stopbits=1, xonxoff=false, rtscts=false, vmin=0, vtime=0.0)

Any idea?

How to keep the pin's value

Hi, I really enjoy using this amazing gpio library !

BTW, when I use gpio_write function, it doesn't keep the value.
If I write 1 to the pin connected LED, the LED flashes for a moment.
Is this correct behavior ?
And can I keep the value without sleep() in C code ?

Thanks.

How to set pinmodes to ALT0 in Raspberry pi

Hello,

I am in the process of migrating from wiring pi to c-periphery for my current project. In wiring pi, I am able to set the pin modes to alt0 via pinModeAlt() function to activate SPI hardware capability, does your library provide a way to do this?

Warning in spi.c

Hi!

There is a little warning for int/pointer casting in the spi.c.
Can you fix it to keep the "clean-coding"?

I tried several version of GCC, but all got the same warning. My GCC version is the following:

root@myboard:~/# gcc --version
gcc (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Here is what i got in the GCC warning message.

root@myboard:~/# gcc -pthread src/gpio.c src/spi.c spi_test.c -o spi_test -lm
src/spi.c: In function 'spi_transfer':
src/spi.c:92:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     spi_xfer.tx_buf = (__u64)txbuf;
                       ^
src/spi.c:93:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     spi_xfer.rx_buf = (__u64)rxbuf;
                       ^

Warning spi.c in function 'spi_tostring'

Hi!

There are some "directive" warning in the spi.c.
Can you fix it to keep the "clean-coding"?

c-periphery/src/spi.c: In function 'spi_tostring':
c-periphery/src/spi.c:300:65: warning: '%u' directive output may be truncated writing between 1 and 3 bytes into a region of size 2 [-Wformat-truncation=]
         snprintf(bits_per_word_str, sizeof(bits_per_word_str), "%u", bits_per_word);
                                                                 ^~
c-periphery/src/spi.c:300:64: note: directive argument in the range [0, 255]
         snprintf(bits_per_word_str, sizeof(bits_per_word_str), "%u", bits_per_word);
                                                                ^~~~
c-periphery/src/spi.c:300:9: note: 'snprintf' output between 2 and 4 bytes into a destination of size 2
         snprintf(bits_per_word_str, sizeof(bits_per_word_str), "%u", bits_per_word);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Bias compile settings

I had to use CFLAGS=-DPERIPHERY_GPIO_CDEV_SUPPORT -DGPIOHANDLE_REQUEST_BIAS_PULL_UP -DGPIOHANDLE_REQUEST_BIAS_PULL_DOWN -DGPIOHANDLE_REQUEST_BIAS_DISABLE or I'd get "Kernel version does not support configuring GPIO line bias". Is that the correct way to use bias?

ADC - implemented?

Hello!

have you implemented the ADC (analog inputs) in your code too?

Change param name

int gpio_set_bias(gpio_t *gpio, gpio_bias_t edge);

Change from edge to bias like getter,

Handle allocating on stack

Can you change the handle struct declaration in your .h and .c files for all peripheral gpio, spi, led ... etc? For example if i move struct spi_handle { ... } from spi.c to spi.h i can able to use spi without any spi_new() allocation, so i can allocate it in stack, too in my main. Probably it should be useful and an optional alternative way for small and quick programs. Without this modification in headers the static allocation is not working because there are any declaration error in build.

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include "spi.h"

int main(void) {
    spi_t spi;
    uint8_t buf[4] = { 0xaa, 0xbb, 0xcc, 0xdd };

    // not need in this case
    //spi = spi_new();

    /* Open spidev1.0 with mode 0 and max speed 1MHz */
    if (spi_open(&spi, "/dev/spidev1.0", 0, 1000000) < 0) {
        fprintf(stderr, "spi_open(): %s\n", spi_errmsg(&spi));
        exit(1);
    }

    /* Shift out and in 4 bytes */
    if (spi_transfer(&spi, buf, buf, sizeof(buf)) < 0) {
        fprintf(stderr, "spi_transfer(): %s\n", spi_errmsg(&spi));
        exit(1);
    }

    printf("shifted in: 0x%02x 0x%02x 0x%02x 0x%02x\n", buf[0], buf[1], buf[2], buf[3]);

    spi_close(&spi);

    // not need in this case
    //spi_free(spi);

    return 0;
}

GPIO library doesn't work on devices which don't create "gpioXX" folders

On some microprocessor kernels (such as the Atmel ATSAMA5D4 series), rather than creating a folder names gpioXX to correspond to pin number XX, the name of the folder is the actual "natural" pin name. For example, on the ATSAMA5D4, there are 5 32-bit GPIO banks, A-E. Pin A15 has a pin number 15 (0 * 32 + 15), but the corresponding folder is pioA15. Pin D8 is pin number 104 (3 * 32 + 8) but the corresponding folder is pioD8. Because the c-periphery library is specifically looking for a folder named gpioXX, gpio_open fails and the library basically can't be used on these devices.

Any plans to create a configurable cs_change in spi.c?

Hi!
It would be nice if there be any function or method to configurate spi_xfer.cs_change to 0 or 1.
My embedded board is supporting burst transfer in SPI and i need to change it to 1 manually in source always to use the normal mode (default is 0 in your code which is the burst mode).

Building on Rasberry Pi

Hi,
I have built c-periphery, lua and lua-periphery on Rasberry Pi OS.

When I try to control the led, using the example in the lua-periphery README, I get the following error message:

Opening LED: opening 'brightness': No such file or directory [errno 2]

Additionally, when I try the GPIO example from the same README, I get the following error:

c-periphery library built without character device GPIO support.

I have built basically everything from scratch on the Rasberry Pi itself.

Is there anything I'm missing, any sanity checks, or steps I can take to avoid these error messages?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.