microsd  2.1.0.0
microsd.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef MICROSD_H
29 #define MICROSD_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_in.h"
46 #include "MikroSDK.PhysicalDrive"
47 #include "MikroSDK.FileSystem"
48 
73 #define MICROSD_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
74 #define MICROSD_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
75  // microsd_set
77 
92 #define MICROSD_MAP_MIKROBUS( cfg, mikrobus ) \
93  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
94  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
95  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
96  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
97  cfg.cd_pin = MIKROBUS( mikrobus, MIKROBUS_AN );
98  // microsd_map // microsd
101 
106 typedef struct
107 {
108  digital_in_t cd_pin;
109 
110  sdspi_physical_drive_t sd_pdrive;
111 
112  fatfs_logical_drive_t fat_ldrive;
113 
114 } microsd_t;
115 
120 typedef struct
121 {
122  // Communication gpio pins
123  pin_name_t miso;
124  pin_name_t mosi;
125  pin_name_t sck;
126  pin_name_t cs;
128  pin_name_t cd_pin;
130 } microsd_cfg_t;
131 
136 typedef enum
137 {
139  MICROSD_ERROR = -1
140 
142 
159 
173 err_t microsd_init ( microsd_t *ctx, microsd_cfg_t *cfg );
174 
185 
186 #ifdef __cplusplus
187 }
188 #endif
189 #endif // MICROSD_H
190  // microsd
192 
193 // ------------------------------------------------------------------------ END
microsd_init
err_t microsd_init(microsd_t *ctx, microsd_cfg_t *cfg)
microSD initialization function.
microsd_t::fat_ldrive
fatfs_logical_drive_t fat_ldrive
Definition: microsd.h:112
microsd_cfg_t::cd_pin
pin_name_t cd_pin
Definition: microsd.h:128
microsd_return_value_t
microsd_return_value_t
microSD Click return value data.
Definition: microsd.h:137
microsd_t
microSD Click context object.
Definition: microsd.h:107
MICROSD_ERROR
@ MICROSD_ERROR
Definition: microsd.h:139
microsd_t::sd_pdrive
sdspi_physical_drive_t sd_pdrive
Definition: microsd.h:110
MICROSD_OK
@ MICROSD_OK
Definition: microsd.h:138
microsd_cfg_t::cs
pin_name_t cs
Definition: microsd.h:126
microsd_get_card_detect
uint8_t microsd_get_card_detect(microsd_t *ctx)
microSD get card detect function.
microsd_cfg_t::miso
pin_name_t miso
Definition: microsd.h:123
microsd_cfg_t::mosi
pin_name_t mosi
Definition: microsd.h:124
microsd_cfg_t::sck
pin_name_t sck
Definition: microsd.h:125
microsd_t::cd_pin
digital_in_t cd_pin
Definition: microsd.h:108
microsd_cfg_t
microSD Click configuration object.
Definition: microsd.h:121
microsd_cfg_setup
void microsd_cfg_setup(microsd_cfg_t *cfg)
microSD configuration object setup function.