aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpio
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpio')
-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.