driver: led: move to new logger

Move drivers to new logger and change samples enabling logging in
prj.conf.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2018-10-08 18:10:25 -04:00
commit 7e61660c9c
4 changed files with 45 additions and 59 deletions

View file

@ -13,26 +13,9 @@ menuconfig LED
if LED
config SYS_LOG_LED_LEVEL
int "LED system log level"
depends on SYS_LOG
default 0
range 0 4
help
Sets the log level for LED drivers. You must have
system logging enabled.
Levels are:
- 0 OFF, do not write
- 1 ERROR, only write SYS_LOG_ERR
- 2 WARNING, write SYS_LOG_WRN in addition to previous level
- 3 INFO, write SYS_LOG_INF in addition to previous levels
- 4 DEBUG, write SYS_LOG_DBG in addition to previous levels
module = LED
module-str = led
source "subsys/logging/Kconfig.template.log_config"
config LED_INIT_PRIORITY
int "LED initialization priority"

View file

@ -22,8 +22,9 @@
#include <misc/util.h>
#include <zephyr.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_LED_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_LED_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(lp3943);
#include "led_context.h"
@ -72,7 +73,7 @@ static int lp3943_get_led_reg(u32_t *led, u8_t *reg)
*led -= 12;
break;
default:
SYS_LOG_ERR("Invalid LED specified");
LOG_ERR("Invalid LED specified");
return -EINVAL;
}
@ -93,7 +94,7 @@ static int lp3943_set_dim_states(struct lp3943_data *data, u32_t led, u8_t mode)
if (i2c_reg_update_byte(data->i2c, CONFIG_LP3943_I2C_ADDRESS, reg,
LP3943_MASK << (led << 1),
mode << (led << 1))) {
SYS_LOG_ERR("LED reg update failed");
LOG_ERR("LED reg update failed");
return -EIO;
}
@ -131,7 +132,7 @@ static int lp3943_led_blink(struct device *dev, u32_t led,
val = (period * 255) / dev_data->max_period;
if (i2c_reg_write_byte(data->i2c, CONFIG_LP3943_I2C_ADDRESS,
reg, val)) {
SYS_LOG_ERR("LED write failed");
LOG_ERR("LED write failed");
return -EIO;
}
@ -172,7 +173,7 @@ static int lp3943_led_set_brightness(struct device *dev, u32_t led,
val = (value * 255) / dev_data->max_brightness;
if (i2c_reg_write_byte(data->i2c, CONFIG_LP3943_I2C_ADDRESS,
reg, val)) {
SYS_LOG_ERR("LED write failed");
LOG_ERR("LED write failed");
return -EIO;
}
@ -200,7 +201,7 @@ static inline int lp3943_led_on(struct device *dev, u32_t led)
if (i2c_reg_update_byte(data->i2c, CONFIG_LP3943_I2C_ADDRESS, reg,
LP3943_MASK << (led << 1),
mode << (led << 1))) {
SYS_LOG_ERR("LED reg update failed");
LOG_ERR("LED reg update failed");
return -EIO;
}
@ -221,7 +222,7 @@ static inline int lp3943_led_off(struct device *dev, u32_t led)
/* Set LED state to OFF */
if (i2c_reg_update_byte(data->i2c, CONFIG_LP3943_I2C_ADDRESS, reg,
LP3943_MASK << (led << 1), 0)) {
SYS_LOG_ERR("LED reg update failed");
LOG_ERR("LED reg update failed");
return -EIO;
}
@ -235,7 +236,7 @@ static int lp3943_led_init(struct device *dev)
data->i2c = device_get_binding(CONFIG_LP3943_I2C_MASTER_DEV_NAME);
if (data->i2c == NULL) {
SYS_LOG_DBG("Failed to get I2C device");
LOG_DBG("Failed to get I2C device");
return -EINVAL;
}

View file

@ -33,8 +33,9 @@
#include <device.h>
#include <zephyr.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_LED_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_LED_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(lp5562);
#include "led_context.h"
@ -185,7 +186,7 @@ static int lp5562_get_pwm_reg(enum lp5562_led_channels channel, u8_t *reg)
*reg = LP5562_B_PWM;
break;
default:
SYS_LOG_ERR("Invalid channel given.");
LOG_ERR("Invalid channel given.");
return -EINVAL;
}
@ -310,7 +311,7 @@ static int lp5562_set_led_source(struct device *dev,
LP5562_LED_MAP,
LP5562_CHANNEL_MASK(channel),
source << (channel << 1))) {
SYS_LOG_ERR("LED reg update failed.");
LOG_ERR("LED reg update failed.");
return -EIO;
}
@ -369,7 +370,7 @@ static bool lp5562_is_engine_executing(struct device *dev,
if (i2c_reg_read_byte(data->i2c, CONFIG_LP5562_I2C_ADDRESS,
LP5562_ENABLE, &enabled)) {
SYS_LOG_ERR("Failed to read ENABLE register.");
LOG_ERR("Failed to read ENABLE register.");
return false;
}
@ -398,13 +399,13 @@ static int lp5562_get_available_engine(struct device *dev,
for (src = LP5562_SOURCE_ENGINE_1; src < LP5562_SOURCE_COUNT; src++) {
if (!lp5562_is_engine_executing(dev, src)) {
SYS_LOG_DBG("Available engine: %d", src);
LOG_DBG("Available engine: %d", src);
*engine = src;
return 0;
}
}
SYS_LOG_ERR("No unused engine available");
LOG_ERR("No unused engine available");
return -ENODEV;
}
@ -548,21 +549,21 @@ static int lp5562_program_command(struct device *dev,
ret = lp5562_get_engine_ram_base_addr(engine, &prog_base_addr);
if (ret) {
SYS_LOG_ERR("Failed to get base RAM address.");
LOG_ERR("Failed to get base RAM address.");
return ret;
}
if (i2c_reg_write_byte(data->i2c, CONFIG_LP5562_I2C_ADDRESS,
prog_base_addr + (command_index << 1),
command_msb)) {
SYS_LOG_ERR("Failed to update LED.");
LOG_ERR("Failed to update LED.");
return -EIO;
}
if (i2c_reg_write_byte(data->i2c, CONFIG_LP5562_I2C_ADDRESS,
prog_base_addr + (command_index << 1) + 1,
command_lsb)) {
SYS_LOG_ERR("Failed to update LED.");
LOG_ERR("Failed to update LED.");
return -EIO;
}
@ -735,7 +736,7 @@ static int lp5562_update_blinking_brightness(struct device *dev,
ret = lp5562_start_program_exec(dev, engine);
if (ret) {
SYS_LOG_ERR("Failed to execute program.");
LOG_ERR("Failed to execute program.");
return ret;
}
@ -758,7 +759,7 @@ static int lp5562_led_blink(struct device *dev, u32_t led,
ret = lp5562_set_led_source(dev, led, engine);
if (ret) {
SYS_LOG_ERR("Failed to set LED source.");
LOG_ERR("Failed to set LED source.");
return ret;
}
@ -796,7 +797,7 @@ static int lp5562_led_blink(struct device *dev, u32_t led,
ret = lp5562_start_program_exec(dev, engine);
if (ret) {
SYS_LOG_ERR("Failed to execute program.");
LOG_ERR("Failed to execute program.");
return ret;
}
@ -846,7 +847,7 @@ static int lp5562_led_set_brightness(struct device *dev, u32_t led, u8_t value)
if (i2c_reg_write_byte(data->i2c, CONFIG_LP5562_I2C_ADDRESS,
reg, val)) {
SYS_LOG_ERR("LED write failed");
LOG_ERR("LED write failed");
return -EIO;
}
@ -891,7 +892,7 @@ static int lp5562_led_init(struct device *dev)
data->i2c = device_get_binding(CONFIG_LP5562_I2C_MASTER_DEV_NAME);
if (data->i2c == NULL) {
SYS_LOG_ERR("Failed to get I2C device");
LOG_ERR("Failed to get I2C device");
return -EINVAL;
}
@ -904,7 +905,7 @@ static int lp5562_led_init(struct device *dev)
if (i2c_reg_write_byte(data->i2c, CONFIG_LP5562_I2C_ADDRESS,
LP5562_ENABLE,
LP5562_ENABLE_CHIP_EN)) {
SYS_LOG_ERR("Enabling LP5562 LED chip failed.");
LOG_ERR("Enabling LP5562 LED chip failed.");
return -EIO;
}
@ -912,19 +913,19 @@ static int lp5562_led_init(struct device *dev)
LP5562_CONFIG,
(LP5562_CONFIG_INTERNAL_CLOCK ||
LP5562_CONFIG_PWRSAVE_EN))) {
SYS_LOG_ERR("Configuring LP5562 LED chip failed.");
LOG_ERR("Configuring LP5562 LED chip failed.");
return -EIO;
}
if (i2c_reg_write_byte(data->i2c, CONFIG_LP5562_I2C_ADDRESS,
LP5562_OP_MODE, 0x00)) {
SYS_LOG_ERR("Disabling all engines failed.");
LOG_ERR("Disabling all engines failed.");
return -EIO;
}
if (i2c_reg_write_byte(data->i2c, CONFIG_LP5562_I2C_ADDRESS,
LP5562_LED_MAP, 0x00)) {
SYS_LOG_ERR("Setting all LEDs to manual control failed.");
LOG_ERR("Setting all LEDs to manual control failed.");
return -EIO;
}

View file

@ -14,8 +14,9 @@
#include <misc/util.h>
#include <zephyr.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_LED_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_LED_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(pca9633);
#include "led_context.h"
@ -67,7 +68,7 @@ static int pca9633_led_blink(struct device *dev, u32_t led,
if (i2c_reg_write_byte(data->i2c, CONFIG_PCA9633_I2C_ADDRESS,
PCA9633_GRPPWM,
gdc)) {
SYS_LOG_ERR("LED reg write failed");
LOG_ERR("LED reg write failed");
return -EIO;
}
@ -81,7 +82,7 @@ static int pca9633_led_blink(struct device *dev, u32_t led,
if (i2c_reg_write_byte(data->i2c, CONFIG_PCA9633_I2C_ADDRESS,
PCA9633_GRPFREQ,
gfrq)) {
SYS_LOG_ERR("LED reg write failed");
LOG_ERR("LED reg write failed");
return -EIO;
}
@ -90,7 +91,7 @@ static int pca9633_led_blink(struct device *dev, u32_t led,
PCA9633_MODE2,
PCA9633_MODE2_DMBLNK,
PCA9633_MODE2_DMBLNK)) {
SYS_LOG_ERR("LED reg update failed");
LOG_ERR("LED reg update failed");
return -EIO;
}
@ -99,7 +100,7 @@ static int pca9633_led_blink(struct device *dev, u32_t led,
PCA9633_LEDOUT,
PCA9633_MASK << (led << 1),
PCA9633_LED_GRP_PWM << (led << 1))) {
SYS_LOG_ERR("LED reg update failed");
LOG_ERR("LED reg update failed");
return -EIO;
}
@ -123,7 +124,7 @@ static int pca9633_led_set_brightness(struct device *dev, u32_t led,
if (i2c_reg_write_byte(data->i2c, CONFIG_PCA9633_I2C_ADDRESS,
PCA9633_PWM_BASE + led,
val)) {
SYS_LOG_ERR("LED reg write failed");
LOG_ERR("LED reg write failed");
return -EIO;
}
@ -132,7 +133,7 @@ static int pca9633_led_set_brightness(struct device *dev, u32_t led,
PCA9633_LEDOUT,
PCA9633_MASK << (led << 1),
PCA9633_LED_PWM << (led << 1))) {
SYS_LOG_ERR("LED reg update failed");
LOG_ERR("LED reg update failed");
return -EIO;
}
@ -148,7 +149,7 @@ static inline int pca9633_led_on(struct device *dev, u32_t led)
PCA9633_LEDOUT,
PCA9633_MASK << (led << 1),
PCA9633_LED_ON << (led << 1))) {
SYS_LOG_ERR("LED reg update failed");
LOG_ERR("LED reg update failed");
return -EIO;
}
@ -164,7 +165,7 @@ static inline int pca9633_led_off(struct device *dev, u32_t led)
PCA9633_LEDOUT,
PCA9633_MASK << (led << 1),
PCA9633_LED_OFF)) {
SYS_LOG_ERR("LED reg update failed");
LOG_ERR("LED reg update failed");
return -EIO;
}
@ -178,7 +179,7 @@ static int pca9633_led_init(struct device *dev)
data->i2c = device_get_binding(CONFIG_PCA9633_I2C_MASTER_DEV_NAME);
if (data->i2c == NULL) {
SYS_LOG_DBG("Failed to get I2C device");
LOG_DBG("Failed to get I2C device");
return -EINVAL;
}