1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-26 12:16:04 +00:00
Atmosphere/fusee/fusee-secondary/src/sd_utils.c

42 lines
894 B
C
Raw Normal View History

#include <stdio.h>
2018-04-07 22:43:54 +01:00
#include "sd_utils.h"
#include "hwinit.h"
#include "sdmmc.h"
#include "lib/printk.h"
2018-05-04 23:11:22 +01:00
#include "lib/fatfs/ff.h"
/* This is used by diskio.h. */
struct mmc sd_mmc;
static int initialized_sd = 0;
void save_sd_state(void **mmc) {
*mmc = &sd_mmc;
}
void resume_sd_state(void *mmc) {
sd_mmc = *(struct mmc *)mmc;
initialized_sd = 1;
}
int initialize_sd(void) {
if (initialized_sd) {
return 1;
}
mc_enable_ahb_redirect();
if (sdmmc_init(&sd_mmc, SWITCH_MICROSD) == 0) {
printk("Initialized SD card!\n");
initialized_sd = 1;
}
return initialized_sd;
}
size_t read_sd_file(void *dst, size_t dst_size, const char *filename) {
FILE *file = fopen(filename, "rb");
if (file == NULL) {
return 0;
} else {
size_t sz = fread(dst, 1, dst_size, file);
fclose(file);
return sz;
}
2018-05-04 23:11:22 +01:00
}