Skip to content
Snippets Groups Projects
Commit d39f1cc7 authored by fortissBot's avatar fortissBot
Browse files

added code for gpio

refs 7890
parent 1f854191
No related branches found
No related tags found
No related merge requests found
#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
......
......@@ -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);
}
......@@ -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} */
......
......@@ -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} */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment