Private
Public Access
2
0

maa: change the linking of maa and make gpio functions match maa_ spec

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2014-04-27 23:11:31 +01:00
parent a28d538321
commit ed0a1f6085
14 changed files with 79 additions and 57 deletions

View File

@@ -29,60 +29,57 @@
#include "gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
static int
gpio_get_valfp(gpio_t *gpio)
maa_gpio_get_valfp(gpio_t *gpio)
{
char bu[64];
sprintf(bu, "/sys/class/gpio/gpio%d/value", gpio->pin);
if((gpio->value_fp = fopen(bu, "r+b")) == NULL) {
if ((gpio->value_fp = fopen(bu, "r+b")) == NULL) {
return 1;
}
return 0;
}
void
gpio_init(gpio_t *gpio, int pin)
maa_result_t
maa_gpio_init(gpio_t *gpio, int pin)
{
FILE *export_f;
if((export_f = fopen("/sys/class/gpio/export", "w")) == NULL) {
if ((export_f = fopen("/sys/class/gpio/export", "w")) == NULL) {
fprintf(stderr, "Failed to open export for writing!\n");
} else {
fprintf(export_f, "%d", pin);
fclose(export_f);
}
gpio->pin = pin;
return MAA_SUCCESS;
}
int
gpio_set(int pin)
maa_gpio_set(int pin)
{
//Stuff
return 0;
}
void
gpio_mode(gpio_t *gpio, gpio_mode_t mode)
maa_gpio_mode(gpio_t *gpio, gpio_mode_t mode)
{
//gpio->pin
}
void
gpio_dir(gpio_t *gpio, gpio_dir_t dir)
maa_gpio_dir(gpio_t *gpio, gpio_dir_t dir)
{
if(gpio->value_fp != NULL) {
if (gpio->value_fp != NULL) {
gpio->value_fp = NULL;
}
char filepath[64];
snprintf(filepath, 64, "/sys/class/gpio/gpio%d/direction", gpio->pin);
FILE *direction;
if((direction = fopen(filepath, "w")) == NULL) {
if ((direction = fopen(filepath, "w")) == NULL) {
fprintf(stderr, "Failed to open direction for writing!\n");
} else {
fprintf(direction, dir);
@@ -92,10 +89,10 @@ gpio_dir(gpio_t *gpio, gpio_dir_t dir)
}
int
gpio_read(gpio_t *gpio)
maa_gpio_read(gpio_t *gpio)
{
if(gpio->value_fp == NULL) {
gpio_get_valfp(gpio);
if (gpio->value_fp == NULL) {
maa_gpio_get_valfp(gpio);
}
fseek(gpio->value_fp, SEEK_SET, 0);
char buffer[2];
@@ -105,10 +102,10 @@ gpio_read(gpio_t *gpio)
}
void
gpio_write(gpio_t *gpio, int value)
maa_gpio_write(gpio_t *gpio, int value)
{
if(gpio->value_fp == NULL) {
gpio_get_valfp(gpio);
if (gpio->value_fp == NULL) {
maa_gpio_get_valfp(gpio);
}
fseek(gpio->value_fp, SEEK_SET, 0);
fprintf(gpio->value_fp, "%d", value);
@@ -117,18 +114,14 @@ gpio_write(gpio_t *gpio, int value)
}
void
gpio_close(gpio_t *gpio)
maa_gpio_close(gpio_t *gpio)
{
FILE *unexport_f;
if((unexport_f = fopen("/sys/class/gpio/unexport", "w")) == NULL) {
if ((unexport_f = fopen("/sys/class/gpio/unexport", "w")) == NULL) {
fprintf(stderr, "Failed to open unexport for writing!\n");
} else {
fprintf(unexport_f, "%d", gpio->pin);
fclose(unexport_f);
}
}
#ifdef __cplusplus
}
#endif