diff --git a/Makefile.dep b/Makefile.dep index 340278cc70..5d81cb0c6a 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -80,3 +80,7 @@ endif ifneq (,$(filter ccn_lite,$(USEMODULE))) USEMODULE += crypto endif + +ifneq (,$(filter rgbled,$(USEMODULE))) + USEMODULE += color +endif diff --git a/drivers/Makefile b/drivers/Makefile index 6789873156..b46e603904 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -34,6 +34,9 @@ endif ifneq (,$(filter lm75a,$(USEMODULE))) DIRS += lm75a endif +ifneq (,$(filter rgbled,$(USEMODULE))) + DIRS += rgbled +endif all: @for i in $(DIRS) ; do "$(MAKE)" -C $$i || exit 1; done ; diff --git a/drivers/include/rgbled.h b/drivers/include/rgbled.h new file mode 100644 index 0000000000..a7f52fbba0 --- /dev/null +++ b/drivers/include/rgbled.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @defgroup driver_rgbled RGB-LED driver + * @ingroup drivers + * @brief High-level driver for RGB-LEDs + * @{ + * + * @file + * @brief High-level driver for easy handling of RGB-LEDs + * + * @author Hauke Petersen + */ + +#ifndef __RGBLED_H +#define __RGBLED_H + +#include "color.h" +#include "periph/pwm.h" + + +/** + * @name Descriptor struct for rgbleds + */ +typedef struct { + pwm_t device; + int channel_r; + int channel_g; + int channel_b; +} rgbled_t; + + +/** + * @brief Initialize the RGB LED by assigning PWM channels to colors + * + * @param[in] led Struct identifying the LED + * @param[in] pwm PWM device to drive the LED + * @param[in] channel_r PWM channel connected to red + * @param[in] channel_g PWM channel connected to green + * @param[in] channel_b PWM channel connected to blue + */ +void rgbled_init(rgbled_t *led, pwm_t pwm, int channel_r, int channel_g, int channel_b); + +/** + * @brief Set the RGB-LED to the given color value + * + * @param[in] led Struct identifying the LED to set + * @param[in] color Color to set the led to + */ +void rgbled_set(rgbled_t *led, color_rgb_t *color); + +#endif /* __RGBLED_H */ +/** @} */ diff --git a/drivers/rgbled/Makefile b/drivers/rgbled/Makefile new file mode 100644 index 0000000000..e438a2f4eb --- /dev/null +++ b/drivers/rgbled/Makefile @@ -0,0 +1,3 @@ +MODULE = rgbled + +include $(RIOTBASE)/Makefile.base diff --git a/drivers/rgbled/rgbled.c b/drivers/rgbled/rgbled.c new file mode 100644 index 0000000000..39a29feafd --- /dev/null +++ b/drivers/rgbled/rgbled.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup driver_rgbled + * @{ + * + * @file + * @brief High-level driver for easy handling of RGB-LEDs + * + * @author Hauke Petersen + * + * @} + */ + +#include "rgbled.h" + + +/** + * @name Drive the RGB-LED by default with 500Hz + */ +#define PWM_FREQU (500) + +/** + * @name Set the default resolution to 8-bit per color (for a 24-bit color space) + */ +#define PWM_RES (255) + + +void rgbled_init(rgbled_t *led, pwm_t pwm, int channel_r, int channel_g, int channel_b) +{ + led->device = pwm; + led->channel_r = channel_r; + led->channel_g = channel_g; + led->channel_b = channel_b; + pwm_init(pwm, PWM_LEFT, PWM_FREQU, PWM_RES); +} + +void rgbled_set(rgbled_t *led, color_rgb_t *color) +{ + pwm_set(led->device, led->channel_r, (unsigned int)color->r); + pwm_set(led->device, led->channel_g, (unsigned int)color->g); + pwm_set(led->device, led->channel_b, (unsigned int)color->b); +}