-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw_config.c
79 lines (65 loc) · 2.32 KB
/
hw_config.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
/* hw_config.c
Copyright 2021 Carl John Kugler III
Licensed under the Apache License, Version 2.0 (the License); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
*/
/*
This file should be tailored to match the hardware design.
There should be one element of the spi[] array for each hardware SPI used.
There should be one element of the sd_cards[] array for each SD card slot.
The name is should correspond to the FatFs "logical drive" identifier.
(See http://elm-chan.org/fsw/ff/doc/filename.html#vol)
The rest of the constants will depend on the type of
socket, which SPI it is driven by, and how it is wired.
*/
#include <a2pico.h>
#include <hw_config.h>
// Hardware Configuration of SPI "objects"
// Note: multiple SD cards can be driven by one SPI if they use different slave
// selects.
static spi_t spis[] = { // One for each SPI.
{
.hw_inst = spi0,
.miso_gpio = GPIO_SPI0_RX,
.mosi_gpio = GPIO_SPI0_TX,
.sck_gpio = GPIO_SPI0_SCK,
.baud_rate = 12500 * 1000
// .baud_rate = 25 * 1000 * 1000 // Actual frequency: 20833333.
}
};
// Hardware Configuration of the SD Card "objects"
static sd_card_t sd_cards[] = { // One for each SD card
{
.pcName = "0:", // Name used to mount device
.spi = &spis[0], // Pointer to the SPI driving this card
.ss_gpio = GPIO_SPI0_CSN, // The SPI slave select for this SD card
.use_card_detect = false,
}
};
/* ********************************************************************** */
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 <= spi_get_num()) {
return &spis[num];
} else {
return NULL;
}
}