Added app modes, extracted into mode controllers.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "buttons.h"
|
||||
|
||||
#define BTN_PIN_PLUS ((gpio_num_t)39)
|
||||
#define BTN_PIN_OK ((gpio_num_t)37)
|
||||
#define BTN_PIN_MINUS ((gpio_num_t)38)
|
||||
|
||||
void buttons_init()
|
||||
{
|
||||
gpio_config_t buttons_config;
|
||||
buttons_config.intr_type = (gpio_int_type_t)GPIO_PIN_INTR_DISABLE;
|
||||
buttons_config.mode = GPIO_MODE_INPUT;
|
||||
buttons_config.pull_up_en = (gpio_pullup_t)1;
|
||||
buttons_config.pull_down_en = (gpio_pulldown_t)0;
|
||||
buttons_config.pin_bit_mask = (1LL << BTN_PIN_MINUS);
|
||||
gpio_config(&buttons_config);
|
||||
buttons_config.pin_bit_mask = (1LL << BTN_PIN_OK);
|
||||
gpio_config(&buttons_config);
|
||||
buttons_config.pin_bit_mask = (1LL << BTN_PIN_PLUS);
|
||||
gpio_config(&buttons_config);
|
||||
}
|
||||
|
||||
bool buttons_pressed_ok() { return gpio_get_level(BTN_PIN_OK) == 0; }
|
||||
bool buttons_pressed_plus() { return gpio_get_level(BTN_PIN_PLUS) == 0; }
|
||||
bool buttons_pressed_minus() { return gpio_get_level(BTN_PIN_MINUS) == 0; }
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void buttons_init();
|
||||
bool buttons_pressed_ok();
|
||||
bool buttons_pressed_plus();
|
||||
bool buttons_pressed_minus();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
void delay(unsigned int ms)
|
||||
{
|
||||
vTaskDelay(ms / portTICK_RATE_MS);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef _COMMON_H_
|
||||
#define _COMMON_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void delay(unsigned int ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,113 @@
|
||||
|
||||
#include "spi_master_lobo.h"
|
||||
#include "EPD.h"
|
||||
#include <stdlib.h>
|
||||
#include "esp_system.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_heap_alloc_caps.h"
|
||||
#include "esp_log.h"
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
|
||||
void display_init()
|
||||
{
|
||||
// drawing buffer
|
||||
disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * (EPD_DISPLAY_HEIGHT/8), MALLOC_CAP_DMA);
|
||||
assert(disp_buffer);
|
||||
drawBuff = disp_buffer;
|
||||
|
||||
// gray-scale drawing buffer
|
||||
gs_disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * EPD_DISPLAY_HEIGHT, MALLOC_CAP_DMA);
|
||||
assert(gs_disp_buffer);
|
||||
gs_drawBuff = gs_disp_buffer;
|
||||
}
|
||||
|
||||
|
||||
spi_lobo_device_interface_config_t devcfg;
|
||||
spi_lobo_bus_config_t buscfg;
|
||||
void spi_init()
|
||||
{
|
||||
gpio_set_direction(DC_Pin, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(DC_Pin, 1);
|
||||
gpio_set_direction(RST_Pin, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(RST_Pin, 0);
|
||||
gpio_set_direction(BUSY_Pin, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(BUSY_Pin, GPIO_PULLUP_ONLY);
|
||||
|
||||
#ifdef POWER_Pin
|
||||
gpio_set_direction(POWER_Pin, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(POWER_Pin, 1);
|
||||
#endif
|
||||
|
||||
buscfg.miso_io_num = -1; // set SPI MISO pin
|
||||
buscfg.mosi_io_num = MOSI_Pin; // set SPI MOSI pin
|
||||
buscfg.sclk_io_num = SCK_Pin; // set SPI CLK pin
|
||||
buscfg.quadwp_io_num=-1;
|
||||
buscfg.quadhd_io_num=-1;
|
||||
buscfg.max_transfer_sz = 5*1024; // max transfer size is 4736 bytes
|
||||
|
||||
devcfg.clock_speed_hz=40000000; // SPI clock is 40 MHz
|
||||
devcfg.mode=0; // SPI mode 0
|
||||
devcfg.spics_io_num=-1; // we will use external CS pin
|
||||
devcfg.spics_ext_io_num = CS_Pin; // external CS pin
|
||||
devcfg.flags=SPI_DEVICE_HALFDUPLEX; // ALWAYS SET to HALF DUPLEX MODE for display spi !!
|
||||
}
|
||||
|
||||
void display_connect()
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret=spi_lobo_bus_add_device(SPI_BUS, &buscfg, &devcfg, &disp_spi);
|
||||
assert(ret==ESP_OK);
|
||||
printf("SPI: display device added to spi bus\r\n");
|
||||
|
||||
ret = spi_lobo_device_select(disp_spi, 1);
|
||||
assert(ret==ESP_OK);
|
||||
ret = spi_lobo_device_deselect(disp_spi);
|
||||
assert(ret==ESP_OK);
|
||||
|
||||
printf("SPI: attached display device, speed=%u\r\n", spi_lobo_get_speed(disp_spi));
|
||||
printf("SPI: bus uses native pins: %s\r\n", spi_lobo_uses_native_pins(disp_spi) ? "true" : "false");
|
||||
}
|
||||
|
||||
void display_splash_screen()
|
||||
{
|
||||
EPD_DisplayClearPart();
|
||||
EPD_fillScreen(0);
|
||||
EPD_UpdateScreen();
|
||||
|
||||
EPD_setFont(COMIC24_FONT, NULL);
|
||||
EPD_print("LilyBook", 30, 30);
|
||||
EPD_setFont(DEFAULT_FONT, NULL);
|
||||
EPD_print("Version:", 30, 70);
|
||||
EPD_print(APP_VERSION, 100, 70);
|
||||
EPD_UpdateScreen();
|
||||
}
|
||||
|
||||
void display_clear()
|
||||
{
|
||||
EPD_fillScreen(_bg);
|
||||
}
|
||||
|
||||
void display_refresh()
|
||||
{
|
||||
EPD_DisplayClearPart();
|
||||
EPD_fillScreen(_bg);
|
||||
}
|
||||
|
||||
void display_update()
|
||||
{
|
||||
EPD_UpdateScreen();
|
||||
}
|
||||
|
||||
extern void EPD_wake();
|
||||
void display_wake()
|
||||
{
|
||||
EPD_wake();
|
||||
}
|
||||
|
||||
void display_sleep()
|
||||
{
|
||||
EPD_PowerOff();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void display_init();
|
||||
void spi_init();
|
||||
void display_connect();
|
||||
void display_splash_screen();
|
||||
|
||||
void display_clear();
|
||||
void display_refresh();
|
||||
void display_update();
|
||||
|
||||
void display_wake();
|
||||
void display_sleep();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,125 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdspi_host.h"
|
||||
#include "sdmmc_cmd.h"
|
||||
#include "spiffs_vfs.h"
|
||||
#include "storage.h"
|
||||
|
||||
static const char *tag = "storage";
|
||||
|
||||
// This example can use SDMMC and SPI peripherals to communicate with SD card.
|
||||
// By default, SDMMC peripheral is used.
|
||||
// To enable SPI mode, uncomment the following line:
|
||||
|
||||
//#define USE_SPI_MODE
|
||||
|
||||
// When testing SD and SPI modes, keep in mind that once the card has been
|
||||
// initialized in SPI mode, it can not be reinitialized in SD mode without
|
||||
// toggling power to the card.
|
||||
|
||||
#ifdef USE_SPI_MODE
|
||||
// Pin mapping when using SPI mode.
|
||||
// With this mapping, SD card can be used both in SPI and 1-line SD mode.
|
||||
// Note that a pull-up on CS line is required in SD mode.
|
||||
#define PIN_NUM_MISO ((gpio_num_t)2)
|
||||
#define PIN_NUM_MOSI ((gpio_num_t)15)
|
||||
#define PIN_NUM_CLK ((gpio_num_t)14)
|
||||
#define PIN_NUM_CS ((gpio_num_t)13)
|
||||
#endif //USE_SPI_MODE
|
||||
|
||||
int sdcard_init()
|
||||
{
|
||||
#ifndef USE_SPI_MODE
|
||||
ESP_LOGI(tag, "Using SDMMC peripheral");
|
||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
|
||||
// This initializes the slot without card detect (CD) and write protect (WP) signals.
|
||||
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
|
||||
// To use 1-line SD mode, uncomment the following line:
|
||||
slot_config.width = 1;
|
||||
|
||||
// GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups.
|
||||
// Internal pull-ups are not sufficient. However, enabling internal pull-ups
|
||||
// does make a difference some boards, so we do that here.
|
||||
gpio_set_pull_mode((gpio_num_t)15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
|
||||
gpio_set_pull_mode((gpio_num_t)2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
|
||||
//gpio_set_pull_mode((gpio_num_t)4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only
|
||||
//gpio_set_pull_mode((gpio_num_t)12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only
|
||||
gpio_set_pull_mode((gpio_num_t)13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
|
||||
|
||||
#else
|
||||
ESP_LOGI(TAG, "Using SPI peripheral");
|
||||
|
||||
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
|
||||
sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
|
||||
slot_config.gpio_miso = PIN_NUM_MISO;
|
||||
slot_config.gpio_mosi = PIN_NUM_MOSI;
|
||||
slot_config.gpio_sck = PIN_NUM_CLK;
|
||||
slot_config.gpio_cs = PIN_NUM_CS;
|
||||
// This initializes the slot without card detect (CD) and write protect (WP) signals.
|
||||
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
|
||||
#endif //USE_SPI_MODE
|
||||
|
||||
// Options for mounting the filesystem.
|
||||
// If format_if_mount_failed is set to true, SD card will be partitioned and
|
||||
// formatted in case when mounting fails.
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = false,
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
|
||||
// Use settings defined above to initialize SD card and mount FAT filesystem.
|
||||
// Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
|
||||
// Please check its source code and implement error recovery when developing
|
||||
// production applications.
|
||||
sdmmc_card_t* card;
|
||||
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
if (ret == ESP_FAIL) {
|
||||
ESP_LOGE(tag, "Failed to mount filesystem. "
|
||||
"If you want the card to be formatted, set format_if_mount_failed = true.");
|
||||
} else {
|
||||
ESP_LOGE(tag, "Failed to initialize the card (%s). "
|
||||
"Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Card has been initialized, print its properties
|
||||
sdmmc_card_print_info(stdout, card);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int storage_init()
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
vfs_spiffs_register();
|
||||
if (spiffs_is_mounted) {
|
||||
ESP_LOGI(tag, "File system mounted.");
|
||||
} else {
|
||||
ESP_LOGE(tag, "Error mounting file system.");
|
||||
ret += 1 << 1;
|
||||
}
|
||||
|
||||
if (sdcard_init() == 0) {
|
||||
ESP_LOGI(tag, "SD card mounted.");
|
||||
} else {
|
||||
ESP_LOGE(tag, "Error mounting SD card.");
|
||||
ret += 1 << 2;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int storage_init();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user