From f7eb2d8870452cfabebe9c8c2f42848d645ef87b Mon Sep 17 00:00:00 2001 From: Patryk Paluch Date: Wed, 10 Jul 2024 21:08:57 +0200 Subject: [PATCH 1/4] feat: add sd for tbean --- main/include/sd_card.h | 6 +++--- main/platformio.ini | 2 +- main/src/main.cpp | 41 +++++++++++++++++++++++++++++------------ main/src/sd_card.cpp | 16 +++++++++++++++- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/main/include/sd_card.h b/main/include/sd_card.h index 4b16cc4..a655e8f 100644 --- a/main/include/sd_card.h +++ b/main/include/sd_card.h @@ -4,11 +4,11 @@ #include "SPI.h" namespace sd { -static constexpr std::uint8_t DEFAULT_DATA_PIN = 32U; +static constexpr std::uint8_t DEFAULT_DATA_PIN = 33U; void init(); -void write(const char *data); -void write(const String &data); +void write(const char *data, const char *filename); +void write(const String &data, const String &filename ); void read(const char *filename); void read(const String &filename); }; // namespace sd \ No newline at end of file diff --git a/main/platformio.ini b/main/platformio.ini index a11ae02..b823f7f 100644 --- a/main/platformio.ini +++ b/main/platformio.ini @@ -10,7 +10,7 @@ [env:ttgo-t-beam] build_unflags = -std=gnu++11 -build_flags = -std=gnu++17 -Wall +build_flags = -std=gnu++17 -Wall -DSD_SCK=25 -DSD_MISO=15 -DSD_MOSI=32 -DSD_SS=33 build_src_flags = -Wextra -Werror platform = espressif32 board = ttgo-t-beam diff --git a/main/src/main.cpp b/main/src/main.cpp index d0f8d3b..44e4b08 100644 --- a/main/src/main.cpp +++ b/main/src/main.cpp @@ -1,10 +1,22 @@ +#define SPI3_MISO GPIO32 +#define SPI3_MOSI GPIO15 +#define SPI3_SCK GPIO25 +#define SPI3_SS GPIO33 + + #include +#define SCK GPIO25 +#define MISO GPIO32 +#define MOSI GPIO15 +#define SS 33 + #include #include "bmp.h" #include "gps.h" #include "led.h" #include "memory.h" +#include "sd_card.h" std::uint8_t constexpr MY_SDA = 21; std::uint8_t constexpr MY_SCL = 22; @@ -14,22 +26,27 @@ std::uint32_t constexpr DEFAULT_TASK_SIZE = 10000; void setup() { Wire.begin(MY_SDA, MY_SCL); Serial.begin(BAUD_RATE); + delay(500); Serial.println("--- ROCKET COMPUTER START ---"); + String penis = "Penis"; + sd::init(); + sd::write(penis, "/penis.file"); + Serial.println("--- DONE ---"); - memory::init(); - gps::init(); - bmp::init(); + // memory::init(); + // gps::init(); + // bmp::init(); - xTaskCreate(led::blink_task, "blink", DEFAULT_TASK_SIZE, nullptr, 1, - nullptr); - xTaskCreate(gps::gps_task, "gps", DEFAULT_TASK_SIZE, nullptr, 1, nullptr); - xTaskCreate(bmp::get_bmp, "bmp", DEFAULT_TASK_SIZE, nullptr, 1, nullptr); - xTaskCreate(bmp::print_data, "bmp print", DEFAULT_TASK_SIZE, nullptr, 1, - nullptr); + // xTaskCreate(led::blink_task, "blink", DEFAULT_TASK_SIZE, nullptr, 1, + // nullptr); + // xTaskCreate(gps::gps_task, "gps", DEFAULT_TASK_SIZE, nullptr, 1, nullptr); + // xTaskCreate(bmp::get_bmp, "bmp", DEFAULT_TASK_SIZE, nullptr, 1, nullptr); + // xTaskCreate(bmp::print_data, "bmp print", DEFAULT_TASK_SIZE, nullptr, 1, + // nullptr); - memory::print_data(); - memory::config = memory::Config{222, 456.78, "Hello, EEPROM2!"}; - memory::save_config(memory::config); + // memory::print_data(); + // memory::config = memory::Config{222, 456.78, "Hello, EEPROM2!"}; + // memory::save_config(memory::config); } void loop() {} diff --git a/main/src/sd_card.cpp b/main/src/sd_card.cpp index 280355d..cfc250a 100644 --- a/main/src/sd_card.cpp +++ b/main/src/sd_card.cpp @@ -1,11 +1,25 @@ #include "sd_card.h" + +// TODO make it better +#ifndef SD_SCK +// t-bean +#define SD_SCK 25 +#define SD_MISO 15 +#define SD_MOSI 32 +#define SD_SS 33 +#endif + namespace sd { namespace { fs::File File; } void init() { - if (!SD.begin(sd::DEFAULT_DATA_PIN)) { + // TODO if lolin then SD.begin(sd::DEFAULT_DATA_PIN) // without spi + SPIClass spi(VSPI); + spi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_SS); + + if (!SD.begin(sd::DEFAULT_DATA_PIN, spi)) { Serial.println("Card Mount Failed"); return; } From 0906ea42022f07b7bd3b7d9b81da79b576f8bff9 Mon Sep 17 00:00:00 2001 From: Patryk Paluch Date: Wed, 10 Jul 2024 21:30:15 +0200 Subject: [PATCH 2/4] cleanup --- main/platformio.ini | 2 +- main/src/sd_card.cpp | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/main/platformio.ini b/main/platformio.ini index b823f7f..f8b4bc6 100644 --- a/main/platformio.ini +++ b/main/platformio.ini @@ -10,7 +10,7 @@ [env:ttgo-t-beam] build_unflags = -std=gnu++11 -build_flags = -std=gnu++17 -Wall -DSD_SCK=25 -DSD_MISO=15 -DSD_MOSI=32 -DSD_SS=33 +build_flags = -std=gnu++17 -Wall -DSD_CUSTOM_SPI=1 -DSD_SCK=25 -DSD_MISO=15 -DSD_MOSI=32 -DSD_SS=33 build_src_flags = -Wextra -Werror platform = espressif32 board = ttgo-t-beam diff --git a/main/src/sd_card.cpp b/main/src/sd_card.cpp index cfc250a..349580a 100644 --- a/main/src/sd_card.cpp +++ b/main/src/sd_card.cpp @@ -1,25 +1,23 @@ #include "sd_card.h" -// TODO make it better -#ifndef SD_SCK -// t-bean -#define SD_SCK 25 -#define SD_MISO 15 -#define SD_MOSI 32 -#define SD_SS 33 -#endif - namespace sd { namespace { fs::File File; } -void init() { - // TODO if lolin then SD.begin(sd::DEFAULT_DATA_PIN) // without spi - SPIClass spi(VSPI); - spi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_SS); - if (!SD.begin(sd::DEFAULT_DATA_PIN, spi)) { +bool SDBegin() { + #ifdef SD_CUSTOM_SPI + SPIClass spi(VSPI); + spi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_SS); + return SD.begin(sd::DEFAULT_DATA_PIN, spi); + #else + return SD.begin(sd::DEFAULT_DATA_PIN); + #endif +} + +void init() { + if (!SDBegin()) { Serial.println("Card Mount Failed"); return; } From 59773019b34fc860b575cf7b58ec9d2938d1af7c Mon Sep 17 00:00:00 2001 From: Bartosz Date: Wed, 10 Jul 2024 21:44:41 +0200 Subject: [PATCH 3/4] undo --- main/include/sd_card.h | 6 +++--- main/src/main.cpp | 41 ++++++++++++----------------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/main/include/sd_card.h b/main/include/sd_card.h index a655e8f..48b7668 100644 --- a/main/include/sd_card.h +++ b/main/include/sd_card.h @@ -4,11 +4,11 @@ #include "SPI.h" namespace sd { -static constexpr std::uint8_t DEFAULT_DATA_PIN = 33U; +static constexpr std::uint8_t DEFAULT_DATA_PIN = 32U; void init(); -void write(const char *data, const char *filename); -void write(const String &data, const String &filename ); +void write(const char *data, char *filename); +void write(const String &data, String &filename); void read(const char *filename); void read(const String &filename); }; // namespace sd \ No newline at end of file diff --git a/main/src/main.cpp b/main/src/main.cpp index 44e4b08..d0f8d3b 100644 --- a/main/src/main.cpp +++ b/main/src/main.cpp @@ -1,22 +1,10 @@ -#define SPI3_MISO GPIO32 -#define SPI3_MOSI GPIO15 -#define SPI3_SCK GPIO25 -#define SPI3_SS GPIO33 - - #include -#define SCK GPIO25 -#define MISO GPIO32 -#define MOSI GPIO15 -#define SS 33 - #include #include "bmp.h" #include "gps.h" #include "led.h" #include "memory.h" -#include "sd_card.h" std::uint8_t constexpr MY_SDA = 21; std::uint8_t constexpr MY_SCL = 22; @@ -26,27 +14,22 @@ std::uint32_t constexpr DEFAULT_TASK_SIZE = 10000; void setup() { Wire.begin(MY_SDA, MY_SCL); Serial.begin(BAUD_RATE); - delay(500); Serial.println("--- ROCKET COMPUTER START ---"); - String penis = "Penis"; - sd::init(); - sd::write(penis, "/penis.file"); - Serial.println("--- DONE ---"); - // memory::init(); - // gps::init(); - // bmp::init(); + memory::init(); + gps::init(); + bmp::init(); - // xTaskCreate(led::blink_task, "blink", DEFAULT_TASK_SIZE, nullptr, 1, - // nullptr); - // xTaskCreate(gps::gps_task, "gps", DEFAULT_TASK_SIZE, nullptr, 1, nullptr); - // xTaskCreate(bmp::get_bmp, "bmp", DEFAULT_TASK_SIZE, nullptr, 1, nullptr); - // xTaskCreate(bmp::print_data, "bmp print", DEFAULT_TASK_SIZE, nullptr, 1, - // nullptr); + xTaskCreate(led::blink_task, "blink", DEFAULT_TASK_SIZE, nullptr, 1, + nullptr); + xTaskCreate(gps::gps_task, "gps", DEFAULT_TASK_SIZE, nullptr, 1, nullptr); + xTaskCreate(bmp::get_bmp, "bmp", DEFAULT_TASK_SIZE, nullptr, 1, nullptr); + xTaskCreate(bmp::print_data, "bmp print", DEFAULT_TASK_SIZE, nullptr, 1, + nullptr); - // memory::print_data(); - // memory::config = memory::Config{222, 456.78, "Hello, EEPROM2!"}; - // memory::save_config(memory::config); + memory::print_data(); + memory::config = memory::Config{222, 456.78, "Hello, EEPROM2!"}; + memory::save_config(memory::config); } void loop() {} From 035f2a307c3800c7f0b2307759ccc64a2ad20aaa Mon Sep 17 00:00:00 2001 From: Bartosz Date: Wed, 10 Jul 2024 21:46:13 +0200 Subject: [PATCH 4/4] undo testing --- main/include/sd_card.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/include/sd_card.h b/main/include/sd_card.h index 48b7668..4b16cc4 100644 --- a/main/include/sd_card.h +++ b/main/include/sd_card.h @@ -7,8 +7,8 @@ namespace sd { static constexpr std::uint8_t DEFAULT_DATA_PIN = 32U; void init(); -void write(const char *data, char *filename); -void write(const String &data, String &filename); +void write(const char *data); +void write(const String &data); void read(const char *filename); void read(const String &filename); }; // namespace sd \ No newline at end of file