[Armadeus-commitlog] armadeus branch, master, updated. armadeus-5.2-202-gbe50ded
Brought to you by:
sszy
|
From: SebR <se...@us...> - 2013-03-12 16:32:25
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via be50ded1e9cb4b9da81a36972761b92f5a8475a3 (commit)
via cb375466613a8e68b4b0d85922020549c3cc1014 (commit)
from bbcb713ce0a6a20fccb45ffc5d8988e6b90054e0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit be50ded1e9cb4b9da81a36972761b92f5a8475a3
Merge: cb37546 bbcb713
Author: seb <seb...@ar...>
Date: Tue Mar 12 17:31:59 2013 +0100
Merge branch 'master' of ssh://git.code.sf.net/p/armadeus/code
commit cb375466613a8e68b4b0d85922020549c3cc1014
Author: seb <seb...@ar...>
Date: Tue Mar 12 17:29:56 2013 +0100
[as_devices] add as_led : basic support for leds
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/Makefile | 1 +
target/packages/as_devices/c/as_led.c | 171 +++++++++++++++++++++++++++++++++
target/packages/as_devices/c/as_led.h | 105 ++++++++++++++++++++
3 files changed, 277 insertions(+), 0 deletions(-)
create mode 100644 target/packages/as_devices/c/as_led.c
create mode 100644 target/packages/as_devices/c/as_led.h
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index 2aab51f..41bc090 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -12,6 +12,7 @@ ifeq ($(ARMADEUS_LINUX_VERSION),2.6.29.6)
OBJ += as_gpio_2_6_29.o
else
OBJ += as_gpio.o
+OBJ += as_led.o
endif
OBJ += as_dac.o
OBJ += as_adc.o
diff --git a/target/packages/as_devices/c/as_led.c b/target/packages/as_devices/c/as_led.c
new file mode 100644
index 0000000..85721b9
--- /dev/null
+++ b/target/packages/as_devices/c/as_led.c
@@ -0,0 +1,171 @@
+/*
+ ** C wrapper for GPIOs usage.
+ **
+ ** Copyright (C) 2013 The Armadeus Project - ARMadeus Systems
+ ** Sébastien Royen <seb...@ar...>
+ **
+ ** This library is free software; you can redistribute it and/or
+ ** modify it under the terms of the GNU Lesser General Public
+ ** License as published by the Free Software Foundation; either
+ ** version 2.1 of the License, or (at your option) any later version.
+ **
+ ** This library is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ** Lesser General Public License for more details.
+ **
+ ** You should have received a copy of the GNU Lesser General Public
+ ** License along with this library; if not, write to the Free Software
+ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h> /* for close() */
+#include <errno.h>
+
+#include "as_helpers.h"
+#include "as_led.h"
+
+#undef ERROR
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+
+#define SYS_CLASS_LEDS_PATH "/sys/class/leds"
+
+/*------------------------------------------------------------------------------*/
+
+static int32_t led_echo(struct as_led_device *a_led_dev, char *a_filename,
+ char *a_content, int32_t a_length)
+{
+ char buf[64];
+ int32_t result = -1;
+ int fd;
+
+ snprintf(buf, sizeof(buf), SYS_CLASS_LEDS_PATH"/%s/%s",
+ a_led_dev->led_name, a_filename);
+ fd = open(buf, O_WRONLY);
+ if (fd < 0) {
+ ERROR("Can't open %s\n", buf);
+ } else {
+ if (a_length != write(fd, a_content, a_length)) {
+ ERROR("Error when writing %s to %s\n", a_content, buf);
+ } else {
+ result = 0;
+ }
+ close(fd);
+ }
+ return result;
+}
+
+/*------------------------------------------------------------------------------*/
+
+struct as_led_device *as_led_open(char *a_led_name)
+{
+ struct as_led_device *dev;
+ char buf[64];
+
+ dev = malloc(sizeof(struct as_led_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate as_led_device structure\n");
+ } else {
+ snprintf(dev->led_name, sizeof(dev->led_name), "%s", a_led_name);
+ snprintf(buf, sizeof(buf), SYS_CLASS_LEDS_PATH"/%s/brightness", dev->led_name);
+ dev->file_brightness = open(buf, O_RDWR);
+ if (dev->file_brightness < 0) {
+ ERROR("Can't open %s\n", buf);
+ } else {
+ snprintf(buf, sizeof(buf), SYS_CLASS_LEDS_PATH"/%s/max_brightness", dev->led_name);
+ dev->file_max_brightness = open(buf, O_RDONLY);
+ if (dev->file_max_brightness < 0) {
+ ERROR("Can't open %s\n", buf);
+ } else {
+ return dev;
+ }
+ close(dev->file_brightness);
+ }
+ free(dev);
+ dev = NULL;
+ }
+
+ return NULL;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_led_close(struct as_led_device *a_led_dev)
+{
+ if(a_led_dev == NULL){
+ ERROR("device is NULL\n");
+ return -1;
+ }
+ close(a_led_dev->file_max_brightness);
+ close(a_led_dev->file_brightness);
+ free(a_led_dev);
+ return 0;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_led_get_max_brightness(struct as_led_device *a_led_dev)
+{
+ int32_t result;
+
+ if (0 == as_read_int(a_led_dev->file_max_brightness, &result)) {
+ return result;
+ }
+ return -1;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_led_set_brightness(struct as_led_device *a_led_dev, uint32_t a_brightness)
+{
+ return as_write_buffer(a_led_dev->file_brightness, a_brightness);
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_led_get_brightness(struct as_led_device *a_led_dev)
+{
+ int32_t result;
+
+ if (0 == as_read_int(a_led_dev->file_brightness, &result)) {
+ return result;
+ }
+ return -1;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_led_start_blinking(struct as_led_device *a_led_dev,
+ int32_t a_delay_on, int32_t a_delay_off)
+{
+ char buf[64];
+ int32_t length;
+ int32_t result = -1;
+
+ if (led_echo(a_led_dev, "trigger", "timer\n", 6) == 0) {
+ length = snprintf(buf, sizeof(buf), "%d\n", a_delay_on);
+ if (length > 0
+ && led_echo(a_led_dev, "delay_on", buf, length) == 0) {
+ length = snprintf(buf, sizeof(buf), "%d\n", a_delay_off);
+ if (length > 0
+ && led_echo(a_led_dev, "delay_off", buf, length) == 0) {
+ result = 0;
+ }
+ }
+ }
+ return result;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_led_stop_blinking(struct as_led_device *a_led_dev)
+{
+ if (led_echo(a_led_dev, "trigger", "none\n", 5) == 0) {
+ return 0;
+ }
+ return -1;
+}
+
diff --git a/target/packages/as_devices/c/as_led.h b/target/packages/as_devices/c/as_led.h
new file mode 100644
index 0000000..b9ae389
--- /dev/null
+++ b/target/packages/as_devices/c/as_led.h
@@ -0,0 +1,105 @@
+/*
+** The ARMadeus Project
+**
+** Copyright (C) 2013 The armadeus systems team
+** Sébastien Royen <seb...@ar...>
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __ASLED_H__
+#define __ASLED_H__
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/**
+ * Store led parameters
+ */
+struct as_led_device {
+ char led_name[32];
+ int file_brightness;
+ int file_max_brightness;
+};
+
+
+/** @brief Initialize led access
+ *
+ * @param a_led_name char* name of the led
+ *
+ * @return NULL on error
+ */
+struct as_led_device *as_led_open(char *a_led_name);
+
+/** @brief Close led access
+ *
+ * @param a_led_dev as_led_device pointer structure
+ *
+ * @return error if negative
+ */
+int32_t as_led_close(struct as_led_device *a_led_dev);
+
+/** @brief Get max brightness
+ *
+ * @param a_led_dev as_led_device pointer structure
+ *
+ * @return maximum allowed brightness, negative value on error
+ */
+int32_t as_led_get_max_brightness(struct as_led_device *a_led_dev);
+
+/** @brief Set brightness
+ *
+ * @param a_led_dev as_led_device pointer structure
+ * @param a_brightness uint32_t requested value for led brighthness
+ *
+ * @return current brightness, negative value on error
+ */
+int32_t as_led_set_brightness(struct as_led_device *a_led_dev, uint32_t a_brightness);
+
+/** @brief Get brightness
+ *
+ * @param a_led_dev as_led_device pointer structure
+ *
+ * @return current brightness, negative value on error
+ */
+int32_t as_led_get_brightness(struct as_led_device *a_led_dev);
+
+/** @brief Make a led blinking
+ *
+ * @param a_led_dev as_led_device pointer structure
+ * @param a_delay_on uint32_t value for led on time
+ * @param a_delay_off uint32_t value for led off time
+ *
+ * @return negative value on error
+ */
+int32_t as_led_start_blinking(struct as_led_device *a_led_dev, int32_t a_delay_on, int32_t a_delay_off);
+
+/** @brief Led stop blinking
+ *
+ * @param a_led_dev as_led_device pointer structure
+ *
+ * @return negative value on error
+ */
+int32_t as_led_stop_blinking(struct as_led_device *a_led_dev);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __ASLED_H__ */
hooks/post-receive
--
armadeus
|