This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathemusdcard.c
124 lines (101 loc) · 3.49 KB
/
emusdcard.c
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* ATARI ST HDC Emulator
*
* File: emusdcard.c
* Author: Steve Bradford
* Created: 1st Nov 2022
*
* Shell
*/
#include <stdio.h>
#include <pico/stdlib.h>
#include "pico.h"
#include "hardware/spi.h"
#include "emu.h"
#if USEDMA
void spi0_dma_isr();
#endif
// Hardware Configuration of SPI "objects"
// Note: multiple SD cards can be driven by one SPI if they use different slave
// selects.
spi_t spis[] = { // One for each SPI.
{
.hw_inst = spi0, // SPI instance
.miso_gpio = SPI_SDO, // SDO
.mosi_gpio = SPI_SDI, // SDI
.sck_gpio = SPI_CLK, // CLK
/*
* The choice of SD card does matter
* Samsung EVO Plus 24MHz and 50MHz (CPU CLOCK needs to be 200 MHz) tested OK
*/
.baud_rate = 50 * MHZ,
// Following attributes are dynamically assigned
#if USEDMA
.dma_isr = spi0_dma_isr,
#endif
.initialized = false, // initialized flag
}
};
// Hardware Configuration of the SD Card "objects"
sd_card_t sd_cards[] = { // One for each SD card
{
.pcName = "sd0:", // Name used to mount device - refer to ffconf.h
.spi = &spis[0], // Pointer to the SPI driving this card
.ss_gpio = MICROSD_CARD_CS0, // The SPI slave select GPIO for this SD card
.card_detect_gpio = MICROSD_CARD_CD0, // Card detect
.card_detected_true = false, // What the GPIO read returns when a card is
// present. Use -1 if there is no card detect.
.use_card_detect = true,
// Following attributes are dynamically assigned
.m_Status = STA_NOINIT,
.sectors = 0,
.card_type = 0,
},
{
.pcName = "sd1:", // Name used to mount device - refer to ffconf.h
.spi = &spis[0], // Pointer to the SPI driving this card
.ss_gpio = MICROSD_CARD_CS1, // The SPI slave select GPIO for this SD card
.card_detect_gpio = MICROSD_CARD_CD1, // Card detect
.card_detected_true = false, // What the GPIO read returns when a card is
// present. Use -1 if there is no card detect.
.use_card_detect = true,
// Following attributes are dynamically assigned
.m_Status = STA_NOINIT,
.sectors = 0,
.card_type = 0,
}
};
#if USEDMA
void spi0_dma_isr() { spi_irq_handler(&spis[0]); }
#endif
/* ********************************************************************** */
size_t sd_get_num() { return count_of(sd_cards); }
sd_card_t *sd_get_by_num(size_t num) {
if (num <= sd_get_num()) {
return &sd_cards[num];
} else {
return NULL;
}
}
size_t spi_get_num() { return count_of(spis); }
spi_t *spi_get_by_num(size_t num) {
if (num <= sd_get_num()) {
return &spis[num];
} else {
return NULL;
}
}
/* ------------------------------------------------------------------------- */
/* the following needs to be included for ff_conf.h when using multiple partitions */
/*
PARTITION VolToPart [FF_VOLUMES] = {
{0, 0},
{0, 1},
{0, 2},
{0, 3},
{1, 0},
{1, 1},
{1, 2},
{1, 3}
};
*/