-
Notifications
You must be signed in to change notification settings - Fork 0
/
spi_dma.h
executable file
·53 lines (41 loc) · 1.49 KB
/
spi_dma.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
#include "Arduino.h"
#include "dubsiren.h"
#ifndef __SPI_DMA_H
#define __SPI_DMA_H
#define DMA_CH_WRITE 0
#define DMA_CH_READ 1
#define SPI_CMD_READ 3
#define SPI_CMD_WRITE 2
enum dma_state_t {DMA_IDLE, DMA_READ, DMA_WRITE, DMA_WRITE_A, DMA_WRITE_B, DMA_READ_A, DMA_READ_B};
typedef struct __attribute__((packed)) spi_address_s {
uint8_t byte2;
uint8_t byte1;
uint8_t byte0;
} spi_address_t;
typedef struct __attribute__((packed)) spi_buffer_s {
uint8_t opcode;
spi_address_t address;
uint16_t data[SPI_BLOCK_SIZE];
} spi_buffer_t;
void printDataBuffer (uint16_t *buffer);
class SpiDma {
private:
void _setupSpi ();
void _setupDma ();
public:
volatile spi_buffer_t read_buffer[2]; // the opcode and address are not used but the dma will return bytes when they are written
volatile spi_buffer_t write_buffer[2]; // also, the compiler does not allow making these volatile
volatile bool transfer_active;
SpiDma ();
void read (int buffer_index, uint32_t address);
void write (int buffer_index, uint32_t address);
void erase (); // erase the entire ram ic
void irqHandler ();
// void printReadBuffer (int index) {_printBuffer(&read_buffer[index].data[0]);}
//void printWriteBuffer (int index) {_printBuffer(&write_buffer[index].data[0]);}
void printReadBuffer (int index);
void printWriteBuffer (int index);
void printBtCount (int channel);
void printDmaDescriptor (int channel, bool writeback);
};
#endif