libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Attributes | List of all members
SDSafeSPI Class Reference

SPI interface routines for SD & SDHC & MMC cards. More...

#include <sdsafespi.h>

Public Member Functions

int Start (const int basepin)
 Start a new cog with the SPI driver. More...
 
int Start (const int pin_do, const int pin_clk, const int pin_di, const int pin_cs)
 Start a new cog with the SPI driver. More...
 
void ReadBlock (const int block_index, char *buffer_address)
 
void WriteBlock (const int block_index, char *buffer_address)
 
void ReleaseCard (void)
 Release the SPI bus and allow other devices to use it. More...
 
void Stop (void)
 Kill the assembly driver cog. More...
 
bool HasError (void) const
 If there was an error in the SD routines then this function will return an error code. More...
 
void ClearError (void)
 Resets the error flag to kNoError. More...
 
int GetError (void) const
 

Static Public Attributes

static const int kCardTypeMMC = 1
 
static const int kCardTypeSD = 2
 
static const int kCardTypeSDHC = 3
 
static const int kNoError = 0
 
static const int kErrorCardNotReset = -1
 
static const int kError3v3NotSupported = -2
 
static const int kErrorOcrFailed = -3
 
static const int kErrorBlockNotLongAligned = -4
 
static const int kErrorAsmNoReadToken = 100
 
static const int kErrorAsmBlockNotWritten = 101
 
static const int kErrorSpiEngineNotRunning = -999
 
static const int kErrorCardBusyTimeout = -1000
 

Detailed Description

SPI interface routines for SD & SDHC & MMC cards.

C++ conversion by SRLM, based on sdsafespi.spin version 0.3.0 by Jonathan "lonesock" Dummer.

This uses multiblock SPI mode exclusively.

This is the "SAFE" version...uses

Warning
You should check the error code after each function call. Something may have gone wrong, and this is the only way to know! If there is an error, the safest thing to do would be to destroy the object instance, fix the error, and try again. For some errors, it may be ok to simply clear the error and try again.

Notes:

Todo:
(SRLM): Convert the SD SPI driver to GAS instead of binary.
Author
SRLM (srlm@.nosp@m.srlm.nosp@m.produ.nosp@m.ctio.nosp@m.ns.co.nosp@m.m)

Member Function Documentation

void SDSafeSPI::ClearError ( void  )
inline

Resets the error flag to kNoError.

int SDSafeSPI::GetError ( void  ) const
inline
bool SDSafeSPI::HasError ( void  ) const
inline

If there was an error in the SD routines then this function will return an error code.

Returns
The error code.
void SDSafeSPI::ReadBlock ( const int  block_index,
char *  buffer_address 
)
inline
void SDSafeSPI::ReleaseCard ( void  )
inline

Release the SPI bus and allow other devices to use it.

The SPI bus is re-acquired the next time a block is transfered.

Warning
If you release the lines, make sure that the other devices are not using the bus the next time you do an SD operation.
int SDSafeSPI::Start ( const int  basepin)
inline

Start a new cog with the SPI driver.

Warning
requires that the pins be both consecutive, and in the order
  1. DO
  2. CLK
  3. DI
  4. CS
Returns
The card type constant.
int SDSafeSPI::Start ( const int  pin_do,
const int  pin_clk,
const int  pin_di,
const int  pin_cs 
)
inline

Start a new cog with the SPI driver.

Parameters
pin_do
pin_clk
pin_di
pin_cs
Returns
The card type constant.

Here is the call graph for this function:

void SDSafeSPI::Stop ( void  )
inline

Kill the assembly driver cog.

Here is the call graph for this function:

void SDSafeSPI::WriteBlock ( const int  block_index,
char *  buffer_address 
)
inline

Member Data Documentation

const int SDSafeSPI::kCardTypeMMC = 1
static
const int SDSafeSPI::kCardTypeSD = 2
static
const int SDSafeSPI::kCardTypeSDHC = 3
static
const int SDSafeSPI::kError3v3NotSupported = -2
static
const int SDSafeSPI::kErrorAsmBlockNotWritten = 101
static
const int SDSafeSPI::kErrorAsmNoReadToken = 100
static
const int SDSafeSPI::kErrorBlockNotLongAligned = -4
static
const int SDSafeSPI::kErrorCardBusyTimeout = -1000
static
const int SDSafeSPI::kErrorCardNotReset = -1
static
const int SDSafeSPI::kErrorOcrFailed = -3
static
const int SDSafeSPI::kErrorSpiEngineNotRunning = -999
static
const int SDSafeSPI::kNoError = 0
static

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