summaryrefslogtreecommitdiff
path: root/src/resource/resource_led.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/resource/resource_led.c')
-rw-r--r--src/resource/resource_led.c75
1 files changed, 43 insertions, 32 deletions
diff --git a/src/resource/resource_led.c b/src/resource/resource_led.c
index dcfef73..9c40a5d 100644
--- a/src/resource/resource_led.c
+++ b/src/resource/resource_led.c
@@ -43,9 +43,9 @@
#define CONFIG_KEY_RPI_USE_L2C_RGB "rgb.l2c.use"
-#define DEFAULT_RGB_GPIO_R 14
-#define DEFAULT_RGB_GPIO_G 15
-#define DEFAULT_RGB_GPIO_B 18
+#define DEFAULT_RGB_GPIO_R 23
+#define DEFAULT_RGB_GPIO_G 24
+#define DEFAULT_RGB_GPIO_B 25
#define DEFAULT_RGB_L2C_R 8
#define DEFAULT_RGB_L2C_G 9
@@ -119,6 +119,13 @@ static inline void _led_bi_set(bi_led_color_e color)
static inline void _rgb_gpio_set(bool red, bool green, bool blue)
{
+ if (!s_info.use_rgb_gpio) {
+ _D("gpio rgb led is turned OFF");
+ return;
+ }
+
+ _D("RGB GPIO: [%d, %d, %d]", red, green, blue);
+
int ret = peripheral_gpio_write(s_info.rgb_gpio[0], red);
ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
@@ -127,20 +134,14 @@ static inline void _rgb_gpio_set(bool red, bool green, bool blue)
ret = peripheral_gpio_write(s_info.rgb_gpio[2], blue);
ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
-
- _D("RGB GPIO: [%d, %d, %d]", red, green, blue);
}
-static inline void _rgb_l2c_set(bool red, bool green, bool blue)
+static inline void _rgb_l2c_set(int red, int green, int blue)
{
-//#define R 51
-//#define G 231
-//#define B 157
-
-//#define R 88
-//#define G 51
-//#define B 231
-
+ if (!s_info.use_rgb_l2c) {
+ _D("l2c rgb led is turned OFF");
+ return;
+ }
int ret = resource_pca9685_set_value_to_channel(DEFAULT_RGB_L2C_R, 0, RGB_TO_REGISTER(red));
ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
@@ -175,20 +176,20 @@ static gboolean _restore_rgb_l2c_color_cb(gpointer data)
static peripheral_gpio_h _init_gpio(int default_gpio, char *key)
{
peripheral_gpio_h gpio;
- int ret = PERIPHERAL_ERROR_NONE;
+
int pin = 0;
bool modified = config_get_int_with_default(CONFIG_GRP_RPI, key, default_gpio, &pin);
- _D("gpio: %d", pin);
+ _D("Initializing gpio: %d", pin);
if (modified) {
config_save();
}
- peripheral_gpio_open(pin, &gpio);
+ int ret = peripheral_gpio_open(pin, &gpio);
retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret, 0);
- peripheral_gpio_set_direction(gpio, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
+ ret = peripheral_gpio_set_direction(gpio, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret, 0);
return gpio;
@@ -227,6 +228,18 @@ static void _init_rgb_gpio_led(void)
s_info.rgb_gpio[2] = _init_gpio(DEFAULT_RGB_GPIO_B, CONFIG_KEY_RPI_RGB_GPIO_B);
}
+void _init_l2c(int default_channel, char *config_key)
+{
+ int channel;
+ bool modified = config_get_int_with_default(CONFIG_GRP_RPI, config_key, default_channel, &channel);
+ if (modified) {
+ config_save();
+ }
+
+ int ret = resource_pca9685_init(channel, 60);
+ ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
+}
+
static void _init_rgb_l2c_led(void)
{
bool modified = config_get_int_with_default(CONFIG_GRP_RPI, CONFIG_KEY_RPI_USE_L2C_RGB, 1, &s_info.use_rgb_l2c);
@@ -239,21 +252,16 @@ static void _init_rgb_l2c_led(void)
return;
}
- int ret = resource_pca9685_init(DEFAULT_RGB_L2C_R, 60);
- ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
-
- ret = resource_pca9685_init(DEFAULT_RGB_L2C_G, 60);
- ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
-
- ret = resource_pca9685_init(DEFAULT_RGB_L2C_B, 60);
- ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
+ _init_l2c(DEFAULT_RGB_L2C_R, CONFIG_KEY_RPI_RGB_L2C_R);
+ _init_l2c(DEFAULT_RGB_L2C_G, CONFIG_KEY_RPI_RGB_L2C_G);
+ _init_l2c(DEFAULT_RGB_L2C_B, CONFIG_KEY_RPI_RGB_L2C_B);
}
void resource_led_init(void)
{
_D("Initialize Led");
- _init_bi_led();
_init_rgb_gpio_led();
+ _init_bi_led();
_init_rgb_l2c_led();
}
@@ -262,6 +270,12 @@ void resource_led_destroy(void)
peripheral_gpio_close(s_info.gpio_bi_led[LED_COLOR_RED]);
peripheral_gpio_close(s_info.gpio_bi_led[LED_COLOR_GREEN]);
+ peripheral_gpio_close(s_info.rgb_gpio[0]);
+ peripheral_gpio_close(s_info.rgb_gpio[1]);
+ peripheral_gpio_close(s_info.rgb_gpio[2]);
+
+ resource_rgb_l2c_set(0, 0, 0);
+
resource_pca9685_fini(DEFAULT_RGB_L2C_R);
resource_pca9685_fini(DEFAULT_RGB_L2C_G);
resource_pca9685_fini(DEFAULT_RGB_L2C_B);
@@ -276,8 +290,6 @@ void resource_bi_led_set(bi_led_color_e color)
s_info.current_color = color;
_led_bi_set(color);
-
- peripheral_gpio_write(s_info.rgb_gpio[LED_COLOR_RED], 1);
}
void resource_bi_led_blink(bi_led_color_e color, unsigned timeout)
@@ -318,7 +330,7 @@ void resource_gpio_rgb_blink(bool red, bool green, bool blue, unsigned timeout)
g_timeout_add(timeout, _restore_rgb_gpio_color_cb, NULL);
}
-void resource_rgb_l2c_set(bool red, bool green, bool blue)
+void resource_rgb_l2c_set(int red, int green, int blue)
{
if (red == s_info.current_rgb_l2c_color[0] &&
green == s_info.current_rgb_l2c_color[1] &&
@@ -326,7 +338,6 @@ void resource_rgb_l2c_set(bool red, bool green, bool blue)
return;
}
-
s_info.current_rgb_l2c_color[0] = red;
s_info.current_rgb_l2c_color[1] = green;
s_info.current_rgb_l2c_color[2] = blue;
@@ -334,7 +345,7 @@ void resource_rgb_l2c_set(bool red, bool green, bool blue)
_rgb_l2c_set(red, green, blue);
}
-void resource_rgb_l2c_blink(bool red, bool green, bool blue, unsigned timeout)
+void resource_rgb_l2c_blink(int red, int green, int blue, unsigned timeout)
{
if (red == s_info.current_rgb_l2c_color[0] &&
green == s_info.current_rgb_l2c_color[1] &&