Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
260 Kevin 1
#ifndef DEFINES_H
2
#define	DEFINES_H
3
 
4
#include <xc.h>
5
#include <stdint.h>
6
 
7
// <editor-fold defaultstate="collapsed" desc="I/O Pins">
8
    /* Pins Mapping
9
     * 2 - RA5 - LSM303_DRDY
10
     * 3 - RA4 - L3GD20_DRDY
11
     * 5 - RC5 - UART_RX
12
     * 6 - RC4 - UART TX
13
     * 7 - RC3 - ADDR_3
14
     * 8 - RC6 - BTN_CAP_0
15
     * 9 - RC7 - BTN_CAP_1
16
     * 10 - RB7 - SCL_2
17
     * 11 - RB6 - SCL_1
18
     * 12 - RB5 - SDA_2
19
     * 13 - RB4 - SDA_1
20
     * 14 - RC2 - ADDR_2
21
     * 15 - RC1 - ADDR_1
22
     * 16 - RC0 - ADDR_0
23
     * 17 - RA2 - BTN_INT
24
     */
25
#define LSM303_INT_TRIS TRISAbits.TRISA5
26
#define L3GD20_INT_TRIS TRISAbits.TRISA4
27
#define UART_RX_TRIS    TRISCbits.TRISC5
28
#define UART_TX_TRIS    TRISCbits.TRISC4
29
 
30
#define BTN_CAP_0_TRIS  TRISCbits.TRISC6
31
#define BTN_CAP_1_TRIS  TRISCbits.TRISC7
32
 
33
#define BTN_INT_TRIS    TRISAbits.TRISA2
34
 
35
#define I2C_ADDR_3_TRIS TRISCbits.TRISC3
36
#define I2C_ADDR_2_TRIS TRISCbits.TRISC2
37
#define I2C_ADDR_1_TRIS TRISCbits.TRISC1
38
#define I2C_ADDR_0_TRIS TRISCbits.TRISC0
39
 
40
#define I2C_ADDR_3_WPU  WPUCbits.WPUC3
41
#define I2C_ADDR_2_WPU  WPUCbits.WPUC2
42
#define I2C_ADDR_1_WPU  WPUCbits.WPUC1
43
#define I2C_ADDR_0_WPU  WPUCbits.WPUC0
44
 
273 Kevin 45
#define I2C_ADDR_3_PORT  PORTCbits.RC3
46
#define I2C_ADDR_2_PORT  PORTCbits.RC2
47
#define I2C_ADDR_1_PORT  PORTCbits.RC1
48
#define I2C_ADDR_0_PORT  PORTCbits.RC0
260 Kevin 49
 
50
#define I2C_1_CLK_TRIS  TRISBbits.TRISB6
51
#define I2C_1_DAT_TRIS  TRISBbits.TRISB4
52
 
53
#define I2C_2_CLK_TRIS  TRISBbits.TRISB7
54
#define I2C_2_DAT_TRIS  TRISBbits.TRISB5
55
// </editor-fold>
56
 
57
#define _XTAL_FREQ      32000000
58
 
59
#define CMD_QUERY_BTN   0x0A
60
#define CMD_SET_LEDS    0x0B
273 Kevin 61
#define CMD_RESET       0x0C
275 Kevin 62
#define CMD_ACTIVE      0x0D
260 Kevin 63
 
273 Kevin 64
#define OP_STATE_IDLE   0x10
65
#define OP_STATE_ACTIVE 0x20
66
 
67
#define RESET_POR   0x0
68
#define RESET_BOR   0x1
69
#define RESET_MCLR  0x2
70
#define RESET_WDT   0x3
71
#define RESET_RST   0x4
72
#define RESET_STK   0x5
73
 
74
#define I2C1_SLAVE_PREFIX   0x10
75
 
260 Kevin 76
typedef union {
77
    struct {
78
        unsigned BTN_L_N    :1;
79
        unsigned BTN_L_E    :1;
270 Kevin 80
        unsigned BTN_R_E    :1;
260 Kevin 81
        unsigned BTN_R_N    :1;
82
        unsigned BTN_R_S    :1;
83
        unsigned BTN_R_W    :1;
270 Kevin 84
        unsigned BTN_L_S    :1;
85
        unsigned BTN_L_W    :1;
260 Kevin 86
    };
87
    uint8_t w;
88
} BTN_STATUS;
89
 
90
typedef union {
91
    struct {
270 Kevin 92
        uint8_t LED_0;
93
        uint8_t LED_1;
94
        uint8_t LED_2;
95
        uint8_t LED_3;
96
        uint8_t LED_4;
97
        uint8_t LED_5;
98
        uint8_t LED_6;
99
        uint8_t LED_7;
100
        uint8_t LED_N;
101
        uint8_t LED_W;
102
        uint8_t LED_E;
103
        uint8_t LED_S;
104
        uint8_t LED_A;
105
        uint8_t LED_B;
106
        uint8_t LED_C;
107
        uint8_t LED_D;
108
    } single;
109
    uint8_t w[16];
110
} LED_VALUES;
260 Kevin 111
 
273 Kevin 112
void Reset_Board(uint8_t next_state);
113
uint8_t Get_Last_Reset(void);
114
 
275 Kevin 115
void Check_I2C(void);
270 Kevin 116
void Idle_Animation(void);
260 Kevin 117
 
118
#endif	/* DEFINES_H */
119