DUDS
Distributed Update of Data from Something
DigitalPinMasterSyncSerial.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
13 
14 namespace duds { namespace hardware { namespace interface {
15 
39 
41  // must be very careful to retire on all failures
46  enum PinPos {
63  };
67  std::shared_ptr<PinStore> store;
68  union {
72  unsigned int pins[3];
73  struct {
77  unsigned int clk;
81  unsigned int dat;
85  unsigned int datI;
86  };
87  };
111  static void checkPins(const DigitalPinSet &ps, Flags cfg);
112 protected:
117  virtual void open();
121  virtual void close();
125  virtual void start();
129  virtual void stop();
133  virtual void transfer(
134  const std::uint8_t * __restrict__ out,
135  std::uint8_t * __restrict__ in,
136  int bits
137  );
138 public:
146  DigitalPinMasterSyncSerial(const DigitalPinSet &pset, Flags flags, int period);
160  void setPins(const PinIndex &pi);
172  void setPins(const std::shared_ptr<PinIndex> &pi) {
173  setPins(*pi);
174  }
190  void setPins(
191  const std::shared_ptr<PinStore> &store,
192  unsigned int clock,
193  unsigned int data
194  );
211  void setPins(
212  const std::shared_ptr<PinStore> &store,
213  unsigned int clock,
214  unsigned int output,
215  unsigned int input
216  );
233  void setChipSelect(const ChipSelect &cs);
242  void clockFrequency(unsigned int freq);
251  void clockPeriod(unsigned int nanos);
252 };
253 
254 } } } // namespaces
255 
unsigned int clockFrequency() const noexcept
Computes and returns the maximum clock frequency in Hertz.
Provides access to multiple pins on a DigitalPort.
unsigned int dat
The pin ID for data, output if full-duplex.
A synchronous serial implementation using DigitalPin objects.
void setPins(const PinIndex &pi)
Sets the pins to use based on names already set in the PinIndex.
unsigned int clockPeriod() const noexcept
Returns the minimum clock period in nanoseconds.
virtual void open()
Gets the required access objects.
An object to wrap together a ChipSelectManager and chip ID to simplify code that needs to repeatedly ...
Definition: ChipSelect.hpp:24
virtual void stop()
Deselects the device and assures the clock is in the idle state.
Represents a set of pins on a single DigitalPort.
An object used to provide chip select control to a single user at a time.
Definition: ChipAccess.hpp:22
virtual void close()
Relinquishes the access objects.
virtual void start()
Selects the device, which may be the same as doing nothing.
Provides access to a single pin on a DigitalPort.
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.
An abstraction for the master side of a simple synchronous serial communication connection to some de...
void setPins(const std::shared_ptr< PinIndex > &pi)
Sets the pins to use based on names already set in the PinIndex.
std::shared_ptr< PinStore > store
The store of pins that manages the pins used by this serial interface.
ChipAccess chipAcc
Chip access for for serial interfaces that require chip selection.
static void checkPins(const DigitalPinSet &ps, Flags cfg)
Checks the pins&#39; capabilities to assure they can be used in the intended role.
void setChipSelect(const ChipSelect &cs)
Sets the ChipSelect object to use for selections.
unsigned int datI
The pin ID for data input if full-duplex.