Subversion Repositories Code-Repo

Rev

Blame | Last modification | View Log | RSS feed

#ifndef DEFINES_H
#define DEFINES_H

#include <xc.h>
#include <stdint.h>

// <editor-fold defaultstate="collapsed" desc="I/O Pins">
    /* Pins Mapping
     * 2 - RA5 - LSM303_DRDY
     * 3 - RA4 - L3GD20_DRDY
     * 5 - RC5 - UART_RX
     * 6 - RC4 - UART TX
     * 7 - RC3 - ADDR_3
     * 8 - RC6 - BTN_CAP_0
     * 9 - RC7 - BTN_CAP_1
     * 10 - RB7 - SCL_2
     * 11 - RB6 - SCL_1
     * 12 - RB5 - SDA_2
     * 13 - RB4 - SDA_1
     * 14 - RC2 - ADDR_2
     * 15 - RC1 - ADDR_1
     * 16 - RC0 - ADDR_0
     * 17 - RA2 - BTN_INT
     */
#define LSM303_INT_TRIS TRISAbits.TRISA5
#define L3GD20_INT_TRIS TRISAbits.TRISA4
#define UART_RX_TRIS    TRISCbits.TRISC5
#define UART_TX_TRIS    TRISCbits.TRISC4

#define BTN_CAP_0_TRIS  TRISCbits.TRISC6
#define BTN_CAP_1_TRIS  TRISCbits.TRISC7

#define BTN_INT_TRIS    TRISAbits.TRISA2

#define I2C_ADDR_3_TRIS TRISCbits.TRISC3
#define I2C_ADDR_2_TRIS TRISCbits.TRISC2
#define I2C_ADDR_1_TRIS TRISCbits.TRISC1
#define I2C_ADDR_0_TRIS TRISCbits.TRISC0

#define I2C_ADDR_3_WPU  WPUCbits.WPUC3
#define I2C_ADDR_2_WPU  WPUCbits.WPUC2
#define I2C_ADDR_1_WPU  WPUCbits.WPUC1
#define I2C_ADDR_0_WPU  WPUCbits.WPUC0

#define I2C_ADDR_3_LAT  LATCbits.LATC3
#define I2C_ADDR_2_LAT  LATCbits.LATC2
#define I2C_ADDR_1_LAT  LATCbits.LATC1
#define I2C_ADDR_0_LAT  LATCbits.LATC0

#define I2C_1_CLK_TRIS  TRISBbits.TRISB6
#define I2C_1_DAT_TRIS  TRISBbits.TRISB4

#define I2C_2_CLK_TRIS  TRISBbits.TRISB7
#define I2C_2_DAT_TRIS  TRISBbits.TRISB5
// </editor-fold>

#define _XTAL_FREQ      32000000

#define CMD_QUERY_BTN   0x0A
#define CMD_SET_LEDS    0x0B

typedef union {
    struct {
        unsigned BTN_L_N    :1;
        unsigned BTN_L_E    :1;
        unsigned BTN_L_S    :1;
        unsigned BTN_L_W    :1;
        unsigned BTN_R_N    :1;
        unsigned BTN_R_E    :1;
        unsigned BTN_R_S    :1;
        unsigned BTN_R_W    :1;
    };
    uint8_t w;
} BTN_STATUS;

typedef union {
    struct {
        unsigned LED_A      :1;
        unsigned LED_B      :1;
        unsigned LED_C      :1;
        unsigned LED_D      :1;
        unsigned LED_1      :1;
        unsigned LED_2      :1;
        unsigned LED_3      :1;
        unsigned LED_4      :1;
        unsigned LED_5      :1;
        unsigned LED_6      :1;
        unsigned LED_7      :1;
        unsigned LED_8      :1;
        unsigned LED_N      :1;
        unsigned LED_E      :1;
        unsigned LED_S      :1;
        unsigned LED_W      :1;
    };
    uint8_t w[2];
} LED_STATUS;

void Pins_Read(BTN_STATUS *btns);
void Leds_Write(LED_STATUS *leds);

#endif  /* DEFINES_H */