mirror of
https://github.com/Dejvino/lilybook.git
synced 2024-11-14 20:33:28 +00:00
136 lines
3.4 KiB
C++
136 lines
3.4 KiB
C++
|
#include <time.h>
|
||
|
#include <errno.h>
|
||
|
#include <sys/fcntl.h>
|
||
|
#include <stdio.h>
|
||
|
#include <time.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include "freertos/FreeRTOS.h"
|
||
|
#include "freertos/task.h"
|
||
|
#include "esp_system.h"
|
||
|
#include "driver/gpio.h"
|
||
|
#include "esp_system.h"
|
||
|
#include "esp_heap_alloc_caps.h"
|
||
|
#include "spiffs_vfs.h"
|
||
|
#include "esp_log.h"
|
||
|
#include "spi_master_lobo.h"
|
||
|
#include "img_hacking.c"
|
||
|
#include "EPD.h"
|
||
|
|
||
|
#define APP_VERSION "0.1"
|
||
|
|
||
|
static struct tm* tm_info;
|
||
|
static char tmp_buff[128];
|
||
|
static time_t time_now, time_last = 0;
|
||
|
static const char *file_fonts[3] = {"/spiffs/fonts/DotMatrix_M.fon", "/spiffs/fonts/Ubuntu.fon", "/spiffs/fonts/Grotesk24x48.fon"};
|
||
|
static const char tag[] = "[LilyBook]";
|
||
|
esp_err_t ret;
|
||
|
|
||
|
void display_init()
|
||
|
{
|
||
|
disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * (EPD_DISPLAY_HEIGHT/8), MALLOC_CAP_DMA);
|
||
|
assert(disp_buffer);
|
||
|
drawBuff = disp_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()
|
||
|
{
|
||
|
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 fs_init()
|
||
|
{
|
||
|
vfs_spiffs_register();
|
||
|
if (spiffs_is_mounted) {
|
||
|
ESP_LOGI(tag, "File system mounted.");
|
||
|
}
|
||
|
else {
|
||
|
ESP_LOGE(tag, "Error mounting file system.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
extern "C" void app_main()
|
||
|
{
|
||
|
display_init();
|
||
|
spi_init();
|
||
|
|
||
|
vTaskDelay(500 / portTICK_RATE_MS);
|
||
|
|
||
|
printf("\n LilyBook v%s\n\n", APP_VERSION);
|
||
|
|
||
|
display_connect();
|
||
|
|
||
|
EPD_DisplayClearFull();
|
||
|
|
||
|
fs_init();
|
||
|
|
||
|
printf("==== START ====\r\n\n");
|
||
|
|
||
|
_gs = 1;
|
||
|
uint32_t tstart;
|
||
|
int pass = 0;
|
||
|
int f = DEFAULT_FONT;
|
||
|
while (1) {
|
||
|
EPD_DisplayClearPart();
|
||
|
|
||
|
EPD_fillScreen(_bg);
|
||
|
_fg = 15;
|
||
|
_bg = 0;
|
||
|
|
||
|
EPD_setFont(f++ % USER_FONT, NULL);
|
||
|
EPD_print("Welcome to LilyBook", 10, 10);
|
||
|
EPD_UpdateScreen();
|
||
|
|
||
|
EPD_wait(5000);
|
||
|
|
||
|
EPD_PowerOff();
|
||
|
EPD_wait(8000);
|
||
|
}
|
||
|
|
||
|
}
|