-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi.h
75 lines (62 loc) · 1.7 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* spi.h
*
* Created on: Mar 18, 2023
* Author: dylan
*/
#ifndef SPI_H_
#define SPI_H_
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "defines.h"
/**
* Initialize the UCB0 SPI peripheral.
*/
void spi_init();
/**
* One SPI transaction: shift out the bytes on *output*, while reading the results to the buffer *input*.
* Both buffers are the same size, specified by parameter `size`.
*/
void spi_transaction(const uint8_t *output, uint8_t *input, size_t size);
/**
* Send size bytes from output, ignoring any incoming received bytes.
*/
void spi_send(const uint8_t *output, size_t size);
/*
* Blocking DMA version of spi_send.
* TODO: merge spi_send and spi_send_dma
*/
void spi_send_dma(const uint8_t *output, size_t size);
/*
* Receive size bytes into input, repeating the same fillByte on the output.
*/
void spi_receive(uint8_t *input, uint8_t fillByte, size_t size);
/**
* Blocking DMA version of spi_receive.
* TODO: merge spi_receive and spi_receive_dma
*/
void spi_receive_dma(uint8_t *input, uint8_t fillByte, size_t size);
/**
* Send the single byte `byte` and return the received byte.
*/
uint8_t spi_send_byte(uint8_t byte);
/**
* Wrapper around spi_send_byte that sends 0xFF and returns the received byte.
*/
uint8_t spi_receive_byte();
/**
* Prepare DMA2 to perform a block -> single address bytewise
* transfer, but don't start the DMA yet.
*/
void dma_tx_setup(const uint8_t *buf, size_t size);
// Unfortunate hack: this flag is to true / 1 whenever a DMA completes
// and triggers the DMA_VECTOR ISR.
extern volatile bool dmaDone;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* SPI_H_ */