COSA
An Object-Oriented Platform for Arduino Programming
|
#include <SPI.hh>
Classes | |
class | Driver |
Public Types | |
enum | Clock { DIV2_CLOCK = 0x04, DIV4_CLOCK = 0x00, DIV8_CLOCK = 0x05, DIV16_CLOCK = 0x01, DIV32_CLOCK = 0x06, DIV64_CLOCK = 0x02, DIV128_CLOCK = 0x03, DEFAULT_CLOCK = DIV4_CLOCK } |
enum | Order { MSB_ORDER = 0, LSB_ORDER = 1, DEFAULT_ORDER = MSB_ORDER } |
enum | Pulse { ACTIVE_LOW = 0, ACTIVE_HIGH = 1, PULSE_LOW = 2, PULSE_HIGH = 3, DEFAULT_PULSE = ACTIVE_LOW } |
Public Member Functions | |
SPI () | |
bool | attach (Driver *dev) |
void | acquire (Driver *dev) |
void | release () |
void | begin () |
void | end () |
uint8_t | transfer (uint8_t data) |
void | transfer_start (uint8_t data) |
uint8_t | transfer_await () |
uint8_t | transfer_next (uint8_t data) |
void | transfer (void *buf, size_t count) |
void | transfer (void *dst, const void *src, size_t count) |
void | read (void *buf, size_t count) |
void | write (const void *buf, size_t count) |
void | write_P (const void *buf, size_t count) |
void | write (const iovec_t *vec) |
Static Public Member Functions | |
static void | powerup () |
static void | powerdown () |
Serial Peripheral Interface (SPI) device class. A device driver should inherit from SPI::Driver and defined SPI commands and higher level functions. The SPI::Driver class supports multiple SPI devices with possible different configuration (clock, bit order, mode) and integrates with both device chip select and possible interrupt pins.
SPI slave circuit with chip select and interrupt pin. Note that Tiny uses USI but the software interface is the same but MOSI/MISO pins are DI/DO. Do not confuse with SPI chip programming pins on Tiny.
enum SPI::Clock |
Clock selectors.
enum SPI::Order |
enum SPI::Pulse |
SPI::SPI | ( | ) |
Construct serial peripheral interface for master.
void SPI::acquire | ( | Driver * | dev | ) |
Acquire the SPI device driver. Initiate SPI hardware registers and disable SPI interrupt sources. The function will yield until the device driver has been acquired. Interrupts from SPI devices are disabled until the device driver is released. Used in the below format for a device driver:
Each transfer that requires chip select should be enclosed in a block with begin() and end(). There may be several transfer blocks in a transaction. The transaction is terminated with release().
[in] | dev | device driver context. |
bool SPI::attach | ( | Driver * | dev | ) |
|
inline |
Mark the beginning of a transfer block. Select the device by asserting the chip select pin according to the pulse pattern. Used in the format:
The transfer block should be terminated with end(). Typically the transfer block is a command (read/write) with a possible parameter block.
|
inline |
void SPI::read | ( | void * | buf, |
size_t | count | ||
) |
void SPI::release | ( | ) |
|
inline |
void SPI::transfer | ( | void * | buf, |
size_t | count | ||
) |
void SPI::transfer | ( | void * | dst, |
const void * | src, | ||
size_t | count | ||
) |
|
inline |
|
inline |
|
inline |
void SPI::write | ( | const void * | buf, |
size_t | count | ||
) |
|
inline |
void SPI::write_P | ( | const void * | buf, |
size_t | count | ||
) |