#include "led.h"

#ifdef ALPS_IN_PCA10040
static const uint8_t m_board_led_list[LEDS_NUMBER] = LEDS_LIST;

void led_off(uint32_t led_idx)
{
    ASSERT(led_idx < LEDS_NUMBER);
    nrf_gpio_pin_write(m_board_led_list[led_idx], LEDS_ACTIVE_STATE ? 0 : 1);
}

void led_on(uint32_t led_idx)
{
    ASSERT(led_idx < LEDS_NUMBER);
    nrf_gpio_pin_write(m_board_led_list[led_idx], LEDS_ACTIVE_STATE ? 1 : 0);
}


void led_toggle(uint32_t led_idx)
{
    nrf_gpio_pin_toggle(m_board_led_list[led_idx]);
}


void led_off_all(void)
{
    uint32_t i;
    for (i = 0; i < LEDS_NUMBER; ++i)
    {
        led_off(i);
    }
}

void led_gpio_init(void)
{
    int i;
    for(i =0; i < LEDS_NUMBER; i++)
    {
        nrf_gpio_cfg_output(m_board_led_list[i]);
    }
    led_off_all();
}

#endif // ALPS_IN_PCA10040

#ifdef BOARD_ALPS
#include "aw2013.h"
extern aw2013_dev_t aw2013_device;
#endif
void led_invert(uint32_t led_idx)
{
    ASSERT(led_idx < LEDS_NUMBER);
    nrf_gpio_pin_toggle(m_board_led_list[led_idx]);
#ifdef BOARD_ALPS
    static bool state = false;
    if(state)
    {
        aw2013_set_brightness(&aw2013_device, AW_LED0, 0);
    }else
    {
        aw2013_set_brightness(&aw2013_device, AW_LED0, 127);
    }
    state = !state;
#endif
}


