-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsd.h
102 lines (85 loc) · 2.93 KB
/
sd.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************************
* @file sd.h
* @brief SD: Manages SDIO in 4-bit mode for microSD operations.
*******************************************************************************
*/
#ifndef NERVE__SD_H
#define NERVE__SD_H
/** Includes. *****************************************************************/
#include "diskio.h"
#include "fatfs.h"
#include "fatfs_platform.h"
#include "ff.h"
#include "ff_gen_drv.h"
#include "ffconf.h"
#include "integer.h"
#include "main.h"
#include "stdbool.h"
#include <stdio.h>
#include <string.h>
/** STM32 port and pin configs. ***********************************************/
extern SD_HandleTypeDef hsd;
// SDIO.
#define SDIO_SD_DETECT_PORT GPIOC
#define SDIO_SD_DETECT_PIN GPIO_PIN_4
#define SDIO_HSD hsd
/** Public variables. *********************************************************/
extern volatile int sd_write_counter;
extern Disk_drvTypeDef disk;
/** Public functions. *********************************************************/
/**
* @breif Determine if SD card is detected for SD implementation.
*
* @return Result SDIO card detect status.
* @retval 0 -> Success, card is detected.
* @retval 1 -> Failure, card is not detected.
*
* @note SDIO card detect is typically active high, but STM32's FATFS platform
* BSP SDIO_Detect implementation uses active low. Thus, active low means a card
* is detected and vice versa.
*/
uint8_t sdio_card_detected();
/**
* @brief Mounts the SD card filesystem.
*
* @param file_result: Pointer to the result variable.
* @param SDFatFs: Pointer to the FATFS object.
*/
void sdio_mount_sd(FRESULT *file_result, FATFS *SDFatFs);
/**
* @brief Unmounts the SD card filesystem.
*
* @param file_result: Pointer to the result variable.
* @param SDFatFs: Pointer to the FATFS object.
*/
void sdio_unmount_sd(FRESULT *file_result, FATFS *SDFatFs);
/**
* @brief Opens a file on the SD card in write mode.
*
* @param file_result: Pointer to the result variable.
* @param file_name: Name of the file to open or create on the SD card.
*/
void sdio_open_write_mode_sd_file(FRESULT *file_result, char *file_name);
/**
* @brief Write buffer to the current open file on the SD card.
*
* @param file_result: Pointer to the result variable.
* @param data_buffer: Pointer to the data buffer.
* @param data_buffer_length: Number of bytes to be written.
* @param bytes_written: Pointer to number of bytes written (error check).
*/
void sdio_write_sd_file(FRESULT *file_result, void *data_buffer,
UINT data_buffer_length, UINT *bytes_written);
/**
* @brief Closes the current open file on the SD card.
*
* @param file_result: Pointer to the result variable.
*/
void sdio_close_sd_card_file(FRESULT *file_result);
/**
* @brief Adjust or sets file name for the SD card file operations.
*
* @param sd_file_name: Character pointer to the file name string.
*/
void sdio_set_file_name(char *sd_file_name);
#endif