Private
Public Access
2
0

gpio: rework of gpio - using open() for value_fp

* fixes maa_gpio_read by using simple posix file io
* fixes blink sample to have much more error checking
* blink sample now takes an argument

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2014-05-13 15:35:27 +01:00
parent aa60cae49d
commit 126b1314b0
5 changed files with 150 additions and 38 deletions

View File

@@ -1,15 +1,17 @@
add_executable (i2c_HMC5883L i2c_HMC5883L.c)
add_executable (hellomaa hellomaa.c)
add_executable (cycle-pwm3 cycle-pwm3.c)
add_executable (blink-io8 blink-io8.c)
add_executable (blink-io blink-io.c)
add_executable (analogin_a0 analogin_a0.c)
add_executable (isr_pin6 isr_pin6.c)
add_executable (gpio_read6 gpio_read6.c)
include_directories(${PROJECT_SOURCE_DIR}/api ${PROJECT_SOURCE_DIR}/include)
target_link_libraries (hellomaa maa ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (i2c_HMC5883L maa m ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (cycle-pwm3 maa ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (blink-io8 maa ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (blink-io maa ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (analogin_a0 maa ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (isr_pin6 maa ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (gpio_read6 maa ${CMAKE_THREAD_LIBS_INIT})

100
examples/blink-io.c Normal file
View File

@@ -0,0 +1,100 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include "gpio.h"
#define DEFAULT_IOPIN 8
int running = 0;
static int iopin;
void
sig_handler(int signo)
{
if (signo == SIGINT) {
printf("closing IO%d nicely\n", iopin);
running = -1;
}
}
int
main(int argc, char **argv)
{
maa_result_t r = MAA_SUCCESS;
iopin = DEFAULT_IOPIN;
if (argc < 2) {
printf("Provide an int arg if you want to flash on something other than %d\n", DEFAULT_IOPIN);
} else {
iopin = strtol(argv[1], NULL, 10);
}
maa_init();
fprintf(stdout, "MAA Version: %s\nStarting Blinking on IO%d\n",
maa_get_version(), iopin);
maa_gpio_context* gpio;
gpio = maa_gpio_init(iopin);
printf("Initialised pin%d which is atually pin%d\n", iopin, gpio->pin);
// set direction to OUT
r = maa_gpio_dir(gpio, MAA_GPIO_OUT);
if (r != MAA_SUCCESS) {
maa_result_print(r);
}
signal(SIGINT, sig_handler);
while (running == 0) {
r = maa_gpio_write(gpio, 0);
if (r != MAA_SUCCESS) {
maa_result_print(r);
} else {
printf("off\n");
}
sleep(1);
r = maa_gpio_write(gpio, 1);
if (r != MAA_SUCCESS) {
maa_result_print(r);
} else {
printf("on\n");
}
sleep(1);
}
r = maa_gpio_close(gpio);
if (r != MAA_SUCCESS) {
maa_result_print(r);
}
return r;
}

View File

@@ -31,17 +31,21 @@ int
main(int argc, char **argv)
{
maa_init();
fprintf(stdout, "MAA Version: %s\nStarting Blinking on IO8\n",
fprintf(stdout, "MAA Version: %s\nStarting Read on IO6\n",
maa_get_version());
maa_gpio_context* gpio;
gpio = maa_gpio_init(8);
maa_gpio_dir(gpio, MAA_GPIO_OUT);
while (1) {
maa_gpio_write(gpio, 0);
sleep(1);
maa_gpio_write(gpio, 1);
maa_gpio_context* gpio;
gpio = maa_gpio_init(6);
maa_gpio_dir(gpio, MAA_GPIO_IN);
for (;;) {
fprintf(stdout, "Gpio is %d\n", maa_gpio_read(gpio));
sleep(1);
}
maa_gpio_close(gpio);
return 0;
}