-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi.h
40 lines (32 loc) · 1.1 KB
/
spi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Based on the work by Neil MacMillan
Functions for using the atmega328p as an SPI master.
*/
#ifndef SPI_H_
#define SPI_H_
#include <stdio.h>
#include <avr/io.h>
#include <stdlib.h>
/**
* Initialize the SPI port as a master.
* This function must be called once before using the SPI interface.
*/
void spiInit();
/**
* Write a block of data to the slave, and read the data returned from the slave into a buffer.
* The data and buffer memory blocks must be the same length.
* \param data A pointer to the contiguous memory block to write to the slave.
* \param buffer A pointer to the contiguous memory block to which the SPI data are to be written.
* \param len The length of the memory blocks, in bytes.
*/
void spiReadWriteBlock (uint8_t * data, uint8_t * buffer, uint8_t len);
/**
* Write a byte to the slave, and get the return byte from the slave.
*/
uint8_t spiReadWriteByte(uint8_t byte);
// More confenience functions
void spiWriteByte(uint8_t byte);
uint8_t spiReadByte(void);
void spiWriteBlock(uint8_t* data, uint8_t len);
void spiReadBlock(uint8_t* buffer, uint8_t len);
#endif /* SPI_H_ */