/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include <eCxx/eCxx_LEDDriver.h>

#include "NodeMCU_Common.h"


//
// Pin numbers
//
static constexpr eCxx::uint8_t BCM_R = 14;
static constexpr eCxx::uint8_t BCM_G = 13;
static constexpr eCxx::uint8_t BCM_B = 15;


//
// Include common source code for BCMOutput test application
//
#include "../CommonCode/BCMOutput_Common.h"


//
// ISR for updating BCM
//
static void ICACHE_RAM_ATTR bcmISR()
{ bcmRGB.update(); }


//
// The init function
//
void eCxx_user_init()
{
    // Initialize application
    initBasicNodeMCUApp();

    // Enable the 74LVC541 buffers on the eCxx NodeMCU development board because
    // the pins defined above are buffered
    App::setPinMode  ( eCxx::NodeMCU::D0, eCxx::Application::PinMode::Output ); // GPIO16
    App::digitalWrite( eCxx::NodeMCU::D0, false                              ); // The buffers are active low

    // Initialize UART
    App::uart().begin(9600);

    // Initialize BCM pins
    eCxx_user_init_initializeBCMPin();

    // Initialize periodic interrupt for BCM
    // NOTE : Using lambda callback seems does not work because BCMOutput<T> is a template class
    App::attachPeriodicInterrupt(bcmISR, 25000U);
}


//
// The task function
//
void eCxx_user_task()
{
    // Process event and update the BCM animation
    eCxx_user_task_updateBCMAnimation();
}
