aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2016-11-10 09:16:35 +0200
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2016-11-10 09:16:35 +0200
commitd8b27510426e95470f9579395f50f353bd105d83 (patch)
tree39d888fe9a25acd96e917486f7db05ded495466c /src
parent5abe95c474262dfc0d43cd8fdd5248c9b48a8ecf (diff)
downloadlibrin-d8b27510426e95470f9579395f50f353bd105d83.tar.gz
librin-d8b27510426e95470f9579395f50f353bd105d83.tar.bz2
librin-d8b27510426e95470f9579395f50f353bd105d83.zip
gpio: implement some more features.
Diffstat (limited to 'src')
-rw-r--r--src/gpio/gpio.c50
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.