-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdcard.h
54 lines (45 loc) · 1.07 KB
/
sdcard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* sdcard.h
*
* Created on: Mar 18, 2023
* Author: dylan
*/
#ifndef SDCARD_H_
#define SDCARD_H_
#include "defines.h"
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
// Most recent SD card error code (think errno but for the SD card)
extern uint16_t sd_errorCode;
// Most recent R1 byte - see SD spec for bit field meanings
extern uint16_t sd_status;
// Connected SD card type
extern uint8_t sd_cardType;
/**
* Byte for command, 4 bytes for argument.
* Returns the first byte of the response (R1 byte)
* or 0xFF if it times out.
*/
uint8_t sd_command(uint8_t cmd, uint32_t arg);
/**
* Execute application-specific command acmd with
* 4-byte argument arg, then return the R1 byte of the result.
*/
uint8_t sd_acmd(uint8_t acmd, uint32_t arg);
/**
* Read a single 512 byte block into `buf`, at the index
* `sector`.
*/
bool sd_read_block(uint32_t sector, uint8_t *buf);
/**
* Initialize the SD card, returning true if the initialization failed.
*/
bool sd_init();
#ifdef __cplusplus
}
#endif
#endif /* SDCARD_H_ */