diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/GPIO.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/GPIO.h index f3b686b671a445d44547fc905225daba2fff7fbe..c2d81c8e51dbc82f7b13fe24ede124ea810df1fd 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/GPIO.h +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/GPIO.h @@ -1,6 +1,7 @@ #ifndef __GPIO_H #define __GPIO_H +#include <wiringPi.h> #include "inc-gen/data_dictionary.h" // types @@ -8,6 +9,8 @@ typedef int GPIO_PIN_T; // init, term void gpio_init(GPIO_PIN_T pin); +void gpio_init_in(GPIO_PIN_T pin); +void gpio_init_out(GPIO_PIN_T pin); void gpio_term(GPIO_PIN_T pin); // noval diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c index e6ddf63a2a458b53b13db75dbcc796ceff27a975..a04192d7ccea68cecfbf6aa4d0b7b4702189e910 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c @@ -8,8 +8,24 @@ void gpio_init(GPIO_PIN_T pin) { // important, since all pins are accessing the same method if(gpio_initialized) return; + if(wiringPiSetup() == -1) { + perror("cannot setup wiring pi\n"); + return; + } + gpio_initialized = true; - // TODO initialize... +} + +void gpio_init_in(GPIO_PIN_T pin) { + gpio_init(pin); + + pinMode(pin, INPUT); +} + +void gpio_init_out(GPIO_PIN_T pin) { + gpio_init(pin); + + pinMode(pin, OUTPUT); } void gpio_term(GPIO_PIN_T pin) { @@ -30,11 +46,11 @@ void gpio_set_noval(GPIO_PIN_T pin) { // readers GEN_TYPE_boolean gpio_read(GPIO_PIN_T pin) { - return false; + return digitalRead(pin); } // writers void gpio_write(GPIO_PIN_T pin, GEN_TYPE_boolean value) { - + digitalWrite(pin, value); } diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/GPIExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/GPIExecutable.java index 24fb61a8c1aa26847833bff7e6d2600c54c5ec8d..5d6b311db416fdc8b9cd6301069b8e526afe0058 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/GPIExecutable.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/GPIExecutable.java @@ -46,7 +46,7 @@ public class GPIExecutable extends GenericReceiverExecutable { /** {@inheritDoc} */ @Override public IExpressionTerm getInitialization() { - return funcCall("gpio_init", intConst(getPinFromModelElement(modelElement))); + return funcCall("gpio_init_in", intConst(getPinFromModelElement(modelElement))); } /** {@inheritDoc} */ diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/GPOExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/GPOExecutable.java index a7c689ae7d2df563305661e4b74360436809605b..a64a68c0eecb5bae7c02ff61790f039bf3fb43ab 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/GPOExecutable.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/GPOExecutable.java @@ -46,7 +46,7 @@ public class GPOExecutable extends GenericTransmitterExecutable { /** {@inheritDoc} */ @Override public IExpressionTerm getInitialization() { - return funcCall("gpio_init", intConst(getPinFromModelElement(modelElement))); + return funcCall("gpio_init_out", intConst(getPinFromModelElement(modelElement))); } /** {@inheritDoc} */