class::hal::Spi

class hal::Spi
  : public hal::Periph< spi_info_t, spi_attr_t, SpiAttributes, 's'>

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;
}

Members

Spi(

port_t port
)

int get_info()
SpiInfo get_info() const
int init(

u32 o_flags,
u32 freq,
u32 width,
const spi_pin_assignment_t * pin_assignment
)

int initialize(

u32 o_flags,
u32 freq,
u32 width,
const spi_pin_assignment_t * pin_assignment
)

int initialize()
int initialize()
int set_attr(

u32 o_flags,
u32 freq,
u32 width,
const spi_pin_assignment_t * pin_assignment
) const

int swap(

int byte
) const

int transfer(

const void * write_data,
void * read_data,
int nbytes
)

enum spi_flags

Details

Spi(

port_t port
)

Constructs a SPI object using port.


int get_info()

Gets the peripheral info.

Parameters

  • info A reference to the info object that will be written.

Returns

Zero on success, less than one for an error


SpiInfo get_info() const

int init(

u32 o_flags,
u32 freq,
u32 width,
const spi_pin_assignment_t * pin_assignment
)


int initialize(

u32 o_flags,
u32 freq,
u32 width,
const spi_pin_assignment_t * pin_assignment
)


int initialize()

Initializes the hardware using the default attributes.

Returns

Less than zero on an error.

The system should set the error number to ENOSYS if no default attributes are provided.


int initialize()

Initializes the peripheral using the provided attributes


int set_attr(

u32 o_flags,
u32 freq,
u32 width,
const spi_pin_assignment_t * pin_assignment
) const


int swap(

int byte
) const

swap a byte on the SPI bus


int transfer(

const void * write_data,
void * read_data,
int nbytes
)


enum spi_flags

X

Thanks for Coming!

Subscribe to news and updates