Subversion Repositories Code-Repo

Rev

Blame | Last modification | View Log | RSS feed

#ifndef SPI_H
#define SPI_H

#define MAXSPIBUF 64

// Option to use interrupt. If interrupt are used, SPI write does not block but
//  there is a longer delay between reading/writing data
//#define SPI2_USE_INTERRUPT

// Option to write only
#define SPI2_WRITE_ONLY

// SPI speed selection
#define SPI2_FOSC_64        1
#define SPI2_FOSC_16        2
#define SPI2_FOSC_8         3
#define SPI2_FOSC_4         4

typedef struct __SPI_DATA {
    unsigned char buffer_in[MAXSPIBUF];
    unsigned char buffer_in_read_ind;
    unsigned char buffer_in_write_ind;
    unsigned char buffer_in_len;

    unsigned char buffer_out[MAXSPIBUF];
    unsigned char buffer_out_ind;
    unsigned char buffer_out_len;
} SPI_DATA;

void SPI2_Init(unsigned char speed);
void SPI2_Recv_Interrupt_Handler(void);
void SPI2_Write(unsigned char *msg, unsigned int length);
void SPI2_Write_Repeat(unsigned char c, unsigned int length);
void SPI2_Read(unsigned char length);
unsigned char SPI2_Buffer_Len(void);
unsigned char SPI2_Buffer_Read(unsigned char *buffer);

#endif  /* SPI_H */