11 #include <duds/hardware/interface/DigitalPinMasterSyncSerial.hpp> 18 std::this_thread::sleep_for(std::chrono::nanoseconds(nanos));
21 namespace duds {
namespace hardware {
namespace interface {
24 clk(-1), dat(-1), datI(-1) { }
58 if (cfg & MssFullDuplex) {
84 static const std::string names[4] = {
87 std::string(
"output"),
95 pi.pinNumbers(find + 0, find + 3,
pins, 3);
98 pi.pinNumbers(find + 0, find + 2,
pins, 2);
101 std::shared_ptr<PinStore> nps = pi.store();
118 const std::shared_ptr<PinStore> &ps,
141 const std::shared_ptr<PinStore> &ps,
182 if ((
clk != -1) && (
dat != -1) &&
215 for (
int loop = 2; loop >= 0; loop--) {
242 const std::uint8_t * __restrict__ out,
243 std::uint8_t * __restrict__ in,
250 const std::uint8_t *outpos = out;
252 std::uint8_t *inpos = in;
274 extrabits = bits % 8;
275 if (extrabits == 0) {
280 bitpos = 0x80 >> (extrabits - 1);
283 for (; bits; bits--) {
286 acc[1].setState(*outpos & bitpos);
295 if (inpin.getState()) {
302 acc[0].setState(
flags & MssOutFallInRise);
306 if (
flags & MssMSbFirst) {
307 if (!(bitpos >>= 1)) {
313 if (!(bitpos <<= 1)) {
321 if (in && extrabits) {
324 in[0] >>= 8 - extrabits;
unsigned int clk
The pin ID for the clock.
unsigned int clockFrequency() const noexcept
Computes and returns the maximum clock frequency in Hertz.
A full-duplex configuration or data transfer operation was requested on a half-duplex serial interfac...
A chip select object was specified on a serial interface that does not use a chip select...
int chipId() const
Returns the chip ID of the chip this object will select.
unsigned int dat
The pin ID for data, output if full-duplex.
boost::error_info< struct Info_PinName, std::string > PinErrorName
A name or function associated with the pin(s).
boost::error_info< struct Info_ChipId, int > ChipSelectIdError
The chip select ID relavent to the error.
static constexpr Flags MssMSbFirst
Send data MSb first, little endian.
static constexpr Flags MssFullDuplex
Communication is full duplex.
static constexpr Flags MssCommunicating
Indicates that communication is underway.
void setPins(const PinIndex &pi)
Sets the pins to use based on names already set in the PinIndex.
The operation has too few or much data to work on the pins, which can alternately be stated as having...
The input pin for full-duplex.
unsigned int clockPeriod() const noexcept
Returns the minimum clock period in nanoseconds.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
The requested operation is not supported by the specific pin.
virtual void open()
Gets the required access objects.
boost::error_info< struct Info_PinId, unsigned int > PinErrorId
The pin global ID involved in the error.
DigitalPinCap capabilities(unsigned int pos) const
Returns the capabilities of the specified pin.
bool configured() const
Returns true if this object was configured with a chip to select.
static constexpr Flags MssUseSelect
Use a select line to tell a device to pay attention to the master.
DigitalPinMasterSyncSerial()
An object to wrap together a ChipSelectManager and chip ID to simplify code that needs to repeatedly ...
virtual void stop()
Deselects the device and assures the clock is in the idle state.
unsigned int minHalfPeriod
The minimum time between changing the clock edge in nanoseconds.
bool haveManager() const
Returns true if this object has an associated manager.
unsigned int size() const
Returns the number of pins in this object.
A half-duplex configuration was requested on a full-duplex serial interface.
Represents a set of pins on a single DigitalPort.
static constexpr Flags MssOpen
Indicates that all required resources for communication have been acquired.
virtual void close()
Relinquishes the access objects.
~DigitalPinMasterSyncSerial()
A ChipSelectManager is required for the operation but is not set.
virtual void start()
Selects the device, which may be the same as doing nothing.
Provides access to a single pin on a DigitalPort.
void deselect()
Deselects the chip.
ChipSelect sel
Chip selection for serial interfaces that require it.
virtual void transfer(const std::uint8_t *__restrict__ out, std::uint8_t *__restrict__ in, int bits)
Moves data about.
std::unique_ptr< ChipAccess > access()
Obtains a ChipAccess object.
An abstraction for the master side of a simple synchronous serial communication connection to some de...
void retire()
Relinquish access.
static void nanodelay(int nanos)
The data pin for half-duplex.
static constexpr Flags MssReady
Indictates that all required resources for communication have been identified and passed a validity c...
static constexpr Flags MssOutFallInRise
Output on the falling edge of the clock and read on the rising edge.
A transfer operation was requested when not in the communicating state.
void forceClose()
Attempts to forcibly cease communications by calling condStop() and close().
The requested operation requires communication to not already be in use.
std::shared_ptr< PinStore > store
The store of pins that manages the pins used by this serial interface.
static constexpr Flags MssClockIdleHigh
Before communication begins, and after it ends, the clock line should have a high logic level...
unsigned int globalId(unsigned int pos) const
Returns the global pin ID of the pin at the given position inside this set of pins.
ChipAccess chipAcc
Chip access for for serial interfaces that require chip selection.
static void checkPins(const DigitalPinSet &ps, Flags cfg)
Checks the pins' capabilities to assure they can be used in the intended role.
Indicates an attempt to select a non-existant chip.
void setChipSelect(const ChipSelect &cs)
Sets the ChipSelect object to use for selections.
Flags flags
Configuration flags.
unsigned int datI
The pin ID for data input if full-duplex.
void select()
Selects the chip.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
void retire() noexcept
Relinquish access.
The output pin for full-duplex.