ESPHome  2024.7.0
Public Member Functions
esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE > Class Template Reference

The SPIDevice is what components using the SPI will create. More...

#include <spi.h>

Inheritance diagram for esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >:
esphome::spi::SPIClient

Public Member Functions

 SPIDevice ()
 
 SPIDevice (SPIComponent *parent, GPIOPin *cs_pin)
 
void spi_setup () override
 
void spi_teardown () override
 
void set_spi_parent (SPIComponent *parent)
 
void set_cs_pin (GPIOPin *cs)
 
void set_data_rate (uint32_t data_rate)
 
void set_bit_order (SPIBitOrder order)
 
void set_mode (SPIMode mode)
 
uint8_t read_byte ()
 
void read_array (uint8_t *data, size_t length)
 
void write (uint16_t data, size_t num_bits)
 Write a single data item, up to 32 bits. More...
 
void write_cmd_addr_data (size_t cmd_bits, uint32_t cmd, size_t addr_bits, uint32_t address, const uint8_t *data, size_t length, uint8_t bus_width=1)
 
void write_byte (uint8_t data)
 
void transfer_array (uint8_t *data, size_t length)
 Write the array data, replace with received data. More...
 
uint8_t transfer_byte (uint8_t data)
 
void write_byte16 (uint16_t data)
 Write 16 bit data. More...
 
void write_array16 (const uint16_t *data, size_t length)
 Write an array of data as 16 bit values, byte-swapping if required. More...
 
void enable ()
 
void disable ()
 
void write_array (const uint8_t *data, size_t length)
 
template<size_t N>
void write_array (const std::array< uint8_t, N > &data)
 
void write_array (const std::vector< uint8_t > &data)
 
template<size_t N>
void transfer_array (std::array< uint8_t, N > &data)
 
- Public Member Functions inherited from esphome::spi::SPIClient
 SPIClient (SPIBitOrder bit_order, SPIMode mode, uint32_t data_rate)
 
bool spi_is_ready ()
 

Additional Inherited Members

- Protected Attributes inherited from esphome::spi::SPIClient
SPIBitOrder bit_order_ {BIT_ORDER_MSB_FIRST}
 
SPIMode mode_ {MODE0}
 
uint32_t data_rate_ {1000000}
 
SPIComponentparent_ {nullptr}
 
GPIOPincs_ {nullptr}
 
SPIDelegatedelegate_ {SPIDelegate::NULL_DELEGATE}
 

Detailed Description

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
class esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >

The SPIDevice is what components using the SPI will create.

Template Parameters
BIT_ORDER
CLOCK_POLARITY
CLOCK_PHASE
DATA_RATE

Definition at line 408 of file spi.h.

Constructor & Destructor Documentation

◆ SPIDevice() [1/2]

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::SPIDevice ( )
inline

Definition at line 410 of file spi.h.

◆ SPIDevice() [2/2]

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::SPIDevice ( SPIComponent parent,
GPIOPin cs_pin 
)
inline

Definition at line 412 of file spi.h.

Member Function Documentation

◆ disable()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::disable ( )
inline

Definition at line 482 of file spi.h.

◆ enable()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::enable ( )
inline

Definition at line 480 of file spi.h.

◆ read_array()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::read_array ( uint8_t *  data,
size_t  length 
)
inline

Definition at line 433 of file spi.h.

◆ read_byte()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
uint8_t esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::read_byte ( )
inline

Definition at line 431 of file spi.h.

◆ set_bit_order()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::set_bit_order ( SPIBitOrder  order)
inline

Definition at line 427 of file spi.h.

◆ set_cs_pin()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::set_cs_pin ( GPIOPin cs)
inline

Definition at line 423 of file spi.h.

◆ set_data_rate()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::set_data_rate ( uint32_t  data_rate)
inline

Definition at line 425 of file spi.h.

◆ set_mode()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::set_mode ( SPIMode  mode)
inline

Definition at line 429 of file spi.h.

◆ set_spi_parent()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::set_spi_parent ( SPIComponent parent)
inline

Definition at line 421 of file spi.h.

◆ spi_setup()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::spi_setup ( )
inlineoverridevirtual

Reimplemented from esphome::spi::SPIClient.

Definition at line 417 of file spi.h.

◆ spi_teardown()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::spi_teardown ( )
inlineoverridevirtual

Reimplemented from esphome::spi::SPIClient.

Definition at line 419 of file spi.h.

◆ transfer_array() [1/2]

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::transfer_array ( uint8_t *  data,
size_t  length 
)
inline

Write the array data, replace with received data.

Parameters
data
length

Definition at line 464 of file spi.h.

◆ transfer_array() [2/2]

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
template<size_t N>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::transfer_array ( std::array< uint8_t, N > &  data)
inline

Definition at line 490 of file spi.h.

◆ transfer_byte()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
uint8_t esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::transfer_byte ( uint8_t  data)
inline

Definition at line 466 of file spi.h.

◆ write()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::write ( uint16_t  data,
size_t  num_bits 
)
inline

Write a single data item, up to 32 bits.

Parameters
dataThe data
num_bitsThe number of bits to write. The lower num_bits of data will be sent.

Definition at line 440 of file spi.h.

◆ write_array() [1/3]

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::write_array ( const uint8_t *  data,
size_t  length 
)
inline

Definition at line 484 of file spi.h.

◆ write_array() [2/3]

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
template<size_t N>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::write_array ( const std::array< uint8_t, N > &  data)
inline

Definition at line 486 of file spi.h.

◆ write_array() [3/3]

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::write_array ( const std::vector< uint8_t > &  data)
inline

Definition at line 488 of file spi.h.

◆ write_array16()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::write_array16 ( const uint16_t *  data,
size_t  length 
)
inline

Write an array of data as 16 bit values, byte-swapping if required.

Use of this should be avoided as it is horribly slow.

Parameters
data
length

Definition at line 478 of file spi.h.

◆ write_byte()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::write_byte ( uint8_t  data)
inline

Definition at line 457 of file spi.h.

◆ write_byte16()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::write_byte16 ( uint16_t  data)
inline

Write 16 bit data.

The driver will byte-swap if required.

Definition at line 470 of file spi.h.

◆ write_cmd_addr_data()

template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, SPIDataRate DATA_RATE>
void esphome::spi::SPIDevice< BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, DATA_RATE >::write_cmd_addr_data ( size_t  cmd_bits,
uint32_t  cmd,
size_t  addr_bits,
uint32_t  address,
const uint8_t *  data,
size_t  length,
uint8_t  bus_width = 1 
)
inline

Definition at line 452 of file spi.h.


The documentation for this class was generated from the following file: