theCore C++ embedded framework
SDSPI driver module
Collaboration diagram for SDSPI driver module:

Data Structures

struct  ecl::sdspi_state
 Struct to hold SDSPI driver state, resulting from SDSPI API calls. More...
 
struct  ecl::sdspi_card_info
 SDSPI card information struct. More...
 
class  ecl::sdspi< spi_dev, gpio_cs >
 SDSPI driver class. More...
 

Functions

static err ecl::sdspi< spi_dev, gpio_cs >::init ()
 Initializes SDSPI driver and SD card. More...
 
static err ecl::sdspi< spi_dev, gpio_cs >::deinit ()
 De-initializes SDSPI driver and SD card. More...
 
static err ecl::sdspi< spi_dev, gpio_cs >::write (const uint8_t *data, size_t &count)
 Writes given data to SD card from current offset. More...
 
static err ecl::sdspi< spi_dev, gpio_cs >::read (uint8_t *data, size_t &count)
 Reads data from SD card from current offset to given buffer. More...
 
static err ecl::sdspi< spi_dev, gpio_cs >::flush ()
 Flushes cached data. More...
 
static err ecl::sdspi< spi_dev, gpio_cs >::seek (off_t offt)
 Seeks to the given position, in bytes. More...
 
static err ecl::sdspi< spi_dev, gpio_cs >::tell (off_t &offt)
 Tells current position. More...
 
static constexpr size_t ecl::sdspi< spi_dev, gpio_cs >::get_block_length ()
 Returns a length of a block. More...
 
static err ecl::sdspi< spi_dev, gpio_cs >::get_info (sdspi_card_info &info)
 Gets card info. More...
 
static const sdspi_stateecl::sdspi< spi_dev, gpio_cs >::get_state ()
 Gets state of the driver, resulted from last API call. More...
 

Detailed Description

Function Documentation

◆ init()

template<class spi_dev , class gpio_cs >
err ecl::sdspi< spi_dev, gpio_cs >::init ( )
static

Initializes SDSPI driver and SD card.

Precondition
Un-initialized SDSPI driver.
Postcondition
Initialized SDSPI driver. Offset is set to 0. State obtainable via get_state() is populated with relevant data.
Return values
err::ioI/O error on SPI.
err::genericOperation failed. Use get_state() to get more information.
err::okOperation succeed.
Here is the call graph for this function:

◆ deinit()

template<class spi_dev , class gpio_cs >
err ecl::sdspi< spi_dev, gpio_cs >::deinit ( )
static

De-initializes SDSPI driver and SD card.

Precondition
Initialized SDSPI driver.
Postcondition
Uninitialized SDSPI driver.
Return values
err::ioI/O error on SPI.
err::genericOperation failed. Use get_state() to get more information.
err::okOperation succeed.

◆ write()

template<class spi_dev , class gpio_cs >
err ecl::sdspi< spi_dev, gpio_cs >::write ( const uint8_t *  data,
size_t &  count 
)
static

Writes given data to SD card from current offset.

Precondition
Initialized SDSPI driver.
Postcondition
Current offset is increased by the amount of data written. State obtainable via get_state() is populated with relevant data.
Todo:
how to catch end-of-space on SD card?

Data written may be a subject to caching. Use flush() call to make sure that all data is written to SD card.

Parameters
[in]dataData to write.
[in,out]countData size in bytes to write on entry. Data bytes actually written on exit.
Return values
err::ioI/O error on SPI.
err::genericOperation failed. Use get_state() to get more information.
err::okOperation succeed.

◆ read()

template<class spi_dev , class gpio_cs >
err ecl::sdspi< spi_dev, gpio_cs >::read ( uint8_t *  data,
size_t &  count 
)
static

Reads data from SD card from current offset to given buffer.

Precondition
Initialized SDSPI driver.
Postcondition
Current offset is increased by the amount of data read. State obtainable via get_state() is populated with relevant data.
Todo:
how to catch end-of-space on SD card?
Parameters
[out]dataBuffer to store data into.
[in,out]countData size in bytes to read on entry. Data bytes actually read on exit.
Return values
err::ioI/O error on SPI.
err::genericOperation failed. Use get_state() to get more information.
err::okOperation succeed.

◆ flush()

template<class spi_dev , class gpio_cs >
err ecl::sdspi< spi_dev, gpio_cs >::flush ( )
static

Flushes cached data.

Precondition
Initialized SDSPI driver.
Postcondition
Data from cache is flushed onto SD card. Current offset is unchanged. State obtainable via get_state() is populated with relevant data.
Todo:
how to catch end-of-space on SD card?
Return values
err::ioI/O error on SPI.
err::genericOperation failed. Use get_state() to get more information.
err::okOperation succeed.

◆ seek()

template<class spi_dev , class gpio_cs >
err ecl::sdspi< spi_dev, gpio_cs >::seek ( off_t  offt)
static

Seeks to the given position, in bytes.

Precondition
Initialized SDSPI driver.
Postcondition
Offset is changed to given value. State obtainable via get_state() is populated with relevant data.
Todo:

extend it with seekdir::cur and seekdir::end

how to catch end-of-space on SD card?

Parameters
[in]offtNew offset in bytes.
Return values
err::ioI/O error on SPI.
err::genericOperation failed. Use get_state() to get more information.
err::okOperation succeed.

◆ tell()

template<class spi_dev , class gpio_cs >
err ecl::sdspi< spi_dev, gpio_cs >::tell ( off_t &  offt)
static

Tells current position.

Precondition
Initialized SDSPI driver.
Postcondition
State obtainable via get_state() is populated with relevant data.
Parameters
[out]offtCurrent offset.
Return values
err::ioI/O error on SPI.
err::genericOperation failed. Use get_state() to get more information.
err::okOperation succeed.

◆ get_block_length()

template<class spi_dev , class gpio_cs >
constexpr size_t ecl::sdspi< spi_dev, gpio_cs >::get_block_length ( )
static

Returns a length of a block.

◆ get_info()

template<class spi_dev , class gpio_cs >
err ecl::sdspi< spi_dev, gpio_cs >::get_info ( sdspi_card_info info)
static

Gets card info.

Precondition
Initialized SDSPI driver.
Postcondition
SD card queried for card information. State obtainable via get_state() is populated with relevant data.
Parameters
[out]infoCard info.
Return values
err::ioI/O error on SPI.
err::genericOperation failed. Use get_state() to get more information.
err::okOperation succeed.
Here is the call graph for this function:

◆ get_state()

template<class spi_dev , class gpio_cs >
const sdspi_state & ecl::sdspi< spi_dev, gpio_cs >::get_state ( )
static

Gets state of the driver, resulted from last API call.

Precondition
Driver in any state (either successfully or unsuccessfully initialized).
Postcondition
State obtainable via get_state() is populated with relevant data.
Returns
Currect driver state.