vsergeev / c-periphery Goto Github PK
View Code? Open in Web Editor NEWA C library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
License: MIT License
A C library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
License: MIT License
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.
Hi, I created static library .so from your dynamic a. library for control GPIO via python script. But discrete output not operates in Jetson Nano (SPI works), maybe Jetson nano some specific ?
https://github.com/Ildaron/EEG-with-JetsonNano/tree/master/GUI
Exactly same code works in Raspbian without any problems.
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
libgpiod has the ability to add a line consumer, so when you open a line you can give it a name. This makes it handy for other apps to see what has that line open. https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/lib/core.c#n427
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?
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).
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;
}
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;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 ?
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.
I noticed this while browsing the gpio.h source. You use it here
Line 991 in 2379567
/**
* 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;
};
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.
The attached patch fixes a build failure of c-periphery with the musl C library.
GPIO test failed at test_loopback.
Built with yocto for a BeagleBone Black.
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?
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,
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);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do you have any plans to implement serial_readline() with configurable newline character and a timeout? It should be a nice feature in your useful c-periphery libs.
int gpio_set_bias(gpio_t *gpio, gpio_bias_t edge);
Change from edge to bias like getter,
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;
}
This is for pull up, pull down, etc. https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/lib/core.c#n374
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?
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?
I need to know wether this Library depends on RT_PREEMPT.
Couldn't find anything in the docs.
Hello!
have you implemented the ADC (analog inputs) in your code too?
Hello, I'm using deabian system with linux kernel version 4.4, I tried to open gpio by calling the gpio_open_sysfs() API, but returned "Invalid argument", did I called the wrong API? I'm sure the pin sysfs number is correct.
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;
^
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.