Subversion Repositories Code-Repo

Rev

Rev 273 | Blame | Last modification | View Log | RSS feed

#include "defines.h"
#include "IO.h"
#include "MCP23009.h"

void IO_Init(void) {
    // Set all pins to digital I/O
    ANSELA = 0x0;
    ANSELB = 0x0;
    ANSELC = 0x0;

    // Enable weak pull-up if WPU bit is set
    OPTION_REGbits.nWPUEN = 0;

    // Initialize interrupt inputs
    LSM303_INT_TRIS = 1;
    L3GD20_INT_TRIS = 1;
    BTN_INT_TRIS = 1;

    // Initialize UART pins
    UART_RX_TRIS = 1;
    UART_TX_TRIS = 0;

    // Initialize I2C address pins
    I2C_ADDR_0_TRIS = 1;
    I2C_ADDR_1_TRIS = 1;
    I2C_ADDR_2_TRIS = 1;
    I2C_ADDR_3_TRIS = 1;
    // Enable the weak-pullup on the address pins
    I2C_ADDR_0_WPU = 1;
    I2C_ADDR_1_WPU = 1;
    I2C_ADDR_2_WPU = 1;
    I2C_ADDR_3_WPU = 1;

    // Initialize I2C pins (dont really need to as the I2C code does it)
    I2C_1_CLK_TRIS = 1;
    I2C_1_DAT_TRIS = 1;
    I2C_2_CLK_TRIS = 1;
    I2C_2_DAT_TRIS = 1;

    // Set the CPS pins
    CPS_L_TRIS = 1;
    CPS_R_TRIS = 1;
    CPS_L_ANSL = 1;
    CPS_R_ANSL = 1;
    CPS_R_WPU = 0;
    CPS_L_WPU = 0;
}

void IO_IOC_Enable(void) {
    // Clear all IOC flags
    IOCAF = 0x0;
    IOCBF = 0x0;

    // Trigger interrupt on BTN_INT on falling edge
    IOCANbits.IOCAN2 = 1;
    
    // Enable IOC interrupts
    INTCONbits.IOCIE = 1;
}

void IO_Interrupt(void) {
    Reset_Board(OP_STATE_ACTIVE);
}