Manages access to SPI hardware. More...

#include <Controller.h>

Inheritance diagram for HSPI::Controller:
Collaboration diagram for HSPI::Controller:

Public Types

using SelectDevice = void(*)(uint8_t chipSelect, bool active)
 Interrupt callback for custom Controllers. More...
 

Public Member Functions

 Controller (SpiBus id=SpiBus::DEFAULT)
 
 Controller (SpiBus id, SpiPins pins)
 
virtual ~Controller ()
 
bool begin ()
 
void end ()
 Disable HSPI controller. More...
 
IoModes getSupportedIoModes (const Device &dev) const
 Determine which IO modes are supported for the given device. More...
 
void onSelectDevice (SelectDevice callback)
 Set interrupt callback to use for manual CS control (PinSet::manual) or if CS pin is multiplexed. More...
 
virtual bool startDevice (Device &dev, PinSet pinSet, uint8_t chipSelect, uint32_t clockSpeed)
 Assign a device to a CS# using a specific pin set. Only one device may be assigned to any CS. More...
 
virtual void stopDevice (Device &dev)
 Release CS for a device. More...
 
void configChanged (Device &dev)
 Devices call this method to tell the Controller about configuration changes. Internally, we just set a flag and update the register values when required. More...
 
SpiBus getBusId () const
 Get the active bus identifier. More...
 
PinSet getActivePinSet () const
 
void wait (Request &request)
 
bool loopback (bool enable)
 For testing, tie MISO <-> MOSI internally. More...
 

Public Attributes

const SpiPinspins {mPins}
 

Protected Member Functions

virtual void execute (Request &request)
 
void assignDefaultPins (const SpiPins &defPins)
 Assign any default pins. More...
 

Protected Attributes

friend Device
 

Detailed Description

Manages access to SPI hardware.

Member Typedef Documentation

◆ SelectDevice

using HSPI::Controller::SelectDevice = void (*)(uint8_t chipSelect, bool active)

Interrupt callback for custom Controllers.

Parameters
chipSelectThe value passed to startDevice()
activetrue when transaction is about to start, false when completed

For manual CS (PinSet::manual) the actual CS GPIO must be asserted/de-asserted.

Expanding the SPI bus using a HC138 3:8 multiplexer, for example, can also be handled here, setting the GPIO address lines appropriately.

Constructor & Destructor Documentation

◆ Controller() [1/2]

HSPI::Controller::Controller ( SpiBus  id = SpiBus::DEFAULT)
inline

◆ Controller() [2/2]

HSPI::Controller::Controller ( SpiBus  id,
SpiPins  pins 
)
inline

◆ ~Controller()

virtual HSPI::Controller::~Controller ( )
inlinevirtual

Member Function Documentation

◆ assignDefaultPins()

void HSPI::Controller::assignDefaultPins ( const SpiPins defPins)
inlineprotected

Assign any default pins.

◆ begin()

bool HSPI::Controller::begin ( )

◆ configChanged()

void HSPI::Controller::configChanged ( Device dev)

Devices call this method to tell the Controller about configuration changes. Internally, we just set a flag and update the register values when required.

◆ end()

void HSPI::Controller::end ( )

Disable HSPI controller.

Note
Reverts HSPI pins to GPIO and disables the controller

◆ execute()

virtual void HSPI::Controller::execute ( Request request)
protectedvirtual

◆ getActivePinSet()

PinSet HSPI::Controller::getActivePinSet ( ) const
inline

◆ getBusId()

SpiBus HSPI::Controller::getBusId ( ) const
inline

Get the active bus identifier.

On successful call to begin() returns actual bus in use.

◆ getSupportedIoModes()

IoModes HSPI::Controller::getSupportedIoModes ( const Device dev) const

Determine which IO modes are supported for the given device.

May be restricted by both controller and device capabilities.

◆ loopback()

bool HSPI::Controller::loopback ( bool  enable)

For testing, tie MISO <-> MOSI internally.

enable true to enable loopback, false for normal receive operation

Return values
trueon success, false if loopback not supported

◆ onSelectDevice()

void HSPI::Controller::onSelectDevice ( SelectDevice  callback)
inline

Set interrupt callback to use for manual CS control (PinSet::manual) or if CS pin is multiplexed.

Note
Callback MUST be marked IRAM_ATTR

◆ startDevice()

virtual bool HSPI::Controller::startDevice ( Device dev,
PinSet  pinSet,
uint8_t  chipSelect,
uint32_t  clockSpeed 
)
virtual

Assign a device to a CS# using a specific pin set. Only one device may be assigned to any CS.

Custom controllers should override this method to verify/configure chip selects, and also provide a callback (via onSelectDevice()).

◆ stopDevice()

virtual void HSPI::Controller::stopDevice ( Device dev)
virtual

Release CS for a device.

◆ wait()

void HSPI::Controller::wait ( Request request)

Member Data Documentation

◆ Device

friend HSPI::Controller::Device
protected

◆ pins

const SpiPins& HSPI::Controller::pins {mPins}

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