From afa85cdc0fb8d4c0ef664d9273a49a5ead2ca8d4 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 25 Jun 2019 15:53:56 -0400 Subject: [PATCH] cleanup: include/: move led_strip.h to drivers/led_strip.h move led_strip.h to drivers/led_strip.h and create a shim for backward-compatibility. No functional changes to the headers. A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES. Related to #16539 Signed-off-by: Anas Nashif --- drivers/led_strip/apa102.c | 2 +- drivers/led_strip/lpd880x.c | 2 +- drivers/led_strip/ws2812.c | 2 +- drivers/led_strip/ws2812b_sw.c | 2 +- include/drivers/led_strip.h | 129 ++++++++++++++++++ include/led_strip.h | 124 +---------------- samples/drivers/led_apa102/src/main.c | 2 +- samples/drivers/led_lpd8806/src/main.c | 2 +- samples/drivers/led_ws2812/src/main.c | 2 +- .../application_development/cpp/src/main.cpp | 2 +- 10 files changed, 142 insertions(+), 127 deletions(-) create mode 100644 include/drivers/led_strip.h diff --git a/drivers/led_strip/apa102.c b/drivers/led_strip/apa102.c index 32116df31f..b94d9d1ebd 100644 --- a/drivers/led_strip/apa102.c +++ b/drivers/led_strip/apa102.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include struct apa102_data { diff --git a/drivers/led_strip/lpd880x.c b/drivers/led_strip/lpd880x.c index 9e8acc6d74..8456d9333c 100644 --- a/drivers/led_strip/lpd880x.c +++ b/drivers/led_strip/lpd880x.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include diff --git a/drivers/led_strip/ws2812.c b/drivers/led_strip/ws2812.c index 1928d38517..1d7d4a0dcd 100644 --- a/drivers/led_strip/ws2812.c +++ b/drivers/led_strip/ws2812.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include diff --git a/drivers/led_strip/ws2812b_sw.c b/drivers/led_strip/ws2812b_sw.c index 147999dee9..f44fca42df 100644 --- a/drivers/led_strip/ws2812b_sw.c +++ b/drivers/led_strip/ws2812b_sw.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include diff --git a/include/drivers/led_strip.h b/include/drivers/led_strip.h new file mode 100644 index 0000000000..a7bea65dcd --- /dev/null +++ b/include/drivers/led_strip.h @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2017 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_LED_STRIP_H_ +#define ZEPHYR_INCLUDE_DRIVERS_LED_STRIP_H_ + +/** + * @file + * @brief Public API for controlling linear strips of LEDs. + * + * This library abstracts the chipset drivers for individually + * addressable strips of LEDs. + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Color value for a single RGB LED. + * + * Individual strip drivers may ignore lower-order bits if their + * resolution in any channel is less than a full byte. + */ +struct led_rgb { +#ifdef CONFIG_LED_STRIP_RGB_SCRATCH + /* + * Pad/scratch space needed by some drivers. Users should + * ignore. + */ + u8_t scratch; +#endif + /** Red channel */ + u8_t r; + /** Green channel */ + u8_t g; + /** Blue channel */ + u8_t b; +}; + +/** + * @typedef led_api_update_rgb + * @brief Callback API for updating an RGB LED strip + * + * @see led_strip_update_rgb() for argument descriptions. + */ +typedef int (*led_api_update_rgb)(struct device *dev, struct led_rgb *pixels, + size_t num_pixels); + +/** + * @typedef led_api_update_channels + * @brief Callback API for updating channels without an RGB interpretation. + * + * @see led_strip_update_channels() for argument descriptions. + */ +typedef int (*led_api_update_channels)(struct device *dev, u8_t *channels, + size_t num_channels); + +/** + * @brief LED strip driver API + * + * This is the mandatory API any LED strip driver needs to expose. + */ +struct led_strip_driver_api { + led_api_update_rgb update_rgb; + led_api_update_channels update_channels; +}; + +/** + * @brief Update an LED strip made of RGB pixels + * + * Important: + * This routine may overwrite @a pixels. + * + * This routine immediately updates the strip display according to the + * given pixels array. + * + * @param dev LED strip device + * @param pixels Array of pixel data + * @param num_pixels Length of pixels array + * @return 0 on success, negative on error + * @warning May overwrite @a pixels + */ +static inline int led_strip_update_rgb(struct device *dev, + struct led_rgb *pixels, + size_t num_pixels) { + const struct led_strip_driver_api *api = + (const struct led_strip_driver_api *)dev->driver_api; + + return api->update_rgb(dev, pixels, num_pixels); +} + +/** + * @brief Update an LED strip on a per-channel basis. + * + * Important: + * This routine may overwrite @a channels. + * + * This routine immediately updates the strip display according to the + * given channels array. Each channel byte corresponds to an + * individually addressable color channel or LED. Channels + * are updated linearly in strip order. + * + * @param dev LED strip device + * @param channels Array of per-channel data + * @param num_channels Length of channels array + * @return 0 on success, negative on error + * @warning May overwrite @a channels + */ +static inline int led_strip_update_channels(struct device *dev, + u8_t *channels, + size_t num_channels) { + const struct led_strip_driver_api *api = + (const struct led_strip_driver_api *)dev->driver_api; + + return api->update_channels(dev, channels, num_channels); +} + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_LED_STRIP_H_ */ diff --git a/include/led_strip.h b/include/led_strip.h index 05800fecaa..778ddfdb4a 100644 --- a/include/led_strip.h +++ b/include/led_strip.h @@ -1,129 +1,15 @@ /* - * Copyright (c) 2017 Linaro Limited + * Copyright (c) 2019 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ - #ifndef ZEPHYR_INCLUDE_LED_STRIP_H_ #define ZEPHYR_INCLUDE_LED_STRIP_H_ -/** - * @file - * @brief Public API for controlling linear strips of LEDs. - * - * This library abstracts the chipset drivers for individually - * addressable strips of LEDs. - */ - -#include -#include - -#ifdef __cplusplus -extern "C" { +#ifndef CONFIG_COMPAT_INCLUDES +#warning "This header file has moved, include instead." #endif -/** - * @brief Color value for a single RGB LED. - * - * Individual strip drivers may ignore lower-order bits if their - * resolution in any channel is less than a full byte. - */ -struct led_rgb { -#ifdef CONFIG_LED_STRIP_RGB_SCRATCH - /* - * Pad/scratch space needed by some drivers. Users should - * ignore. - */ - u8_t scratch; -#endif - /** Red channel */ - u8_t r; - /** Green channel */ - u8_t g; - /** Blue channel */ - u8_t b; -}; +#include -/** - * @typedef led_api_update_rgb - * @brief Callback API for updating an RGB LED strip - * - * @see led_strip_update_rgb() for argument descriptions. - */ -typedef int (*led_api_update_rgb)(struct device *dev, struct led_rgb *pixels, - size_t num_pixels); - -/** - * @typedef led_api_update_channels - * @brief Callback API for updating channels without an RGB interpretation. - * - * @see led_strip_update_channels() for argument descriptions. - */ -typedef int (*led_api_update_channels)(struct device *dev, u8_t *channels, - size_t num_channels); - -/** - * @brief LED strip driver API - * - * This is the mandatory API any LED strip driver needs to expose. - */ -struct led_strip_driver_api { - led_api_update_rgb update_rgb; - led_api_update_channels update_channels; -}; - -/** - * @brief Update an LED strip made of RGB pixels - * - * Important: - * This routine may overwrite @a pixels. - * - * This routine immediately updates the strip display according to the - * given pixels array. - * - * @param dev LED strip device - * @param pixels Array of pixel data - * @param num_pixels Length of pixels array - * @return 0 on success, negative on error - * @warning May overwrite @a pixels - */ -static inline int led_strip_update_rgb(struct device *dev, - struct led_rgb *pixels, - size_t num_pixels) { - const struct led_strip_driver_api *api = - (const struct led_strip_driver_api *)dev->driver_api; - - return api->update_rgb(dev, pixels, num_pixels); -} - -/** - * @brief Update an LED strip on a per-channel basis. - * - * Important: - * This routine may overwrite @a channels. - * - * This routine immediately updates the strip display according to the - * given channels array. Each channel byte corresponds to an - * individually addressable color channel or LED. Channels - * are updated linearly in strip order. - * - * @param dev LED strip device - * @param channels Array of per-channel data - * @param num_channels Length of channels array - * @return 0 on success, negative on error - * @warning May overwrite @a channels - */ -static inline int led_strip_update_channels(struct device *dev, - u8_t *channels, - size_t num_channels) { - const struct led_strip_driver_api *api = - (const struct led_strip_driver_api *)dev->driver_api; - - return api->update_channels(dev, channels, num_channels); -} - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_INCLUDE_LED_STRIP_H_ */ +#endif /* ZEPHYR_INCLUDE_LED_STRIP_H_ */ diff --git a/samples/drivers/led_apa102/src/main.c b/samples/drivers/led_apa102/src/main.c index 47a9217e73..2a68f11b5e 100644 --- a/samples/drivers/led_apa102/src/main.c +++ b/samples/drivers/led_apa102/src/main.c @@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(main); #include -#include +#include #include #include #include diff --git a/samples/drivers/led_lpd8806/src/main.c b/samples/drivers/led_lpd8806/src/main.c index 3fce27808a..68a3ab4f8c 100644 --- a/samples/drivers/led_lpd8806/src/main.c +++ b/samples/drivers/led_lpd8806/src/main.c @@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(main); #include -#include +#include #include #include #include diff --git a/samples/drivers/led_ws2812/src/main.c b/samples/drivers/led_ws2812/src/main.c index e850387034..ca3ed3d0b9 100644 --- a/samples/drivers/led_ws2812/src/main.c +++ b/samples/drivers/led_ws2812/src/main.c @@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(main); #include -#include +#include #include #include #include diff --git a/tests/application_development/cpp/src/main.cpp b/tests/application_development/cpp/src/main.cpp index d209a18839..03ef8b7dfe 100644 --- a/tests/application_development/cpp/src/main.cpp +++ b/tests/application_development/cpp/src/main.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include