mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/ws281x: introduce WS281X_HAVE_INIT
This brings the backend-dependant init() function in line with `WS281X_HAVE_PREPARE_TRANSMISSION` and `WS281X_HAVE_END_TRANSMISSION`.
This commit is contained in:
parent
720eff3416
commit
11d77271cf
@ -693,11 +693,6 @@ ifneq (,$(filter ws281x,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ws281x_vt100,$(USEMODULE)))
|
||||
CFLAGS += -DWS281X_HAVE_PREPARE_TRANSMISSION
|
||||
CFLAGS += -DWS281X_HAVE_END_TRANSMISSION
|
||||
endif
|
||||
|
||||
ifneq (,$(filter xbee,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_uart
|
||||
FEATURES_REQUIRED += periph_gpio
|
||||
|
@ -59,6 +59,7 @@
|
||||
|
||||
#include "color.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "ws281x_backend.h"
|
||||
#include "ws281x_constants.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
@ -92,6 +93,7 @@ typedef struct {
|
||||
ws281x_params_t params; /**< Parameters of the LED chain */
|
||||
} ws281x_t;
|
||||
|
||||
#if defined(WS281X_HAVE_INIT) || defined(DOXYGEN)
|
||||
/**
|
||||
* @brief Initialize an WS281x RGB LED chain
|
||||
*
|
||||
@ -103,6 +105,12 @@ typedef struct {
|
||||
* @retval -EIO Failed to initialize the data GPIO pin
|
||||
*/
|
||||
int ws281x_init(ws281x_t *dev, const ws281x_params_t *params);
|
||||
#else
|
||||
static inline int ws281x_init(ws281x_t *dev, const ws281x_params_t *params) {
|
||||
dev->params = *params;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Writes the color data of the user supplied buffer
|
||||
|
@ -203,3 +203,19 @@ void ws281x_write_buffer(ws281x_t *dev, const void *buf, size_t size)
|
||||
#error "No low level WS281x implementation for ATmega CPUs for your CPU clock"
|
||||
#endif
|
||||
}
|
||||
|
||||
int ws281x_init(ws281x_t *dev, const ws281x_params_t *params)
|
||||
{
|
||||
if (!dev || !params || !params->buf) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memset(dev, 0, sizeof(ws281x_t));
|
||||
dev->params = *params;
|
||||
|
||||
if (gpio_init(dev->params.pin, GPIO_OUT)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
50
drivers/ws281x/include/ws281x_backend.h
Normal file
50
drivers/ws281x/include/ws281x_backend.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Marian Buschsieweke
|
||||
*
|
||||
* 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 drivers_ws281x
|
||||
*
|
||||
* @{
|
||||
* @file
|
||||
* @brief Backend configuration for WS2812/SK6812 RGB LEDs
|
||||
*
|
||||
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
|
||||
*/
|
||||
|
||||
#ifndef WS281X_BACKEND_H
|
||||
#define WS281X_BACKEND_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Properties of the ATmega backend.
|
||||
* @{
|
||||
*/
|
||||
#ifdef MODULE_WS281X_ATMEGA
|
||||
#define WS281X_HAVE_INIT (1)
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Properties of the VT100 terminal backend.
|
||||
* @{
|
||||
*/
|
||||
#ifdef MODULE_WS281X_VT100
|
||||
#define WS281X_HAVE_PREPARE_TRANSMISSION (1)
|
||||
#define WS281X_HAVE_END_TRANSMISSION (1)
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WS281X_BACKEND_H */
|
||||
/** @} */
|
@ -31,25 +31,6 @@
|
||||
/* Default buffer used in ws281x_params.h. Will be optimized out if unused */
|
||||
uint8_t ws281x_buf[WS281X_PARAM_NUMOF * WS281X_BYTES_PER_DEVICE];
|
||||
|
||||
/* Some backend will need a custom init function. Declaring this as weak symbol
|
||||
* allows them to provide their own. */
|
||||
int __attribute__((weak)) ws281x_init(ws281x_t *dev,
|
||||
const ws281x_params_t *params)
|
||||
{
|
||||
if (!dev || !params || !params->buf) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memset(dev, 0, sizeof(ws281x_t));
|
||||
dev->params = *params;
|
||||
|
||||
if (gpio_init(dev->params.pin, GPIO_OUT)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ws281x_set_buffer(void *_dest, uint16_t n, color_rgb_t c)
|
||||
{
|
||||
uint8_t *dest = _dest;
|
||||
|
Loading…
Reference in New Issue
Block a user