Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8RF24utilitypigpiospi.h

68 lines · 1.2 KB · Objective-C

1/*
2 *
3 */
4
5#ifndef RF24_UTILITY_PIGPIO_SPI_H_
6#define RF24_UTILITY_PIGPIO_SPI_H_
7
8#include <cstdint>
9#include <stdexcept>
10
11/** Specific exception for SPI errors */
12class SPIException : public std::runtime_error
13{
14public:
15 explicit SPIException(const std::string& msg)
16 : std::runtime_error(msg)
17 {
18 }
19};
20
21class SPI
22{
23
24public:
25 /**
26 * SPI constructor
27 */
28 SPI();
29
30 /**
31 * Start SPI
32 */
33 void begin(int busNo, uint32_t spi_speed);
34
35 /**
36 * Transfer a single byte
37 * @param tx Byte to send
38 * @return Data returned via spi
39 */
40 uint8_t transfer(char tx);
41
42 /**
43 * Transfer a buffer of data
44 * @param txBuf Transmit buffer
45 * @param rxBuf Receive buffer
46 * @param len Length of the data
47 */
48 void transfernb(char* txBuf, char* rxBuf, uint32_t len);
49
50 /**
51 * Transfer a buffer of data without an rx buffer
52 * @param buf Pointer to a buffer of data
53 * @param len Length of the data
54 */
55 void transfern(char* buf, uint32_t len)
56 {
57 transfernb(buf, buf, len);
58 }
59
60 ~SPI();
61
62private:
63 unsigned spiHandle;
64 bool spiIsInitialized = false;
65 void init(uint32_t spi_speed);
66};
67
68#endif /* RF24_UTILITY_PIGPIO_SPI_H_ */