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


#include <eCxx/eCxx.h>

#include "NodeMCU_Common.h"


//
// Pin numbers
//
static constexpr eCxx::uint8_t PLL = eCxx::NodeMCU::SPI_SS;   // Parallel data latch/load
static constexpr eCxx::uint8_t SDO = eCxx::NodeMCU::SPI_MOSI; // Serial data output
static constexpr eCxx::uint8_t SDI = eCxx::NodeMCU::SPI_MISO; // Serial data input
static constexpr eCxx::uint8_t SCK = eCxx::NodeMCU::SPI_SCK;  // Serial data clock


//
// Include common source code for IOExpanderRW test application
//
#include "../CommonCode/IOExpanderRW_Common.h"


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

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

    // Initialize the IO expander
    eCxx_user_init_IOExpander();
}


//
// The task function
//
void eCxx_user_task()
{
    // Process event and handle the IO expander
    eCxx_user_task_IOExpander();
}
