| 121 |
Kevin |
1 |
#ifndef SPI_H
|
|
|
2 |
#define SPI_H
|
|
|
3 |
|
|
|
4 |
#define MAXSPIBUF 64
|
|
|
5 |
|
|
|
6 |
// Option to use interrupt. If interrupt are used, SPI write does not block but
|
|
|
7 |
// there is a longer delay between reading/writing data
|
|
|
8 |
//#define SPI2_USE_INTERRUPT
|
|
|
9 |
|
|
|
10 |
// Option to write only
|
|
|
11 |
#define SPI2_WRITE_ONLY
|
|
|
12 |
|
|
|
13 |
// SPI speed selection
|
| 123 |
Kevin |
14 |
#define SPI2_FOSC_64 0b0010
|
|
|
15 |
#define SPI2_FOSC_16 0b0001
|
|
|
16 |
#define SPI2_FOSC_8 0b1010
|
|
|
17 |
#define SPI2_FOSC_4 0b0000
|
| 121 |
Kevin |
18 |
|
|
|
19 |
typedef struct __SPI_DATA {
|
|
|
20 |
unsigned char buffer_in[MAXSPIBUF];
|
|
|
21 |
unsigned char buffer_in_read_ind;
|
|
|
22 |
unsigned char buffer_in_write_ind;
|
|
|
23 |
unsigned char buffer_in_len;
|
|
|
24 |
|
|
|
25 |
unsigned char buffer_out[MAXSPIBUF];
|
|
|
26 |
unsigned char buffer_out_ind;
|
|
|
27 |
unsigned char buffer_out_len;
|
|
|
28 |
} SPI_DATA;
|
|
|
29 |
|
|
|
30 |
void SPI2_Init(unsigned char speed);
|
|
|
31 |
void SPI2_Recv_Interrupt_Handler(void);
|
|
|
32 |
void SPI2_Write(unsigned char *msg, unsigned int length);
|
|
|
33 |
void SPI2_Write_Repeat(unsigned char c, unsigned int length);
|
|
|
34 |
void SPI2_Read(unsigned char length);
|
|
|
35 |
unsigned char SPI2_Buffer_Len(void);
|
| 122 |
Kevin |
36 |
unsigned char SPI2_Read_Buffer(unsigned char *buffer);
|
| 121 |
Kevin |
37 |
|
|
|
38 |
#endif /* SPI_H */
|
|
|
39 |
|