5#if defined(USE_ARDUINO) && !defined(USE_ESP32)
7static const char *
const TAG =
"spi-esp-arduino";
8class SPIDelegateHw :
public SPIDelegate {
13 void begin_transaction()
override {
19 ESP_LOGVV(
TAG,
"8266 mangled SPI mode 0x%X",
mode);
24 this->channel_->beginTransaction(settings);
28 void transfer(uint8_t *ptr,
size_t length)
override { this->channel_->transfer(ptr,
length); }
30 void end_transaction()
override {
31 this->channel_->endTransaction();
35 uint8_t transfer(uint8_t data)
override {
return this->channel_->transfer(data); }
37 void write16(uint16_t data)
override { this->channel_->transfer16(data); }
39 void write_array(
const uint8_t *ptr,
size_t length)
override {
41 this->channel_->transfer(*ptr);
45 this->channel_->transfer(ptr,
nullptr,
length);
46#elif defined(USE_ESP8266)
49 if (
reinterpret_cast<uintptr_t
>(ptr) & 0x3) {
50 ESP_LOGVV(
TAG,
"SPI write buffer not word aligned, copying to temporary buffer");
51 auto txbuf = std::vector<uint8_t>(
length);
52 memcpy(txbuf.data(), ptr,
length);
53 this->channel_->writeBytes(txbuf.data(),
length);
55 this->channel_->writeBytes(ptr,
length);
58 this->channel_->writeBytes(ptr,
length);
62 void read_array(uint8_t *ptr,
size_t length)
override { this->channel_->transfer(ptr,
length); }
68class SPIBusHw :
public SPIBus {
70 SPIBusHw(GPIOPin *clk, GPIOPin *sdo, GPIOPin *sdi,
SPIInterface channel) :
SPIBus(clk, sdo, sdi), channel_(channel) {
89 bool release_device,
bool write_only)
override {
90 return new SPIDelegateHw(this->channel_, data_rate, bit_order,
mode, cs_pin);
95 bool is_hw()
override {
return true; }
99 const std::vector<uint8_t> &data_pins) {
100 return new SPIBusHw(clk, sdo, sdi, interface);
BedjetMode mode
BedJet operating mode.
static SPIBus * get_bus(SPIInterface interface, GPIOPin *clk, GPIOPin *sdo, GPIOPin *sdi, const std::vector< uint8_t > &data_pins)
virtual void end_transaction()
virtual void begin_transaction()
static int get_pin_no(GPIOPin *pin)
Implementation of SPI Controller mode.
SPIMode
Modes mapping to clock phase and polarity.
SPIBitOrder
The bit-order for SPI devices. This defines how the data read from and written to the device is inter...
spi_host_device_t SPIInterface