Skip to content

Commit

Permalink
增强文件系统的通用性
Browse files Browse the repository at this point in the history
  • Loading branch information
ClimbSnail committed Jun 13, 2022
1 parent 86044eb commit 4541042
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
2 changes: 0 additions & 2 deletions HoloCubic_Firmware/src/driver/imu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ void IMU::init(uint8_t order, uint8_t auto_calibration,
unsigned long preMillis = millis();
// mpu = MPU6050(0x68, &Wire);
mpu = MPU6050(0x68);
Serial.print(F("Unable to connect to 4.\n"));
while (!mpu.testConnection() && !doDelayMillisTime(timeout, &preMillis, false))
;
Serial.print(F("Unable to connect to 5.\n"));

if (!mpu.testConnection())
{
Expand Down
45 changes: 28 additions & 17 deletions HoloCubic_Firmware/src/driver/sd_card.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "sd_card.h"
#include "SD_MMC.h"
#include <string.h>

int photo_file_num = 0;
char file_name_list[DIR_FILE_NUM][DIR_FILE_NAME_MAX_LEN];

static fs::FS *tf_vfs;

void release_file_info(File_Info *info)
{
File_Info *cur_node = NULL; // 记录当前节点
Expand Down Expand Up @@ -71,16 +74,24 @@ static const char *get_file_basename(const char *path)

void SdCard::init()
{

SPIClass *sd_spi = new SPIClass(HSPI); // another SPI
sd_spi->begin(14, 26, 13, 15); // Replace default HSPI pins
if (!SD.begin(15, *sd_spi, 80000000)) // SD-Card SS pin is 15
{
Serial.println("Card Mount Failed");
return;
}
tf_vfs = &SD;
uint8_t cardType = SD.cardType();

// 目前SD_MMC驱动与硬件引脚存在冲突
// if(!SD_MMC.begin("/", true)){
// Serial.println("Card Mount Failed");
// return;
// }
// tf_vfs = &SD_MMC;
// uint8_t cardType = SD_MMC.cardType();

if (cardType == CARD_NONE)
{
Serial.println("No SD card attached");
Expand Down Expand Up @@ -114,7 +125,7 @@ void SdCard::listDir(const char *dirname, uint8_t levels)
Serial.printf("Listing directory: %s\n", dirname);
photo_file_num = 0;

File root = SD.open(dirname);
File root = tf_vfs->open(dirname);
if (!root)
{
Serial.println("Failed to open directory");
Expand Down Expand Up @@ -163,7 +174,7 @@ File_Info *SdCard::listDir(const char *dirname)
{
Serial.printf("Listing directory: %s\n", dirname);

File root = SD.open(dirname);
File root = tf_vfs->open(dirname);
if (!root)
{
Serial.println("Failed to open directory");
Expand Down Expand Up @@ -255,7 +266,7 @@ File_Info *SdCard::listDir(const char *dirname)
void SdCard::createDir(const char *path)
{
Serial.printf("Creating Dir: %s\n", path);
if (SD.mkdir(path))
if (tf_vfs->mkdir(path))
{
Serial.println("Dir created");
}
Expand All @@ -268,7 +279,7 @@ void SdCard::createDir(const char *path)
void SdCard::removeDir(const char *path)
{
Serial.printf("Removing Dir: %s\n", path);
if (SD.rmdir(path))
if (tf_vfs->rmdir(path))
{
Serial.println("Dir removed");
}
Expand All @@ -282,7 +293,7 @@ void SdCard::readFile(const char *path)
{
Serial.printf("Reading file: %s\n", path);

File file = SD.open(path);
File file = tf_vfs->open(path);
if (!file)
{
Serial.println("Failed to open file for reading");
Expand All @@ -301,7 +312,7 @@ String SdCard::readFileLine(const char *path, int num)
{
Serial.printf("Reading file: %s line: %d\n", path, num);

File file = SD.open(path);
File file = tf_vfs->open(path);
if (!file)
{
return ("Failed to open file for reading");
Expand Down Expand Up @@ -336,7 +347,7 @@ void SdCard::writeFile(const char *path, const char *info)
{
Serial.printf("Writing file: %s\n", path);

File file = SD.open(path, FILE_WRITE);
File file = tf_vfs->open(path, FILE_WRITE);
if (!file)
{
Serial.println("Failed to open file for writing");
Expand All @@ -355,14 +366,14 @@ void SdCard::writeFile(const char *path, const char *info)

File SdCard::open(const String &path, const char *mode)
{
return SD.open(path, FILE_WRITE);
return tf_vfs->open(path, mode);
}

void SdCard::appendFile(const char *path, const char *message)
{
Serial.printf("Appending to file: %s\n", path);

File file = SD.open(path, FILE_APPEND);
File file = tf_vfs->open(path, FILE_APPEND);
if (!file)
{
Serial.println("Failed to open file for appending");
Expand All @@ -382,7 +393,7 @@ void SdCard::appendFile(const char *path, const char *message)
void SdCard::renameFile(const char *path1, const char *path2)
{
Serial.printf("Renaming file %s to %s\n", path1, path2);
if (SD.rename(path1, path2))
if (tf_vfs->rename(path1, path2))
{
Serial.println("File renamed");
}
Expand All @@ -395,7 +406,7 @@ void SdCard::renameFile(const char *path1, const char *path2)
boolean SdCard::deleteFile(const char *path)
{
Serial.printf("Deleting file: %s\n", path);
if (SD.remove(path))
if (tf_vfs->remove(path))
{
Serial.println("File deleted");
return true;
Expand All @@ -410,7 +421,7 @@ boolean SdCard::deleteFile(const char *path)
boolean SdCard::deleteFile(const String &path)
{
Serial.printf("Deleting file: %s\n", path);
if (SD.remove(path))
if (tf_vfs->remove(path))
{
Serial.println("File deleted");
return true;
Expand All @@ -424,7 +435,7 @@ boolean SdCard::deleteFile(const String &path)

void SdCard::readBinFromSd(const char *path, uint8_t *buf)
{
File file = SD.open(path);
File file = tf_vfs->open(path);
size_t len = 0;
if (file)
{
Expand All @@ -451,7 +462,7 @@ void SdCard::readBinFromSd(const char *path, uint8_t *buf)

void SdCard::writeBinToSd(const char *path, uint8_t *buf)
{
File file = SD.open(path, FILE_WRITE);
File file = tf_vfs->open(path, FILE_WRITE);
if (!file)
{
Serial.println("Failed to open file for writing");
Expand All @@ -468,7 +479,7 @@ void SdCard::writeBinToSd(const char *path, uint8_t *buf)

void SdCard::fileIO(const char *path)
{
File file = SD.open(path);
File file = tf_vfs->open(path);
static uint8_t buf[512];
size_t len = 0;
uint32_t start = millis();
Expand Down Expand Up @@ -497,7 +508,7 @@ void SdCard::fileIO(const char *path)
Serial.println("Failed to open file for reading");
}

file = SD.open(path, FILE_WRITE);
file = tf_vfs->open(path, FILE_WRITE);
if (!file)
{
Serial.println("Failed to open file for writing");
Expand Down
2 changes: 1 addition & 1 deletion 硬件版本说明.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
致新人:制作Holocubic一律使用最新版本的外壳以及PCB,最新版本的一定是能互相适配的。

#### 外壳文件
v1.0和v2.0版本均在稚晖君原版的基础上修改的。v1.0和v2.0适配本文件夹中所有版本的主板和拓展板。推荐适配的PCB板子打样1.2mm厚度的(主板及屏幕版)
v1.0和v2.0版本均在稚晖君原版的基础上修改的,底部开了内存卡槽。v1.0和v2.0适配本文件夹中所有版本的主板和拓展板。推荐适配的PCB板子打样1.2mm厚度的(主板及屏幕版)

v1.0的左右加固座偏宽,v2.0优化了这个缺陷。

Expand Down

0 comments on commit 4541042

Please sign in to comment.