Esp32/Core/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  * Based on Arduino-esp32 code
10  *
11  * https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/src/SPI.h
12  * https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-spi.h
13  */
14 
19 #pragma once
20 
21 #include "SPIBase.h"
22 #include "SPISettings.h"
23 
24 //#define SPI_DEBUG 1
25 
26 // for compatibility when porting from Arduino
27 #define SPI_HAS_TRANSACTION 0
28 
29 static constexpr uint8_t SPI_PIN_DEFAULT{0xff};
30 
40 enum class SpiBus {
41  INVALID = 0,
42  MIN = 1,
43  FSPI = 1, // Attached to the flash (can use the same data lines but different SS)
44  HSPI = 2, // Normally mapped to pins 12 - 15, but can be matrixed to any pins
45  VSPI = 3, // Normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins
46  MAX = 3,
47 };
48 
52 struct SpiPins {
53  uint8_t sck{SPI_PIN_DEFAULT};
54  uint8_t miso{SPI_PIN_DEFAULT};
55  uint8_t mosi{SPI_PIN_DEFAULT};
56  uint8_t ss{SPI_PIN_DEFAULT};
57 };
58 
59 class SPIClass : public SPIBase
60 {
61 public:
62  SPIClass(SpiBus id = SpiBus::VSPI) : busId(id)
63  {
64  }
65 
66  SPIClass(SpiBus id, SpiPins pins) : busId(id), pins(pins)
67  {
68  }
69 
70  bool begin() override;
71  void end() override;
72  uint8_t read8() override;
73  uint32_t transfer32(uint32_t val, uint8_t bits = 32) override;
74 
75  using SPIBase::transfer;
76  void transfer(uint8_t* buffer, size_t numberBytes) override;
77 
78 protected:
79  void prepare(SPISettings& settings) override;
80 
81  struct BusInfo;
82  static BusInfo busInfo[];
83 
84  BusInfo& getBusInfo();
85 
88 };
89 
91 extern SPIClass SPI;
Definition: SPISettings.h:66
static constexpr uint8_t SPI_PIN_DEFAULT
Definition: Esp32/Core/SPI.h:29
SPIClass(SpiBus id=SpiBus::VSPI)
Definition: Esp32/Core/SPI.h:62
SPIClass SPI
Global instance of SPI class.
Definition: Common.h:24
SpiBus
Identifies bus selection.
Definition: Esp32/Core/SPI.h:40
SpiPins pins
Definition: Esp32/Core/SPI.h:87
Definition: Esp8266/Core/SPI.h:36
SPIClass(SpiBus id, SpiPins pins)
Definition: Esp32/Core/SPI.h:66
SpiBus busId
Definition: Esp32/Core/SPI.h:86
Definition: SPIBase.h:28
uint8_t transfer(uint8_t val)
Send/receive one bytes of data.
Definition: SPIBase.h:101
SPI pin connections.
Definition: Esp32/Core/SPI.h:52