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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_in.h"
50 #include "MikroSDK.PhysicalDrive"
51 #include "MikroSDK.FileSystem"
52 
77 #define MICROSD_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
78 #define MICROSD_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
79  // microsd_set
81 
96 #define MICROSD_MAP_MIKROBUS( cfg, mikrobus ) \
97  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
98  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
99  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
100  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
101  cfg.cd_pin = MIKROBUS( mikrobus, MIKROBUS_AN );
102  // microsd_map // microsd
105 
110 typedef struct
111 {
112  digital_in_t cd_pin;
113 
114  sdspi_physical_drive_t sd_pdrive;
115 
116  fatfs_logical_drive_t fat_ldrive;
117 
118 } microsd_t;
119 
124 typedef struct
125 {
126  // Communication gpio pins
127  pin_name_t miso;
128  pin_name_t mosi;
129  pin_name_t sck;
130  pin_name_t cs;
132  pin_name_t cd_pin;
134 } microsd_cfg_t;
135 
140 typedef enum
141 {
143  MICROSD_ERROR = -1
144 
146 
163 
177 err_t microsd_init ( microsd_t *ctx, microsd_cfg_t *cfg );
178 
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 #endif // MICROSD_H
194  // microsd
196 
197 // ------------------------------------------------------------------------ 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:116
microsd_cfg_t::cd_pin
pin_name_t cd_pin
Definition: microsd.h:132
microsd_return_value_t
microsd_return_value_t
microSD Click return value data.
Definition: microsd.h:141
microsd_t
microSD Click context object.
Definition: microsd.h:111
MICROSD_ERROR
@ MICROSD_ERROR
Definition: microsd.h:143
microsd_t::sd_pdrive
sdspi_physical_drive_t sd_pdrive
Definition: microsd.h:114
MICROSD_OK
@ MICROSD_OK
Definition: microsd.h:142
microsd_cfg_t::cs
pin_name_t cs
Definition: microsd.h:130
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:127
microsd_cfg_t::mosi
pin_name_t mosi
Definition: microsd.h:128
microsd_cfg_t::sck
pin_name_t sck
Definition: microsd.h:129
microsd_t::cd_pin
digital_in_t cd_pin
Definition: microsd.h:112
microsd_cfg_t
microSD Click configuration object.
Definition: microsd.h:125
microsd_cfg_setup
void microsd_cfg_setup(microsd_cfg_t *cfg)
microSD configuration object setup function.