-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDPolicies.h
37 lines (30 loc) · 1000 Bytes
/
SDPolicies.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
//
// Created by Ethan on 07-Apr-19.
//
#ifndef SDCARD_SDPOLICIES_H
#define SDCARD_SDPOLICIES_H
#include <type_traits>
#include <cstdio>
#include <string>
#include <chrono>
extern "C" {
#include "spiDriver/spidriver.h"
}
extern SPIDriver spiTester;
extern std::string SpiDriverPort;
struct SPIShim {
bool active() { return spiTester.connected > 0; }
bool begin() {
if(!active()) {
spi_connect(&spiTester, SpiDriverPort.c_str());
}
return active();
}
void select() { spi_sel(&spiTester); }
void deSelect() { spi_unsel(&spiTester); }
ssize_t write(const uint8_t* buf, const size_t LEN) { spi_write(&spiTester, (const char*)buf, LEN); return LEN; }
uint8_t write(uint8_t val) { return read(val); }
ssize_t read(uint8_t* buf, const size_t LEN) { spi_read(&spiTester, (char*)buf, LEN); return LEN; }
uint8_t read(uint8_t val = 0xFF) { spi_writeread(&spiTester, (char*)(&val), 1); return val; }
};
#endif //SDCARD_SDPOLICIES_H