diff options
| author | Camil Staps | 2017-01-31 23:15:28 +0100 |
|---|---|---|
| committer | Camil Staps | 2017-01-31 23:15:28 +0100 |
| commit | 631204a1feffa8cf3795060370b14dfb9f53f533 (patch) | |
| tree | 001d32e0157127607f7c088881f098c2eca841a1 /spi.h | |
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 |
