2 * Status LED driver based on GPIO access conventions of Linux
4 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
5 * Licensed under the GPL-2 or later.
9 #include <status_led.h>
12 #ifndef CONFIG_GPIO_LED_INVERTED_TABLE
13 #define CONFIG_GPIO_LED_INVERTED_TABLE {}
16 static led_id_t gpio_led_inv[] = CONFIG_GPIO_LED_INVERTED_TABLE;
18 static int gpio_led_gpio_value(led_id_t mask, int state)
20 int i, gpio_value = (state == STATUS_LED_ON);
22 for (i = 0; i < ARRAY_SIZE(gpio_led_inv); i++) {
23 if (gpio_led_inv[i] == mask)
24 gpio_value = !gpio_value;
30 void __led_init(led_id_t mask, int state)
34 if (gpio_request(mask, "gpio_led") != 0) {
35 printf("%s: failed requesting GPIO%lu!\n", __func__, mask);
39 gpio_value = gpio_led_gpio_value(mask, state);
40 gpio_direction_output(mask, gpio_value);
43 void __led_set(led_id_t mask, int state)
45 int gpio_value = gpio_led_gpio_value(mask, state);
47 gpio_set_value(mask, gpio_value);
50 void __led_toggle(led_id_t mask)
52 gpio_set_value(mask, !gpio_get_value(mask));