-
Notifications
You must be signed in to change notification settings - Fork 9
/
spi.h
77 lines (61 loc) · 1.43 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
76
77
#ifndef SPI_H_
#define SPI_H_
#include <array>
#include <memory>
#include "FreeRTOS.h"
#include "base.h"
#include "hardware/irq.h"
#include "hardware/spi.h"
#include "hardware/timer.h"
#include "ibp.h"
#include "utils.h"
struct IBPSPIArgs {
spi_inst_t* spi_port;
uint32_t rx_pin;
uint32_t tx_pin;
uint32_t cs_pin;
uint32_t sck_pin;
uint32_t baud_rate;
};
struct IBPIRQData {
std::shared_ptr<std::array<uint8_t, IBP_MAX_PACKET_LEN>> rx_buffer;
std::shared_ptr<std::array<uint8_t, IBP_MAX_PACKET_LEN>> tx_buffer;
uint8_t rx_buf_idx;
int8_t rx_packet_size;
uint8_t tx_buf_idx;
uint8_t tx_packet_size;
SemaphoreHandle_t rx_handle;
SemaphoreHandle_t tx_handle;
spi_inst_t* spi_port;
void Clear();
};
class IBPSPIBase : public virtual IBPDeviceBase {
protected:
IBPSPIBase(IBPSPIArgs args);
bool TXEmpty();
void InitSPI(bool slave);
void InitIRQData(irq_handler_t irq_handler);
TaskHandle_t task_handle_;
spi_inst_t* spi_port_;
const uint32_t baud_rate_;
const uint32_t rx_pin_;
const uint32_t tx_pin_;
const uint32_t cs_pin_;
const uint32_t sck_pin_;
IBPIRQData* irq_data_;
};
class IBPSPIDevice : public IBPSPIBase {
public:
Status IBPInitialize() override;
void DeviceTask();
protected:
IBPSPIDevice(IBPSPIArgs args);
};
class IBPSPIHost : public IBPSPIBase {
public:
Status IBPInitialize() override;
void HostTask();
protected:
IBPSPIHost(IBPSPIArgs args);
};
#endif /* SPI_H_ */