Subversion Repositories Code-Repo

Rev

Rev 277 | Details | Compare with Previous | 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_INT_TRIS    TRISAbits.TRISA2
31
 
32
#define I2C_ADDR_3_TRIS TRISCbits.TRISC3
33
#define I2C_ADDR_2_TRIS TRISCbits.TRISC2
34
#define I2C_ADDR_1_TRIS TRISCbits.TRISC1
35
#define I2C_ADDR_0_TRIS TRISCbits.TRISC0
36
 
37
#define I2C_ADDR_3_WPU  WPUCbits.WPUC3
38
#define I2C_ADDR_2_WPU  WPUCbits.WPUC2
39
#define I2C_ADDR_1_WPU  WPUCbits.WPUC1
40
#define I2C_ADDR_0_WPU  WPUCbits.WPUC0
41
 
273 Kevin 42
#define I2C_ADDR_3_PORT  PORTCbits.RC3
43
#define I2C_ADDR_2_PORT  PORTCbits.RC2
44
#define I2C_ADDR_1_PORT  PORTCbits.RC1
45
#define I2C_ADDR_0_PORT  PORTCbits.RC0
260 Kevin 46
 
47
#define I2C_1_CLK_TRIS  TRISBbits.TRISB6
48
#define I2C_1_DAT_TRIS  TRISBbits.TRISB4
49
 
50
#define I2C_2_CLK_TRIS  TRISBbits.TRISB7
51
#define I2C_2_DAT_TRIS  TRISBbits.TRISB5
277 Kevin 52
 
53
#define CPS_R_TRIS  TRISCbits.TRISC6
54
#define CPS_L_TRIS  TRISCbits.TRISC7
55
#define CPS_R_ANSL  ANSELCbits.ANSC6
56
#define CPS_L_ANSL  ANSELCbits.ANSC7
57
#define CPS_R_WPU   WPUCbits.WPUC6
58
#define CPS_L_WPU   WPUCbits.WPUC7
59
 
260 Kevin 60
// </editor-fold>
61
 
62
#define _XTAL_FREQ      32000000
63
 
64
#define CMD_QUERY_BTN   0x0A
65
#define CMD_SET_LEDS    0x0B
273 Kevin 66
#define CMD_RESET       0x0C
275 Kevin 67
#define CMD_ACTIVE      0x0D
260 Kevin 68
 
273 Kevin 69
#define OP_STATE_IDLE   0x10
70
#define OP_STATE_ACTIVE 0x20
71
 
72
#define RESET_POR   0x0
73
#define RESET_BOR   0x1
74
#define RESET_MCLR  0x2
75
#define RESET_WDT   0x3
76
#define RESET_RST   0x4
77
#define RESET_STK   0x5
78
 
79
#define I2C1_SLAVE_PREFIX   0x10
80
 
277 Kevin 81
#define DIR_BRIGHTNESS  0x40
82
#define DIR_S   0x00
83
#define DIR_W   0x01
84
#define DIR_N   0x02
85
#define DIR_E   0x03
86
 
260 Kevin 87
typedef union {
88
    struct {
89
        unsigned BTN_L_N    :1;
90
        unsigned BTN_L_E    :1;
270 Kevin 91
        unsigned BTN_R_E    :1;
260 Kevin 92
        unsigned BTN_R_N    :1;
93
        unsigned BTN_R_S    :1;
94
        unsigned BTN_R_W    :1;
270 Kevin 95
        unsigned BTN_L_S    :1;
96
        unsigned BTN_L_W    :1;
260 Kevin 97
    };
98
    uint8_t w;
99
} BTN_STATUS;
100
 
101
typedef union {
102
    struct {
270 Kevin 103
        uint8_t LED_0;
104
        uint8_t LED_1;
105
        uint8_t LED_2;
106
        uint8_t LED_3;
107
        uint8_t LED_4;
108
        uint8_t LED_5;
109
        uint8_t LED_6;
110
        uint8_t LED_7;
111
        uint8_t LED_N;
112
        uint8_t LED_W;
113
        uint8_t LED_E;
114
        uint8_t LED_S;
115
        uint8_t LED_A;
116
        uint8_t LED_B;
117
        uint8_t LED_C;
118
        uint8_t LED_D;
119
    } single;
120
    uint8_t w[16];
121
} LED_VALUES;
260 Kevin 122
 
273 Kevin 123
void Reset_Board(uint8_t next_state);
124
uint8_t Get_Last_Reset(void);
125
 
277 Kevin 126
void Check_I2C_Idle(void);
270 Kevin 127
void Idle_Animation(void);
260 Kevin 128
 
277 Kevin 129
uint8_t Direction_Rotate_Clockwise(uint8_t);
130
uint8_t Direction_Rotate_CClockwise(uint8_t);
131
 
260 Kevin 132
#endif	/* DEFINES_H */
133