diff options
author | 2016-11-10 09:16:35 +0200 | |
---|---|---|
committer | 2016-11-10 09:16:35 +0200 | |
commit | d8b27510426e95470f9579395f50f353bd105d83 (patch) | |
tree | 39d888fe9a25acd96e917486f7db05ded495466c /src/gpio/gpio.c | |
parent | 5abe95c474262dfc0d43cd8fdd5248c9b48a8ecf (diff) | |
download | librin-d8b27510426e95470f9579395f50f353bd105d83.tar.gz librin-d8b27510426e95470f9579395f50f353bd105d83.tar.bz2 librin-d8b27510426e95470f9579395f50f353bd105d83.zip |
gpio: implement some more features.
Diffstat (limited to 'src/gpio/gpio.c')
-rw-r--r-- | src/gpio/gpio.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/gpio/gpio.c b/src/gpio/gpio.c index 45639a3..4c48919 100644 --- a/src/gpio/gpio.c +++ b/src/gpio/gpio.c @@ -118,6 +118,56 @@ unsigned int rin_gpio_readval(const unsigned int num, unsigned int * const val) return 0; } + +unsigned int rin_gpio_writesequence(const struct rin_gpio_dataset * const dataset) +{ + unsigned char *data; + size_t i; + + if (!dataset || !dataset->data) { + return 1; + } + data = dataset->data; + for (i = 0; i < dataset->len; ++i) { + unsigned char a; + unsigned char bit; + + a = data[i / CHAR_BIT]; + bit = !(!(a & (1 << (i % CHAR_BIT)))); + rin_gpio_setval(dataset->signalpin, bit); + rin_gpio_pulse(dataset->clockpin, dataset->pulseduration); + if (dataset->delay) { + nanosleep(dataset->delay, NULL); + } + } + return 0; +} + +unsigned int rin_gpio_on(const unsigned int num) +{ + return rin_gpio_setval(1, num); +} + +unsigned int rin_gpio_off(const unsigned int num) +{ + return rin_gpio_setval(0, num); +} + +unsigned int rin_gpio_pulse(const unsigned int num, const struct timespec * const pulselen) +{ + unsigned int ret; + + ret = rin_gpio_on(num); + if (ret) { + return ret; + } + if (pulselen) { + nanosleep(pulselen, NULL); + } + ret = rin_gpio_off(num); + return ret; +} + /* * right now is rpi V1 specific, should be rewritten when/if we support * other platforms. |