ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Macros | Functions | Variables
mmc.c File Reference
#include "user_config.h"
#include "mmc_hal.h"
#include "printf/mathio.h"
#include "fatfs.sup/fatfs.h"

Go to the source code of this file.

Macros

#define CS_LOW()   mmc_spi_begin() /* Set MMC_CS = low */
 
#define CS_HIGH()   mmc_spi_end() /* Set MMC_CS = high */
 
#define MMC_CD   mmc_ins_status() /* Test if card detected. yes:true, no:false, default:true */
 
#define MMC_WP   mmc_wp_status() /* Test if write protected. yes:true, no:false, default:false */
 
#define FCLK_SLOW()   mmc_slow() /* Set SPI slow clock (100-400kHz) */
 
#define FCLK_FAST()   mmc_fast() /* Set SPI fast clock (20MHz max) */
 
#define CMD0   (0) /* GO_IDLE_STATE */
 
#define CMD1   (1) /* SEND_OP_COND (MMC) */
 
#define ACMD41   (0x80+41) /* SEND_OP_COND (SDC) */
 
#define CMD8   (8) /* SEND_IF_COND */
 
#define CMD9   (9) /* SEND_CSD */
 
#define CMD10   (10) /* SEND_CID */
 
#define CMD12   (12) /* STOP_TRANSMISSION */
 
#define ACMD13   (0x80+13) /* SD_STATUS (SDC) */
 
#define CMD16   (16) /* SET_BLOCKLEN */
 
#define CMD17   (17) /* READ_SINGLE_BLOCK */
 
#define CMD18   (18) /* READ_MULTIPLE_BLOCK */
 
#define CMD23   (23) /* SET_BLOCK_COUNT (MMC) */
 
#define ACMD23   (0x80+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */
 
#define CMD24   (24) /* WRITE_BLOCK */
 
#define CMD25   (25) /* WRITE_MULTIPLE_BLOCK */
 
#define CMD32   (32) /* ERASE_ER_BLK_START */
 
#define CMD33   (33) /* ERASE_ER_BLK_END */
 
#define CMD38   (38) /* ERASE */
 
#define CMD48   (48) /* READ_EXTR_SINGLE */
 
#define CMD49   (49) /* WRITE_EXTR_SINGLE */
 
#define CMD55   (55) /* APP_CMD */
 
#define CMD58   (58) /* READ_OCR */
 

Functions

static MEMSPACE void power_on (void)
 power on More...
 
static MEMSPACE void power_off (void)
 power off More...
 
static BYTE xchg_spi (BYTE dat)
 send/receive a SPI byte More...
 
static void rcvr_spi_multi (BYTE *p, UINT cnt)
 Receive a data block fast. More...
 
static void xmit_spi_multi (const BYTE *p, UINT cnt)
 Send a data block fast. More...
 
MEMSPACE int wait_ready (UINT wt)
 wait for card ready More...
 
static MEMSPACE void deselect (void)
 Deselect the card and release SPI bus. More...
 
static MEMSPACE int select (void)
 Select the card and wait for ready. More...
 
static MEMSPACE int rcvr_datablock (BYTE *buff, UINT btr)
 Receive a data packet from MMC. More...
 
static MEMSPACE BYTE send_cmd (BYTE cmd, DWORD arg)
 Send a data packet to MMC. More...
 
MEMSPACE DSTATUS mmc_disk_initialize (void)
 Public Functions. More...
 
MEMSPACE DSTATUS mmc_disk_status (void)
 Get Disk Status. More...
 
MEMSPACE DRESULT mmc_disk_read (BYTE *buff, DWORD sector, UINT count)
 Read Sector(s) More...
 
void mmc_disk_timerproc (void)
 Write Sector(s) More...
 

Variables

volatile DSTATUS Stat = STA_NOINIT
 
static volatile BYTE Timer1
 
static volatile BYTE Timer2
 
static BYTE CardType
 

Macro Definition Documentation

#define ACMD13   (0x80+13) /* SD_STATUS (SDC) */

Definition at line 61 of file mmc.c.

Referenced by mmc_disk_read().

#define ACMD23   (0x80+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */

Definition at line 66 of file mmc.c.

Referenced by mmc_disk_read().

#define ACMD41   (0x80+41) /* SEND_OP_COND (SDC) */

Definition at line 56 of file mmc.c.

Referenced by mmc_disk_initialize().

#define CMD0   (0) /* GO_IDLE_STATE */

Definition at line 54 of file mmc.c.

Referenced by mmc_disk_initialize(), and send_cmd().

#define CMD1   (1) /* SEND_OP_COND (MMC) */

Definition at line 55 of file mmc.c.

Referenced by mmc_disk_initialize().

#define CMD10   (10) /* SEND_CID */

Definition at line 59 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD12   (12) /* STOP_TRANSMISSION */

Definition at line 60 of file mmc.c.

Referenced by mmc_disk_read(), and send_cmd().

#define CMD16   (16) /* SET_BLOCKLEN */

Definition at line 62 of file mmc.c.

Referenced by mmc_disk_initialize().

#define CMD17   (17) /* READ_SINGLE_BLOCK */

Definition at line 63 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD18   (18) /* READ_MULTIPLE_BLOCK */

Definition at line 64 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD23   (23) /* SET_BLOCK_COUNT (MMC) */

Definition at line 65 of file mmc.c.

#define CMD24   (24) /* WRITE_BLOCK */

Definition at line 67 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD25   (25) /* WRITE_MULTIPLE_BLOCK */

Definition at line 68 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD32   (32) /* ERASE_ER_BLK_START */

Definition at line 69 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD33   (33) /* ERASE_ER_BLK_END */

Definition at line 70 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD38   (38) /* ERASE */

Definition at line 71 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD48   (48) /* READ_EXTR_SINGLE */

Definition at line 72 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD49   (49) /* WRITE_EXTR_SINGLE */

Definition at line 73 of file mmc.c.

Referenced by mmc_disk_read().

#define CMD55   (55) /* APP_CMD */

Definition at line 74 of file mmc.c.

Referenced by send_cmd().

#define CMD58   (58) /* READ_OCR */

Definition at line 75 of file mmc.c.

Referenced by mmc_disk_initialize(), and mmc_disk_read().

#define CMD8   (8) /* SEND_IF_COND */

Definition at line 57 of file mmc.c.

Referenced by mmc_disk_initialize(), and send_cmd().

#define CMD9   (9) /* SEND_CSD */

Definition at line 58 of file mmc.c.

Referenced by mmc_disk_read().

#define CS_HIGH ( )    mmc_spi_end() /* Set MMC_CS = high */

Definition at line 40 of file mmc.c.

Referenced by deselect().

#define CS_LOW ( )    mmc_spi_begin() /* Set MMC_CS = low */

Definition at line 39 of file mmc.c.

Referenced by select().

#define FCLK_FAST ( )    mmc_fast() /* Set SPI fast clock (20MHz max) */

Definition at line 45 of file mmc.c.

Referenced by mmc_disk_initialize().

#define FCLK_SLOW ( )    mmc_slow() /* Set SPI slow clock (100-400kHz) */

Definition at line 44 of file mmc.c.

Referenced by mmc_disk_initialize().

#define MMC_CD   mmc_ins_status() /* Test if card detected. yes:true, no:false, default:true */

Definition at line 42 of file mmc.c.

Referenced by mmc_disk_timerproc().

#define MMC_WP   mmc_wp_status() /* Test if write protected. yes:true, no:false, default:false */

Definition at line 43 of file mmc.c.

Referenced by mmc_disk_timerproc().

Function Documentation

static MEMSPACE void deselect ( void  )
static

Deselect the card and release SPI bus.

Returns
void

Definition at line 189 of file mmc.c.

Referenced by mmc_disk_initialize(), mmc_disk_read(), select(), and send_cmd().

MEMSPACE DSTATUS mmc_disk_initialize ( void  )

Public Functions.

Initialize Disk Drive

Returns
Stat

Definition at line 340 of file mmc.c.

Referenced by disk_initialize().

MEMSPACE DRESULT mmc_disk_read ( BYTE buff,
DWORD  sector,
UINT  count 
)

Read Sector(s)

Parameters
[in]buffread buffer
[in]sectorstart sector number
[in]countsector count
Returns
0 ok
non zero error

Definition at line 433 of file mmc.c.

Referenced by disk_read().

MEMSPACE DSTATUS mmc_disk_status ( void  )

Get Disk Status.

Returns
Stat
STA_NOINIT if no drive

Definition at line 420 of file mmc.c.

Referenced by disk_status().

void mmc_disk_timerproc ( void  )

Write Sector(s)

Parameters
[out]buffwrite buffer
[in]sectorstart sector number
[in]countsector count
Returns
0 ok
non zero error Miscellaneous Functions
Parameters
[in]cmdControl code
[in|out]buff: Send/Receive buffer
Returns
result mmc timer processes

Definition at line 708 of file mmc.c.

Referenced by disk_timerproc(), and mmc_task().

static MEMSPACE void power_off ( void  )
static

power off

Returns
void

Definition at line 110 of file mmc.c.

Referenced by mmc_disk_initialize(), and mmc_disk_read().

static MEMSPACE void power_on ( void  )
static

power on

Returns
void

Definition at line 97 of file mmc.c.

static MEMSPACE int rcvr_datablock ( BYTE buff,
UINT  btr 
)
static

Receive a data packet from MMC.

Parameters
[in]buffData buffer to read data into
[in]btrBytes to read
Returns
1 Successful
0 Error

Definition at line 224 of file mmc.c.

Referenced by mmc_disk_read().

static void rcvr_spi_multi ( BYTE p,
UINT  cnt 
)
static

Receive a data block fast.

Parameters
[in]pData block to be read
[in]cntBytes to read
Returns
void

Definition at line 139 of file mmc.c.

Referenced by rcvr_datablock().

static MEMSPACE int select ( void  )
static

Select the card and wait for ready.

Returns
1 Successful
0 Timeout

Definition at line 202 of file mmc.c.

Referenced by mmc_disk_read(), and send_cmd().

static MEMSPACE BYTE send_cmd ( BYTE  cmd,
DWORD  arg 
)
static

Send a data packet to MMC.

Parameters
[in]buffData buffer to write
[in]btrBytes to write
Returns
1 Successful
0 Error Send a command packet to MMC
Parameters
[in]send_cmdCommend Index
[in]cmdArgument
Returns
R1 resp
bit7==1Send failed

Definition at line 288 of file mmc.c.

Referenced by mmc_disk_initialize(), and mmc_disk_read().

MEMSPACE int wait_ready ( UINT  wt)

wait for card ready

Parameters
[in]wtms to wait
Returns
1 Ready
0 Timeout

Definition at line 169 of file mmc.c.

Referenced by mmc_disk_read(), rcvr_datablock(), and select().

static BYTE xchg_spi ( BYTE  dat)
static

send/receive a SPI byte

Parameters
[in]datdata to send
Returns
Data read

Definition at line 126 of file mmc.c.

Referenced by deselect(), mmc_disk_initialize(), mmc_disk_read(), rcvr_datablock(), select(), send_cmd(), and wait_ready().

static void xmit_spi_multi ( const BYTE p,
UINT  cnt 
)
static

Send a data block fast.

Parameters
[out]pData block to be sent
[in]cntBytes to send
Returns
void

Definition at line 152 of file mmc.c.

Referenced by rcvr_datablock().

Variable Documentation

BYTE CardType
static

Definition at line 85 of file mmc.c.

Referenced by mmc_disk_initialize(), and mmc_disk_read().

volatile DSTATUS Stat = STA_NOINIT
volatile BYTE Timer1
static

Definition at line 82 of file mmc.c.

Referenced by mmc_disk_timerproc().

volatile BYTE Timer2
static

Definition at line 82 of file mmc.c.

Referenced by mmc_disk_timerproc().