Serial Wombat Arduino Library

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
SerialWombatSPI Class Reference

A pin mode for the Serial Wombat 8B or SW18AB chips which allows SPI communication over I2C. More...

`#include <SerialWombatSPI.h>`

Inheritance diagram for SerialWombatSPI:
[legend]
Collaboration diagram for SerialWombatSPI:
[legend]

## Public Member Functions
| SerialWombatSPI (SerialWombatChip &serialWombat)
| Constructor for the SerialWombatSPI class.
int16_t | begin (uint8_t pin, uint8_t SPIMode, uint8_t MOSIpin=255, uint8_t MISOpin=255, uint8_t CSpin=255)
uint8_t | transfer (uint8_t data, bool csSaysStayLow=false)
uint16_t | transfer (uint16_t data, bool csSaysStayLow=false)
void | transfer (void *buf, size_t count, bool csSaysStayLow=false)
int16_t | transferPacketUpTo32Bits (uint8_t *outBuf, uint8_t *inBuf, size_t bitCount, bool csSaysStayLow=false)
int16_t | transferPacket40Bits (uint8_t *outBuf, uint8_t *inBuf, bool csSaysStayLow=false)
int16_t | setCSHigh ()
Public Member Functions inherited from SerialWombatPin
| SerialWombatPin (SerialWombatChip &serialWombatChip)
| Instantiates a Serial Wombat Pin.
| SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
| Instantiates a Serial Wombat Pin.
uint16_t | readPublicData ()
| Read the 16 Bit public data associated with this pin.
void | pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
| Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
void | digitalWrite (uint8_t val)
| Set output pin High or Low.
int | digitalRead ()
| Reads the state of the Pin.
uint16_t | writePublicData (uint16_t value)
| Write a 16 bit value to this pin.
uint8_t | pin ()
| Returns the current SW pin number. Used primarily for virtual calls by derived classes.
uint8_t | swPinModeNumber ()
| Returns the Mode number. Used primarily by derived classes to populate packet data.
int16_t | initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
int16_t | disable ()
| Disables the pin mode (if applicable)
int16_t | enablePullup (bool enabled)
| Enables the weak pull up on a pin. Implemented on SW18AB and SW8B only.
int16_t | enablePulldown (bool enabled)
| Enables the weak pull down on a pin. Implemented on SW18AB and SW8B only.
int16_t | enableOpenDrain (bool enabled)
| Enables open drain mode on a pin. Implemented on SW18AB and SW8B only.
int16_t | forceDMA (bool enabled)
| Forces use of DMA instead of hardware timing resources on SW18AB.
void | setPinNumberForTesting (uint8_t pin)
| A function designed for testing only. May have unpredictable results if used in real time. Not intended for general use.

## Static Public Member Functions
static void | beginTransaction (SerialWombatSPISettings settings)
static void | end ()

## Additional Inherited Members
Protected Attributes inherited from SerialWombatPin
uint8_t | _pin = 255
SerialWombatChip & | _sw
uint8_t | _pinMode = 0

## Detailed Description

A pin mode for the Serial Wombat 8B or SW18AB chips which allows SPI communication over I2C.

This pin mode allows the Serial Wombat 8B or SW18AB to send and receive SPI data over I2C. This pin mode is good for low to moderate bandwidth SPI devices due to the overhead of the I2C bus. Suggested applications include shfit registers, low speed ADC, and LED current drivers. This pin mode is intended as a much more efficient alternative to bit-banging SPI using pin high and low I2C commands.

This pin mode is assigned to the clock pin. Additonal pins can be assigned as MOSI, MISO and CS pins.
The clock speed is not configurable, and is about 250kHz on the SW8B.

Unlike other pin modes, all functionality of this pin mode occurs during the I2C communcation handling instead of the 1mS pin update. This is not a problem for the SW8B because it only has to service 6 or less other pins every 1mS, but for the 18AB can be problematic if many other pins are in use as the time to bit-bang the SPI transaction may cause frame overflows. For the 8B up to 5 SPI bytes can be transferred per I2C transaction, but for the 18AB only 1 byte can be transferred by default to minimize the chance of frame overflows.

SPI modes 0, 1, and 3 are supported. Mode 2 is not a commonly used mode, and is left out to reduce the flash space required by the pin mode.

If a chip select pin is specified the chip select is set low before the SPI transaction. The chip select can be configured to stay low or go high after completion of the SPI transaction allowing for long transactions.

This pin mode is designed to function similarly to the Arduino SPIClass with similar interfaces. Unlike Arduino there are no interupt based options, the clock speed is fixed, and the bitOrder is ignored (always MSB first).

See the Examples in the examples area for usage.

A Tutorial video is avaialble:

https://youtu.be/TODO

The class inherits from the Arduino Sream class, so functions such as write can be used once the class is initialized.

Definition at line 97 of file SerialWombatSPI.h.

## Constructor & Destructor Documentation

## ◆ SerialWombatSPI()

SerialWombatSPI::SerialWombatSPI | ( | SerialWombatChip & | serialWombat | ) |
| inline

Constructor for the SerialWombatSPI class.

Parameters

  serialWombat | The Serial Wombat chip on which the SerialWombatSPI instance will run.

Definition at line 104 of file SerialWombatSPI.h.

## Member Function Documentation

## ◆ begin()

int16_t SerialWombatSPI::begin | ( | uint8_t | pin,
|  | uint8_t | SPIMode,
|  | uint8_t | MOSIpin = 255,
|  | uint8_t | MISOpin = 255,
|  | uint8_t | CSpin = 255 )
| inline

    @brief Initalize the SerialWombatSPI.

Parameters

  pin | The pin that will host the state machine.
  SPIMode | 0, 1 or 3. Mode 2 is not supported to save flash space.
  MOSIpin | Optional pin number for MOSI. Set to 255 to not use a MOSI pin.
  MISOpin | Optional pin number for MISO. Set to 255 to not use a MISO pin.
  CSpin | Optional pin number for Chip Select. Set to 255 to not use a chip select pin.

Returns
  negative error code or positive success

Definition at line 116 of file SerialWombatSPI.h.

## ◆ beginTransaction()

static void SerialWombatSPI::beginTransaction | ( | SerialWombatSPISettings | settings | ) |
| inline static

Definition at line 143 of file SerialWombatSPI.h.

## ◆ end()

static void SerialWombatSPI::end | ( |  | ) |
| inline static

Definition at line 150 of file SerialWombatSPI.h.

## ◆ setCSHigh()

int16_t SerialWombatSPI::setCSHigh | ( |  | ) |
| inline

Definition at line 337 of file SerialWombatSPI.h.

## ◆ transfer() [1/3]

uint16_t SerialWombatSPI::transfer | ( | uint16_t | data,
|  | bool | csSaysStayLow = false )
| inline

Definition at line 182 of file SerialWombatSPI.h.

## ◆ transfer() [2/3]

uint8_t SerialWombatSPI::transfer | ( | uint8_t | data,
|  | bool | csSaysStayLow = false )
| inline

Definition at line 158 of file SerialWombatSPI.h.

## ◆ transfer() [3/3]

void SerialWombatSPI::transfer | ( | void * | buf,
|  | size_t | count,
|  | bool | csSaysStayLow = false )
| inline

Definition at line 205 of file SerialWombatSPI.h.

## ◆ transferPacket40Bits()

int16_t SerialWombatSPI::transferPacket40Bits | ( | uint8_t * | outBuf,
|  | uint8_t * | inBuf,
|  | bool | csSaysStayLow = false )
| inline

Definition at line 311 of file SerialWombatSPI.h.

## ◆ transferPacketUpTo32Bits()

int16_t SerialWombatSPI::transferPacketUpTo32Bits | ( | uint8_t * | outBuf,
|  | uint8_t * | inBuf,
|  | size_t | bitCount,
|  | bool | csSaysStayLow = false )
| inline

Definition at line 277 of file SerialWombatSPI.h.