/*
 * gat_gpio.c
 *
 * just gets the GAT ID and does nothing else.
 * but if you wanted to do things with the GPIO, this is where you could do it.
 *
 * hardware peripherals:
 * - GP1 has UART0 TX and PWM9.
 * - GP2 has UART0 RX and PWM7.
 *
 * errata:
 * - bottom board marked REV3 has addon header mirrored.
 *   to manufacture this, GAT GPIO is cut and inoperable.
 *   todo: add strapping GPIO check to determine board version.
 *
 */


#include "gat_gpio.h"



uint8_t gat_id = 0xff;



static void gat_gpio_idle_lo()
{
    GPIOB_ModeCfg(GAT_GPIO_PIN_GP1 | GAT_GPIO_PIN_GP2, GPIO_ModeIN_PD);
}

void gat_gpio_init()
{
    uint8_t lo, hi;

    // at startup, configure each GPIO as input float.
    GPIOB_ModeCfg(GAT_GPIO_PIN_GP1 | GAT_GPIO_PIN_GP2, GPIO_ModeIN_Floating);

    // get ID from GPIO pins
    lo = (GPIOB_ReadPort() & GAT_GPIO_PIN_GP1) ? 1 : 0;
    hi = (GPIOB_ReadPort() & GAT_GPIO_PIN_GP2) ? 1 : 0;

    gat_id = (hi << 1) | lo;

    // configure as weak pulldowns
    gat_gpio_idle_lo();
}
