mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers: added rgbled driver
This commit is contained in:
parent
b4fceaca89
commit
9e0653afbb
@ -80,3 +80,7 @@ endif
|
|||||||
ifneq (,$(filter ccn_lite,$(USEMODULE)))
|
ifneq (,$(filter ccn_lite,$(USEMODULE)))
|
||||||
USEMODULE += crypto
|
USEMODULE += crypto
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter rgbled,$(USEMODULE)))
|
||||||
|
USEMODULE += color
|
||||||
|
endif
|
||||||
|
@ -34,6 +34,9 @@ endif
|
|||||||
ifneq (,$(filter lm75a,$(USEMODULE)))
|
ifneq (,$(filter lm75a,$(USEMODULE)))
|
||||||
DIRS += lm75a
|
DIRS += lm75a
|
||||||
endif
|
endif
|
||||||
|
ifneq (,$(filter rgbled,$(USEMODULE)))
|
||||||
|
DIRS += rgbled
|
||||||
|
endif
|
||||||
|
|
||||||
all:
|
all:
|
||||||
@for i in $(DIRS) ; do "$(MAKE)" -C $$i || exit 1; done ;
|
@for i in $(DIRS) ; do "$(MAKE)" -C $$i || exit 1; done ;
|
||||||
|
59
drivers/include/rgbled.h
Normal file
59
drivers/include/rgbled.h
Normal file
@ -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 <hauke.petersen@fu-berlin.de>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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 */
|
||||||
|
/** @} */
|
3
drivers/rgbled/Makefile
Normal file
3
drivers/rgbled/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
MODULE = rgbled
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.base
|
49
drivers/rgbled/rgbled.c
Normal file
49
drivers/rgbled/rgbled.c
Normal file
@ -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 <hauke.petersen@fu-berlin.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user