hal::Spi Class Reference
Inheritance diagram for hal::Spi:

Documentation

This class gives access to a SPI port.

#include <sapi/hal.hpp>
int main(int argc, char * argv[]){
char buffer[16];
Spi spi(0); //access to SPI port 0
spi.init(); //init SPI with default settings from BSP
spi.read(buffer, 16); //read 16 bytes from the SPI
spi.close(); //close the SPI (power it off)
return 0;
}

Public Member Functions

 Spi (port_t port)
 
int initialize (u32 o_flags, u32 freq, u32 width=8, const spi_pin_assignment_t *pin_assignment=0)
 
int set_attr (u32 o_flags, u32 freq, u32 width=8, const spi_pin_assignment_t *pin_assignment=0) const
 
int swap (int byte) const
 
- Public Member Functions inherited from hal::Periph< spi_info_t, spi_attr_t, 's'>
 Periph (core_periph_t periph, port_t port)
 
int get_info (spi_info_t &info) const
 
int get_version () const
 
int init ()
 
int set_action (u32 channel, u32 o_events, s8 prio=0, mcu_callback_t callback=0, void *context=0) const
 
int set_attr () const
 
int set_priority (s8 priority, u32 o_events, int channel=0)
 
- Public Member Functions inherited from hal::PeriphObject
int close ()
 
int ioctl (int req, void *arg) const
 
int open (int o_mode=READWRITE)
 
int read (void *buf, int nbyte) const
 
int read (sys::Aio &aio) const
 
int seek (int loc, int whence) const
 
int write (const void *buf, int nbyte) const
 
int write (sys::Aio &aio) const
 
- Public Member Functions inherited from hal::Device
 Device ()
 
int set_signal_action (const DeviceSignal &signal, u32 o_events, u32 channel)
 
- Public Member Functions inherited from sys::File
int create (const char *path, bool overwrite=true, int perms=0666)
 
int fileno () const
 
int flags () const
 
char * gets (var::String &s, char term= '\n') const
 
int ioctl (int req, const void *arg) const
 
int ioctl (int req) const
 
int ioctl (int req, int arg) const
 
int loc () const
 
int open (const char *name, int access, int perms)
 
int open_append (const char *path)
 
int open_readonly (const char *path)
 
int open_readwrite (const char *path)
 
int read (int loc, void *buf, int nbyte) const
 
int readline (char *buf, int nbyte, int timeout_msec, char terminator= '\n') const
 
void set_fileno (int fd)
 
u32 size () const
 
int write (int loc, const void *buf, int nbyte) const
 
int write (const var::String &str) const
 
- Public Member Functions inherited from api::WorkObject
void clear_error_number () const
 
int error_number () const
 

Additional Inherited Members

- Public Types inherited from hal::PeriphObject
typedef unsigned int port_t
 
- Public Types inherited from sys::File
- Static Public Member Functions inherited from sys::File
static int access (const char *path, int o_access)
 
static int copy (var::String &source_path, var::String &dest_path)
 
static bool exists (const char *path)
 
static const char * name (const char *path)
 
static int remove (const char *path)
 
static int rename (var::String &old_path, var::String &new_path)
 
static u32 size (const char *path)
 
static int stat (const char *path, struct stat *st)
 
static const char * suffix (const char *path)
 
- Static Public Member Functions inherited from api::ApiObject
static const char * api_version ()
 
- Protected Member Functions inherited from hal::PeriphObject
int open (const char *name, int flags)
 

Member Enumeration Documentation

anonymous enum
Enumerator
IS_FORMAT_SPI 

See SPI_FLAG_IS_FORMAT_SPI

IS_FORMAT_TI 

See SPI_FLAG_IS_FORMAT_TI

IS_FORMAT_MICROWIRE 

See SPI_FLAG_IS_FORMAT_MICROWIRE

IS_MODE0 

See SPI_FLAG_IS_MODE0

IS_MODE1 

See SPI_FLAG_IS_MODE1

IS_MODE2 

See SPI_FLAG_IS_MODE2

IS_MODE3 

See SPI_FLAG_IS_MODE3

SET_MASTER 

See SPI_FLAG_SET_MASTER

SET_SLAVE 

See SPI_FLAG_SET_SLAVE

IS_FULL_DUPLEX 

See SPI_FLAG_IS_FULL_DUPLEX

IS_HALF_DUPLEX 

See SPI_FLAG_IS_HALF_DUPLEX

Constructor & Destructor Documentation

hal::Spi::Spi ( port_t  port)

Constructs a SPI object using port.

Member Function Documentation

int hal::Spi::initialize ( u32  o_flags,
u32  freq,
u32  width = 8,
const spi_pin_assignment_t *  pin_assignment = 0 
)
inline

Initializes the SPI port as specified.

Parameters
o_flagsSPI Flags
freqSPI bitrate
widthData width
pin_assignmentSPI pin assignment
Returns
Zero on success *
int hal::Spi::set_attr ( u32  o_flags,
u32  freq,
u32  width = 8,
const spi_pin_assignment_t *  pin_assignment = 0 
) const
inline

Sets the SPI attributes.

Parameters
o_flagsSPI Flags
freqSPI bitrate
widthData width
pin_assignmentSPI pin assignment
Returns
Zero on success
int hal::Spi::swap ( int  byte) const

swap a byte on the SPI bus