Manages access to SPI hardware. More...

#include <Controller.h>

Collaboration diagram for HSPI::Controller:
[legend]

Classes

struct  Config
 

Public Types

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

Public Member Functions

virtual ~Controller ()
 
void begin ()
 
void end ()
 Disable HSPI controller. 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)
 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...
 
uint32_t setSpeed (Device &dev, uint32_t frequency)
 Set the clock for a given frequency. More...
 
uint32_t getSpeed (Device &dev) const
 
PinSet getActivePinSet () const
 

Protected Member Functions

virtual void execute (Request &request)
 

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
chipSelect
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()

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

Member Function Documentation

◆ begin()

void 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

◆ getSpeed()

uint32_t HSPI::Controller::getSpeed ( Device dev) const

◆ 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

◆ setSpeed()

uint32_t HSPI::Controller::setSpeed ( Device dev,
uint32_t  frequency 
)

Set the clock for a given frequency.

Parameters
dev
frequencyThe requested clock frequency in Hz
Return values
uint32_tThe actual clock frequency selected

◆ startDevice()

virtual bool HSPI::Controller::startDevice ( Device dev,
PinSet  pinSet,
uint8_t  chipSelect 
)
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.

Member Data Documentation

◆ Device

friend HSPI::Controller::Device
protected

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