/*
 * Interface.c
 */

#include "Interface.h"
#ifdef __MSP430F5529__
#include <msp430f5529.h>
#elif defined __MSP430FR6989__
#include <msp430fr6989.h>
#endif

/**
 * Initialize P1.5 for RESET output.
 *
 * @return none
 */
void initRESET()
{
#ifdef __MSP430F5529__
    // Configure RESET pin on P1.5
    P1DIR |= BIT5; // Set P1.5 as output
    P1OUT |= BIT5; // Set P1.5 HIGH

#elif defined __MSP430FR6989
    // Configure RESET pin on P2.2
    P2DIR |= BIT2; // Set P2.2 as output
    P2OUT |= BIT2; // Set P2.2 HIGH
#endif
}

/**
 * Perform a hardware RESET.
 *
 * @return none
 */
void RESET()
{
#ifdef __MSP430F5529__
    P1OUT &= ~BIT5; // Set P1.5 LOW
    __delay_cycles(RESET_DELAY); // Approx. 1ms delay to hold RESET LOW
    P1OUT |= BIT5; // Set P1.5 HIGH
#elif defined __MSP430FR6989
    P2OUT &= ~BIT2; // Set P2.2 LOW
    __delay_cycles(RESET_DELAY); // Approx. 1ms delay to hold RESET LOW
    P2OUT |= BIT2; // Set P2.2 HIGH
#endif

    __delay_cycles(DISPLAY_POWER_DELAY); // Approx. 1500ms delay to let display power ON
}

/**
 * Find the size of the given array.
 *
 * @param data Array to inspect.
 * @return Size of array.
 */
int arraySize(unsigned char* data)
{
    unsigned int size = 0;
    while(data[size] != '\0')
    {
        size++;
    }
    return size;
}
