This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
hw_config.c
88 lines (75 loc) · 2.73 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
80
81
82
83
84
85
86
87
88
/* 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 <string.h>
//
#include "my_debug.h"
//
#include "hw_config.h"
//
#include "ff.h" /* Obtains integer types */
//
#include "diskio.h" /* Declarations of disk functions */
void spi1_dma_isr();
// 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 = spi1, // SPI component
.miso_gpio = 8, // GPIO number (not pin number)
.mosi_gpio = 11,
.sck_gpio = 10,
.baud_rate = 25 * 1000 * 1000,
.dma_isr = spi1_dma_isr
}
};
// 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 = 9, // The SPI slave select GPIO for this SD card
.use_card_detect = false,
.card_detect_gpio = -1, // Card detect
.card_detected_true = -1, // What the GPIO read returns when a card is
// present. Use -1 if there is no card detect.
.m_Status = STA_NOINIT
}
};
void spi1_dma_isr() { spi_irq_handler(&spis[0]); }
/* ********************************************************************** */
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;
}
}
/* [] END OF FILE */