2018-05-05 16:33:49 +01:00
|
|
|
#include <stdio.h>
|
2018-04-07 22:43:54 +01:00
|
|
|
#include "sd_utils.h"
|
2018-05-04 18:47:05 +01:00
|
|
|
#include "hwinit.h"
|
|
|
|
#include "sdmmc.h"
|
|
|
|
|
|
|
|
/* This is used by diskio.h. */
|
|
|
|
struct mmc sd_mmc;
|
|
|
|
static int initialized_sd = 0;
|
|
|
|
|
|
|
|
int initialize_sd(void) {
|
|
|
|
if (initialized_sd) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
mc_enable_ahb_redirect();
|
|
|
|
if (sdmmc_init(&sd_mmc, SWITCH_MICROSD) == 0) {
|
2018-05-05 22:55:40 +01:00
|
|
|
printf("Initialized SD card!\n");
|
2018-05-04 18:47:05 +01:00
|
|
|
initialized_sd = 1;
|
2018-05-06 16:22:12 +01:00
|
|
|
} else {
|
|
|
|
printf("Failed to initialize the SD card!\n");
|
|
|
|
return 0;
|
2018-05-04 18:47:05 +01:00
|
|
|
}
|
|
|
|
return initialized_sd;
|
|
|
|
}
|
|
|
|
|
2018-04-26 11:47:22 +01:00
|
|
|
size_t read_sd_file(void *dst, size_t dst_size, const char *filename) {
|
2018-05-05 16:33:49 +01:00
|
|
|
FILE *file = fopen(filename, "rb");
|
|
|
|
if (file == NULL) {
|
2018-05-04 18:47:05 +01:00
|
|
|
return 0;
|
2018-05-05 16:33:49 +01:00
|
|
|
} else {
|
|
|
|
size_t sz = fread(dst, 1, dst_size, file);
|
|
|
|
fclose(file);
|
|
|
|
return sz;
|
2018-05-04 18:47:05 +01:00
|
|
|
}
|
2018-05-04 23:11:22 +01:00
|
|
|
}
|