SPI.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * SPI.h
8  *
9  * Created on: Mar 2, 2016
10  * Author: harry-boe
11  *
12  */
13 
18 #pragma once
19 
20 #include "SPIBase.h"
21 #include "SPISettings.h"
22 
23 //#define SPI_DEBUG 1
24 
25 // for compatibility when porting from Arduino
26 #define SPI_HAS_TRANSACTION 0
27 
28 #define SPI_NO 1
29 
35 class SPIClass : public SPIBase
36 {
37 public:
38  /* @brief begin()
39  *
40  * Initializes the SPI bus using the default SPISettings
41  */
42  void begin() override;
43 
49  void end() override
50  {
51  }
52 
61  void beginTransaction(SPISettings mySettings) override;
62 
70  void endTransaction() override
71  {
72 #ifdef SPI_DEBUG
73  debugf("SPIhw::endTransaction()");
74 #endif
75  }
76 
90  unsigned char transfer(unsigned char val) override
91  {
92  return transfer32(val, 8);
93  }
94 
107  uint8_t read8();
108 
122  unsigned short transfer16(unsigned short val) override
123  {
124  return transfer32(val, 16);
125  };
126 
138  void transfer(uint8_t* buffer, size_t numberBytes) override;
139 
140 private:
154  virtual uint32_t transfer32(uint32_t val, uint8_t bits);
155 
156  // prepare/configure HSPI with settings
157  void prepare(SPISettings mySettings);
158 
162  void spi_byte_order(uint8_t byte_order);
163 
167  void spi_mode(uint8_t mode);
168 
173  void setClock(uint8_t prediv, uint8_t cntdiv);
174 
181  uint32_t getFrequency(int freq, int& pre, int clk);
182  void setFrequency(int freq);
183 
184  SPISettings spiSettings;
185  bool isTX = false;
186  bool initialised = false;
187 };
188 
190 extern SPIClass SPI;
191 
void end() override
end()
Definition: SPI.h:49
Definition: SPISettings.h:33
void begin() override
begin(): Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low...
unsigned char transfer(unsigned char val) override
transfer()
Definition: SPI.h:90
SPIClass SPI
Global instance of SPI class.
void endTransaction() override
endTransaction()
Definition: SPI.h:70
uint8_t read8()
read8() read a byte from SPI without setting up registers
Definition: SPI.h:35
unsigned short transfer16(unsigned short val) override
transfer16()
Definition: SPI.h:122
Definition: SPIBase.h:25
void beginTransaction(SPISettings mySettings) override
beginTransaction()
#define debugf
Definition: debug_progmem.h:127