Manages access to SPI hardware. More...
#include <Controller.h>
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 SpiPins & | pins {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
-
chipSelect The value passed to startDevice()
active true 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]
|
inline |
◆ Controller() [2/2]
◆ ~Controller()
|
inlinevirtual |
Member Function Documentation
◆ assignDefaultPins()
|
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 | ( | ) |
◆ execute()
|
protectedvirtual |
◆ getActivePinSet()
|
inline |
◆ getBusId()
|
inline |
Get the active bus identifier.
On successful call to begin() returns actual bus in use.
◆ getSupportedIoModes()
Determine which IO modes are supported for the given device.
May be restricted by both controller and device capabilities.
◆ loopback()
For testing, tie MISO <-> MOSI internally.
enable true to enable loopback, false for normal receive operation
- Return values
-
true on success, false if loopback not supported
◆ onSelectDevice()
|
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 |
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 |
Release CS for a device.
◆ wait()
void HSPI::Controller::wait | ( | Request & | request | ) |
Member Data Documentation
◆ Device
|
protected |
◆ pins
const SpiPins& HSPI::Controller::pins {mPins} |
The documentation for this class was generated from the following file: