Subversion Repositories Code-Repo

Rev

Rev 147 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
121 Kevin 1
#ifndef SPI_H
2
#define	SPI_H
3
 
147 Kevin 4
#include "defines.h"
5
 
121 Kevin 6
#define MAXSPIBUF 64
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
123 Kevin 13
#define SPI2_FOSC_64        0b0010
14
#define SPI2_FOSC_16        0b0001
15
#define SPI2_FOSC_8         0b1010
16
#define SPI2_FOSC_4         0b0000
121 Kevin 17
 
18
typedef struct __SPI_DATA {
147 Kevin 19
#ifndef SPI2_WRITE_ONLY
121 Kevin 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;
147 Kevin 24
#endif
121 Kevin 25
 
26
    unsigned char buffer_out[MAXSPIBUF];
27
    unsigned char buffer_out_ind;
28
    unsigned char buffer_out_len;
29
} SPI_DATA;
30
 
31
void SPI2_Init(unsigned char speed);
32
void SPI2_Write(unsigned char *msg, unsigned int length);
33
void SPI2_Write_Repeat(unsigned char c, unsigned int length);
147 Kevin 34
#ifndef SPI2_WRITE_ONLY
35
void SPI2_Recv_Interrupt_Handler(void);
121 Kevin 36
void SPI2_Read(unsigned char length);
37
unsigned char SPI2_Buffer_Len(void);
122 Kevin 38
unsigned char SPI2_Read_Buffer(unsigned char *buffer);
147 Kevin 39
#endif
121 Kevin 40
 
41
#endif	/* SPI_H */
42