diff options
Diffstat (limited to 'spi.h')
| -rw-r--r-- | spi.h | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -0,0 +1,42 @@ +#ifndef _H_SPI +#define _H_SPI + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#include "spi_config.h" + +#define DUMMY_DATA 0xff + +#ifdef SPI_MSSP1 + #define SSPSTAT SSP1STAT + #define SSPSTATbits SSP1STATbits + #define SSPCON1 SSP1CON1 + #define SSPCON1bits SSP1CON1bits + #define SSPADD SSP1ADD + #define SSPBUF SSP1BUF +#else +#ifdef SPI_MSSP2 + #define SSPSTAT SSP2STAT + #define SSPSTATbits SSP2STATbits + #define SSPCON1 SSP2CON1 + #define SSPCON1bits SSP2CON1bits + #define SSPADD SSP2ADD + #define SSPBUF SSP2BUF +#else + #error define either SPI_MSSP1 or SPI_MSSP2 +#endif +#endif + +#define spi_tx(x) (spi_exchange(x)) +#define spi_rx() (spi_exchange(DUMMY_DATA)) + +void spi_init(void); +uint8_t spi_exchange(uint8_t data); +uint8_t spi_exchange_buffer(uint8_t *in, uint8_t buflen, uint8_t *out); +inline bool spi_is_buffer_full(void); +inline bool spi_has_write_collision_occured(void); +inline void spi_clear_write_collision_status(void); + +#endif |
