STIMA
3
platformio
stima_v3
test_sdfat16
src
SdCard.h
1
/* Arduino FAT16 Library
2
* Copyright (C) 2008 by William Greiman
3
*
4
* This file is part of the Arduino FAT16 Library
5
*
6
* This Library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This Library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
16
* You should have received a copy of the GNU General Public License
17
* along with the Arduino Fat16 Library. If not, see
18
* <http://www.gnu.org/licenses/>.
19
*/
20
#ifndef SdCard_h
21
#define SdCard_h
22
23
//#include <inttypes.h>
24
#define __STDC_LIMIT_MACROS
25
#include <stdint.h>
26
#include <avr/io.h>
27
28
#include "mSPI.h"
29
30
/********************/
31
/* CHIP SELECT PIN */
32
/********************/
33
34
/* !!! don't works !!! */
35
36
/* the default SS pin is PB2 */
37
#ifndef SD_SS_PORT
38
#define SD_SS_PORT B
39
#endif
40
41
/* !!! default changed !!! */
42
#ifndef SD_SS_PIN
43
#define SD_SS_PIN 0
44
#endif
45
46
/* build register name */
47
#define SD_SS_PORT_REG PORTC
48
#define SD_SS_DDR_REG DDRC
49
50
/* init at DIV32 : 8Mhtz -> 250 000 */
51
#define SPI_SCK_INIT_DIVISOR 0x10
52
53
54
//------------------------------------------------------------------------------
55
// SD operation timeouts
56
57
#define SD_MAX_CMD0_TRIES 10
58
#define SD_MAX_TRANSFERTS UINT16_MAX
59
#define SD_MAX_COMMANDS UINT16_MAX
60
61
62
//------------------------------------------------------------------------------
63
// SD card commands
65
#define CMD0 0X00
67
#define CMD8 0X08
69
#define CMD9 0X09
71
#define CMD10 0X0A
73
#define CMD12 0X0C
75
#define CMD13 0X0D
77
#define CMD17 0X11
79
#define CMD18 0X12
81
#define CMD24 0X18
83
#define CMD25 0X19
85
#define CMD32 0X20
88
#define CMD33 0X21
90
#define CMD38 0X26
92
#define CMD55 0X37
94
#define CMD58 0X3A
96
#define CMD59 0X3B
99
#define ACMD23 0X17
102
#define ACMD41 0X29
103
//------------------------------------------------------------------------------
105
#define R1_READY_STATE 0X00
107
#define R1_IDLE_STATE 0X01
109
#define R1_ILLEGAL_COMMAND 0X04
111
#define DATA_START_BLOCK 0XFE
113
#define STOP_TRAN_TOKEN 0XFD
115
#define WRITE_MULTIPLE_TOKEN 0XFC
117
#define DATA_RES_MASK 0X1F
119
#define DATA_RES_ACCEPTED 0X05
120
//------------------------------------------------------------------------------
122
#define CARD_TYPE_SDV1 0x01
124
#define CARD_TYPE_SDV2 0x02
126
#define CARD_TYPE_SDHC 0x03
127
128
//------------------------------------------------------------------------------
129
130
/* return card type */
131
uint8_t SdCard_begin();
132
bool
SdCard_readBlock(uint32_t block, uint8_t cardType);
133
bool
SdCard_writeBlock(uint32_t block, uint8_t cardType);
134
135
#endif
// SdCard_h
Generated by
1.9.1