Subversion Repositories Code-Repo

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
155 Kevin 1
#ifndef SPI_H
2
#define	SPI_H
3
 
4
#define MAXSPIBUF 64
5
 
6
#define SPI2_WRITE_ONLY
7
 
8
// Option to use interrupt. If interrupt are used, SPI write does not block but
9
//  there is a longer delay between reading/writing data
10
//#define SPI2_USE_INTERRUPT
11
 
12
// SPI speed selection
192 Kevin 13
#define SPI2_FOSC_TMR2      0b0011
155 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
18
 
19
typedef struct {
20
#ifndef SPI2_WRITE_ONLY
21
    char buffer_in[MAXSPIBUF];
22
    char buffer_in_read_ind;
23
    char buffer_in_write_ind;
24
    char buffer_in_len;
25
#endif
26
 
27
    char buffer_out[MAXSPIBUF];
28
    char buffer_out_ind;
29
    char buffer_out_len;
30
} SPI_DATA;
31
 
32
void SPI2_Init(SPI_DATA *data, char speed);
33
void SPI2_Write(char *msg, unsigned int length);
34
void SPI2_Write_Repeat(char c, unsigned int length);
35
#ifndef SPI2_WRITE_ONLY
36
void SPI2_Recv_Interrupt_Handler(void);
37
void SPI2_Read(char length);
38
char SPI2_Buffer_Len(void);
39
char SPI2_Read_Buffer(char *buffer);
40
#endif
41
 
192 Kevin 42
void SPI2_DMA_Init(void);
43
void SPI2_DMA_Start(unsigned int length, void *TXADDR, void *RXADDR);
44
 
155 Kevin 45
#endif	/* SPI_H */
46