diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a565c6e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(lilybook) diff --git a/components/epaper/CMakeLists.txt b/components/epaper/CMakeLists.txt new file mode 100644 index 0000000..5fdf8de --- /dev/null +++ b/components/epaper/CMakeLists.txt @@ -0,0 +1,21 @@ +set(COMPONENT_PRIV_INCLUDEDIRS "." "../") +set(COMPONENT_SRCS +"comic24.c" +"DefaultFont.c" +"DejaVuSans18.c" +"DejaVuSans24.c" +"dejavuX.c" +"EPD.c" +"EPDspi.c" +"minya24.c" +"SmallFont.c" +"tooney32.c" +"Ubuntu16.c" +) + +set(COMPONENT_REQUIRES spi_flash) +set(COMPONENT_PRIV_REQUIRES bootloader_support) + +register_component() + + diff --git a/components/epaper/EPDspi.c b/components/epaper/EPDspi.c index c0e38c6..021f99d 100644 --- a/components/epaper/EPDspi.c +++ b/components/epaper/EPDspi.c @@ -9,7 +9,7 @@ */ -#include "spi_master_lobo.h" +#include "spidriver/spi_master_lobo.h" #include #include #include diff --git a/components/epaper/EPDspi.h b/components/epaper/EPDspi.h index 259503f..c3b0155 100644 --- a/components/epaper/EPDspi.h +++ b/components/epaper/EPDspi.h @@ -13,7 +13,7 @@ #define _EPDSPI_H_ #include -#include "spi_master_lobo.h" +#include "spidriver/spi_master_lobo.h" #ifdef __cplusplus extern "C" { diff --git a/components/epaper/component.mk b/components/epaper/component.mk index 0f76ee5..7f260a7 100644 --- a/components/epaper/component.mk +++ b/components/epaper/component.mk @@ -4,4 +4,4 @@ # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) COMPONENT_SRCDIRS := . -COMPONENT_ADD_INCLUDEDIRS := . +COMPONENT_ADD_INCLUDEDIRS := . ../ diff --git a/components/spidriver/CMakeLists.txt b/components/spidriver/CMakeLists.txt new file mode 100644 index 0000000..97de11d --- /dev/null +++ b/components/spidriver/CMakeLists.txt @@ -0,0 +1,9 @@ +set(COMPONENT_PRIV_INCLUDEDIRS ".") +set(COMPONENT_SRCS "spi_master_lobo.c") + +set(COMPONENT_REQUIRES spi_flash) +set(COMPONENT_PRIV_REQUIRES bootloader_support) + +register_component() + + diff --git a/components/spiffs/CMakeLists.txt b/components/spiffs/CMakeLists.txt new file mode 100644 index 0000000..d16a36d --- /dev/null +++ b/components/spiffs/CMakeLists.txt @@ -0,0 +1,17 @@ +set(COMPONENT_PRIV_INCLUDEDIRS ".") +set(COMPONENT_SRCS "esp_spiffs.c" + "list.c" + "mutex.c" + "spiffs_cache.c" + "spiffs_check.c" + "spiffs_gc.c" + "spiffs_hydrogen.c" + "spiffs_nucleus.c" + "spiffs_vfs.c") + +set(COMPONENT_REQUIRES spi_flash) +set(COMPONENT_PRIV_REQUIRES bootloader_support) + +register_component() + + diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt new file mode 100644 index 0000000..f78d9dd --- /dev/null +++ b/main/CMakeLists.txt @@ -0,0 +1,5 @@ +FILE(GLOB_RECURSE app_sources *.cpp *.c) +set(COMPONENT_SRCS "${app_sources} main.cpp") +set(COMPONENT_ADD_INCLUDEDIRS "." "../components/") + +register_component() diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index b018664..92cbee7 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "LilyBook Configuration" config SPIFFS_BASE_ADDR hex "SPIFFS Base address" - range 0x100000 0x1FFE000 +# range 0x100000 0x1FFE000 default 0x180000 help Starting address of the SPIFFS area in ESP32 Flash diff --git a/main/core/display.c b/main/core/display.c index 05655c4..f6271fd 100644 --- a/main/core/display.c +++ b/main/core/display.c @@ -1,6 +1,6 @@ -#include "spi_master_lobo.h" -#include "EPD.h" +#include "spidriver/spi_master_lobo.h" +#include "epaper/EPD.h" #include #include "esp_system.h" #include "driver/gpio.h" diff --git a/main/core/storage.c b/main/core/storage.c index b854741..8162fe8 100644 --- a/main/core/storage.c +++ b/main/core/storage.c @@ -9,7 +9,7 @@ #include "driver/sdmmc_host.h" #include "driver/sdspi_host.h" #include "sdmmc_cmd.h" -#include "spiffs_vfs.h" +#include "spiffs/spiffs_vfs.h" #include "storage.h" static const char *tag = "storage"; diff --git a/main/modes/AbstractMenuMode.cpp b/main/modes/AbstractMenuMode.cpp index 26a43a3..01d5c5a 100644 --- a/main/modes/AbstractMenuMode.cpp +++ b/main/modes/AbstractMenuMode.cpp @@ -1,25 +1,23 @@ #include "core/common.h" #include "core/buttons.h" #include "core/display.h" -#include +#include #include "ModeRunner.h" #include "ReaderMode.h" #include "AbstractMenuMode.h" static int baseY = 35; -static int menuSkip = 20; -static int x = 40; -static int menu_options_size = 4; +static int x = 20; -void draw_menu_option(char* text, int line, bool selected) +void draw_menu_option(char* text, int textX, int textHeight, int line, bool selected) { - EPD_print(text, CENTER, baseY + line * menuSkip); + EPD_print(text, textX, baseY + line * textHeight); } -void draw_menu_cursor(int cursor) +void draw_menu_cursor(int cursor, int textHeight) { - EPD_drawRect(x, baseY + cursor * menuSkip, - EPD_DISPLAY_WIDTH - 2*x, menuSkip + 1, 0x0F); + EPD_drawRect(x, baseY + cursor * textHeight, + EPD_DISPLAY_WIDTH - 2*x, textHeight + 1, 0x0F); } void AbstractMenuMode::start() @@ -32,13 +30,18 @@ void AbstractMenuMode::loop() EPD_print(this->getTitle(), CENTER, 0); int line = 0; - EPD_setFont(DEJAVU18_FONT, NULL); + EPD_setFont(this->getOptionsFont(), NULL); + int menu_option_height = EPD_getfontheight() + 1; + int menu_options_limit = (EPD_DISPLAY_HEIGHT - baseY) / (EPD_getfontheight() + 1); char** options = this->getOptions(); int menu_options_size = this->getOptionsSize(); - for (int line = 0; line < menu_options_size; line++) { - draw_menu_option(options[line], line, this->cursor == line); + int start = (this->cursor / menu_options_limit) * menu_options_limit; + int stop = ((this->cursor / menu_options_limit) + 1) * menu_options_limit; + for (int line = start; line < menu_options_size && line < stop; line++) { + draw_menu_option(options[line], this->getOptionsX(), menu_option_height, + line % menu_options_limit, this->cursor == line); } - draw_menu_cursor(this->cursor); + draw_menu_cursor(this->cursor % menu_options_limit, menu_option_height); display_update(); while(1) { @@ -60,3 +63,13 @@ void AbstractMenuMode::loop() void AbstractMenuMode::finish() {} + +int AbstractMenuMode::getOptionsX() +{ + return CENTER; +} + +int AbstractMenuMode::getOptionsFont() +{ + return DEJAVU18_FONT; +} diff --git a/main/modes/AbstractMenuMode.h b/main/modes/AbstractMenuMode.h index 8f215d5..68e7f89 100644 --- a/main/modes/AbstractMenuMode.h +++ b/main/modes/AbstractMenuMode.h @@ -14,6 +14,8 @@ protected: virtual char** getOptions(); virtual int getOptionsSize(); virtual void onOptionSelected(int option); + virtual int getOptionsX(); + virtual int getOptionsFont(); private: int cursor = 0; diff --git a/main/modes/InternalMemoryMenuMode.cpp b/main/modes/InternalMemoryMenuMode.cpp index 7319de8..e53bbc2 100644 --- a/main/modes/InternalMemoryMenuMode.cpp +++ b/main/modes/InternalMemoryMenuMode.cpp @@ -1,7 +1,7 @@ #include "core/common.h" #include "core/buttons.h" #include "core/display.h" -#include +#include #include "InternalMemoryMenuMode.h" void InternalMemoryMenuMode::start() diff --git a/main/modes/MainMenuMode.cpp b/main/modes/MainMenuMode.cpp index b3eb00a..fbbed48 100644 --- a/main/modes/MainMenuMode.cpp +++ b/main/modes/MainMenuMode.cpp @@ -1,7 +1,7 @@ #include "core/common.h" #include "core/buttons.h" #include "core/display.h" -#include +#include #include "ModeRunner.h" #include "ReaderMode.h" #include "InternalMemoryMenuMode.h" @@ -12,7 +12,7 @@ static char* options[] = { "Continue Reading", "Internal Memory", - "SC Card", + "SD Card", "Settings" }; diff --git a/main/modes/SdCardMenuMode.cpp b/main/modes/SdCardMenuMode.cpp index cd2e5ab..a78fab5 100644 --- a/main/modes/SdCardMenuMode.cpp +++ b/main/modes/SdCardMenuMode.cpp @@ -1,23 +1,87 @@ +#include #include "core/common.h" #include "core/buttons.h" #include "core/display.h" -#include +#include +#include +#include +#include +#include +#include #include "SdCardMenuMode.h" -static char* options[] = { - "[Back]", - "/file.txt", - "/book.txt", - "/asdf.gif", - }; +#include "esp_log.h" +static char* TAG = "SdCardMenuMode"; + +// TODO: make use of bytes void SdCardMenuMode::start() { display_refresh(); + + dir_entry_t* dir_chain_start = new dir_entry_t; + strcpy(dir_chain_start->name, "[Back]"); + dir_entry_t* last_entry = dir_chain_start; + int entries = 1; + + struct stat stats; + struct dirent *dir; + DIR* d = opendir(this->basedir); + if (d) + { + while ((dir = readdir(d)) != NULL) + { + ESP_LOGI(TAG, "* %s", dir->d_name); + dir_entry_t* new_entry = new dir_entry_t; + strcpy(new_entry->name, dir->d_name); + char path[64]; + strcpy(path, this->basedir); + strcat(path, dir->d_name); + if (stat(path, &stats) == 0) { + last_entry->bytes = stats.st_size; + } + new_entry->next = NULL; + if (dir_chain_start == NULL) { + dir_chain_start = new_entry; + } + if (last_entry == NULL) { + last_entry = new_entry; + } else { + last_entry->next = new_entry; + last_entry = new_entry; + } + entries++; + } + closedir(d); + } else { + ESP_LOGE(TAG, "Could not open dir."); + } + + this->optionsNames = new char[entries*DIR_ENTRY_NAME_SIZE]; + this->options = new char*[entries]; + this->optionsBytes = new unsigned long[entries]; + this->optionsSize = entries; + last_entry = dir_chain_start; + int i = 0; + while (last_entry != NULL) { + this->options[i] = &this->optionsNames[i * DIR_ENTRY_NAME_SIZE]; + memcpy(this->options[i], last_entry->name, DIR_ENTRY_NAME_SIZE); + this->optionsBytes[i] = last_entry->bytes; + + dir_entry_t* next = (dir_entry_t*)last_entry->next; + delete last_entry; + last_entry = next; + i++; + } + } void SdCardMenuMode::finish() -{} +{ + delete this->options; + delete this->optionsNames; + delete this->optionsBytes; +} char* SdCardMenuMode::getTitle() { @@ -26,12 +90,12 @@ char* SdCardMenuMode::getTitle() char** SdCardMenuMode::getOptions() { - return options; + return this->options; } int SdCardMenuMode::getOptionsSize() { - return 4; + return this->optionsSize; } void SdCardMenuMode::onOptionSelected(int option) @@ -42,3 +106,13 @@ void SdCardMenuMode::onOptionSelected(int option) } // TODO files } + +int SdCardMenuMode::getOptionsX() +{ + return 35; +} + +int SdCardMenuMode::getOptionsFont() +{ + return SMALL_FONT; +} diff --git a/main/modes/SdCardMenuMode.h b/main/modes/SdCardMenuMode.h index a014c32..585dbbd 100644 --- a/main/modes/SdCardMenuMode.h +++ b/main/modes/SdCardMenuMode.h @@ -1,17 +1,31 @@ #include "AppMode.h" #include "AbstractMenuMode.h" +#define DIR_ENTRY_NAME_SIZE 16 +typedef struct { + char name[DIR_ENTRY_NAME_SIZE]; + unsigned long bytes; + void* next; +} dir_entry_t; + class SdCardMenuMode : public AbstractMenuMode { public: - virtual void start(); - virtual void finish(); + void start(); + void finish(); protected: - virtual char* getTitle(); - virtual char** getOptions(); - virtual int getOptionsSize(); - virtual void onOptionSelected(int option); + char* getTitle(); + char** getOptions(); + int getOptionsSize(); + void onOptionSelected(int option); + int getOptionsX(); + int getOptionsFont(); private: + char* basedir = "/sdcard/"; + char** options; + char* optionsNames; + unsigned long* optionsBytes; + int optionsSize; }; diff --git a/main/modes/SettingsMenuMode.cpp b/main/modes/SettingsMenuMode.cpp index b441abc..60d9d5d 100644 --- a/main/modes/SettingsMenuMode.cpp +++ b/main/modes/SettingsMenuMode.cpp @@ -1,7 +1,7 @@ #include "core/common.h" #include "core/buttons.h" #include "core/display.h" -#include +#include #include "SettingsMenuMode.h" static char* options[] = { @@ -38,7 +38,7 @@ void SettingsMenuMode::onOptionSelected(int option) { switch (option) { case 0: - // TODO + this->setFinished(); return; case 1: // TODO @@ -47,7 +47,7 @@ void SettingsMenuMode::onOptionSelected(int option) // TODO break; case 3: - this->setFinished(); + // TODO break; } } diff --git a/main/modes/reader/PagePrinter.cpp b/main/modes/reader/PagePrinter.cpp index e69222d..f065cca 100644 --- a/main/modes/reader/PagePrinter.cpp +++ b/main/modes/reader/PagePrinter.cpp @@ -1,5 +1,5 @@ #include "core/display.h" -#include "EPD.h" +#include "epaper/EPD.h" #include "PagePrinter.h" #include "esp_log.h" diff --git a/main/modes/reader/PageSettingsProvider.cpp b/main/modes/reader/PageSettingsProvider.cpp index d314384..7d44afb 100644 --- a/main/modes/reader/PageSettingsProvider.cpp +++ b/main/modes/reader/PageSettingsProvider.cpp @@ -1,6 +1,6 @@ #include "PageSettingsProvider.h" -#include "EPD.h" -#include "EPDspi.h" // TODO: remove after display config is extracted +#include "epaper/EPD.h" +#include "epaper/EPDspi.h" // TODO: remove after display config is extracted int PageSettingsProvider::getWidth() {