My Project
 All Classes Functions Variables Pages
SPI.h
1 /*
2  * SPI.h
3  *
4  * Created on: Mar 3, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_SPI_H_
9 #define COMPONENTS_CPP_UTILS_SPI_H_
10 #include <driver/spi_master.h>
11 #include <driver/gpio.h>
15 class SPI {
16 public:
17  SPI();
18  virtual ~SPI();
19  void init(
20  int mosiPin = DEFAULT_MOSI_PIN,
21  int misoPin = DEFAULT_MISO_PIN,
22  int clkPin = DEFAULT_CLK_PIN,
23  int csPin = DEFAULT_CS_PIN);
24  void setHost(spi_host_device_t host);
25  void transfer(uint8_t* data, size_t dataLen);
26  uint8_t transferByte(uint8_t value);
27 
31  static const int DEFAULT_MOSI_PIN = GPIO_NUM_13;
32 
36  static const int DEFAULT_MISO_PIN = GPIO_NUM_12;
37 
41  static const int DEFAULT_CLK_PIN = GPIO_NUM_14;
42 
46  static const int DEFAULT_CS_PIN = GPIO_NUM_15;
47 
51  static const int PIN_NOT_SET = -1;
52 
53 private:
54  spi_device_handle_t m_handle;
55  spi_host_device_t m_host;
56 
57 };
58 
59 #endif /* COMPONENTS_CPP_UTILS_SPI_H_ */
static const int PIN_NOT_SET
Value of unset pin.
Definition: SPI.h:51
Handle SPI protocol.
Definition: SPI.h:15
void transfer(uint8_t *data, size_t dataLen)
Send and receive data through SPI. This is a blocking call.
Definition: SPI.cpp:111
SPI()
Construct an instance of the class.
Definition: SPI.cpp:21
virtual ~SPI()
Class instance destructor.
Definition: SPI.cpp:30
void setHost(spi_host_device_t host)
Set the SPI host to use. Call this prior to init().
Definition: SPI.cpp:100
static const int DEFAULT_CLK_PIN
The default CLK pin.
Definition: SPI.h:41
static const int DEFAULT_MISO_PIN
The default MISO pin.
Definition: SPI.h:36
static const int DEFAULT_MOSI_PIN
The default MOSI pin.
Definition: SPI.h:31
static const int DEFAULT_CS_PIN
The default CS pin.
Definition: SPI.h:46
void init(int mosiPin=DEFAULT_MOSI_PIN, int misoPin=DEFAULT_MISO_PIN, int clkPin=DEFAULT_CLK_PIN, int csPin=DEFAULT_CS_PIN)
Initialize SPI.
Definition: SPI.cpp:47
uint8_t transferByte(uint8_t value)
Send and receive a single byte.
Definition: SPI.cpp:141