COSA
An Object-Oriented Platform for Arduino Programming
Soft::SPI::Driver Class Reference

#include <SPI.hh>

Collaboration diagram for Soft::SPI::Driver:
Collaboration graph

Public Member Functions

 Driver (Board::DigitalPin cs, Pulse pulse=DEFAULT_PULSE, Clock clock=DEFAULT_CLOCK, uint8_t mode=0, Order order=MSB_ORDER, Interrupt::Handler *irq=NULL)
 
void set_clock (Clock rate)
 
void set_clock (uint32_t freq)
 

Static Public Member Functions

static Clock clock (uint32_t freq)
 
static Clock cycle (uint16_t ns)
 

Protected Attributes

Driverm_next
 List of drivers. More...
 
Interrupt::Handlerm_irq
 Interrupt handler. More...
 
OutputPin m_cs
 Device chip select pin. More...
 
Pulse m_pulse
 Chip select pulse mode. More...
 
uint8_t m_mode
 Mode for phase and transition. More...
 
Order m_order
 Data direction; bit order. More...
 
uint8_t m_data
 Data to transfer. More...
 

Friends

class SPI
 

Detailed Description

SPI device driver abstract class. Holds SPI state to allow handling of several SPI devices with different clock, mode and/or bit order.

Definition at line 72 of file SPI.hh.

Constructor & Destructor Documentation

Soft::SPI::Driver::Driver ( Board::DigitalPin  cs,
Pulse  pulse = DEFAULT_PULSE,
Clock  clock = DEFAULT_CLOCK,
uint8_t  mode = 0,
Order  order = MSB_ORDER,
Interrupt::Handler irq = NULL 
)

Construct SPI Device driver with given chip select pin, pulse, clock, mode, and bit order.

Parameters
[in]cschip select pin.
[in]pulsechip select pulse mode (default ACTIVE_LOW).
[in]clockSPI hardware setting (default DIV4_CLOCK).
[in]modeSPI mode for phase and transition (0..3, default 0).
[in]orderbit order (default MSB_ORDER).
[in]irqinterrupt handler (default null).

Member Function Documentation

static Clock Soft::SPI::Driver::clock ( uint32_t  freq)
inlinestatic

Calculate SPI clock rate (scale factor) for given frequency.

Parameters
[in]freqdevice max frequency (in Hz).
Returns
clock rate.

Definition at line 97 of file SPI.hh.

static Clock Soft::SPI::Driver::cycle ( uint16_t  ns)
inlinestatic

Calculate SPI clock rate (scale factor) for given clock cycle time in nano seconds.

Parameters
[in]nsmin device clock cycle time.
Returns
clock rate.

Definition at line 115 of file SPI.hh.

void Soft::SPI::Driver::set_clock ( Clock  rate)

Set SPI master clock rate.

Parameters
[in]clockrate.
void Soft::SPI::Driver::set_clock ( uint32_t  freq)
inline

Set SPI master clock frequency.

Parameters
[in]freqdevice max frequency (in Hz).

Definition at line 137 of file SPI.hh.

Friends And Related Function Documentation

friend class SPI
friend

Definition at line 73 of file SPI.hh.

Member Data Documentation

OutputPin Soft::SPI::Driver::m_cs
protected

Device chip select pin.

Definition at line 146 of file SPI.hh.

uint8_t Soft::SPI::Driver::m_data
protected

Data to transfer.

Definition at line 150 of file SPI.hh.

Interrupt::Handler* Soft::SPI::Driver::m_irq
protected

Interrupt handler.

Definition at line 145 of file SPI.hh.

uint8_t Soft::SPI::Driver::m_mode
protected

Mode for phase and transition.

Definition at line 148 of file SPI.hh.

Driver* Soft::SPI::Driver::m_next
protected

List of drivers.

Definition at line 144 of file SPI.hh.

Order Soft::SPI::Driver::m_order
protected

Data direction; bit order.

Definition at line 149 of file SPI.hh.

Pulse Soft::SPI::Driver::m_pulse
protected

Chip select pulse mode.

Definition at line 147 of file SPI.hh.


The documentation for this class was generated from the following file: