Skip to content

Commit

Permalink
Stubbing some FS stuff out
Browse files Browse the repository at this point in the history
  • Loading branch information
thebentern authored and caveman99 committed Feb 9, 2023
1 parent d152afb commit 844736d
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 5 deletions.
4 changes: 3 additions & 1 deletion arch/stm32/stm32wl5e.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ build_type = debug
build_flags =
${arduino_base.build_flags}
-Isrc/platform/stm32wl -g
-DHAL_SUBGHZ_MODULE_ENABLED
#-DHAL_SUBGHZ_MODULE_ENABLED
build_src_filter =
${arduino_base.build_src_filter} -<platform/esp32/> -<nimble/> -<mesh/api/> -<mesh/http/> -<modules/esp32> -<mesh/eth/> -<mqtt/> -<graphics> -<input> -<buzz> -<modules/Telemetry> -<platform/nrf52> -<platform/portduino> -<platform/rp2040>
lib_deps =
${env.lib_deps}
https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b
charlesbaynham/OSFS@^1.2.3 # EEPROM Filesystem
stm32duino/FatFs@^2.0.3
lib_ignore =
mathertel/OneButton@^2.0.3
23 changes: 23 additions & 0 deletions src/FSCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,29 @@ void listDir(const char *dirname, uint8_t levels, boolean del = false)
#ifdef FSCom
#if (defined(ARCH_ESP32) || defined(ARCH_RP2040) || defined(ARCH_PORTDUINO))
char buffer[255];
#elif defined(ARCH_STM32WL)
// Interate through EEPROM
OSFS::result r = OSFS::checkLibVersion();
if (r != OSFS::result::NO_ERROR)
return;
OSFS::fileHeader workingHeader;
uint16_t workingAddress = OSFS::startOfEEPROM + sizeof(OSFS::FSInfo);
while (true) {
OSFS::result r = readNBytesChk(workingAddress, sizeof(OSFS::fileHeader), &workingHeader);
if (r != OSFS::result::NO_ERROR)
return;
if (!isDeletedFile(workingHeader)) {
// DEBUG_MSG(" %s (%i Bytes)\n", workingHeader.fileID, workingHeader.fileSize);
}
if (workingHeader.nextFile == 0) {
return;
}
workingAddress = workingHeader.nextFile;
}
return;
#else
#endif
#ifndef ARCH_STM32WL
File root = FSCom.open(dirname, FILE_O_READ);
if (!root) {
return;
Expand Down Expand Up @@ -149,6 +171,7 @@ void listDir(const char *dirname, uint8_t levels, boolean del = false)
root.close();
#endif
#endif
#endif
}

void rmDir(const char *dirname)
Expand Down
10 changes: 7 additions & 3 deletions src/FSCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
#define FILE_O_READ "r"
#endif

// #if defined(ARCH_STM32WL)
// TODO
// #endif
#if defined(ARCH_STM32WL)
#include "STM32WLFS.h"
#define FSCom STM32WLFS
#define FSBegin() FSCom.begin()
#define FILE_O_WRITE "w"
#define FILE_O_READ "r"
#endif

#if defined(ARCH_RP2040)
// RP2040
Expand Down
1 change: 1 addition & 0 deletions src/platform/stm32wl/File.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "File.h"
47 changes: 47 additions & 0 deletions src/platform/stm32wl/File.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// class File
// {
// public:
// File();
// File(char const *filename, char const *mode);

// public:
// bool open(char const *filename, char const *mode);

// //------------- Stream API -------------//
// virtual size_t write(uint8_t ch) = 0;
// virtual size_t write(uint8_t const *buf, size_t size) = 0;
// size_t write(const char *str)
// {
// if (str == NULL)
// return 0;
// return write((const uint8_t *)str, strlen(str));
// }
// size_t write(const char *buffer, size_t size)
// {
// return write((const uint8_t *)buffer, size);
// }

// virtual int read(void) = 0;
// int read(void *buf, uint16_t nbyte);

// virtual int peek(void) = 0;
// virtual int available(void) = 0;
// virtual void flush(void);

// bool seek(uint32_t pos);
// uint32_t position(void);
// uint32_t size(void);

// bool truncate(uint32_t pos);
// bool truncate(void);

// void close(void);

// operator bool(void);

// bool isOpen(void);
// char const *name(void);

// bool isDirectory(void);
// File openNextFile(char const *mode = "r");
// };
51 changes: 51 additions & 0 deletions src/platform/stm32wl/STM32WLFS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <FatFs.h>
#include <STM32WLFS.h>

uint16_t OSFS::startOfEEPROM = 1;
uint16_t OSFS::endOfEEPROM = E2END;

Stm32wlFS STM32WLFS;

void OSFS::readNBytes(uint16_t address, unsigned int num, byte *output)
{
for (uint16_t i = address; i < address + num; i++) {
*output = EEPROM.read(i);
output++;
}
}

void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte *input)
{
for (uint16_t i = address; i < address + num; i++) {
EEPROM.write(i, *input);
input++;
}
}

bool Stm32wlFS::begin()
{
OSFS::result r = OSFS::checkLibVersion();
if (r == OSFS::result::UNFORMATTED) {
OSFS::format();
}
return true;
}

void Stm32wlFS::mkdir(const char *dirname) {}

bool Stm32wlFS::remove(const char *filename) {}

bool Stm32wlFS::exists(const char *filename)
{
return false;
}

File Stm32wlFS::open(const char *path, const char *mode, const bool create)
{
return File.open(path, mode);
}

File Stm32wlFS::open(const String &path, const char *mode, const bool create)
{
return open(path.c_str(), mode, create);
}
29 changes: 29 additions & 0 deletions src/platform/stm32wl/STM32WLFS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#ifndef Stm32wlFS_H
#define Stm32wlFS_H

#include "File.h"
#include <EEPROM.h>
#include <OSFS.h>

extern uint16_t OSFS::startOfEEPROM;
extern uint16_t OSFS::endOfEEPROM;

#define FILE_READ "r"
#define FILE_WRITE "w"
#define FILE_APPEND "a"

class Stm32wlFS
{
public:
bool begin();
void mkdir(const char *dirname);
bool remove(const char *filename);
bool exists(const char *filename);
File open(char const *path, char const *mode = FILE_READ, const bool create = false);
File open(const String &path, const char *mode = FILE_READ, const bool create = false);
};

extern Stm32wlFS STM32WLFS;

#endif // Stm32wlFS_H
2 changes: 1 addition & 1 deletion src/platform/stm32wl/architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//

#ifndef HW_VENDOR
#define HW_VENDOR HardwareModel_PRIVATE_HW
#define HW_VENDOR meshtastic_HardwareModel_PRIVATE_HW
#endif

/* virtual pins */
Expand Down

0 comments on commit 844736d

Please sign in to comment.