9 static const char *
const TAG =
"spi-esp-arduino";
10 class SPIDelegateHw :
public SPIDelegate {
13 :
SPIDelegate(data_rate, bit_order, mode, cs_pin), channel_(channel) {}
15 void begin_transaction()
override {
17 SPISettings
const settings(this->data_rate_, static_cast<BitOrder>(this->bit_order_), this->mode_);
18 #elif defined(ESP8266) 20 auto mode = (this->
mode_ & 0x01) + ((this->mode_ & 0x02) << 3);
21 ESP_LOGVV(TAG,
"8266 mangled SPI mode 0x%X",
mode);
22 SPISettings
const settings(this->data_rate_, this->bit_order_,
mode);
24 SPISettings
const settings(this->data_rate_, this->bit_order_, this->mode_);
26 this->channel_->beginTransaction(settings);
30 void transfer(uint8_t *ptr,
size_t length)
override { this->channel_->transfer(ptr, length); }
32 void end_transaction()
override {
33 this->channel_->endTransaction();
37 uint8_t transfer(uint8_t data)
override {
return this->channel_->transfer(data); }
39 void write16(uint16_t data)
override { this->channel_->transfer16(data); }
42 void write_array(
const uint8_t *ptr,
size_t length)
override {
44 uint8_t *rxbuf =
new uint8_t[
length];
45 memcpy(rxbuf, ptr, length);
46 this->channel_->transfer((
void *) rxbuf, length);
50 void write_array(
const uint8_t *ptr,
size_t length)
override { this->channel_->writeBytes(ptr, length); }
53 void read_array(uint8_t *ptr,
size_t length)
override { this->channel_->transfer(ptr, length); }
59 class SPIBusHw :
public SPIBus {
61 SPIBusHw(GPIOPin *clk, GPIOPin *sdo, GPIOPin *sdi,
SPIInterface channel) : SPIBus(clk, sdo, sdi), channel_(channel) {
79 SPIDelegate *get_delegate(uint32_t data_rate,
SPIBitOrder bit_order,
SPIMode mode, GPIOPin *cs_pin)
override {
80 return new SPIDelegateHw(this->channel_, data_rate, bit_order, mode, cs_pin);
85 bool is_hw()
override {
return true; }
89 const std::vector<uint8_t> &data_pins) {
90 return new SPIBusHw(clk, sdo, sdi, interface);
SPIClassRP2040 * SPIInterface
static int get_pin_no(GPIOPin *pin)
BedjetMode mode
BedJet operating mode.
SPIMode
Modes mapping to clock phase and polarity.
virtual void end_transaction()
virtual void begin_transaction()
static SPIBus * get_bus(SPIInterface interface, GPIOPin *clk, GPIOPin *sdo, GPIOPin *sdi, const std::vector< uint8_t > &data_pins)
SPIBitOrder
The bit-order for SPI devices. This defines how the data read from and written to the device is inter...
Implementation of SPI Controller mode.