- Fix Visual glitch in Clear Screen - Add Long Time Screenshot - Try fix sd card issue (still not working)
49 lines
1.2 KiB
C
Executable File
49 lines
1.2 KiB
C
Executable File
#include "hw_config.h"
|
|
|
|
#include "diskio.h"
|
|
#include "ff.h" // FatFs
|
|
#include "hardware/spi.h"
|
|
|
|
// 1. SPI hardware + pin config
|
|
static spi_t spi1_config = {
|
|
.hw_inst = spi1,
|
|
.sck_gpio = 10,
|
|
.mosi_gpio = 11,
|
|
.miso_gpio = 12,
|
|
.baud_rate = 10 * 1000 * 1000 // 10 MHz is safe to start
|
|
};
|
|
|
|
// 2. SPI interface for SD card
|
|
static sd_spi_if_t spi_if = {
|
|
.spi = &spi1_config,
|
|
.ss_gpio = 9,
|
|
.set_drive_strength = false // set to true and configure if needed
|
|
};
|
|
|
|
static sd_card_t sd_card = {
|
|
.type = SD_IF_SPI, .spi_if_p = &spi_if, .use_card_detect = false};
|
|
|
|
/**
|
|
* @brief Get the number of SD cards.
|
|
*
|
|
* @return The number of SD cards, which is 1 in this case.
|
|
*/
|
|
size_t sd_get_num() { return 1; }
|
|
|
|
/**
|
|
* @brief Get a pointer to an SD card object by its number.
|
|
*
|
|
* @param[in] num The number of the SD card to get.
|
|
*
|
|
* @return A pointer to the SD card object, or @c NULL if the number is invalid.
|
|
*/
|
|
sd_card_t* sd_get_by_num(size_t num) {
|
|
if (0 == num) {
|
|
// The number 0 is a valid SD card number.
|
|
// Return a pointer to the sd_card object.
|
|
return &sd_card;
|
|
} else {
|
|
// The number is invalid. Return @c NULL.
|
|
return NULL;
|
|
}
|
|
} |