#include <Arduino.h>
#include "gpio.h"

extern void sdCardInsert();
extern void switchImage();
bool gpioInit(void){
    // PIN initialization
    pinMode(BOARD_LED1_PIN , OUTPUT);
    pinMode(BOARD_LED2_PIN , OUTPUT);
    pinMode(BOARD_LED3_PIN , OUTPUT);
    pinMode(BOARD_SDCARD_INSERT, INPUT_PULLUP);
    pinMode(BOARD_SWITCH1_PIN , INPUT_PULLUP);
    pinMode(BOARD_SWITCH2_PIN , INPUT_PULLUP);
    pinMode(BOARD_SWITCH3_PIN , INPUT_PULLUP);
    pinMode(BOARD_SWITCH4_PIN , INPUT_PULLUP);
    pinMode(BOARD_SCSI_TERM_HIGH, OUTPUT);
    pinMode(BOARD_SCSI_TERM_LOW, OUTPUT);
    pinMode(BOARD_SCSI_TERM_POWER, INPUT); //Check if external termination power is provided

    attachInterrupt(BOARD_SDCARD_INSERT,sdCardInsert, CHANGE);
    attachInterrupt(BOARD_SWITCH1_PIN,switchImage, CHANGE);
    attachInterrupt(BOARD_SWITCH2_PIN,switchImage, CHANGE);
    attachInterrupt(BOARD_SWITCH3_PIN,switchImage, CHANGE);
    attachInterrupt(BOARD_SWITCH4_PIN,switchImage, CHANGE);

    pinMode(BOARD_SCSI_ATN, INPUT_PULLUP);
    pinMode(BOARD_SCSI_BSY, INPUT_PULLUP);
    pinMode(BOARD_SCSI_ACK, INPUT_PULLUP);
    pinMode(BOARD_SCSI_RST, INPUT_PULLUP);
    pinMode(BOARD_SCSI_SEL, INPUT_PULLUP);

    // Output port
    pinMode(BOARD_SCSI_MSG, OUTPUT_OPEN_DRAIN);
    pinMode(BOARD_SCSI_CD, OUTPUT_OPEN_DRAIN);
    pinMode(BOARD_SCSI_REQ, OUTPUT_OPEN_DRAIN);
    pinMode(BOARD_SCSI_IO, OUTPUT_OPEN_DRAIN);

    // Control SCSI drivers
    pinMode(BOARD_SCSI_DTD, OUTPUT_OPEN_DRAIN);
    pinMode(BOARD_SCSI_IND, OUTPUT_OPEN_DRAIN);
    pinMode(BOARD_SCSI_TAD, OUTPUT_OPEN_DRAIN);
    pinMode(BOARD_TRANS_OE, OUTPUT_OPEN_DRAIN);
}
  