drivers: led: introduce led_get_info syscall

When supported by the driver the led_get_info syscall allows a user
to retrieve the following information about each LED available:

- The LED label.
- The number of colors/channels.
- And for a multicolor LED a pointer to a channel-color mapping.

Signed-off-by: Simon Guinot <simon.guinot@seagate.com>
Signed-off-by: Maxime Bittan <maxime.bittan@seagate.com>
This commit is contained in:
Simon Guinot 2020-06-05 13:51:47 +02:00 committed by Carles Cufí
parent 745d5ac7e1
commit 713809f0ce
2 changed files with 64 additions and 0 deletions

View file

@ -16,6 +16,15 @@ static inline int z_vrfy_led_blink(struct device *dev, uint32_t led,
}
#include <syscalls/led_blink_mrsh.c>
static inline int z_vrfy_led_get_info(struct device *dev, uint32_t led,
const struct led_info **info)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_LED));
Z_OOPS(Z_SYSCALL_MEMORY_WRITE(info, sizeof(*info)));
return z_impl_led_get_info(dev, led, info);
}
#include <syscalls/led_get_info_mrsh.c>
static inline int z_vrfy_led_set_brightness(struct device *dev, uint32_t led,
uint8_t value)
{

View file

@ -22,6 +22,23 @@
#include <zephyr/types.h>
#include <device.h>
/**
* @brief LED information structure
*
* This structure gathers useful information about LED controller.
*
* @param label LED label.
* @param num_colors Number of colors per LED.
* @param index Index of the LED on the controller.
* @param color_mapping Mapping of the LED colors.
*/
struct led_info {
const char *label;
uint32_t index;
uint8_t num_colors;
const uint8_t *color_mapping;
};
/**
* @typedef led_api_blink()
* @brief Callback API for blinking an LED
@ -31,6 +48,15 @@
typedef int (*led_api_blink)(struct device *dev, uint32_t led,
uint32_t delay_on, uint32_t delay_off);
/**
* @typedef led_api_get_info()
* @brief Optional API callback to get LED information
*
* @see led_get_info() for argument descriptions.
*/
typedef int (*led_api_get_info)(struct device *dev, uint32_t led,
const struct led_info **info);
/**
* @typedef led_api_set_brightness()
* @brief Callback API for setting brightness of an LED
@ -61,10 +87,13 @@ typedef int (*led_api_off)(struct device *dev, uint32_t led);
* This is the mandatory API any LED driver needs to expose.
*/
__subsystem struct led_driver_api {
/* Mandatory callbacks. */
led_api_blink blink;
led_api_set_brightness set_brightness;
led_api_on on;
led_api_off off;
/* Optional callbacks. */
led_api_get_info get_info;
};
/**
@ -90,6 +119,32 @@ static inline int z_impl_led_blink(struct device *dev, uint32_t led,
return api->blink(dev, led, delay_on, delay_off);
}
/**
* @brief Get LED information
*
* This optional routine provides information about a LED.
*
* @param dev LED device
* @param led LED number
* @param info Pointer to a pointer filled with LED information
* @return 0 on success, negative on error
*/
__syscall int led_get_info(struct device *dev, uint32_t led,
const struct led_info **info);
static inline int z_impl_led_get_info(struct device *dev, uint32_t led,
const struct led_info **info)
{
const struct led_driver_api *api =
(const struct led_driver_api *)dev->api;
if (!api->get_info) {
*info = NULL;
return -ENOTSUP;
}
return api->get_info(dev, led, info);
}
/**
* @brief Set LED brightness
*