#include "resource/resource_led.h"
#include "config.h"
-#define DEFAULT_LED_RED 17
-#define DEFAULT_LED_GREEN 27
-#define CONFIG_KEY_RPI_PIN_LED_RED "bi.red"
-#define CONFIG_KEY_RPI_PIN_LED_GREEN "bi.green"
+#define DEFAULT_BI_LED_RED 17
+#define DEFAULT_BI_LED_GREEN 27
+#define CONFIG_KEY_RPI_BI_LED_RED "bi.red"
+#define CONFIG_KEY_RPI_BI_LED_GREEN "bi.green"
#define CONFIG_KEY_RPI_USE_BI_LED "bi.use"
+
+#define DEFAULT_RGB_LED_RED 12
+#define DEFAULT_RGB_LED_GREEN 13
+#define DEFAULT_RGB_LED_BLUE 24
+#define CONFIG_KEY_RPI_RGB_LED_RED "rgb.red"
+#define CONFIG_KEY_RPI_RGB_LED_GREEN "rgb.green"
+#define CONFIG_KEY_RPI_RGB_LED_BLUE "rgb.blue"
+#define CONFIG_KEY_RPI_USE_RGB_LED "rgb.use"
+
#define CONFIG_GRP_RPI "Rpi.led"
typedef struct _led_s {
peripheral_gpio_h gpio_bi_led[2];
+ peripheral_pwm_h pwn_rgb_led[3];
led_color_e current_color;
int use_bi_led;
+ int use_rgb_led;
} led_s;
static led_s s_info = {
}
+static peripheral_pwm_h _init_pwm(int default_pwm_pin, char *key)
+{
+ peripheral_pwm_h pwm;
+ int pin;
+
+ bool modified = config_get_int_with_default(CONFIG_GRP_RPI, key, default_pwm_pin, &pin);
+ _D("PWN: %d, DUTY: %u, period: %u", pin, (unsigned)2e6, (unsigned)2e7);
+
+ if (modified) {
+ config_save();
+ }
+
+ int ret = peripheral_pwm_open(1, pin, &pwm);
+ retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret, NULL);
+
+ ret = peripheral_pwm_set_period(pwm, (unsigned)2e7);
+ retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret, NULL);
+
+ ret = peripheral_pwm_set_duty_cycle(pwm, (unsigned)2e6);
+ retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret, NULL);
+
+ ret = peripheral_pwm_set_enabled(pwm, true);
+ retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret, NULL);
+
+
+
+ return pwm;
+}
+
+static void _init_rgb_led(void)
+{
+ bool modified = config_get_int_with_default(CONFIG_GRP_RPI, CONFIG_KEY_RPI_USE_RGB_LED, 1, &s_info.use_rgb_led);
+ if (modified) {
+ config_save();
+ }
+
+ if (s_info.use_rgb_led) {
+ s_info.pwn_rgb_led[LED_COLOR_RED] = _init_pwm(DEFAULT_RGB_LED_RED, CONFIG_KEY_RPI_RGB_LED_RED);
+ s_info.pwn_rgb_led[LED_COLOR_GREEN] = _init_pwm(DEFAULT_RGB_LED_GREEN, CONFIG_KEY_RPI_RGB_LED_GREEN);
+ s_info.pwn_rgb_led[LED_COLOR_BLUE] = _init_pwm(DEFAULT_RGB_LED_BLUE, CONFIG_KEY_RPI_RGB_LED_BLUE);
+
+
+ peripheral_pwm_set_duty_cycle(s_info.pwn_rgb_led[LED_COLOR_RED], (unsigned)1e7);
+ }
+}
+
static void _init_bi_led(void)
{
bool modified = config_get_int_with_default(CONFIG_GRP_RPI, CONFIG_KEY_RPI_USE_BI_LED, 1, &s_info.use_bi_led);
+ if (modified) {
+ config_save();
+ }
if (s_info.use_bi_led) {
- s_info.gpio_bi_led[LED_COLOR_RED] = _init_gpio(DEFAULT_LED_RED, CONFIG_KEY_RPI_PIN_LED_RED);
- s_info.gpio_bi_led[LED_COLOR_GREEN] = _init_gpio(DEFAULT_LED_GREEN, CONFIG_KEY_RPI_PIN_LED_GREEN);
+ s_info.gpio_bi_led[LED_COLOR_RED] = _init_gpio(DEFAULT_BI_LED_RED, CONFIG_KEY_RPI_BI_LED_RED);
+ s_info.gpio_bi_led[LED_COLOR_GREEN] = _init_gpio(DEFAULT_BI_LED_GREEN, CONFIG_KEY_RPI_BI_LED_GREEN);
} else {
_D("BI-Led is turned OFF");
}
-
- if (modified) {
- config_save();
- }
}
void resource_led_init(void)
{
_D("Initialize Led");
_init_bi_led();
+ _init_rgb_led();
}
void resource_led_destroy(void)