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

#include <SPI.hh>

Inheritance diagram for SPI::Driver:
Inheritance graph
Collaboration diagram for SPI::Driver:
Collaboration graph

Public Member Functions

 Driver (Board::DigitalPin cs, Pulse pulse=DEFAULT_PULSE, Clock rate=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 width. More...
 
uint8_t m_spcr
 SPI/SPCR hardware control register setting. More...
 
uint8_t m_spsr
 SPI/SPSR hardware status register. More...
 

Friends

class SPI
 

Detailed Description

SPI device driver abstract class. Holds SPI/USI hardware settings to allow handling of several SPI devices with different clock, mode and/or bit order. Handles device chip select and disables/enables interrupts during SPI transaction.

Definition at line 93 of file SPI.hh.

Constructor & Destructor Documentation

SPI::Driver::Driver ( Board::DigitalPin  cs,
Pulse  pulse = DEFAULT_PULSE,
Clock  rate = 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]rateSPI 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).

Definition at line 25 of file SOFT_SPI.cpp.

Member Function Documentation

static Clock 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 117 of file SPI.hh.

static Clock 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 135 of file SPI.hh.

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

Set SPI master clock rate.

Parameters
[in]clockrate.

Definition at line 297 of file SPI.cpp.

void SPI::Driver::set_clock ( uint32_t  freq)
inline

Set SPI master clock frequency.

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

Definition at line 157 of file SPI.hh.

Friends And Related Function Documentation

friend class SPI
friend

Definition at line 176 of file SPI.hh.

Member Data Documentation

OutputPin SPI::Driver::m_cs
protected

Device chip select pin.

Definition at line 166 of file SPI.hh.

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

Interrupt handler.

Definition at line 165 of file SPI.hh.

Driver* SPI::Driver::m_next
protected

List of drivers.

Definition at line 164 of file SPI.hh.

Pulse SPI::Driver::m_pulse
protected

Chip select pulse width.

Definition at line 167 of file SPI.hh.

uint8_t SPI::Driver::m_spcr
protected

SPI/SPCR hardware control register setting.

Definition at line 173 of file SPI.hh.

uint8_t SPI::Driver::m_spsr
protected

SPI/SPSR hardware status register.

Definition at line 174 of file SPI.hh.


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