Merge pull request #106 from fvanroie/0.4.0-dev

merge 0.4.0 dev into master
This commit is contained in:
fvanroie 2021-03-23 14:17:10 +01:00 committed by GitHub
commit 2a6a3cd186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
240 changed files with 14731 additions and 10959 deletions

View File

@ -1,12 +1,12 @@
---
Language: Cpp
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
@ -21,51 +21,51 @@ AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 120
CommentPragmas: "^ IWYU pragma:"
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: ".*"
Priority: 1
IncludeIsMainRegex: "$"
IndentCaseLabels: true
IndentWidth: 4
IndentWidth: 4
IndentWrappedFunctionNames: false
IndentPPDirectives: BeforeHash
# IndentPPDirectives: BeforeHash
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
@ -77,21 +77,20 @@ PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Middle
ReflowComments: true
SortIncludes: false
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...
Standard: Cpp11
TabWidth: 4
UseTab: Never

View File

@ -1,48 +1,55 @@
name: Build master branch
name: Build 0.4.0-dev branch
on: [push]
on: [push, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v2
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Set up Python
uses: actions/setup-python@v2
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Enable ESP platforms from platformio_override-template.ini
run: |
sed 's/; user_setups\/esp/user_setups\/esp/g' platformio_override-template.ini > platformio_override.ini
- name: List all files in current folder
run: |
ls -la
- name: Cat platformio_override.ini
run: |
cat platformio_override.ini
- name: Run PlatformIO
run: pio run -e d1-mini-esp32_ili9341 -e lanbon_l8 -e wt32-sc01 -e d1-mini-esp8266_ili9341
- name: Upload output file
uses: actions/upload-artifact@v2
with:
name: hasp-lvgl firmware.zip
path: build_output/firmware/*.bin
- uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v2
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Set up Python
uses: actions/setup-python@v2
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Enable ESP platforms from platformio_override-template.ini
run: |
sed 's/; user_setups\/esp/user_setups\/esp/g' platformio_override-template.ini > platformio_override.ini
- name: Enable Linux platform from platformio_override.ini
run: |
sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini
mkdir -p .pio/libdeps/linux_sdl_64bits/paho/src
- name: Install SDL2 library
run: |
sudo apt-get update
sudo apt-get install libsdl2-dev
- name: List all files in current folder
run: |
ls -la
- name: Cat platformio_override.ini
run: |
cat platformio_override.ini
- name: Run PlatformIO
run: pio run -e d1-mini-esp32_ili9341 -e esp32-touchdown -e huzzah32-featherwing-24 -e huzzah32-featherwing-35 -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits
- name: Upload output file
uses: actions/upload-artifact@v2
with:
name: hasp-lvgl firmware.zip
path: build_output/firmware/*.bin
#- name: Create release and upload firmware
# run: |
# set -x

7
.gitignore vendored
View File

@ -6,18 +6,23 @@
.pio
data/*
src/user_setups/active/*
include/user_config_override.h
src/user_config_override.h
user_config_override.h
platformio_override.ini
user_setups/active/*
build_output/*
build_output/firmware/*.bin
build_output/firmware/*.exe
## Test result files
*.xml
*.bin
## Visual Studio Code specific ######
.vscode
!.vscode
.vscode/*
!.vscode/extensions.json
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json

8
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,8 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ms-vscode.cpptools",
"platformio.platformio-ide"
]
}

View File

@ -11,7 +11,7 @@ Control your home-automation devices from a customizable touchscreen UI connecte
This project is a re-implementation of the popular HASwitchPlate sketch created by aderusha.
The [original HASwitchPlate][1] project uses a Wemos D1 mini and requires a Nextion/TJC HMI display.
This rewrite removes the Nextion/TJC requirement by using the [Littlev Graphics Library][2] on the MCU to drive a cheap commodity display.
This rewrite removes the Nextion/TJC requirement by using the [Light and Versatile Graphics Library][2] on the MCU to drive a cheap commodity display.
This version also adds ESP32 and STM32F4 support to take advantage of the additional hardware capabilities.
@ -72,7 +72,7 @@ For support using hasp-lvgl, please join the [#hasp-lvgl channel][6] on Discord.
[1]: https://github.com/aderusha/HASwitchPlate
[2]: https://github.com/littlevgl/lvgl
[2]: https://github.com/lvgl/lvgl
[3]: https://littlevgl.com/themes
[4]: https://github.com/fvanroie/HMI-Font-Pack/releases
[5]: https://fontawesome.com/cheatsheet/

55
hal/sdl2/app_hal.c Normal file
View File

@ -0,0 +1,55 @@
#include <unistd.h>
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
#include <SDL2/SDL.h>
#include "display/monitor.h"
#include "indev/mouse.h"
#include "indev/mousewheel.h"
#include "indev/keyboard.h"
/**
* A task to measure the elapsed time for LittlevGL
* @param data unused
* @return never return
*/
static int tick_thread(void* data)
{
(void)data;
while(1) {
SDL_Delay(5); /*Sleep for 5 millisecond*/
lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/
}
return 0;
}
void hal_setup(void)
{
// Workaround for sdl2 `-m32` crash
// https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7
#ifndef WIN32
setenv("DBUS_FATAL_WARNINGS", "0", 1);
#endif
/* Add a display
* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
monitor_init(MONITOR_HOR_RES, MONITOR_VER_RES);
/* Add the mouse as input device
* Use the 'mouse' driver which reads the PC's mouse*/
mouse_init();
/* Tick init.
* You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed
* Create an SDL thread to do this*/
SDL_CreateThread(tick_thread, "tick", NULL);
}
void hal_loop(void)
{
// we don't use thise !!
// while(1) {
// SDL_Delay(5);
// lv_task_handler();
// }
}

17
hal/sdl2/app_hal.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef DRIVER_H
#define DRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
void hal_setup(void);
void hal_loop(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*DRIVER_H*/

View File

@ -0,0 +1,50 @@
#include "Arduino.h"
#include "stm32f4xx.h"
//#include "stm32f429i_discovery.h"
#include "tft.h"
//#include "touchpad.h"
#ifdef USE_RTOS_SYSTICK
#include <cmsis_os.h>
#endif
void hal_setup(void)
{
pinMode(PD12, OUTPUT);
digitalWrite(PD12, HIGH);
// HAL_Init();
// /* Configure the system clock to 180 MHz */
// SystemClock_Config();
// /* Start up indication */
// BSP_LED_Init(LED3);
// for (uint8_t i = 0; i < 8; i++) { BSP_LED_Toggle(LED3); delay(50); }
tft_init();
//touchpad_init();
}
// void SysTick_Handler(void)
// {
// HAL_IncTick();
// HAL_SYSTICK_IRQHandler();
// lv_tick_inc(1);
// #ifdef USE_RTOS_SYSTICK
// osSystickHandler();
// #endif
// }
void hal_loop(void)
{
//while (1)
{
delay(5);
lv_task_handler();
}
}

View File

@ -0,0 +1,17 @@
#ifndef DRIVER_H
#define DRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
void hal_setup(void);
void hal_loop(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*DRIVER_H*/

65
hal/stm32f407_btt/tft.c Normal file
View File

@ -0,0 +1,65 @@
/**
* @file disp.c
*
*/
/*********************
* INCLUDES
*********************/
#include <string.h>
#include "tft.h"
#include "stm32f4xx.h"
#include "fsmc_ssd1963.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_disp_drv_t disp_drv;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize your display here
*/
void tft_init(void)
{
static lv_color_t disp_buf1[TFT_HOR_RES * 40];
static lv_disp_buf_t buf;
lv_disp_buf_init(&buf, disp_buf1, NULL, TFT_HOR_RES * 40);
lv_disp_drv_init(&disp_drv);
fsmc_ssd1963_init(0, false);
disp_drv.buffer = &buf;
disp_drv.flush_cb = fsmc_ssd1963_flush;
disp_drv.hor_res = TFT_HOR_RES;
disp_drv.ver_res = TFT_VER_RES;
#if TFT_USE_GPU != 0
DMA2D_Config();
disp_drv.gpu_blend_cb = gpu_mem_blend;
disp_drv.gpu_fill_cb = gpu_mem_fill;
#endif
lv_disp_drv_register(&disp_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/

37
hal/stm32f407_btt/tft.h Normal file
View File

@ -0,0 +1,37 @@
/**
* @file disp.h
*
*/
#ifndef DISP_H
#define DISP_H
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include "lvgl.h"
/*********************
* DEFINES
*********************/
#define TFT_HOR_RES TFT_WIDTH
#define TFT_VER_RES TFT_HEIGHT
#define TFT_EXT_FB 1 /*Frame buffer is located into an external SDRAM*/
#define TFT_USE_GPU 0 /*Enable hardware accelerator*/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void tft_init(void);
/**********************
* MACROS
**********************/
#endif

View File

@ -0,0 +1,123 @@
#include "stm32f4xx.h"
#include "stm32f429i_discovery.h"
#include "tft.h"
#include "touchpad.h"
#ifdef USE_RTOS_SYSTICK
#include <cmsis_os.h>
#endif
/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
* System Clock source = PLL (HSE)
* SYSCLK(Hz) = 180000000
* HCLK(Hz) = 180000000
* AHB Prescaler = 1
* APB1 Prescaler = 4
* APB2 Prescaler = 2
* HSE Frequency(Hz) = 8000000
* PLL_M = 8
* PLL_N = 360
* PLL_P = 2
* PLL_Q = 7
* VDD(V) = 3.3
* Main regulator output voltage = Scale1 mode
* Flash Latency(WS) = 5
* The LTDC Clock is configured as follow :
* PLLSAIN = 192
* PLLSAIR = 4
* PLLSAIDivR = 8
* @param None
* @retval None
*/
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
/* Enable Power Control clock */
__HAL_RCC_PWR_CLK_ENABLE();
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/*##-1- System Clock Configuration #########################################*/
/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 360;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/* Activate the Over-Drive mode */
HAL_PWREx_EnableOverDrive();
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
/*##-2- LTDC Clock Configuration ###########################################*/
/* LCD clock configuration */
/* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 MHz */
/* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 MHz */
/* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 MHz */
/* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 MHz */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}
void hal_setup(void)
{
HAL_Init();
/* Configure the system clock to 180 MHz */
SystemClock_Config();
/* Start up indication */
BSP_LED_Init(LED3);
for (uint8_t i = 0; i < 8; i++) { BSP_LED_Toggle(LED3); HAL_Delay(50); }
tft_init();
touchpad_init();
}
void SysTick_Handler(void)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
lv_tick_inc(1);
#ifdef USE_RTOS_SYSTICK
osSystickHandler();
#endif
}
void hal_loop(void)
{
while(1) {
HAL_Delay(5);
lv_task_handler();
}
}

View File

@ -0,0 +1,17 @@
#ifndef DRIVER_H
#define DRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
void hal_setup(void);
void hal_loop(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*DRIVER_H*/

236
hal/stm32f429_disco/tft.c Normal file
View File

@ -0,0 +1,236 @@
/**
* @file disp.c
*
*/
/*********************
* INCLUDES
*********************/
#include <string.h>
#include "tft.h"
#include "stm32f4xx.h"
#include "stm32f429i_discovery_lcd.h"
#include "ili9341.h"
/*********************
* DEFINES
*********************/
#define SDRAM_BANK_ADDR ((uint32_t)0xD0000000)
#define DMA_STREAM DMA2_Stream0
#define DMA_CHANNEL DMA_CHANNEL_0
#define DMA_STREAM_IRQ DMA2_Stream0_IRQn
#define DMA_STREAM_IRQHANDLER DMA2_Stream0_IRQHandler
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void tft_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p);
/**********************
* STATIC VARIABLES
**********************/
extern LTDC_HandleTypeDef LtdcHandler;
#if TFT_USE_GPU != 0
static DMA2D_HandleTypeDef Dma2dHandle;
#endif
#if TFT_EXT_FB != 0
static __IO uint16_t *my_fb = (__IO uint16_t *)(SDRAM_BANK_ADDR);
#else
static uint16_t my_fb[TFT_HOR_RES * TFT_VER_RES];
#endif
/*DMA to flush to frame buffer*/
static void DMA_Config(void);
static void DMA_TransferComplete(DMA_HandleTypeDef *han);
static void DMA_TransferError(DMA_HandleTypeDef *han);
DMA_HandleTypeDef DmaHandle;
static lv_disp_drv_t disp_drv;
static int32_t x1_flush;
static int32_t y1_flush;
static int32_t x2_flush;
static int32_t y2_fill;
static int32_t y_fill_act;
static const lv_color_t *buf_to_flush;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize your display here
*/
void tft_init(void)
{
static lv_color_t disp_buf1[TFT_HOR_RES * 40];
static lv_disp_buf_t buf;
lv_disp_buf_init(&buf, disp_buf1, NULL, TFT_HOR_RES * 40);
lv_disp_drv_init(&disp_drv);
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(0, (uint32_t)my_fb);
HAL_LTDC_SetPixelFormat(&LtdcHandler, LTDC_PIXEL_FORMAT_RGB565, 0);
DMA_Config();
disp_drv.buffer = &buf;
disp_drv.flush_cb = tft_flush;
disp_drv.hor_res = TFT_HOR_RES;
disp_drv.ver_res = TFT_VER_RES;
#if TFT_USE_GPU != 0
DMA2D_Config();
disp_drv.gpu_blend_cb = gpu_mem_blend;
disp_drv.gpu_fill_cb = gpu_mem_fill;
#endif
lv_disp_drv_register(&disp_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Flush a color buffer
* @param x1 left coordinate of the rectangle
* @param x2 right coordinate of the rectangle
* @param y1 top coordinate of the rectangle
* @param y2 bottom coordinate of the rectangle
* @param color_p pointer to an array of colors
*/
static void tft_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p)
{
/*Return if the area is out the screen*/
if (area->x2 < 0)
return;
if (area->y2 < 0)
return;
if (area->x1 > TFT_HOR_RES - 1)
return;
if (area->y1 > TFT_VER_RES - 1)
return;
/*Truncate the area to the screen*/
int32_t act_x1 = area->x1 < 0 ? 0 : area->x1;
int32_t act_y1 = area->y1 < 0 ? 0 : area->y1;
int32_t act_x2 = area->x2 > TFT_HOR_RES - 1 ? TFT_HOR_RES - 1 : area->x2;
int32_t act_y2 = area->y2 > TFT_VER_RES - 1 ? TFT_VER_RES - 1 : area->y2;
x1_flush = act_x1;
y1_flush = act_y1;
x2_flush = act_x2;
y2_fill = act_y2;
y_fill_act = act_y1;
buf_to_flush = color_p;
/*##-7- Start the DMA transfer using the interrupt mode #*/
/* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */
/* Enable All the DMA interrupts */
HAL_StatusTypeDef err;
err = HAL_DMA_Start_IT(&DmaHandle, (uint32_t)buf_to_flush, (uint32_t)&my_fb[y_fill_act * TFT_HOR_RES + x1_flush],
(x2_flush - x1_flush + 1));
if (err != HAL_OK)
{
while (1)
; /*Halt on error*/
}
}
static void DMA_Config(void)
{
/*## -1- Enable DMA2 clock #################################################*/
__HAL_RCC_DMA2_CLK_ENABLE();
/*##-2- Select the DMA functional Parameters ###############################*/
DmaHandle.Init.Channel = DMA_CHANNEL; /* DMA_CHANNEL_0 */
DmaHandle.Init.Direction = DMA_MEMORY_TO_MEMORY; /* M2M transfer mode */
DmaHandle.Init.PeriphInc = DMA_PINC_ENABLE; /* Peripheral increment mode Enable */
DmaHandle.Init.MemInc = DMA_MINC_ENABLE; /* Memory increment mode Enable */
DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; /* Peripheral data alignment : 16bit */
DmaHandle.Init.MemDataAlignment = DMA_PDATAALIGN_HALFWORD; /* memory data alignment : 16bit */
DmaHandle.Init.Mode = DMA_NORMAL; /* Normal DMA mode */
DmaHandle.Init.Priority = DMA_PRIORITY_HIGH; /* priority level : high */
DmaHandle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; /* FIFO mode enabled */
DmaHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_1QUARTERFULL; /* FIFO threshold: 1/4 full */
DmaHandle.Init.MemBurst = DMA_MBURST_SINGLE; /* Memory burst */
DmaHandle.Init.PeriphBurst = DMA_PBURST_SINGLE; /* Peripheral burst */
/*##-3- Select the DMA instance to be used for the transfer : DMA2_Stream0 #*/
DmaHandle.Instance = DMA_STREAM;
/*##-4- Initialize the DMA stream ##########################################*/
if (HAL_DMA_Init(&DmaHandle) != HAL_OK)
{
while (1)
;
}
/*##-5- Select Callbacks functions called after Transfer complete and Transfer error */
HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_CPLT_CB_ID, DMA_TransferComplete);
HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_ERROR_CB_ID, DMA_TransferError);
/*##-6- Configure NVIC for DMA transfer complete/error interrupts ##########*/
HAL_NVIC_SetPriority(DMA_STREAM_IRQ, 0, 0);
HAL_NVIC_EnableIRQ(DMA_STREAM_IRQ);
}
/**
* @brief DMA conversion complete callback
* @note This function is executed when the transfer complete interrupt
* is generated
* @retval None
*/
static void DMA_TransferComplete(DMA_HandleTypeDef *han)
{
y_fill_act++;
if (y_fill_act > y2_fill)
{
lv_disp_flush_ready(&disp_drv);
}
else
{
buf_to_flush += x2_flush - x1_flush + 1;
/*##-7- Start the DMA transfer using the interrupt mode ####################*/
/* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */
/* Enable All the DMA interrupts */
if (HAL_DMA_Start_IT(han, (uint32_t)buf_to_flush, (uint32_t)&my_fb[y_fill_act * TFT_HOR_RES + x1_flush],
(x2_flush - x1_flush + 1)) != HAL_OK)
{
while (1)
; /*Halt on error*/
}
}
}
/**
* @brief DMA conversion error callback
* @note This function is executed when the transfer error interrupt
* is generated during DMA transfer
* @retval None
*/
static void DMA_TransferError(DMA_HandleTypeDef *han)
{
}
/**
* @brief This function handles DMA Stream interrupt request.
* @param None
* @retval None
*/
void DMA_STREAM_IRQHANDLER(void)
{
/* Check the interrupt and clear flag */
HAL_DMA_IRQHandler(&DmaHandle);
}

37
hal/stm32f429_disco/tft.h Normal file
View File

@ -0,0 +1,37 @@
/**
* @file disp.h
*
*/
#ifndef DISP_H
#define DISP_H
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include "lvgl.h"
/*********************
* DEFINES
*********************/
#define TFT_HOR_RES 240
#define TFT_VER_RES 320
#define TFT_EXT_FB 1 /*Frame buffer is located into an external SDRAM*/
#define TFT_USE_GPU 0 /*Enable hardware accelerator*/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void tft_init(void);
/**********************
* MACROS
**********************/
#endif

View File

@ -0,0 +1,144 @@
/**
* @file indev.c
*
*/
/*********************
* INCLUDES
*********************/
#include "tft.h"
#include "lvgl.h"
#include "stm32f4xx.h"
#include "stm32f429i_discovery.h"
#include "stmpe811.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool touchpad_read(lv_indev_drv_t * drv, lv_indev_data_t *data);
static bool touchpad_get_xy(int16_t *x, int16_t *y);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize your input devices here
*/
void touchpad_init(void)
{
stmpe811_Init(TS_I2C_ADDRESS);
stmpe811_TS_Start(TS_I2C_ADDRESS);
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.read_cb = touchpad_read;
indev_drv.type = LV_INDEV_TYPE_POINTER;
lv_indev_drv_register(&indev_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Read an input device
* @param indev_id id of the input device to read
* @param x put the x coordinate here
* @param y put the y coordinate here
* @return true: the device is pressed, false: released
*/
static bool touchpad_read(lv_indev_drv_t * drv, lv_indev_data_t *data)
{
static int16_t last_x = 0;
static int16_t last_y = 0;
bool detected;
int16_t x;
int16_t y;
detected = touchpad_get_xy(&x, &y);
if(detected) {
data->point.x = x;
data->point.y = y;
last_x = data->point.x;
last_y = data->point.y;
data->state = LV_INDEV_STATE_PR;
} else {
data->point.x = last_x;
data->point.y = last_y;
data->state = LV_INDEV_STATE_REL;
}
return false;
}
static bool touchpad_get_xy(int16_t *x, int16_t *y)
{
static int32_t _x = 0, _y = 0;
int16_t xDiff, yDiff, xr, yr, x_raw, y_raw;;
bool detected;
detected = stmpe811_TS_DetectTouch(TS_I2C_ADDRESS);
if(!detected) return false;
stmpe811_TS_GetXY(TS_I2C_ADDRESS, &x_raw, &y_raw);
/* Y value first correction */
y_raw -= 360;
/* Y value second correction */
yr = y_raw / 11;
/* Return y_raw position value */
if(yr <= 0) yr = 0;
else if (yr > TFT_VER_RES) yr = TFT_VER_RES - 1;
y_raw = yr;
/* X value first correction */
if(x_raw <= 3000) x_raw = 3870 - x_raw;
else x_raw = 3800 - x_raw;
/* X value second correction */
xr = x_raw / 15;
/* Return X position value */
if(xr <= 0) xr = 0;
else if (xr > TFT_HOR_RES) xr = TFT_HOR_RES - 1;
x_raw = xr;
xDiff = x_raw > _x? (x_raw - _x): (_x - x_raw);
yDiff = y_raw > _y? (y_raw - _y): (_y - y_raw);
if (xDiff + yDiff > 5) {
_x = x_raw;
_y = y_raw;
}
/* Update the X and Y position */
*x = _x;
*y = _y;
return true;
}

View File

@ -0,0 +1,32 @@
/**
* @file indev.h
*
*/
#ifndef INDEV_H
#define INDEV_H
/*********************
* INCLUDES
*********************/
#include <stdbool.h>
#include <stdint.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void touchpad_init(void);
/**********************
* MACROS
**********************/
#endif

View File

@ -1,39 +1,4 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
The header files in this folder configure the different components of HASP, LVGL and paho.

7
include/VersionInfo.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef VERSIONINFO_H
#define VERSIONINFO_H
#define BUILD_TIMESTAMP "@BUILD_TIMESTAMP@"
#define CLIENT_VERSION "@CLIENT_VERSION@"
#endif /* VERSIONINFO_H */

View File

@ -1,89 +1,92 @@
#ifndef HASP_CONF_H
#define HASP_CONF_H
// language specific defines
#include "lang/lang.h"
#define HASP_USE_APP 1
#ifndef HASP_USE_DEBUG
#define HASP_USE_DEBUG 1
#define HASP_USE_DEBUG 1
#endif
/* Network Services */
#ifndef HASP_USE_ETHERNET
#define HASP_USE_ETHERNET 0
#define HASP_USE_ETHERNET 0
#endif
#ifndef HASP_USE_WIFI
#define HASP_USE_WIFI (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_WIFI > 0)
#define HASP_USE_WIFI (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_WIFI > 0)
#endif
#define HASP_HAS_NETWORK \
(ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0)
#ifndef HASP_USE_OTA
#define HASP_USE_OTA (HASP_HAS_NETWORK)
#define HASP_USE_OTA (HASP_HAS_NETWORK)
#endif
#ifndef HASP_USE_MQTT
#define HASP_USE_MQTT (HASP_HAS_NETWORK)
#define HASP_USE_MQTT (HASP_HAS_NETWORK)
#endif
#ifndef HASP_USE_HTTP
#define HASP_USE_HTTP (HASP_HAS_NETWORK)
#define HASP_USE_HTTP (HASP_HAS_NETWORK)
#endif
#ifndef HASP_USE_MDNS
#define HASP_USE_MDNS (HASP_HAS_NETWORK)
#define HASP_USE_MDNS (HASP_HAS_NETWORK)
#endif
#ifndef HASP_USE_SYSLOG
#define HASP_USE_SYSLOG (HASP_HAS_NETWORK)
#define HASP_USE_SYSLOG (HASP_HAS_NETWORK)
#endif
#ifndef HASP_USE_TELNET
#define HASP_USE_TELNET 0
#define HASP_USE_TELNET 0
#endif
/* Filesystem */
#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0)
#ifndef HASP_USE_SPIFFS
#ifndef HASP_USE_LITTLEFS
#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
#else
#define HASP_USE_SPIFFS (HASP_USE_LITTLEFS <= 0)
#endif
#ifndef HASP_USE_LITTLEFS
#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
#else
#define HASP_USE_SPIFFS (HASP_USE_LITTLEFS <= 0)
#endif
#endif
#ifndef HASP_USE_LITTLEFS
#define HASP_USE_LITTLEFS (HASP_USE_SPIFFS <= 0)
#define HASP_USE_LITTLEFS (HASP_USE_SPIFFS <= 0)
#endif
#ifndef HASP_USE_EEPROM
#define HASP_USE_EEPROM 1
#define HASP_USE_EEPROM 1
#endif
#ifndef HASP_USE_SDCARD
#define HASP_USE_SDCARD 0
#define HASP_USE_SDCARD 0
#endif
#ifndef HASP_USE_GPIO
#define HASP_USE_GPIO 1
#define HASP_USE_GPIO 1
#endif
#ifndef HASP_USE_QRCODE
#define HASP_USE_QRCODE 1
#define HASP_USE_QRCODE 1
#endif
#ifndef HASP_USE_PNGDECODE
#define HASP_USE_PNGDECODE 0
#define HASP_USE_PNGDECODE 0
#endif
#ifndef HASP_NUM_GPIO_CONFIG
#define HASP_NUM_GPIO_CONFIG 8
#define HASP_NUM_GPIO_CONFIG 8
#endif
#ifndef HASP_NUM_INPUTS
#define HASP_NUM_INPUTS 4 // Number of ACE Buttons
#define HASP_NUM_INPUTS 4 // Number of ACE Buttons
#endif
// #ifndef HASP_NUM_OUTPUTS
@ -91,128 +94,191 @@
// #endif
#ifndef HASP_NUM_PAGES
#if defined(ARDUINO_ARCH_ESP8266)
#define HASP_NUM_PAGES 4
#else
#define HASP_NUM_PAGES 12
#endif
#if defined(ARDUINO_ARCH_ESP8266)
#define HASP_NUM_PAGES 4
#else
#define HASP_NUM_PAGES 12
#endif
#endif
#define HASP_OBJECT_NOTATION "p%ub%u"
/* Includes */
#include <Arduino.h>
#ifdef WINDOWS
#include "winsock2.h"
#include "Windows.h"
#elif defined(POSIX)
#else
#include "Arduino.h"
#endif
#if HASP_USE_SPIFFS > 0
// #if defined(ARDUINO_ARCH_ESP32)
// #include "SPIFFS.h"
// #endif
// #include <FS.h> // Include the SPIFFS library
#include "hasp_filesystem.h"
// #if defined(ARDUINO_ARCH_ESP32)
// #include "SPIFFS.h"
// #endif
// #include <FS.h> // Include the SPIFFS library
#include "hasp_filesystem.h"
#endif
#if HASP_USE_LITTLEFS > 0
// #if defined(ARDUINO_ARCH_ESP32)
// #include "LITTLEFS.h"
// #elif defined(ARDUINO_ARCH_ESP8266)
// #include <FS.h> // Include the FS library
// #include <LittleFS.h>
// #endif
#include "hasp_filesystem.h"
// #if defined(ARDUINO_ARCH_ESP32)
// #include "LITTLEFS.h"
// #elif defined(ARDUINO_ARCH_ESP8266)
// #include <FS.h> // Include the FS library
// #include <LittleFS.h>
// #endif
#include "hasp_filesystem.h"
#endif
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
#include "lv_zifont.h"
#endif
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
#include "lv_zifont.h"
#endif
#endif
#if HASP_USE_EEPROM > 0
#include "hasp_eeprom.h"
#include "hasp_eeprom.h"
#endif
#if HASP_USE_WIFI > 0
#include "net/hasp_wifi.h"
#include "sys/net/hasp_wifi.h"
#if defined(STM32F4xx)
#include "WiFiSpi.h"
#if defined(STM32F4xx)
#include "WiFiSpi.h"
static WiFiSpiClass WiFi;
#endif
#endif
#endif // HASP_USE_WIFI
#if HASP_USE_ETHERNET > 0
#if defined(ARDUINO_ARCH_ESP32)
#include <ETH.h>
#if defined(ARDUINO_ARCH_ESP32)
#include <ETH.h>
#define ETH_ADDR 0
#define ETH_POWER_PIN -1
#define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18
#define NRST 5
#define ETH_TYPE ETH_PHY_LAN8720
#define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT
#define ETH_ADDR 0
#define ETH_POWER_PIN -1
#define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18
#define NRST 5
#define ETH_TYPE ETH_PHY_LAN8720
#define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT
#include "net/hasp_ethernet_esp32.h"
#warning Using ESP32 Ethernet LAN8720
#include "sys/net/hasp_ethernet_esp32.h"
#warning Using ESP32 Ethernet LAN8720
#else
#if USE_BUILTIN_ETHERNET > 0
#include <LwIP.h>
#include <STM32Ethernet.h>
#warning Use built-in STM32 Ethernet
#elif USE_UIP_ETHERNET
#include <UIPEthernet.h>
#include <utility/logging.h>
#warning Use ENC28J60 Ethernet shield
#else
#include "Ethernet.h"
#warning Use W5x00 Ethernet shield
#endif
#include "net/hasp_ethernet_stm32.h"
#endif
#else
#if USE_BUILTIN_ETHERNET > 0
#include <LwIP.h>
#include <STM32Ethernet.h>
#warning Use built-in STM32 Ethernet
#elif USE_UIP_ETHERNET
#include <UIPEthernet.h>
#include <utility/logging.h>
#warning Use ENC28J60 Ethernet shield
#else
#include "Ethernet.h"
#warning Use W5x00 Ethernet shield
#endif
#include "sys/net/hasp_ethernet_stm32.h"
#endif
#endif
#if HASP_USE_MQTT > 0
#include "svc/hasp_mqtt.h"
#include "mqtt/hasp_mqtt.h"
#if defined(WINDOWS) || defined(POSIX)
#define USE_PAHO
#else
#define USE_PUBSUBCLIENT
#endif
#endif
#if HASP_USE_GPIO > 0
#include "hasp_gpio.h"
#include "sys/gpio/hasp_gpio.h"
#endif
#if HASP_USE_HTTP > 0
#include "svc/hasp_http.h"
#include "sys/svc/hasp_http.h"
#endif
#if HASP_USE_TELNET > 0
#include "svc/hasp_telnet.h"
#include "sys/svc/hasp_telnet.h"
#endif
#if HASP_USE_MDNS > 0
#include "svc/hasp_mdns.h"
#include "sys/svc/hasp_mdns.h"
#endif
#if HASP_USE_OTA > 0
#include "svc/hasp_ota.h"
#ifndef HASP_OTA_PORT
#if defined(ARDUINO_ARCH_ESP32)
#define HASP_OTA_PORT 3232
#elif defined(ARDUINO_ARCH_ESP8266)
#define HASP_OTA_PORT 8266
#endif
#endif
#include "sys/svc/hasp_ota.h"
#ifndef HASP_OTA_PORT
#if defined(ARDUINO_ARCH_ESP32)
#define HASP_OTA_PORT 3232
#elif defined(ARDUINO_ARCH_ESP8266)
#define HASP_OTA_PORT 8266
#endif
#endif
#endif
#if HASP_USE_TASMOTA_SLAVE > 0
#include "svc/hasp_slave.h"
#if HASP_USE_TASMOTA_CLIENT > 0
#include "sys/svc/hasp_slave.h"
#endif
#ifndef FPSTR
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper*>(pstr_pointer))
#endif
#ifndef PGM_P
#define PGM_P const char *
#define PGM_P const char*
#endif
#endif // HASP_CONF_H
#if defined(WINDOWS) || defined(POSIX)
#ifndef __FlashStringHelper
#define __FlashStringHelper char
#endif
#ifndef F
#define F(x) (x)
#endif
#ifndef PSTR
#define PSTR(x) x
#endif
#ifndef PROGMEM
#define PROGMEM
#endif
#endif
#if defined(WINDOWS)
#include <Windows.h>
#define delay Sleep
#endif
#if defined(POSIX)
#define delay SDL_Delay
#endif
#if defined(WINDOWS) || defined(POSIX)
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <SDL2/SDL.h>
#define snprintf_P snprintf
#define memcpy_P memcpy
#define strcasecmp_P strcasecmp
#define strcmp_P strcmp
#define strstr_P strstr
#define halRestartMcu()
#define millis SDL_GetTicks
#define DEC 10
#define HEX 16
#define BIN 2
#define guiGetDim() 255
#define guiSetDim(x)
#define guiGetBacklight() 1
#define guiSetBacklight(x)
//#define guiCalibrate()
#endif
#endif // HASP_CONF_H

View File

@ -1,65 +1,70 @@
#ifndef HASP_MACRO_H
#define HASP_MACRO_H
#if HASP_LOG_LEVEL > LOG_LEVEL_FATAL
#define LOG_FATAL(...) \
Log.fatal(__VA_ARGS__); \
while(true) { \
}
#if defined(WINDOWS) || defined(POSIX)
#define LOG_OUTPUT(x, ...) printf(__VA_ARGS__)
#else
#define LOG_FATAL(...) \
do { \
} while(0)
#define LOG_OUTPUT(...) Log.output(...)
#if HASP_LOG_LEVEL > LOG_LEVEL_FATAL
#define LOG_FATAL(...) \
Log.fatal(__VA_ARGS__); \
while(true) { \
}
#else
#define LOG_FATAL(...) \
do { \
} while(0)
#endif
#if HASP_LOG_LEVEL > LOG_LEVEL_ALERT
#define LOG_ALERT(...) Log.alert(__VA_ARGS__)
#define LOG_ALERT(...) Log.alert(__VA_ARGS__)
#else
#define LOG_ALERT(...)
#define LOG_ALERT(...)
#endif
#if HASP_LOG_LEVEL > LOG_LEVEL_CRITICAL
#define LOG_CRITICAL(...) Log.critical(__VA_ARGS__)
#define LOG_CRITICAL(...) Log.critical(__VA_ARGS__)
#else
#define LOG_CRITICAL(...)
#define LOG_CRITICAL(...)
#endif
#if HASP_LOG_LEVEL > LOG_LEVEL_ERROR
#define LOG_ERROR(...) Log.error(__VA_ARGS__)
#define LOG_ERROR(...) Log.error(__VA_ARGS__)
#else
#define LOG_ERROR(...)
#define LOG_ERROR(...)
#endif
#if HASP_LOG_LEVEL > LOG_LEVEL_WARNING
#define LOG_WARNING(...) Log.warning(__VA_ARGS__)
#define LOG_WARNING(...) Log.warning(__VA_ARGS__)
#else
#define LOG_WARNING(...)
#define LOG_WARNING(...)
#endif
#if HASP_LOG_LEVEL > LOG_LEVEL_INFO
#define LOG_INFO(...) Log.notice(__VA_ARGS__)
#define LOG_INFO(...) Log.notice(__VA_ARGS__)
#else
#define LOG_INFO(...)
#define LOG_INFO(...)
#endif
#if HASP_LOG_LEVEL > LOG_LEVEL_TRACE
#define LOG_TRACE(...) Log.trace(__VA_ARGS__)
#define LOG_TRACE(...) Log.trace(__VA_ARGS__)
#else
#define LOG_TRACE(...)
#define LOG_TRACE(...)
#endif
#if HASP_LOG_LEVEL > LOG_LEVEL_VERBOSE
#define LOG_VERBOSE(...) Log.verbose(__VA_ARGS__)
#define LOG_VERBOSE(...) Log.verbose(__VA_ARGS__)
#else
#define LOG_VERBOSE(...)
#define LOG_VERBOSE(...)
#endif
#if HASP_LOG_LEVEL > LOG_LEVEL_DEBUG
#define LOG_DEBUG(...) Log.debug(__VA_ARGS__)
#define LOG_DEBUG(...) Log.debug(__VA_ARGS__)
#else
#define LOG_DEBUG(...)
#define LOG_DEBUG(...)
#endif
#define LOG_OUTPUT(...) Log.output(...)
#endif
#endif
#endif // HASP_MACRO_H

View File

@ -5,9 +5,9 @@
#if 1 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
/* clang-format off */
#ifndef LV_CONF_H
#define LV_CONF_H
/* clang-format off */
#include <stdint.h>
@ -26,6 +26,8 @@
/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX (TFT_WIDTH)
#define LV_VER_RES_MAX (TFT_HEIGHT)
#define LV_HOR_RES (TFT_WIDTH)
#define LV_VER_RES (TFT_HEIGHT)
/* Color depth:
* - 1: 1 byte per pixel
@ -181,14 +183,15 @@ typedef void* lv_group_user_data_t;
typedef void* lv_fs_drv_user_data_t;
/*File system interface*/
#define LV_USE_FS_IF 1
#define LV_USE_FS_IF 0
#if LV_USE_FS_IF
# define LV_FS_IF_FATFS '\0'
#if defined(ARDUINO_ARCH_ESP32) // || defined(ARDUINO_ARCH_ESP8266)
# define LV_FS_IF_PC 'S'
#if defined(STM32F4xx) // || defined(ARDUINO_ARCH_ESP8266)
# define LV_FS_IF_PC '\0'
# define LV_FS_IF_SPIFFS '\0' // internal esp Flash
#else
# define LV_FS_IF_PC '\0'
# define LV_FS_IF_POSIX '\0'
# define LV_FS_IF_SPIFFS '\0' // no internal esp Flash
#endif
#endif /*LV_USE_FS_IF*/
@ -251,12 +254,18 @@ typedef void* lv_img_decoder_user_data_t;
/* 1: use a custom tick source.
* It removes the need to manually update the tick with `lv_tick_inc`) */
#ifdef ARDUINO
#define LV_TICK_CUSTOM 1
#if LV_TICK_CUSTOM == 1
#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the sys time function*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/
#endif /*LV_TICK_CUSTOM*/
#else
#define LV_TICK_CUSTOM 0
#endif
typedef void* lv_disp_drv_user_data_t; /*Type of user data in the display driver*/
typedef void* lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/
@ -431,7 +440,7 @@ typedef void* lv_font_user_data_t;
/*Always enable at least on theme*/
#define LV_USE_THEME_MATERIAL 1 /*A fast and impressive theme*/
#define LV_THEME_DEFAULT_INIT lv_theme_hasp_init // We init the theme ourselves
#define LV_THEME_DEFAULT_INIT lv_theme_material_init // lv_theme_hasp_init // We init the theme ourselves
#define LV_THEME_DEFAULT_COLOR_PRIMARY LV_COLOR_RED
#define LV_THEME_DEFAULT_COLOR_SECONDARY LV_COLOR_BLUE
#define LV_THEME_DEFAULT_FLAG 0 //LV_THEME_MATERIAL_FLAG_NONE
@ -509,9 +518,11 @@ typedef void* lv_font_user_data_t;
/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/
typedef struct {
uint8_t id:8;
uint8_t objid:8;
uint8_t groupid:8;
uint8_t id;
uint8_t transitionid:4;
uint8_t actionid:4;
uint8_t groupid:4;
} lv_obj_user_data_t;
/*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
@ -637,7 +648,7 @@ typedef struct {
#endif
/*Preload (dependencies: lv_arc, lv_anim)*/
#define LV_USE_SPINNER 0
#define LV_USE_SPINNER 1
#if LV_USE_SPINNER != 0
# define LV_SPINNER_DEF_ARC_LENGTH 60 /*[deg]*/
# define LV_SPINNER_DEF_SPIN_TIME 1000 /*[ms]*/

View File

@ -582,9 +582,11 @@ typedef void * lv_font_user_data_t;
*==================*/
typedef struct {
uint8_t id:8;
uint8_t objid:8;
uint8_t groupid:8;
uint8_t id;
uint8_t transitionid:4;
uint8_t actionid:4;
uint8_t groupid:4;
} lv_obj_user_data_t;
#if LV_USE_USER_DATA

View File

@ -1,6 +1,10 @@
/**
* @file lv_drv_conf.h
*
* Configuration file for v7.9.1
*/
/*
* COPY THIS FILE AS lv_drv_conf.h
*/
#if 1 /*Set it to "1" to enable the content*/
@ -13,9 +17,15 @@
/*********************
* DELAY INTERFACE
*********************/
#ifdef ARDUINO
#define LV_DRV_DELAY_INCLUDE <Arduino.h> /*Dummy include by default*/
#define LV_DRV_DELAY_US(us) delayMicroseconds(ud) /*Delay the given number of microseconds*/
#define LV_DRV_DELAY_MS(ms) delay(ms) /*Delay the given number of milliseconds*/
#else
#define LV_DRV_DELAY_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/
#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/
#endif
/*********************
* DISPLAY INTERFACE
@ -93,7 +103,9 @@
#define MONITOR_VER_RES LV_VER_RES
/* Scale window by this factor (useful when simulating small screens) */
#ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1
#endif
/* Used to test true double buffering with only address changing.
* Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */
@ -102,9 +114,6 @@
/*Eclipse: <SDL2/SDL.h> Visual Studio: <SDL.h>*/
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Different rendering might be used if running in a Virtual machine*/
#define MONITOR_VIRTUAL_MACHINE 0
/*Open two windows to test multi display support*/
#define MONITOR_DUAL 0
#endif
@ -116,12 +125,18 @@
#define USE_WINDOWS 0
#endif
#define USE_WINDOWS 0
#if USE_WINDOWS
#define WINDOW_HOR_RES 480
#define WINDOW_VER_RES 320
#endif
/*----------------------------------------
* GTK drivers (monitor, mouse, keyboard
*---------------------------------------*/
#ifndef USE_GTK
#define USE_GTK 0
#endif
/*----------------
* SSD1963
*--------------*/
@ -181,6 +196,17 @@
/*No settings*/
#endif /*USE_ST7565*/
/*------------------------------
* GC9A01 (color, low res.)
*-----------------------------*/
#ifndef USE_GC9A01
#define USE_GC9A01 0
#endif
#if USE_GC9A01
/*No settings*/
#endif /*USE_GC9A01*/
/*------------------------------------------
* UC1610 (4 gray 160*[104|128])
* (EA DOGXL160 160x104 tested)
@ -218,6 +244,20 @@
b) /*((uint8_t) __REV(__RBIT(b)))*/ /*Architecture / compiler dependent byte bits order reverse*/
#endif /*USE_SHARP_MIP*/
/*-------------------------------------------------
* ILI9341 240X320 TFT LCD
*------------------------------------------------*/
#ifndef USE_ILI9341
#define USE_ILI9341 0
#endif
#if USE_ILI9341
#define ILI9341_HOR_RES LV_HOR_RES
#define ILI9341_VER_RES LV_VER_RES
#define ILI9341_GAMMA 1
#define ILI9341_TEARING 0
#endif /*USE_ILI9341*/
/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/
@ -240,6 +280,18 @@
#define FBDEV_PATH "/dev/fb0"
#endif
/*-----------------------------------------
* DRM/KMS device (/dev/dri/cardX)
*-----------------------------------------*/
#ifndef USE_DRM
#define USE_DRM 0
#endif
#if USE_DRM
#define DRM_CARD "/dev/dri/card0"
#define DRM_CONNECTOR_ID -1 /* -1 for the first connected one */
#endif
/*********************
* INPUT DEVICES
*********************/
@ -330,25 +382,25 @@
#define USE_EVDEV 0
#endif
#if USE_EVDEV
#define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test \
them*/
#define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/
#ifndef USE_BSD_EVDEV
#define USE_BSD_EVDEV 0
#endif
#define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */
#if EVDEV_SCALE
#define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */
#define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */
#endif /*EVDEV_SCALE*/
#if USE_EVDEV || USE_BSD_EVDEV
#define EVDEV_NAME \
"/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test \
them*/
#define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/
#define EVDEV_CALIBRATE \
0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
#if EVDEV_CALIBRATE
#define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
#define EVDEV_HOR_MAX 200
#define EVDEV_VER_MIN 200
#define EVDEV_VER_MAX 3800
#endif /*EVDEV_SCALE*/
#define EVDEV_HOR_MIN 0 /*to invert axis swap EVDEV_XXX_MIN by EVDEV_XXX_MAX*/
#define EVDEV_HOR_MAX 4096 /*"evtest" Linux tool can help to get the correct calibraion values>*/
#define EVDEV_VER_MIN 0
#define EVDEV_VER_MAX 4096
#endif /*EVDEV_CALIBRATE*/
#endif /*USE_EVDEV*/
/*-------------------------------

View File

@ -1,4 +1,4 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
/***************************************************

View File

@ -1,602 +0,0 @@
#include "AXP192.h"
AXP192::AXP192()
{
}
void AXP192::begin(void)
{
Wire1.begin(21, 22);
Wire1.setClock(400000);
//AXP192 30H
Write1Byte(0x30, (Read8bit(0x30) & 0x04) | 0X02);
Serial.printf("axp: vbus limit off\n");
//AXP192 GPIO1:OD OUTPUT
Write1Byte(0x92, Read8bit(0x92) & 0xf8);
Serial.printf("axp: gpio1 init\n");
//AXP192 GPIO2:OD OUTPUT
Write1Byte(0x93, Read8bit(0x93) & 0xf8);
Serial.printf("axp: gpio2 init\n");
//AXP192 RTC CHG
Write1Byte(0x35, (Read8bit(0x35) & 0x1c) | 0xa2);
Serial.printf("axp: rtc battery charging enabled\n");
SetESPVoltage(3350);
Serial.printf("axp: esp32 power voltage was set to 3.35v\n");
SetLcdVoltage(2800);
Serial.printf("axp: lcd backlight voltage was set to 2.80v\n");
SetLDOVoltage(2, 3300); //Periph power voltage preset (LCD_logic, SD card)
Serial.printf("axp: lcd logic and sdcard voltage preset to 3.3v\n");
SetLDOVoltage(3, 2000); //Vibrator power voltage preset
Serial.printf("axp: vibrator voltage preset to 2v\n");
SetLDOEnable(2, true);
SetDCDC3(true); // LCD backlight
SetLed(true);
SetCHGCurrent(kCHG_100mA);
//SetAxpPriphPower(1);
//Serial.printf("axp: lcd_logic and sdcard power enabled\n\n");
//pinMode(39, INPUT_PULLUP);
//AXP192 GPIO4
Write1Byte(0X95, (Read8bit(0x95) & 0x72) | 0X84);
Write1Byte(0X36, 0X4C);
Write1Byte(0x82,0xff);
SetLCDRSet(0);
delay(100);
SetLCDRSet(1);
delay(100);
// I2C_WriteByteDataAt(0X15,0XFE,0XFF);
// bus power mode_output
SetBusPowerMode(0);
}
void AXP192::Write1Byte(uint8_t Addr, uint8_t Data)
{
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.write(Data);
Wire1.endTransmission();
}
uint8_t AXP192::Read8bit(uint8_t Addr)
{
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 1);
return Wire1.read();
}
uint16_t AXP192::Read12Bit(uint8_t Addr)
{
uint16_t Data = 0;
uint8_t buf[2];
ReadBuff(Addr, 2, buf);
Data = ((buf[0] << 4) + buf[1]); //
return Data;
}
uint16_t AXP192::Read13Bit(uint8_t Addr)
{
uint16_t Data = 0;
uint8_t buf[2];
ReadBuff(Addr, 2, buf);
Data = ((buf[0] << 5) + buf[1]); //
return Data;
}
uint16_t AXP192::Read16bit(uint8_t Addr)
{
uint16_t ReData = 0;
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 2);
for (int i = 0; i < 2; i++)
{
ReData <<= 8;
ReData |= Wire1.read();
}
return ReData;
}
uint32_t AXP192::Read24bit(uint8_t Addr)
{
uint32_t ReData = 0;
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 3);
for (int i = 0; i < 3; i++)
{
ReData <<= 8;
ReData |= Wire1.read();
}
return ReData;
}
uint32_t AXP192::Read32bit(uint8_t Addr)
{
uint32_t ReData = 0;
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 2);
for (int i = 0; i < 4; i++)
{
ReData <<= 8;
ReData |= Wire1.read();
}
return ReData;
}
void AXP192::ReadBuff(uint8_t Addr, uint8_t Size, uint8_t *Buff)
{
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, (int)Size);
for (int i = 0; i < Size; i++)
{
*(Buff + i) = Wire1.read();
}
}
void AXP192::ScreenBreath(uint8_t brightness)
{
if (brightness > 12)
{
brightness = 12;
}
uint8_t buf = Read8bit(0x28);
Write1Byte(0x28, ((buf & 0x0f) | (brightness << 4)));
}
bool AXP192::GetBatState()
{
if (Read8bit(0x01) | 0x20)
return true;
else
return false;
}
//---------coulombcounter_from_here---------
//enable: void EnableCoulombcounter(void);
//disable: void DisableCOulombcounter(void);
//stop: void StopCoulombcounter(void);
//clear: void ClearCoulombcounter(void);
//get charge data: uint32_t GetCoulombchargeData(void);
//get discharge data: uint32_t GetCoulombdischargeData(void);
//get coulomb val affter calculation: float GetCoulombData(void);
//------------------------------------------
void AXP192::EnableCoulombcounter(void)
{
Write1Byte(0xB8, 0x80);
}
void AXP192::DisableCoulombcounter(void)
{
Write1Byte(0xB8, 0x00);
}
void AXP192::StopCoulombcounter(void)
{
Write1Byte(0xB8, 0xC0);
}
void AXP192::ClearCoulombcounter(void)
{
Write1Byte(0xB8, 0xA0);
}
uint32_t AXP192::GetCoulombchargeData(void)
{
return Read32bit(0xB0);
}
uint32_t AXP192::GetCoulombdischargeData(void)
{
return Read32bit(0xB4);
}
float AXP192::GetCoulombData(void)
{
uint32_t coin = 0;
uint32_t coout = 0;
coin = GetCoulombchargeData();
coout = GetCoulombdischargeData();
//c = 65536 * current_LSB * (coin - coout) / 3600 / ADC rate
//Adc rate can be read from 84H ,change this variable if you change the ADC reate
float ccc = 65536 * 0.5 * (coin - coout) / 3600.0 / 25.0;
return ccc;
}
// Cut all power, except for LDO1 (RTC)
void AXP192::PowerOff(void)
{
Write1Byte(0x32, Read8bit(0x32) | 0b10000000);
}
void AXP192::SetAdcState(bool state)
{
// Enable / Disable all ADCs
Write1Byte(0x82, state ? 0xff : 0x00);
}
void AXP192::PrepareToSleep(void)
{
// Disable ADCs
SetAdcState(false);
// Turn LED off
SetLed(false);
// Turn LCD backlight off
SetDCDC3(false);
}
void AXP192::RestoreFromLightSleep(void)
{
// Turn LCD backlight on
SetDCDC3(true);
// Turn LED on
SetLed(true);
// Enable ADCs
SetAdcState(true);
}
uint8_t AXP192::GetWarningLeve(void)
{
Wire1.beginTransmission(0x34);
Wire1.write(0x47);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 1);
uint8_t buf = Wire1.read();
return (buf & 0x01);
}
// -- sleep
void AXP192::DeepSleep(uint64_t time_in_us)
{
PrepareToSleep();
if (time_in_us > 0)
{
esp_sleep_enable_timer_wakeup(time_in_us);
}
else
{
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
}
(time_in_us == 0) ? esp_deep_sleep_start() : esp_deep_sleep(time_in_us);
// Never reached - after deep sleep ESP32 restarts
}
void AXP192::LightSleep(uint64_t time_in_us)
{
PrepareToSleep();
if (time_in_us > 0)
{
esp_sleep_enable_timer_wakeup(time_in_us);
}
else
{
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
}
esp_light_sleep_start();
RestoreFromLightSleep();
}
uint8_t AXP192::GetWarningLevel(void)
{
return Read8bit(0x47) & 0x01;
}
float AXP192::GetBatVoltage()
{
float ADCLSB = 1.1 / 1000.0;
uint16_t ReData = Read12Bit(0x78);
return ReData * ADCLSB;
}
float AXP192::GetBatCurrent()
{
float ADCLSB = 0.5;
uint16_t CurrentIn = Read13Bit(0x7A);
uint16_t CurrentOut = Read13Bit(0x7C);
return (CurrentIn - CurrentOut) * ADCLSB;
}
float AXP192::GetVinVoltage()
{
float ADCLSB = 1.7 / 1000.0;
uint16_t ReData = Read12Bit(0x56);
return ReData * ADCLSB;
}
float AXP192::GetVinCurrent()
{
float ADCLSB = 0.625;
uint16_t ReData = Read12Bit(0x58);
return ReData * ADCLSB;
}
float AXP192::GetVBusVoltage()
{
float ADCLSB = 1.7 / 1000.0;
uint16_t ReData = Read12Bit(0x5A);
return ReData * ADCLSB;
}
float AXP192::GetVBusCurrent()
{
float ADCLSB = 0.375;
uint16_t ReData = Read12Bit(0x5C);
return ReData * ADCLSB;
}
float AXP192::GetTempInAXP192()
{
float ADCLSB = 0.1;
const float OFFSET_DEG_C = -144.7;
uint16_t ReData = Read12Bit(0x5E);
return OFFSET_DEG_C + ReData * ADCLSB;
}
float AXP192::GetBatPower()
{
float VoltageLSB = 1.1;
float CurrentLCS = 0.5;
uint32_t ReData = Read24bit(0x70);
return VoltageLSB * CurrentLCS * ReData / 1000.0;
}
float AXP192::GetBatChargeCurrent()
{
float ADCLSB = 0.5;
uint16_t ReData = Read12Bit(0x7A);
return ReData * ADCLSB;
}
float AXP192::GetAPSVoltage()
{
float ADCLSB = 1.4 / 1000.0;
uint16_t ReData = Read12Bit(0x7E);
return ReData * ADCLSB;
}
float AXP192::GetBatCoulombInput()
{
uint32_t ReData = Read32bit(0xB0);
return ReData * 65536 * 0.5 / 3600 / 25.0;
}
float AXP192::GetBatCoulombOut()
{
uint32_t ReData = Read32bit(0xB4);
return ReData * 65536 * 0.5 / 3600 / 25.0;
}
void AXP192::SetCoulombClear()
{
Write1Byte(0xB8, 0x20);
}
void AXP192::SetLDO2(bool State)
{
uint8_t buf = Read8bit(0x12);
if (State == true)
buf = (1 << 2) | buf;
else
buf = ~(1 << 2) & buf;
Write1Byte(0x12, buf);
}
void AXP192::SetDCDC3(bool State)
{
uint8_t buf = Read8bit(0x12);
if (State == true)
buf = (1 << 1) | buf;
else
buf = ~(1 << 1) & buf;
Write1Byte(0x12, buf);
}
uint8_t AXP192::AXPInState()
{
return Read8bit(0x00);
}
bool AXP192::isACIN()
{
return ( Read8bit(0x00) & 0x80 ) ? true : false;
}
bool AXP192::isCharging()
{
return ( Read8bit(0x00) & 0x04 ) ? true : false;
}
bool AXP192::isVBUS()
{
return ( Read8bit(0x00) & 0x20 ) ? true : false;
}
void AXP192::SetLDOVoltage(uint8_t number, uint16_t voltage)
{
voltage = (voltage > 3300) ? 15 : (voltage / 100) - 18;
switch (number)
{
//uint8_t reg, data;
case 2:
Write1Byte(0x28, (Read8bit(0x28) & 0X0F) | (voltage << 4));
break;
case 3:
Write1Byte(0x28, (Read8bit(0x28) & 0XF0) | voltage);
break;
}
}
void AXP192::SetDCVoltage(uint8_t number, uint16_t voltage)
{
uint8_t addr;
if (number > 2)
return;
voltage = (voltage < 700) ? 0 : (voltage - 700) / 25;
switch (number)
{
case 0:
addr = 0x26;
break;
case 1:
addr = 0x25;
break;
case 2:
addr = 0x27;
break;
}
Write1Byte(addr, (Read8bit(addr) & 0X80) | (voltage & 0X7F));
}
void AXP192::SetESPVoltage(uint16_t voltage)
{
if (voltage >= 3000 && voltage <= 3400)
{
SetDCVoltage(0, voltage);
}
}
void AXP192::SetLcdVoltage(uint16_t voltage)
{
if (voltage >= 2500 && voltage <= 3300)
{
SetDCVoltage(2, voltage);
}
}
void AXP192::SetLDOEnable(uint8_t number, bool state)
{
uint8_t mark = 0x01;
if ((number < 2) || (number > 3))
return;
mark <<= number;
if (state)
{
Write1Byte(0x12, (Read8bit(0x12) | mark));
}
else
{
Write1Byte(0x12, (Read8bit(0x12) & (~mark)));
}
}
void AXP192::SetLCDRSet(bool state)
{
uint8_t reg_addr = 0x96;
uint8_t gpio_bit = 0x02;
uint8_t data;
data = Read8bit(reg_addr);
if (state)
{
data |= gpio_bit;
}
else
{
data &= ~gpio_bit;
}
Write1Byte(reg_addr, data);
}
void AXP192::SetBusPowerMode(uint8_t state)
{
uint8_t data;
if (state == 0)
{
data = Read8bit(0x91);
Write1Byte(0x91, (data & 0X0F) | 0XF0);
data = Read8bit(0x90);
Write1Byte(0x90, (data & 0XF8) | 0X02); //set GPIO0 to LDO OUTPUT , pullup N_VBUSEN to disable supply from BUS_5V
data = Read8bit(0x91);
data = Read8bit(0x12); //read reg 0x12
Write1Byte(0x12, data | 0x40); //set EXTEN to enable 5v boost
}
else
{
data = Read8bit(0x12); //read reg 0x10
Write1Byte(0x12, data & 0XBF); //set EXTEN to disable 5v boost
//delay(2000);
data = Read8bit(0x90);
Write1Byte(0x90, (data & 0xF8) | 0X01); //set GPIO0 to float , using enternal pulldown resistor to enable supply from BUS_5VS
}
}
void AXP192::SetLed(uint8_t state)
{
uint8_t reg_addr=0x94;
uint8_t data;
data=Read8bit(reg_addr);
if(state)
{
data=data&0XFD;
}
else
{
data|=0X02;
}
Write1Byte(reg_addr,data);
}
//set led state(GPIO high active,set 1 to enable amplifier)
void AXP192::SetSpkEnable(uint8_t state)
{
uint8_t reg_addr=0x94;
uint8_t gpio_bit=0x04;
uint8_t data;
data=Read8bit(reg_addr);
if(state)
{
data|=gpio_bit;
}
else
{
data&=~gpio_bit;
}
Write1Byte(reg_addr,data);
}
void AXP192::SetCHGCurrent(uint8_t state)
{
uint8_t data = Read8bit(0x33);
data &= 0xf0;
data = data | ( state & 0x0f );
Write1Byte(0x33,data);
}

View File

@ -1,106 +0,0 @@
#ifndef __AXP192_H__
#define __AXP192_H__
#include <Wire.h>
#include <Arduino.h>
#define SLEEP_MSEC(us) (((uint64_t)us) * 1000L)
#define SLEEP_SEC(us) (((uint64_t)us) * 1000000L)
#define SLEEP_MIN(us) (((uint64_t)us) * 60L * 1000000L)
#define SLEEP_HR(us) (((uint64_t)us) * 60L * 60L * 1000000L)
#define AXP_ADDR 0X34
#define PowerOff(x) SetSleep(x)
class AXP192 {
public:
enum CHGCurrent{
kCHG_100mA = 0,
kCHG_190mA,
kCHG_280mA,
kCHG_360mA,
kCHG_450mA,
kCHG_550mA,
kCHG_630mA,
kCHG_700mA,
kCHG_780mA,
kCHG_880mA,
kCHG_960mA,
kCHG_1000mA,
kCHG_1080mA,
kCHG_1160mA,
kCHG_1240mA,
kCHG_1320mA,
};
AXP192();
void begin(void);
void ScreenBreath(uint8_t brightness);
bool GetBatState();
void EnableCoulombcounter(void);
void DisableCoulombcounter(void);
void StopCoulombcounter(void);
void ClearCoulombcounter(void);
uint32_t GetCoulombchargeData(void);
uint32_t GetCoulombdischargeData(void);
float GetCoulombData(void);
void PowerOff(void);
void SetAdcState(bool state);
// -- sleep
void PrepareToSleep(void);
void RestoreFromLightSleep(void);
void DeepSleep(uint64_t time_in_us = 0);
void LightSleep(uint64_t time_in_us = 0);
uint8_t GetWarningLeve(void);
public:
// void SetChargeVoltage( uint8_t );
// void SetChargeCurrent( uint8_t );
float GetBatVoltage();
float GetBatCurrent();
float GetVinVoltage();
float GetVinCurrent();
float GetVBusVoltage();
float GetVBusCurrent();
float GetTempInAXP192();
float GetBatPower();
float GetBatChargeCurrent();
float GetAPSVoltage();
float GetBatCoulombInput();
float GetBatCoulombOut();
uint8_t GetWarningLevel(void);
void SetCoulombClear();
void SetLDO2( bool State );
void SetDCDC3( bool State );
uint8_t AXPInState();
bool isACIN();
bool isCharging();
bool isVBUS();
void SetLDOVoltage(uint8_t number , uint16_t voltage);
void SetDCVoltage(uint8_t number , uint16_t voltage);
void SetESPVoltage(uint16_t voltage);
void SetLcdVoltage(uint16_t voltage);
void SetLDOEnable( uint8_t number ,bool state );
void SetLCDRSet( bool state );
void SetBusPowerMode( uint8_t state );
void SetLed(uint8_t state);
void SetSpkEnable(uint8_t state);
void SetCHGCurrent(uint8_t state);
private:
void Write1Byte( uint8_t Addr , uint8_t Data );
uint8_t Read8bit( uint8_t Addr );
uint16_t Read12Bit( uint8_t Addr);
uint16_t Read13Bit( uint8_t Addr);
uint16_t Read16bit( uint8_t Addr );
uint32_t Read24bit( uint8_t Addr );
uint32_t Read32bit( uint8_t Addr );
void ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff );
};
#endif

View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2020 M5Stack
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -29,85 +29,87 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "ArduinoLog.h"
#ifdef ARDUINO
#include "ArduinoLog.h"
void Logging::begin(int level, bool showLevel)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
setLevel(0, level);
setLevel(1, level);
setLevel(2, level);
setShowLevel(0, showLevel);
#endif
#endif
}
void Logging::registerOutput(uint8_t slot, Print * logOutput, int level, bool showLevel)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
if(slot >= 3) return;
setLevel(slot, level);
setShowLevel(slot, showLevel);
_logOutput[slot] = logOutput;
#endif
#endif
}
void Logging::unregisterOutput(uint8_t slot)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
if(slot >= 3) return;
_logOutput[slot] = NULL;
#endif
#endif
}
void Logging::setLevel(uint8_t slot, int level)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
_level[slot] = constrain(level, LOG_LEVEL_SILENT, LOG_LEVEL_OUTPUT);
#endif
#endif
}
int Logging::getLevel(uint8_t slot) const
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
return _level[slot];
#else
#else
return 0;
#endif
#endif
}
void Logging::setShowLevel(uint8_t slot, bool showLevel)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
_showLevel[slot] = showLevel;
#endif
#endif
}
bool Logging::getShowLevel(uint8_t slot) const
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
return _showLevel[slot];
#else
#else
return false;
#endif
#endif
}
void Logging::setPrefix(printfunction f)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
_prefix = f;
#endif
#endif
}
void Logging::setSuffix(printfunction f)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
_suffix = f;
#endif
#endif
}
void Logging::print(Print * logOutput, const __FlashStringHelper * format, va_list args)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
PGM_P p = reinterpret_cast<PGM_P>(format);
char c = pgm_read_byte(p++);
for(; c != 0; c = pgm_read_byte(p++)) {
@ -118,12 +120,12 @@ void Logging::print(Print * logOutput, const __FlashStringHelper * format, va_li
logOutput->print(c);
}
}
#endif
#endif
}
void Logging::print(Print * logOutput, const char * format, va_list args)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
for(; *format != 0; ++format) {
if(*format == '%') {
++format;
@ -132,12 +134,12 @@ void Logging::print(Print * logOutput, const char * format, va_list args)
logOutput->print(*format);
}
}
#endif
#endif
}
void Logging::printFormat(Print * logOutput, const char format, va_list * args)
{
#ifndef DISABLE_LOGGING
#ifndef DISABLE_LOGGING
if(format == '%') {
logOutput->print(format);
} else if(format == 's') {
@ -179,7 +181,9 @@ void Logging::printFormat(Print * logOutput, const char format, va_list * args)
logOutput->print(F("false"));
}
}
#endif
#endif
}
Logging Log = Logging();
#endif // ARDUINO

View File

@ -17,12 +17,12 @@ Licensed under the MIT License <http://opensource.org/licenses/MIT>.
#include <inttypes.h>
#include <stdarg.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "Arduino.h"
#else
#include "WProgram.h"
#include "WProgram.h"
#endif
//#include "StringStream.h"
typedef void (*printfunction)(uint8_t tag, int level, Print *);
typedef void (*printfunction)(uint8_t tag, int level, Print*);
//#include <stdint.h>
//#include <stddef.h>
@ -92,7 +92,7 @@ class Logging {
*/
Logging()
#ifndef DISABLE_LOGGING
// : _level(LOG_LEVEL_SILENT), _showLevel(true)
// : _level(LOG_LEVEL_SILENT), _showLevel(true)
#endif
{}
@ -116,7 +116,7 @@ class Logging {
* \return void
*
*/
void registerOutput(uint8_t slot, Print * logOutput, int level, bool showLevel);
void registerOutput(uint8_t slot, Print* logOutput, int level, bool showLevel);
/**
* Unregister the printer in a certain slot
@ -311,11 +311,11 @@ class Logging {
}
private:
void print(Print * logOutput, const char * format, va_list args);
void print(Print* logOutput, const char* format, va_list args);
void print(Print * logOutput, const __FlashStringHelper * format, va_list args);
void print(Print* logOutput, const __FlashStringHelper* format, va_list args);
void printFormat(Print * logOutput, const char format, va_list * args);
void printFormat(Print* logOutput, const char format, va_list* args);
template <class T> void printLevel(uint8_t tag, int level, T msg, ...)
{
@ -343,7 +343,7 @@ class Logging {
#ifndef DISABLE_LOGGING
int _level[3];
bool _showLevel[3];
Print * _logOutput[3];
Print* _logOutput[3];
printfunction _prefix = NULL;
printfunction _suffix = NULL;

View File

@ -1,5 +1,5 @@
This directory is intended for project specific (private) libraries.
This directory is intended for project specific (customized) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory

View File

@ -1 +0,0 @@
**/*.o

View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2019 LittlevGL
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,7 +0,0 @@
# Display and Touch pad drivers
Display controller and touchpad driver to can be directly used with [LittlevGL](https://littlevgl.com).
To learn more about using drivers in LittlevGL visit the [Porting guide](https://littlevgl.com/porting).
If you used a new display or touch pad driver with LittlevGL please share it with other people!

View File

@ -1,425 +0,0 @@
/**
* @file R61581.c
*
*/
/*********************
* INCLUDES
*********************/
#include "R61581.h"
#if USE_R61581 != 0
#include <stdbool.h>
#include "lvgl/lv_core/lv_vdb.h"
#include LV_DRV_DISP_INCLUDE
#include LV_DRV_DELAY_INCLUDE
/*********************
* DEFINES
*********************/
#define R61581_CMD_MODE 0
#define R61581_DATA_MODE 1
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void r61581_io_init(void);
static void r61581_reset(void);
static void r61581_set_tft_spec(void);
static inline void r61581_cmd_mode(void);
static inline void r61581_data_mode(void);
static inline void r61581_cmd(uint8_t cmd);
static inline void r61581_data(uint8_t data);
/**********************
* STATIC VARIABLES
**********************/
static bool cmd_mode = true;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the R61581 display controller
* @return HW_RES_OK or any error from hw_res_t enum
*/
void r61581_init(void)
{
r61581_io_init();
/*Slow mode until the PLL is not started in the display controller*/
LV_DRV_DISP_PAR_SLOW;
r61581_reset();
r61581_set_tft_spec();
r61581_cmd(0x13); //SET display on
r61581_cmd(0x29); //SET display on
LV_DRV_DELAY_MS(30);
/*Parallel to max speed*/
LV_DRV_DISP_PAR_FAST;
}
void r61581_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
{
/*Return if the area is out the screen*/
if(x2 < 0) return;
if(y2 < 0) return;
if(x1 > R61581_HOR_RES - 1) return;
if(y1 > R61581_VER_RES - 1) return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > R61581_HOR_RES - 1 ? R61581_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > R61581_VER_RES - 1 ? R61581_VER_RES - 1 : y2;
//Set the rectangular area
r61581_cmd(0x002A);
r61581_data(act_x1 >> 8);
r61581_data(0x00FF & act_x1);
r61581_data(act_x2 >> 8);
r61581_data(0x00FF & act_x2);
r61581_cmd(0x002B);
r61581_data(act_y1 >> 8);
r61581_data(0x00FF & act_y1);
r61581_data(act_y2 >> 8);
r61581_data(0x00FF & act_y2);
r61581_cmd(0x2c);
int16_t i;
uint16_t full_w = x2 - x1 + 1;
r61581_data_mode();
#if LV_COLOR_DEPTH == 16
uint16_t act_w = act_x2 - act_x1 + 1;
for(i = act_y1; i <= act_y2; i++) {
LV_DRV_DISP_PAR_WR_ARRAY((uint16_t *)color_p, act_w);
color_p += full_w;
}
#else
int16_t j;
for(i = act_y1; i <= act_y2; i++) {
for(j = 0; j <= act_x2 - act_x1 + 1; j++) {
LV_DRV_DISP_PAR_WR_WORD(lv_color_to16(color_p[j]));
color_p += full_w;
}
}
#endif
lv_flush_ready();
}
void r61581_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
{
/*Return if the area is out the screen*/
if(x2 < 0) return;
if(y2 < 0) return;
if(x1 > R61581_HOR_RES - 1) return;
if(y1 > R61581_VER_RES - 1) return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > R61581_HOR_RES - 1 ? R61581_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > R61581_VER_RES - 1 ? R61581_VER_RES - 1 : y2;
//Set the rectangular area
r61581_cmd(0x002A);
r61581_data(act_x1 >> 8);
r61581_data(0x00FF & act_x1);
r61581_data(act_x2 >> 8);
r61581_data(0x00FF & act_x2);
r61581_cmd(0x002B);
r61581_data(act_y1 >> 8);
r61581_data(0x00FF & act_y1);
r61581_data(act_y2 >> 8);
r61581_data(0x00FF & act_y2);
r61581_cmd(0x2c);
r61581_data_mode();
uint16_t color16 = lv_color_to16(color);
uint32_t size = (act_x2 - act_x1 + 1) * (act_y2 - act_y1 + 1);
uint32_t i;
for(i = 0; i < size; i++) {
LV_DRV_DISP_PAR_WR_WORD(color16);
}
}
void r61581_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
{
/*Return if the area is out the screen*/
if(x2 < 0) return;
if(y2 < 0) return;
if(x1 > R61581_HOR_RES - 1) return;
if(y1 > R61581_VER_RES - 1) return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > R61581_HOR_RES - 1 ? R61581_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > R61581_VER_RES - 1 ? R61581_VER_RES - 1 : y2;
//Set the rectangular area
r61581_cmd(0x002A);
r61581_data(act_x1 >> 8);
r61581_data(0x00FF & act_x1);
r61581_data(act_x2 >> 8);
r61581_data(0x00FF & act_x2);
r61581_cmd(0x002B);
r61581_data(act_y1 >> 8);
r61581_data(0x00FF & act_y1);
r61581_data(act_y2 >> 8);
r61581_data(0x00FF & act_y2);
r61581_cmd(0x2c);
int16_t i;
uint16_t full_w = x2 - x1 + 1;
r61581_data_mode();
#if LV_COLOR_DEPTH == 16
uint16_t act_w = act_x2 - act_x1 + 1;
for(i = act_y1; i <= act_y2; i++) {
LV_DRV_DISP_PAR_WR_ARRAY((uint16_t *)color_p, act_w);
color_p += full_w;
}
#else
int16_t j;
for(i = act_y1; i <= act_y2; i++) {
for(j = 0; j <= act_x2 - act_x1 + 1; j++) {
LV_DRV_DISP_PAR_WR_WORD(lv_color_to16(color_p[j]));
color_p += full_w;
}
}
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Io init
*/
static void r61581_io_init(void)
{
LV_DRV_DISP_CMD_DATA(R61581_CMD_MODE)
cmd_mode = true;
}
/**
* Reset
*/
static void r61581_reset(void)
{
/*Hardware reset*/
LV_DRV_DISP_RST(1);
LV_DRV_DELAY_MS(50);
LV_DRV_DISP_RST(0);
LV_DRV_DELAY_MS(50);
LV_DRV_DISP_RST(1);
LV_DRV_DELAY_MS(50);
/*Chip enable*/
LV_DRV_DISP_PAR_CS(1);
LV_DRV_DELAY_MS(10);
LV_DRV_DISP_PAR_CS(0);
LV_DRV_DELAY_MS(5);
/*Software reset*/
r61581_cmd(0x01);
LV_DRV_DELAY_MS(20);
r61581_cmd(0x01);
LV_DRV_DELAY_MS(20);
r61581_cmd(0x01);
LV_DRV_DELAY_MS(20);
}
/**
* TFT specific initialization
*/
static void r61581_set_tft_spec(void)
{
r61581_cmd(0xB0);
r61581_data(0x00);
r61581_cmd(0xB3);
r61581_data(0x02);
r61581_data(0x00);
r61581_data(0x00);
r61581_data(0x10);
r61581_cmd(0xB4);
r61581_data(0x00);//0X10
r61581_cmd(0xB9); //PWM
r61581_data(0x01);
r61581_data(0xFF); //FF brightness
r61581_data(0xFF);
r61581_data(0x18);
/*Panel Driving Setting*/
r61581_cmd(0xC0);
r61581_data(0x02);
r61581_data(0x3B);
r61581_data(0x00);
r61581_data(0x00);
r61581_data(0x00);
r61581_data(0x01);
r61581_data(0x00);//NW
r61581_data(0x43);
/*Display Timing Setting for Normal Mode */
r61581_cmd(0xC1);
r61581_data(0x08);
r61581_data(0x15); //CLOCK
r61581_data(R61581_VFP);
r61581_data(R61581_VBP);
/*Source/VCOM/Gate Driving Timing Setting*/
r61581_cmd(0xC4);
r61581_data(0x15);
r61581_data(0x03);
r61581_data(0x03);
r61581_data(0x01);
/*Interface Setting*/
r61581_cmd(0xC6);
r61581_data((R61581_DPL << 0) |
(R61581_EPL << 1) |
(R61581_HSPL << 4) |
(R61581_VSPL << 5));
/*Gamma Set*/
r61581_cmd(0xC8);
r61581_data(0x0c);
r61581_data(0x05);
r61581_data(0x0A);
r61581_data(0x6B);
r61581_data(0x04);
r61581_data(0x06);
r61581_data(0x15);
r61581_data(0x10);
r61581_data(0x00);
r61581_data(0x31);
r61581_cmd(0x36);
if(R61581_ORI == 0) r61581_data(0xE0);
else r61581_data(0x20);
r61581_cmd(0x0C);
r61581_data(0x55);
r61581_cmd(0x3A);
r61581_data(0x55);
r61581_cmd(0x38);
r61581_cmd(0xD0);
r61581_data(0x07);
r61581_data(0x07);
r61581_data(0x14);
r61581_data(0xA2);
r61581_cmd(0xD1);
r61581_data(0x03);
r61581_data(0x5A);
r61581_data(0x10);
r61581_cmd(0xD2);
r61581_data(0x03);
r61581_data(0x04);
r61581_data(0x04);
r61581_cmd(0x11);
LV_DRV_DELAY_MS(10);
r61581_cmd(0x2A);
r61581_data(0x00);
r61581_data(0x00);
r61581_data(((R61581_HOR_RES - 1) >> 8) & 0XFF);
r61581_data((R61581_HOR_RES - 1) & 0XFF);
r61581_cmd(0x2B);
r61581_data(0x00);
r61581_data(0x00);
r61581_data(((R61581_VER_RES - 1) >> 8) & 0XFF);
r61581_data((R61581_VER_RES - 1) & 0XFF);
LV_DRV_DELAY_MS(10);
r61581_cmd(0x29);
LV_DRV_DELAY_MS(5);
r61581_cmd(0x2C);
LV_DRV_DELAY_MS(5);
}
/**
* Command mode
*/
static inline void r61581_cmd_mode(void)
{
if(cmd_mode == false) {
LV_DRV_DISP_CMD_DATA(R61581_CMD_MODE)
cmd_mode = true;
}
}
/**
* Data mode
*/
static inline void r61581_data_mode(void)
{
if(cmd_mode != false) {
LV_DRV_DISP_CMD_DATA(R61581_DATA_MODE);
cmd_mode = false;
}
}
/**
* Write command
* @param cmd the command
*/
static inline void r61581_cmd(uint8_t cmd)
{
r61581_cmd_mode();
LV_DRV_DISP_PAR_WR_WORD(cmd);
}
/**
* Write data
* @param data the data
*/
static inline void r61581_data(uint8_t data)
{
r61581_data_mode();
LV_DRV_DISP_PAR_WR_WORD(data);
}
#endif

View File

@ -1,57 +0,0 @@
/**
* @file R61581.h
*
*/
#ifndef R61581_H
#define R61581_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_R61581
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void r61581_init(void);
void r61581_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
void r61581_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
void r61581_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
/**********************
* MACROS
**********************/
#endif /* USE_R61581 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* R61581_H */

View File

@ -1,182 +0,0 @@
/**
* @file SHARP_MIP.c
*
*/
/*-------------------------------------------------------------------------------------------------
* SHARP memory in pixel monochrome display series
* LS012B7DD01 (184x38 pixels.)
* LS013B7DH03 (128x128 pixels.)
* LS013B7DH05 (144x168 pixels.)
* LS027B7DH01 (400x240 pixels.) (tested)
* LS032B7DD02 (336x536 pixels.)
* LS044Q7DH01 (320x240 pixels.)
*
* These displays need periodic com inversion, there are two ways :
* - software com inversion :
* define SHARP_MIP_SOFT_COM_INVERSION 1 and set EXTMODE display pin LOW,
* call sharp_mip_com_inversion() periodically
* - hardware com inversion with EXTCOMIN display pin :
* define SHARP_MIP_SOFT_COM_INVERSION 0,
* set EXTMODE display pin HIGH and handle
* EXTCOMIN waveform (for example with mcu pwm output),
* see datasheet pages 8-12 for details
*
* VDB size : (LV_VER_RES / X) * (2 + LV_HOR_RES / 8) + 2 bytes, structure :
* [FRAME_HEADER (1 byte)] [GATE_ADDR (1 byte )] [LINE_DATA (LV_HOR_RES / 8 bytes)] 1st line
* [DUMMY (1 byte)] [GATE_ADDR (1 byte )] [LINE_DATA (LV_HOR_RES / 8 bytes)] 2nd line
* ...........................................................................................
* [DUMMY (1 byte)] [GATE_ADDR (1 byte )] [LINE_DATA (LV_HOR_RES / 8 bytes)] last line
* [DUMMY (2 bytes)]
*
* Since extra bytes (dummy, addresses, header) are stored in VDB, we need to use
* an "oversized" VDB. Buffer declaration in "lv_port_disp.c" becomes for example :
* static lv_disp_buf_t disp_buf;
* static uint8_t buf[(LV_VER_RES_MAX / X) * (2 + (LV_HOR_RES_MAX / 8)) + 2];
* lv_disp_buf_init(&disp_buf, buf, NULL, LV_VER_RES_MAX * LV_HOR_RES_MAX / X);
*-----------------------------------------------------------------------------------------------*/
/*********************
* INCLUDES
*********************/
#include "SHARP_MIP.h"
#if USE_SHARP_MIP
#include <stdbool.h>
#include LV_DRV_DISP_INCLUDE
#include LV_DRV_DELAY_INCLUDE
/*********************
* DEFINES
*********************/
#define SHARP_MIP_HEADER 0
#define SHARP_MIP_UPDATE_RAM_FLAG (1 << 7) /* (M0) Mode flag : H -> update memory, L -> maintain memory */
#define SHARP_MIP_COM_INVERSION_FLAG (1 << 6) /* (M1) Frame inversion flag : relevant when EXTMODE = L, */
/* H -> outputs VCOM = H, L -> outputs VCOM = L */
#define SHARP_MIP_CLEAR_SCREEN_FLAG (1 << 5) /* (M2) All clear flag : H -> clear all pixels */
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
#if SHARP_MIP_SOFT_COM_INVERSION
static bool_t com_output_state = false;
#endif
/**********************
* MACROS
**********************/
/*
* Return the VDB byte index corresponding to the pixel
* relatives coordinates (x, y) in the area.
* The area is rounded to a whole screen line.
*/
#define BUFIDX(x, y) (((x) >> 3) + ((y) * (2 + (SHARP_MIP_HOR_RES >> 3))) + 2)
/*
* Return the byte bitmask of a pixel bit corresponding
* to VDB arrangement (8 pixels per byte on lines).
*/
#define PIXIDX(x) SHARP_MIP_REV_BYTE(1 << ((x) & 7))
/**********************
* GLOBAL FUNCTIONS
**********************/
void sharp_mip_init(void) {
/* These displays have nothing to initialize */
}
void sharp_mip_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) {
/*Return if the area is out the screen*/
if(area->y2 < 0) return;
if(area->y1 > SHARP_MIP_VER_RES - 1) return;
/*Truncate the area to the screen*/
uint16_t act_y1 = area->y1 < 0 ? 0 : area->y1;
uint16_t act_y2 = area->y2 > SHARP_MIP_VER_RES - 1 ? SHARP_MIP_VER_RES - 1 : area->y2;
uint8_t * buf = (uint8_t *) color_p; /*Get the buffer address*/
uint16_t buf_h = (act_y2 - act_y1 + 1); /*Number of buffer lines*/
uint16_t buf_size = buf_h * (2 + SHARP_MIP_HOR_RES / 8) + 2; /*Buffer size in bytes */
/* Set lines to flush dummy byte & gate address in VDB*/
for(uint16_t act_y = 0 ; act_y < buf_h ; act_y++) {
buf[BUFIDX(0, act_y) - 1] = SHARP_MIP_REV_BYTE((act_y1 + act_y + 1));
buf[BUFIDX(0, act_y) - 2] = 0;
}
/* Set last dummy two bytes in VDB */
buf[BUFIDX(0, buf_h) - 1] = 0;
buf[BUFIDX(0, buf_h) - 2] = 0;
/* Set frame header in VDB */
buf[0] = SHARP_MIP_HEADER |
SHARP_MIP_UPDATE_RAM_FLAG;
/* Write the frame on display memory */
LV_DRV_DISP_SPI_CS(1);
LV_DRV_DISP_SPI_WR_ARRAY(buf, buf_size);
LV_DRV_DISP_SPI_CS(0);
lv_disp_flush_ready(disp_drv);
}
void sharp_mip_set_px(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa) {
(void) disp_drv;
(void) buf_w;
(void) opa;
if (lv_color_to1(color) != 0) {
buf[BUFIDX(x, y)] |= PIXIDX(x); /*Set VDB pixel bit to 1 for other colors than BLACK*/
} else {
buf[BUFIDX(x, y)] &= ~PIXIDX(x); /*Set VDB pixel bit to 0 for BLACK color*/
}
}
void sharp_mip_rounder(lv_disp_drv_t * disp_drv, lv_area_t * area) {
(void) disp_drv;
/* Round area to a whole line */
area->x1 = 0;
area->x2 = SHARP_MIP_HOR_RES - 1;
}
#if SHARP_MIP_SOFT_COM_INVERSION
void sharp_mip_com_inversion(void) {
uint8_t inversion_header[2] = {0};
/* Set inversion header */
if (com_output_state) {
com_output_state = false;
} else {
inversion_header[0] |= SHARP_MIP_COM_INVERSION_FLAG;
com_output_state = true;
}
/* Write inversion header on display memory */
LV_DRV_DISP_SPI_CS(1);
LV_DRV_DISP_SPI_WR_ARRAY(inversion_header, 2);
LV_DRV_DISP_SPI_CS(0);
}
#endif
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,63 +0,0 @@
/**
* @file SHARP_MIP.h
*
*/
#ifndef SHARP_MIP_H
#define SHARP_MIP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_SHARP_MIP
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void sharp_mip_init(void);
void sharp_mip_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
void sharp_mip_rounder(lv_disp_drv_t * disp_drv, lv_area_t * area);
void sharp_mip_set_px(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa);
#if SHARP_MIP_SOFT_COM_INVERSION
void sharp_mip_com_inversion(void);
#endif
/**********************
* MACROS
**********************/
#endif /* USE_SHARP_MIP */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SHARP_MIP_H */

View File

@ -1,292 +0,0 @@
/**
* @file SSD1963.c
*
*/
/*********************
* INCLUDES
*********************/
#include "SSD1963.h"
#if USE_SSD1963
#include <stdbool.h>
#include LV_DRV_DISP_INCLUDE
#include LV_DRV_DELAY_INCLUDE
/*********************
* DEFINES
*********************/
#define SSD1963_CMD_MODE 0
#define SSD1963_DATA_MODE 1
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static inline void ssd1963_cmd_mode(void);
static inline void ssd1963_data_mode(void);
static inline void ssd1963_cmd(uint8_t cmd);
static inline void ssd1963_data(uint8_t data);
static void ssd1963_io_init(void);
static void ssd1963_reset(void);
static void ssd1963_set_clk(void);
static void ssd1963_set_tft_spec(void);
static void ssd1963_init_bl(void);
/**********************
* STATIC VARIABLES
**********************/
static bool cmd_mode = true;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void ssd1963_init(void)
{
LV_DRV_DISP_CMD_DATA(SSD1963_CMD_MODE);
cmd_mode = true;
LV_DRV_DELAY_MS(250);
ssd1963_cmd(0x00E2); //PLL multiplier, set PLL clock to 120M
ssd1963_data(0x0023); //N=0x36 for 6.5M, 0x23 for 10M crystal
ssd1963_data(0x0002);
ssd1963_data(0x0004);
ssd1963_cmd(0x00E0); // PLL enable
ssd1963_data(0x0001);
LV_DRV_DELAY_MS(1);
ssd1963_cmd(0x00E0);
ssd1963_data(0x0003); // now, use PLL output as system clock
LV_DRV_DELAY_MS(1);
ssd1963_cmd(0x0001); // software reset
LV_DRV_DELAY_MS(1);
ssd1963_cmd(0x00E6); //PLL setting for PCLK, depends on resolution
ssd1963_data(0x0001); //HX8257C
ssd1963_data(0x0033); //HX8257C
ssd1963_data(0x0033); //HX8257C
ssd1963_cmd(0x00B0); //LCD SPECIFICATION
ssd1963_data(0x0020);
ssd1963_data(0x0000);
ssd1963_data(((SSD1963_HOR_RES - 1) >> 8) & 0X00FF); //Set HDP
ssd1963_data((SSD1963_HOR_RES - 1) & 0X00FF);
ssd1963_data(((SSD1963_VER_RES - 1) >> 8) & 0X00FF); //Set VDP
ssd1963_data((SSD1963_VER_RES - 1) & 0X00FF);
ssd1963_data(0x0000);
LV_DRV_DELAY_MS(1);//Delay10us(5);
ssd1963_cmd(0x00B4); //HSYNC
ssd1963_data((SSD1963_HT >> 8) & 0X00FF); //Set HT
ssd1963_data(SSD1963_HT & 0X00FF);
ssd1963_data((SSD1963_HPS >> 8) & 0X00FF); //Set HPS
ssd1963_data(SSD1963_HPS & 0X00FF);
ssd1963_data(SSD1963_HPW); //Set HPW
ssd1963_data((SSD1963_LPS >> 8) & 0X00FF); //SetLPS
ssd1963_data(SSD1963_LPS & 0X00FF);
ssd1963_data(0x0000);
ssd1963_cmd(0x00B6); //VSYNC
ssd1963_data((SSD1963_VT >> 8) & 0X00FF); //Set VT
ssd1963_data(SSD1963_VT & 0X00FF);
ssd1963_data((SSD1963_VPS >> 8) & 0X00FF); //Set VPS
ssd1963_data(SSD1963_VPS & 0X00FF);
ssd1963_data(SSD1963_VPW); //Set VPW
ssd1963_data((SSD1963_FPS >> 8) & 0X00FF); //Set FPS
ssd1963_data(SSD1963_FPS & 0X00FF);
ssd1963_cmd(0x00B8);
ssd1963_data(0x000f); //GPIO is controlled by host GPIO[3:0]=output GPIO[0]=1 LCD ON GPIO[0]=1 LCD OFF
ssd1963_data(0x0001); //GPIO0 normal
ssd1963_cmd(0x00BA);
ssd1963_data(0x0001); //GPIO[0] out 1 --- LCD display on/off control PIN
ssd1963_cmd(0x0036); //rotation
ssd1963_data(0x0008); //RGB=BGR
ssd1963_cmd(0x003A); //Set the current pixel format for RGB image data
ssd1963_data(0x0050); //16-bit/pixel
ssd1963_cmd(0x00F0); //Pixel Data Interface Format
ssd1963_data(0x0003); //16-bit(565 format) data
ssd1963_cmd(0x00BC);
ssd1963_data(0x0040); //contrast value
ssd1963_data(0x0080); //brightness value
ssd1963_data(0x0040); //saturation value
ssd1963_data(0x0001); //Post Processor Enable
LV_DRV_DELAY_MS(1);
ssd1963_cmd(0x0029); //display on
ssd1963_cmd(0x00BE); //set PWM for B/L
ssd1963_data(0x0006);
ssd1963_data(0x0080);
ssd1963_data(0x0001);
ssd1963_data(0x00f0);
ssd1963_data(0x0000);
ssd1963_data(0x0000);
ssd1963_cmd(0x00d0);
ssd1963_data(0x000d);
//DisplayBacklightOn();
LV_DRV_DELAY_MS(30);
}
void ssd1963_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
/*Return if the area is out the screen*/
if(area->x2 < 0) return;
if(area->y2 < 0) return;
if(area->x1 > SSD1963_HOR_RES - 1) return;
if(area->y1 > SSD1963_VER_RES - 1) return;
/*Truncate the area to the screen*/
int32_t act_x1 = area->x1 < 0 ? 0 : area->x1;
int32_t act_y1 = area->y1 < 0 ? 0 : area->y1;
int32_t act_x2 = area->x2 > SSD1963_HOR_RES - 1 ? SSD1963_HOR_RES - 1 : area->x2;
int32_t act_y2 = area->y2 > SSD1963_VER_RES - 1 ? SSD1963_VER_RES - 1 : area->y2;
//Set the rectangular area
ssd1963_cmd(0x002A);
ssd1963_data(act_x1 >> 8);
ssd1963_data(0x00FF & act_x1);
ssd1963_data(act_x2 >> 8);
ssd1963_data(0x00FF & act_x2);
ssd1963_cmd(0x002B);
ssd1963_data(act_y1 >> 8);
ssd1963_data(0x00FF & act_y1);
ssd1963_data(act_y2 >> 8);
ssd1963_data(0x00FF & act_y2);
ssd1963_cmd(0x2c);
int16_t i;
uint16_t full_w = area->x2 - area->x1 + 1;
ssd1963_data_mode();
LV_DRV_DISP_PAR_CS(0);
#if LV_COLOR_DEPTH == 16
uint16_t act_w = act_x2 - act_x1 + 1;
for(i = act_y1; i <= act_y2; i++) {
LV_DRV_DISP_PAR_WR_ARRAY((uint16_t *)color_p, act_w);
color_p += full_w;
}
LV_DRV_DISP_PAR_CS(1);
#else
int16_t j;
for(i = act_y1; i <= act_y2; i++) {
for(j = 0; j <= act_x2 - act_x1 + 1; j++) {
LV_DRV_DISP_PAR_WR_WORD(color_p[j]);
color_p += full_w;
}
}
#endif
lv_disp_flush_ready(disp_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void ssd1963_io_init(void)
{
LV_DRV_DISP_CMD_DATA(SSD1963_CMD_MODE);
cmd_mode = true;
}
static void ssd1963_reset(void)
{
/*Hardware reset*/
LV_DRV_DISP_RST(1);
LV_DRV_DELAY_MS(50);
LV_DRV_DISP_RST(0);
LV_DRV_DELAY_MS(50);
LV_DRV_DISP_RST(1);
LV_DRV_DELAY_MS(50);
/*Chip enable*/
LV_DRV_DISP_PAR_CS(0);
LV_DRV_DELAY_MS(10);
LV_DRV_DISP_PAR_CS(1);
LV_DRV_DELAY_MS(5);
/*Software reset*/
ssd1963_cmd(0x01);
LV_DRV_DELAY_MS(20);
ssd1963_cmd(0x01);
LV_DRV_DELAY_MS(20);
ssd1963_cmd(0x01);
LV_DRV_DELAY_MS(20);
}
/**
* Command mode
*/
static inline void ssd1963_cmd_mode(void)
{
if(cmd_mode == false) {
LV_DRV_DISP_CMD_DATA(SSD1963_CMD_MODE);
cmd_mode = true;
}
}
/**
* Data mode
*/
static inline void ssd1963_data_mode(void)
{
if(cmd_mode != false) {
LV_DRV_DISP_CMD_DATA(SSD1963_DATA_MODE);
cmd_mode = false;
}
}
/**
* Write command
* @param cmd the command
*/
static inline void ssd1963_cmd(uint8_t cmd)
{
LV_DRV_DISP_PAR_CS(0);
ssd1963_cmd_mode();
LV_DRV_DISP_PAR_WR_WORD(cmd);
LV_DRV_DISP_PAR_CS(1);
}
/**
* Write data
* @param data the data
*/
static inline void ssd1963_data(uint8_t data)
{
LV_DRV_DISP_PAR_CS(0);
ssd1963_data_mode();
LV_DRV_DISP_PAR_WR_WORD(data);
LV_DRV_DISP_PAR_CS(1);
}
#endif

View File

@ -1,150 +0,0 @@
/**
* @file SSD1963.h
*
*/
#ifndef SSD1963_H
#define SSD1963_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_SSD1963
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
// SSD1963 command table
#define CMD_NOP 0x00 //No operation
#define CMD_SOFT_RESET 0x01 //Software reset
#define CMD_GET_PWR_MODE 0x0A //Get the current power mode
#define CMD_GET_ADDR_MODE 0x0B //Get the frame memory to the display panel read order
#define CMD_GET_PIXEL_FORMAT 0x0C //Get the current pixel format
#define CMD_GET_DISPLAY_MODE 0x0D //Returns the display mode
#define CMD_GET_SIGNAL_MODE 0x0E //
#define CMD_GET_DIAGNOSTIC 0x0F
#define CMD_ENT_SLEEP 0x10
#define CMD_EXIT_SLEEP 0x11
#define CMD_ENT_PARTIAL_MODE 0x12
#define CMD_ENT_NORMAL_MODE 0x13
#define CMD_EXIT_INVERT_MODE 0x20
#define CMD_ENT_INVERT_MODE 0x21
#define CMD_SET_GAMMA 0x26
#define CMD_BLANK_DISPLAY 0x28
#define CMD_ON_DISPLAY 0x29
#define CMD_SET_COLUMN 0x2A
#define CMD_SET_PAGE 0x2B
#define CMD_WR_MEMSTART 0x2C
#define CMD_RD_MEMSTART 0x2E
#define CMD_SET_PARTIAL_AREA 0x30
#define CMD_SET_SCROLL_AREA 0x33
#define CMD_SET_TEAR_OFF 0x34 //synchronization information is not sent from the display
#define CMD_SET_TEAR_ON 0x35 //sync. information is sent from the display
#define CMD_SET_ADDR_MODE 0x36 //set fram buffer read order to the display panel
#define CMD_SET_SCROLL_START 0x37
#define CMD_EXIT_IDLE_MODE 0x38
#define CMD_ENT_IDLE_MODE 0x39
#define CMD_SET_PIXEL_FORMAT 0x3A //defines how many bits per pixel is used
#define CMD_WR_MEM_AUTO 0x3C
#define CMD_RD_MEM_AUTO 0x3E
#define CMD_SET_TEAR_SCANLINE 0x44
#define CMD_GET_SCANLINE 0x45
#define CMD_RD_DDB_START 0xA1
#define CMD_RD_DDB_AUTO 0xA8
#define CMD_SET_PANEL_MODE 0xB0
#define CMD_GET_PANEL_MODE 0xB1
#define CMD_SET_HOR_PERIOD 0xB4
#define CMD_GET_HOR_PERIOD 0xB5
#define CMD_SET_VER_PERIOD 0xB6
#define CMD_GET_VER_PERIOD 0xB7
#define CMD_SET_GPIO_CONF 0xB8
#define CMD_GET_GPIO_CONF 0xB9
#define CMD_SET_GPIO_VAL 0xBA
#define CMD_GET_GPIO_STATUS 0xBB
#define CMD_SET_POST_PROC 0xBC
#define CMD_GET_POST_PROC 0xBD
#define CMD_SET_PWM_CONF 0xBE
#define CMD_GET_PWM_CONF 0xBF
#define CMD_SET_LCD_GEN0 0xC0
#define CMD_GET_LCD_GEN0 0xC1
#define CMD_SET_LCD_GEN1 0xC2
#define CMD_GET_LCD_GEN1 0xC3
#define CMD_SET_LCD_GEN2 0xC4
#define CMD_GET_LCD_GEN2 0xC5
#define CMD_SET_LCD_GEN3 0xC6
#define CMD_GET_LCD_GEN3 0xC7
#define CMD_SET_GPIO0_ROP 0xC8
#define CMD_GET_GPIO0_ROP 0xC9
#define CMD_SET_GPIO1_ROP 0xCA
#define CMD_GET_GPIO1_ROP 0xCB
#define CMD_SET_GPIO2_ROP 0xCC
#define CMD_GET_GPIO2_ROP 0xCD
#define CMD_SET_GPIO3_ROP 0xCE
#define CMD_GET_GPIO3_ROP 0xCF
#define CMD_SET_ABC_DBC_CONF 0xD0
#define CMD_GET_ABC_DBC_CONF 0xD1
#define CMD_SET_DBC_HISTO_PTR 0xD2
#define CMD_GET_DBC_HISTO_PTR 0xD3
#define CMD_SET_DBC_THRES 0xD4
#define CMD_GET_DBC_THRES 0xD5
#define CMD_SET_ABM_TMR 0xD6
#define CMD_GET_ABM_TMR 0xD7
#define CMD_SET_AMB_LVL0 0xD8
#define CMD_GET_AMB_LVL0 0xD9
#define CMD_SET_AMB_LVL1 0xDA
#define CMD_GET_AMB_LVL1 0xDB
#define CMD_SET_AMB_LVL2 0xDC
#define CMD_GET_AMB_LVL2 0xDD
#define CMD_SET_AMB_LVL3 0xDE
#define CMD_GET_AMB_LVL3 0xDF
#define CMD_PLL_START 0xE0 //start the PLL
#define CMD_PLL_STOP 0xE1 //disable the PLL
#define CMD_SET_PLL_MN 0xE2
#define CMD_GET_PLL_MN 0xE3
#define CMD_GET_PLL_STATUS 0xE4 //get the current PLL status
#define CMD_ENT_DEEP_SLEEP 0xE5
#define CMD_SET_PCLK 0xE6 //set pixel clock (LSHIFT signal) frequency
#define CMD_GET_PCLK 0xE7 //get pixel clock (LSHIFT signal) freq. settings
#define CMD_SET_DATA_INTERFACE 0xF0
#define CMD_GET_DATA_INTERFACE 0xF1
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void ssd1963_init(void);
void ssd1963_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
/**********************
* MACROS
**********************/
#endif /* USE_SSD1963 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SSD1963_H */

View File

@ -1,289 +0,0 @@
/**
* @file ST7565.c
*
*/
/*********************
* INCLUDES
*********************/
#include "ST7565.h"
#if USE_ST7565
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "lvgl/lv_core/lv_vdb.h"
#include LV_DRV_DISP_INCLUDE
#include LV_DRV_DELAY_INCLUDE
/*********************
* DEFINES
*********************/
#define ST7565_BAUD 2000000 /*< 2,5 MHz (400 ns)*/
#define ST7565_CMD_MODE 0
#define ST7565_DATA_MODE 1
#define ST7565_HOR_RES 128
#define ST7565_VER_RES 64
#define CMD_DISPLAY_OFF 0xAE
#define CMD_DISPLAY_ON 0xAF
#define CMD_SET_DISP_START_LINE 0x40
#define CMD_SET_PAGE 0xB0
#define CMD_SET_COLUMN_UPPER 0x10
#define CMD_SET_COLUMN_LOWER 0x00
#define CMD_SET_ADC_NORMAL 0xA0
#define CMD_SET_ADC_REVERSE 0xA1
#define CMD_SET_DISP_NORMAL 0xA6
#define CMD_SET_DISP_REVERSE 0xA7
#define CMD_SET_ALLPTS_NORMAL 0xA4
#define CMD_SET_ALLPTS_ON 0xA5
#define CMD_SET_BIAS_9 0xA2
#define CMD_SET_BIAS_7 0xA3
#define CMD_RMW 0xE0
#define CMD_RMW_CLEAR 0xEE
#define CMD_INTERNAL_RESET 0xE2
#define CMD_SET_COM_NORMAL 0xC0
#define CMD_SET_COM_REVERSE 0xC8
#define CMD_SET_POWER_CONTROL 0x28
#define CMD_SET_RESISTOR_RATIO 0x20
#define CMD_SET_VOLUME_FIRST 0x81
#define CMD_SET_VOLUME_SECOND 0x00
#define CMD_SET_STATIC_OFF 0xAC
#define CMD_SET_STATIC_ON 0xAD
#define CMD_SET_STATIC_REG 0x00
#define CMD_SET_BOOSTER_FIRST 0xF8
#define CMD_SET_BOOSTER_234 0x00
#define CMD_SET_BOOSTER_5 0x01
#define CMD_SET_BOOSTER_6 0x03
#define CMD_NOP 0xE3
#define CMD_TEST 0xF0
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void st7565_sync(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
static void st7565_command(uint8_t cmd);
static void st7565_data(uint8_t data);
/**********************
* STATIC VARIABLES
**********************/
static uint8_t lcd_fb[ST7565_HOR_RES * ST7565_VER_RES / 8] = {0xAA, 0xAA};
static uint8_t pagemap[] = { 7, 6, 5, 4, 3, 2, 1, 0 };
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the ST7565
*/
void st7565_init(void)
{
LV_DRV_DISP_RST(1);
LV_DRV_DELAY_MS(10);
LV_DRV_DISP_RST(0);
LV_DRV_DELAY_MS(10);
LV_DRV_DISP_RST(1);
LV_DRV_DELAY_MS(10);
LV_DRV_DISP_SPI_CS(0);
st7565_command(CMD_SET_BIAS_7);
st7565_command(CMD_SET_ADC_NORMAL);
st7565_command(CMD_SET_COM_NORMAL);
st7565_command(CMD_SET_DISP_START_LINE);
st7565_command(CMD_SET_POWER_CONTROL | 0x4);
LV_DRV_DELAY_MS(50);
st7565_command(CMD_SET_POWER_CONTROL | 0x6);
LV_DRV_DELAY_MS(50);
st7565_command(CMD_SET_POWER_CONTROL | 0x7);
LV_DRV_DELAY_MS(10);
st7565_command(CMD_SET_RESISTOR_RATIO | 0x6); // Defaulted to 0x26 (but could also be between 0x20-0x27 based on display's specs)
st7565_command(CMD_DISPLAY_ON);
st7565_command(CMD_SET_ALLPTS_NORMAL);
/*Set brightness*/
st7565_command(CMD_SET_VOLUME_FIRST);
st7565_command(CMD_SET_VOLUME_SECOND | (0x18 & 0x3f));
LV_DRV_DISP_SPI_CS(1);
memset(lcd_fb, 0x00, sizeof(lcd_fb));
}
void st7565_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
{
/*Return if the area is out the screen*/
if(x2 < 0) return;
if(y2 < 0) return;
if(x1 > ST7565_HOR_RES - 1) return;
if(y1 > ST7565_VER_RES - 1) return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > ST7565_HOR_RES - 1 ? ST7565_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > ST7565_VER_RES - 1 ? ST7565_VER_RES - 1 : y2;
int32_t x, y;
/*Set the first row in */
/*Refresh frame buffer*/
for(y = act_y1; y <= act_y2; y++) {
for(x = act_x1; x <= act_x2; x++) {
if(lv_color_to1(*color_p) != 0) {
lcd_fb[x + (y / 8)*ST7565_HOR_RES] &= ~(1 << (7 - (y % 8)));
} else {
lcd_fb[x + (y / 8)*ST7565_HOR_RES] |= (1 << (7 - (y % 8)));
}
color_p ++;
}
color_p += x2 - act_x2; /*Next row*/
}
st7565_sync(act_x1, act_y1, act_x2, act_y2);
lv_flush_ready();
}
void st7565_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
{
/*Return if the area is out the screen*/
if(x2 < 0) return;
if(y2 < 0) return;
if(x1 > ST7565_HOR_RES - 1) return;
if(y1 > ST7565_VER_RES - 1) return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > ST7565_HOR_RES - 1 ? ST7565_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > ST7565_VER_RES - 1 ? ST7565_VER_RES - 1 : y2;
int32_t x, y;
uint8_t white = lv_color_to1(color);
/*Refresh frame buffer*/
for(y = act_y1; y <= act_y2; y++) {
for(x = act_x1; x <= act_x2; x++) {
if(white != 0) {
lcd_fb[x + (y / 8)*ST7565_HOR_RES] |= (1 << (7 - (y % 8)));
} else {
lcd_fb[x + (y / 8)*ST7565_HOR_RES] &= ~(1 << (7 - (y % 8)));
}
}
}
st7565_sync(act_x1, act_y1, act_x2, act_y2);
}
void st7565_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
{
/*Return if the area is out the screen*/
if(x2 < 0) return;
if(y2 < 0) return;
if(x1 > ST7565_HOR_RES - 1) return;
if(y1 > ST7565_VER_RES - 1) return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > ST7565_HOR_RES - 1 ? ST7565_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > ST7565_VER_RES - 1 ? ST7565_VER_RES - 1 : y2;
int32_t x, y;
/*Set the first row in */
/*Refresh frame buffer*/
for(y = act_y1; y <= act_y2; y++) {
for(x = act_x1; x <= act_x2; x++) {
if(lv_color_to1(*color_p) != 0) {
lcd_fb[x + (y / 8)*ST7565_HOR_RES] &= ~(1 << (7 - (y % 8)));
} else {
lcd_fb[x + (y / 8)*ST7565_HOR_RES] |= (1 << (7 - (y % 8)));
}
color_p ++;
}
color_p += x2 - act_x2; /*Next row*/
}
st7565_sync(act_x1, act_y1, act_x2, act_y2);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Flush a specific part of the buffer to the display
* @param x1 left coordinate of the area to flush
* @param y1 top coordinate of the area to flush
* @param x2 right coordinate of the area to flush
* @param y2 bottom coordinate of the area to flush
*/
static void st7565_sync(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
LV_DRV_DISP_SPI_CS(0);
uint8_t c, p;
for(p = y1 / 8; p <= y2 / 8; p++) {
st7565_command(CMD_SET_PAGE | pagemap[p]);
st7565_command(CMD_SET_COLUMN_LOWER | (x1 & 0xf));
st7565_command(CMD_SET_COLUMN_UPPER | ((x1 >> 4) & 0xf));
st7565_command(CMD_RMW);
for(c = x1; c <= x2; c++) {
st7565_data(lcd_fb[(ST7565_HOR_RES * p) + c]);
}
}
LV_DRV_DISP_SPI_CS(1);
}
/**
* Write a command to the ST7565
* @param cmd the command
*/
static void st7565_command(uint8_t cmd)
{
LV_DRV_DISP_CMD_DATA(ST7565_CMD_MODE);
LV_DRV_DISP_SPI_WR_BYTE(cmd);
}
/**
* Write data to the ST7565
* @param data the data
*/
static void st7565_data(uint8_t data)
{
LV_DRV_DISP_CMD_DATA(ST7565_DATA_MODE);
LV_DRV_DISP_SPI_WR_BYTE(data);
}
#endif

View File

@ -1,58 +0,0 @@
/**
* @file ST7565.h
*
*/
#ifndef ST7565_H
#define ST7565_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_ST7565
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void st7565_init(void);
void st7565_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
void st7565_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
void st7565_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
/**********************
* MACROS
**********************/
#endif /* USE_ST7565 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* ST7565_H */

View File

@ -1,206 +0,0 @@
/**
* @file UC1610.c
*
*/
/*********************
* INCLUDES
*********************/
#include "UC1610.h"
#if USE_UC1610
#include <stdbool.h>
#include LV_DRV_DISP_INCLUDE
#include LV_DRV_DELAY_INCLUDE
/*********************
* DEFINES
*********************/
#define UC1610_CMD_MODE 0
#define UC1610_DATA_MODE 1
#define UC1610_RESET_MODE 0
#define UC1610_SET_MODE 1
/* hardware control commands */
#define UC1610_SYSTEM_RESET 0xE2 /* software reset */
#define UC1610_NOP 0xE3
#define UC1610_SET_TEMP_COMP 0x24 /* set temperature compensation, default -0.05%/°C */
#define UC1610_SET_PANEL_LOADING 0x29 /* set panel loading, default 16~21 nF */
#define UC1610_SET_PUMP_CONTROL 0x2F /* default internal Vlcd (8x pump) */
#define UC1610_SET_LCD_BIAS_RATIO 0xEB /* default 11 */
#define UC1610_SET_VBIAS_POT 0x81 /* 1 byte (0~255) to follow setting the contrast, default 0x81 */
#define UC1610_SET_LINE_RATE 0xA0 /* default 12,1 Klps */
#define UC1610_SET_DISPLAY_ENABLE 0xAE /* + 1 / 0 : exit sleep mode / entering sleep mode */
#define UC1610_SET_LCD_GRAY_SHADE 0xD0 /* default 24% between the two gray shade levels */
#define UC1610_SET_COM_END 0xF1 /* set the number of used com electrodes (lines number -1) */
/* ram address control */
#define UC1610_SET_AC 0x88 /* set ram address control */
#define UC1610_AC_WA_FLAG 1 /* automatic column/page increment wrap around (1 : cycle increment) */
#define UC1610_AC_AIO_FLAG (1 << 1) /* auto increment order (0/1 : column/page increment first) */
#define UC1610_AC_PID_FLAG (1 << 2) /* page address auto increment order (0/1 : +1/-1) */
/* set cursor ram address */
#define UC1610_SET_CA_LSB 0x00 /* + 4 LSB bits */
#define UC1610_SET_CA_MSB 0x10 /* + 4 MSB bits // MSB + LSB values range : 0~159 */
#define UC1610_SET_PA 0x60 /* + 5 bits // values range : 0~26 */
/* display control commands */
#define UC1610_SET_FIXED_LINES 0x90 /* + 4 bits = 2xFL */
#define UC1610_SET_SCROLL_LINES_LSB 0x40 /* + 4 LSB bits scroll up display by N (7 bits) lines */
#define UC1610_SET_SCROLL_LINES_MSB 0x50 /* + 3 MSB bits */
#define UC1610_SET_ALL_PIXEL_ON 0xA4 /* + 1 / 0 : set all pixel on, reverse */
#define UC1610_SET_INVERSE_DISPLAY 0xA6 /* + 1 / 0 : inverse all data stored in ram, reverse */
#define UC1610_SET_MAPPING_CONTROL 0xC0 /* control mirorring */
#define UC1610_SET_MAPPING_CONTROL_LC_FLAG 1
#define UC1610_SET_MAPPING_CONTROL_MX_FLAG (1 << 1)
#define UC1610_SET_MAPPING_CONTROL_MY_FLAG (1 << 2)
/* window program mode */
#define UC1610_SET_WINDOW_PROGRAM_ENABLE 0xF8 /* + 1 / 0 : enable / disable window programming mode, */
/* reset before changing boundaries */
#define UC1610_SET_WP_STARTING_CA 0xF4 /* 1 byte to follow for column address */
#define UC1610_SET_WP_ENDING_CA 0xF6 /* 1 byte to follow for column address */
#define UC1610_SET_WP_STARTING_PA 0xF5 /* 1 byte to follow for page address */
#define UC1610_SET_WP_ENDING_PA 0xF7 /* 1 byte to follow for page address */
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static uint8_t cmd_buf[12];
/**********************
* MACROS
**********************/
/* Return the byte bitmask of a pixel color corresponding to VDB arrangement */
#define PIXIDX(y, c) ((c) << (((y) & 3) << 1))
/**********************
* GLOBAL FUNCTIONS
**********************/
void uc1610_init(void) {
LV_DRV_DELAY_MS(12);
/* initialization sequence */
#if UC1610_INIT_HARD_RST
LV_DRV_DISP_RST(UC1610_RESET_MODE); /* hardware reset */
LV_DRV_DELAY_MS(1);
LV_DRV_DISP_RST(UC1610_SET_MODE);
#else
cmd_buf[0] = UC1610_SYSTEM_RESET; /* software reset */
LV_DRV_DISP_CMD_DATA(UC1610_CMD_MODE);
LV_DRV_DISP_SPI_CS(0);
LV_DRV_DISP_SPI_WR_ARRAY(cmd_buf, 1);
LV_DRV_DISP_SPI_CS(1);
#endif
LV_DRV_DELAY_MS(2);
cmd_buf[0] = UC1610_SET_COM_END; /* set com end value */
cmd_buf[1] = UC1610_VER_RES - 1;
cmd_buf[2] = UC1610_SET_PANEL_LOADING;
cmd_buf[3] = UC1610_SET_LCD_BIAS_RATIO;
cmd_buf[4] = UC1610_SET_VBIAS_POT; /* set contrast */
cmd_buf[5] = (UC1610_INIT_CONTRAST * 255) / 100;
#if UC1610_TOP_VIEW
cmd_buf[6] = UC1610_SET_MAPPING_CONTROL | /* top view */
UC1610_SET_MAPPING_CONTROL_MY_FLAG |
UC1610_SET_MAPPING_CONTROL_MX_FLAG;
#else
cmd_buf[6] = UC1610_SET_MAPPING_CONTROL; /* bottom view */
#endif
cmd_buf[7] = UC1610_SET_SCROLL_LINES_LSB | 0; /* set scroll line on line 0 */
cmd_buf[8] = UC1610_SET_SCROLL_LINES_MSB | 0;
cmd_buf[9] = UC1610_SET_AC | UC1610_AC_WA_FLAG; /* set auto increment wrap around */
cmd_buf[10] = UC1610_SET_INVERSE_DISPLAY | 1; /* invert colors to complies lv color system */
cmd_buf[11] = UC1610_SET_DISPLAY_ENABLE | 1; /* turn display on */
LV_DRV_DISP_CMD_DATA(UC1610_CMD_MODE);
LV_DRV_DISP_SPI_CS(0);
LV_DRV_DISP_SPI_WR_ARRAY(cmd_buf, 12);
LV_DRV_DISP_SPI_CS(1);
}
void uc1610_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) {
/*Return if the area is out the screen*/
if(area->x2 < 0) return;
if(area->y2 < 0) return;
if(area->x1 > UC1610_HOR_RES - 1) return;
if(area->y1 > UC1610_VER_RES - 1) return;
/*Truncate the area to the screen*/
uint8_t act_x1 = area->x1 < 0 ? 0 : area->x1;
uint8_t act_y1 = area->y1 < 0 ? 0 : area->y1;
uint8_t act_x2 = area->x2 > UC1610_HOR_RES - 1 ? UC1610_HOR_RES - 1 : area->x2;
uint8_t act_y2 = area->y2 > UC1610_VER_RES - 1 ? UC1610_VER_RES - 1 : area->y2;
uint8_t * buf = (uint8_t *) color_p;
uint16_t buf_size = (act_x2 - act_x1 + 1) * (((act_y2 - act_y1) >> 2) + 1);
/*Set display window to fill*/
cmd_buf[0] = UC1610_SET_WINDOW_PROGRAM_ENABLE | 0; /* before changing boundaries */
cmd_buf[1] = UC1610_SET_WP_STARTING_CA;
cmd_buf[2] = act_x1;
cmd_buf[3] = UC1610_SET_WP_ENDING_CA;
cmd_buf[4] = act_x2;
cmd_buf[5] = UC1610_SET_WP_STARTING_PA;
cmd_buf[6] = act_y1 >> 2;
cmd_buf[7] = UC1610_SET_WP_ENDING_PA;
cmd_buf[8] = act_y2 >> 2;
cmd_buf[9] = UC1610_SET_WINDOW_PROGRAM_ENABLE | 1; /* entering window programming */
LV_DRV_DISP_CMD_DATA(UC1610_CMD_MODE);
LV_DRV_DISP_SPI_CS(0);
LV_DRV_DISP_SPI_WR_ARRAY(cmd_buf, 10);
LV_DRV_DISP_SPI_CS(1);
/*Flush VDB on display memory*/
LV_DRV_DISP_CMD_DATA(UC1610_DATA_MODE);
LV_DRV_DISP_SPI_CS(0);
LV_DRV_DISP_SPI_WR_ARRAY(buf, buf_size);
LV_DRV_DISP_SPI_CS(1);
lv_disp_flush_ready(disp_drv);
}
void uc1610_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa) {
(void) disp_drv;
(void) opa;
uint16_t idx = x + buf_w * (y >> 2);
/* Convert color to depth 2 */
#if LV_COLOR_DEPTH == 1
uint8_t color2 = color.full * 3;
#else
uint8_t color2 = color.full >> (LV_COLOR_DEPTH - 2);
#endif
buf[idx] &= ~PIXIDX(y, 3); /* reset pixel color */
buf[idx] |= PIXIDX(y, color2); /* write new color */
}
void uc1610_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area) {
(void) disp_drv;
/* Round y window to display memory page size */
area->y1 = (area->y1 & (~3));
area->y2 = (area->y2 & (~3)) + 3;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,58 +0,0 @@
/**
* @file UC1610.h
*
*/
#ifndef UC1610_H
#define UC1610_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_UC1610
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void uc1610_init(void);
void uc1610_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
void uc1610_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area);
void uc1610_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa);
/**********************
* MACROS
**********************/
#endif /* USE_UC1610 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UC1610_H */

View File

@ -1,12 +0,0 @@
CSRCS += fbdev.c
CSRCS += monitor.c
CSRCS += R61581.c
CSRCS += SSD1963.c
CSRCS += ST7565.c
CSRCS += UC1610.c
CSRCS += SHARP_MIP.c
DEPPATH += --dep-path $(LVGL_DIR)/lv_drivers/display
VPATH += :$(LVGL_DIR)/lv_drivers/display
CFLAGS += "-I$(LVGL_DIR)/lv_drivers/display"

View File

@ -1,241 +0,0 @@
/**
* @file fbdev.c
*
*/
/*********************
* INCLUDES
*********************/
#include "fbdev.h"
#if USE_FBDEV || USE_BSD_FBDEV
#include <stdlib.h>
#include <unistd.h>
#include <stddef.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#if USE_BSD_FBDEV
#include <sys/fcntl.h>
#include <sys/time.h>
#include <sys/consio.h>
#include <sys/fbio.h>
#else /* USE_BSD_FBDEV */
#include <linux/fb.h>
#endif /* USE_BSD_FBDEV */
/*********************
* DEFINES
*********************/
#ifndef FBDEV_PATH
#define FBDEV_PATH "/dev/fb0"
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STRUCTURES
**********************/
struct bsd_fb_var_info{
uint32_t xoffset;
uint32_t yoffset;
uint32_t xres;
uint32_t yres;
int bits_per_pixel;
};
struct bsd_fb_fix_info{
long int line_length;
};
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
#if USE_BSD_FBDEV
static struct bsd_fb_var_info vinfo;
static struct bsd_fb_fix_info finfo;
#else
static struct fb_var_screeninfo vinfo;
static struct fb_fix_screeninfo finfo;
#endif /* USE_BSD_FBDEV */
static char *fbp = 0;
static long int screensize = 0;
static int fbfd = 0;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void fbdev_init(void)
{
// Open the file for reading and writing
fbfd = open(FBDEV_PATH, O_RDWR);
if(fbfd == -1) {
perror("Error: cannot open framebuffer device");
return;
}
printf("The framebuffer device was opened successfully.\n");
#if USE_BSD_FBDEV
struct fbtype fb;
unsigned line_length;
//Get fb type
if (ioctl(fbfd, FBIOGTYPE, &fb) != 0) {
perror("ioctl(FBIOGTYPE)");
return;
}
//Get screen width
if (ioctl(fbfd, FBIO_GETLINEWIDTH, &line_length) != 0) {
perror("ioctl(FBIO_GETLINEWIDTH)");
return;
}
vinfo.xres = (unsigned) fb.fb_width;
vinfo.yres = (unsigned) fb.fb_height;
vinfo.bits_per_pixel = fb.fb_depth + 8;
vinfo.xoffset = 0;
vinfo.yoffset = 0;
finfo.line_length = line_length;
#else /* USE_BSD_FBDEV */
// Get fixed screen information
if(ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
perror("Error reading fixed information");
return;
}
// Get variable screen information
if(ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
perror("Error reading variable information");
return;
}
#endif /* USE_BSD_FBDEV */
printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
// Figure out the size of the screen in bytes
screensize = finfo.smem_len; //finfo.line_length * vinfo.yres;
// Map the device to memory
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
if((intptr_t)fbp == -1) {
perror("Error: failed to map framebuffer device to memory");
return;
}
memset(fbp, 0, screensize);
printf("The framebuffer device was mapped to memory successfully.\n");
}
void fbdev_exit(void)
{
close(fbfd);
}
/**
* Flush a buffer to the marked area
* @param drv pointer to driver where this function belongs
* @param area an area where to copy `color_p`
* @param color_p an array of pixel to copy to the `area` part of the screen
*/
void fbdev_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p)
{
if(fbp == NULL ||
area->x2 < 0 ||
area->y2 < 0 ||
area->x1 > (int32_t)vinfo.xres - 1 ||
area->y1 > (int32_t)vinfo.yres - 1) {
lv_disp_flush_ready(drv);
return;
}
/*Truncate the area to the screen*/
int32_t act_x1 = area->x1 < 0 ? 0 : area->x1;
int32_t act_y1 = area->y1 < 0 ? 0 : area->y1;
int32_t act_x2 = area->x2 > (int32_t)vinfo.xres - 1 ? (int32_t)vinfo.xres - 1 : area->x2;
int32_t act_y2 = area->y2 > (int32_t)vinfo.yres - 1 ? (int32_t)vinfo.yres - 1 : area->y2;
lv_coord_t w = lv_area_get_width(area);
long int location = 0;
long int byte_location = 0;
unsigned char bit_location = 0;
/*32 or 24 bit per pixel*/
if(vinfo.bits_per_pixel == 32 || vinfo.bits_per_pixel == 24) {
uint32_t * fbp32 = (uint32_t *)fbp;
int32_t y;
for(y = act_y1; y <= act_y2; y++) {
location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length / 4;
memcpy(&fbp32[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4);
color_p += w;
}
}
/*16 bit per pixel*/
else if(vinfo.bits_per_pixel == 16) {
uint16_t * fbp16 = (uint16_t *)fbp;
int32_t y;
for(y = act_y1; y <= act_y2; y++) {
location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length / 2;
memcpy(&fbp16[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 2);
color_p += w;
}
}
/*8 bit per pixel*/
else if(vinfo.bits_per_pixel == 8) {
uint8_t * fbp8 = (uint8_t *)fbp;
int32_t y;
for(y = act_y1; y <= act_y2; y++) {
location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length;
memcpy(&fbp8[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1));
color_p += w;
}
}
/*1 bit per pixel*/
else if(vinfo.bits_per_pixel == 1) {
uint8_t * fbp8 = (uint8_t *)fbp;
int32_t x;
int32_t y;
for(y = act_y1; y <= act_y2; y++) {
for(x = act_x1; x <= act_x2; x++) {
location = (x + vinfo.xoffset) + (y + vinfo.yoffset) * vinfo.xres;
byte_location = location / 8; /* find the byte we need to change */
bit_location = location % 8; /* inside the byte found, find the bit we need to change */
fbp8[byte_location] &= ~(((uint8_t)(1)) << bit_location);
fbp8[byte_location] |= ((uint8_t)(color_p->full)) << bit_location;
color_p++;
}
color_p += area->x2 - act_x2;
}
} else {
/*Not supported bit per pixel*/
}
//May be some direct update command is required
//ret = ioctl(state->fd, FBIO_UPDATE, (unsigned long)((uintptr_t)rect));
lv_disp_flush_ready(drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,58 +0,0 @@
/**
* @file fbdev.h
*
*/
#ifndef FBDEV_H
#define FBDEV_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_FBDEV || USE_BSD_FBDEV
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void fbdev_init(void);
void fbdev_exit(void);
void fbdev_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p);
/**********************
* MACROS
**********************/
#endif /*USE_FBDEV*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*FBDEV_H*/

View File

@ -1,415 +0,0 @@
/**
* @file monitor.c
*
*/
/*********************
* INCLUDES
*********************/
#include "monitor.h"
#if USE_MONITOR
#ifndef MONITOR_SDL_INCLUDE_PATH
# define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
#endif
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include MONITOR_SDL_INCLUDE_PATH
#include "../indev/mouse.h"
#include "../indev/keyboard.h"
#include "../indev/mousewheel.h"
/*********************
* DEFINES
*********************/
#define SDL_REFR_PERIOD 50 /*ms*/
#ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1
#endif
#ifndef MONITOR_HOR_RES
#define MONITOR_HOR_RES LV_HOR_RES
#endif
#ifndef MONITOR_VER_RES
#define MONITOR_VER_RES LV_VER_RES
#endif
#if defined(__APPLE__) && defined(TARGET_OS_MAC)
# if __APPLE__ && TARGET_OS_MAC
#define MONITOR_APPLE
# endif
#endif
#if defined(__EMSCRIPTEN__)
# define MONITOR_EMSCRIPTEN
#endif
/**********************
* TYPEDEFS
**********************/
typedef struct {
SDL_Window * window;
SDL_Renderer * renderer;
SDL_Texture * texture;
volatile bool sdl_refr_qry;
#if MONITOR_DOUBLE_BUFFERED
uint32_t * tft_fb_act;
#else
uint32_t tft_fb[LV_HOR_RES_MAX * LV_VER_RES_MAX];
#endif
}monitor_t;
/**********************
* STATIC PROTOTYPES
**********************/
static int monitor_sdl_refr_thread(void * param);
static void window_create(monitor_t * m);
static void window_update(monitor_t * m);
/***********************
* GLOBAL PROTOTYPES
***********************/
/**********************
* STATIC VARIABLES
**********************/
monitor_t monitor;
#if MONITOR_DUAL
monitor_t monitor2;
#endif
static volatile bool sdl_inited = false;
static volatile bool sdl_quit_qry = false;
int quit_filter(void * userdata, SDL_Event * event);
static void monitor_sdl_clean_up(void);
static void monitor_sdl_init(void);
#ifdef MONITOR_EMSCRIPTEN
void monitor_sdl_refr_core(void); /* called from Emscripten loop */
#else
static void monitor_sdl_refr_core(void);
#endif
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the monitor
*/
void monitor_init(void)
{
/*OSX needs to initialize SDL here*/
#if defined(MONITOR_APPLE) || defined(MONITOR_EMSCRIPTEN)
monitor_sdl_init();
#endif
#ifndef MONITOR_EMSCRIPTEN
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
while(sdl_inited == false); /*Wait until 'sdl_refr' initializes the SDL*/
#endif
}
/**
* Flush a buffer to the marked area
* @param drv pointer to driver where this function belongs
* @param area an area where to copy `color_p`
* @param color_p an array of pixel to copy to the `area` part of the screen
*/
void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
lv_coord_t hres = disp_drv->rotated == 0 ? disp_drv->hor_res : disp_drv->ver_res;
lv_coord_t vres = disp_drv->rotated == 0 ? disp_drv->ver_res : disp_drv->hor_res;
// printf("x1:%d,y1:%d,x2:%d,y2:%d\n", area->x1, area->y1, area->x2, area->y2);
/*Return if the area is out the screen*/
if(area->x2 < 0 || area->y2 < 0 || area->x1 > hres - 1 || area->y1 > vres - 1) {
lv_disp_flush_ready(disp_drv);
return;
}
#if MONITOR_DOUBLE_BUFFERED
monitor.tft_fb_act = (uint32_t *)color_p;
monitor.sdl_refr_qry = true;
/*IMPORTANT! It must be called to tell the system the flush is ready*/
lv_disp_flush_ready(disp_drv);
#else
int32_t y;
#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/
int32_t x;
for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) {
for(x = area->x1; x <= area->x2; x++) {
monitor.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p);
color_p++;
}
}
#else
uint32_t w = lv_area_get_width(area);
for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) {
memcpy(&monitor.tft_fb[y * MONITOR_HOR_RES + area->x1], color_p, w * sizeof(lv_color_t));
color_p += w;
}
#endif
monitor.sdl_refr_qry = true;
/*IMPORTANT! It must be called to tell the system the flush is ready*/
lv_disp_flush_ready(disp_drv);
#endif
}
#if MONITOR_DUAL
/**
* Flush a buffer to the marked area
* @param drv pointer to driver where this function belongs
* @param area an area where to copy `color_p`
* @param color_p an array of pixel to copy to the `area` part of the screen
*/
void monitor_flush2(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
lv_coord_t hres = disp_drv->rotated == 0 ? disp_drv->hor_res : disp_drv->ver_res;
lv_coord_t vres = disp_drv->rotated == 0 ? disp_drv->ver_res : disp_drv->hor_res;
/*Return if the area is out the screen*/
if(area->x2 < 0 || area->y2 < 0 || area->x1 > hres - 1 || area->y1 > vres - 1) {
lv_disp_flush_ready(disp_drv);
return;
}
#if MONITOR_DOUBLE_BUFFERED
monitor2.tft_fb_act = (uint32_t *)color_p;
monitor2.sdl_refr_qry = true;
/*IMPORTANT! It must be called to tell the system the flush is ready*/
lv_disp_flush_ready(disp_drv);
#else
int32_t y;
#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/
int32_t x;
for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) {
for(x = area->x1; x <= area->x2; x++) {
monitor2.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p);
color_p++;
}
}
#else
uint32_t w = lv_area_get_width(area);
for(y = area->y1; y <= area->y2 && y < disp_drv->ver_res; y++) {
memcpy(&monitor2.tft_fb[y * disp_drv->hor_res + area->x1], color_p, w * sizeof(lv_color_t));
color_p += w;
}
#endif
monitor2.sdl_refr_qry = true;
/*IMPORTANT! It must be called to tell the system the flush is ready*/
lv_disp_flush_ready(disp_drv);
#endif
}
#endif
/**********************
* STATIC FUNCTIONS
**********************/
/**
* SDL main thread. All SDL related task have to be handled here!
* It initializes SDL, handles drawing and the mouse.
*/
static int monitor_sdl_refr_thread(void * param)
{
(void)param;
/*If not OSX initialize SDL in the Thread*/
#ifndef MONITOR_APPLE
monitor_sdl_init();
#endif
/*Run until quit event not arrives*/
while(sdl_quit_qry == false) {
/*Refresh handling*/
monitor_sdl_refr_core();
}
monitor_sdl_clean_up();
exit(0);
return 0;
}
int quit_filter(void * userdata, SDL_Event * event)
{
(void)userdata;
if(event->type == SDL_WINDOWEVENT) {
if(event->window.event == SDL_WINDOWEVENT_CLOSE) {
sdl_quit_qry = true;
}
}
else if(event->type == SDL_QUIT) {
sdl_quit_qry = true;
}
return 1;
}
static void monitor_sdl_clean_up(void)
{
SDL_DestroyTexture(monitor.texture);
SDL_DestroyRenderer(monitor.renderer);
SDL_DestroyWindow(monitor.window);
#if MONITOR_DUAL
SDL_DestroyTexture(monitor2.texture);
SDL_DestroyRenderer(monitor2.renderer);
SDL_DestroyWindow(monitor2.window);
#endif
SDL_Quit();
}
static void monitor_sdl_init(void)
{
/*Initialize the SDL*/
SDL_Init(SDL_INIT_VIDEO);
SDL_SetEventFilter(quit_filter, NULL);
window_create(&monitor);
#if MONITOR_DUAL
window_create(&monitor2);
int x, y;
SDL_GetWindowPosition(monitor2.window, &x, &y);
SDL_SetWindowPosition(monitor.window, x + MONITOR_HOR_RES / 2 + 10, y);
SDL_SetWindowPosition(monitor2.window, x - MONITOR_HOR_RES / 2 - 10, y);
#endif
sdl_inited = true;
}
#ifdef MONITOR_EMSCRIPTEN
void monitor_sdl_refr_core(void)
#else
static void monitor_sdl_refr_core(void)
#endif
{
if(monitor.sdl_refr_qry != false) {
monitor.sdl_refr_qry = false;
window_update(&monitor);
}
#if MONITOR_DUAL
if(monitor2.sdl_refr_qry != false) {
monitor2.sdl_refr_qry = false;
window_update(&monitor2);
}
#endif
#if !defined(MONITOR_APPLE) && !defined(MONITOR_EMSCRIPTEN)
SDL_Event event;
while(SDL_PollEvent(&event)) {
#if USE_MOUSE != 0
mouse_handler(&event);
#endif
#if USE_MOUSEWHEEL != 0
mousewheel_handler(&event);
#endif
#if USE_KEYBOARD
keyboard_handler(&event);
#endif
if((&event)->type == SDL_WINDOWEVENT) {
switch((&event)->window.event) {
#if SDL_VERSION_ATLEAST(2, 0, 5)
case SDL_WINDOWEVENT_TAKE_FOCUS:
#endif
case SDL_WINDOWEVENT_EXPOSED:
window_update(&monitor);
#if MONITOR_DUAL
window_update(&monitor2);
#endif
break;
default:
break;
}
}
}
#endif /*MONITOR_APPLE*/
/*Sleep some time*/
SDL_Delay(SDL_REFR_PERIOD);
}
static void window_create(monitor_t * m)
{
m->window = SDL_CreateWindow("TFT Simulator",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
#if MONITOR_VIRTUAL_MACHINE || defined(MONITOR_EMSCRIPTEN)
m->renderer = SDL_CreateRenderer(m->window, -1, SDL_RENDERER_SOFTWARE);
#else
m->renderer = SDL_CreateRenderer(m->window, -1, 0);
#endif
m->texture = SDL_CreateTexture(m->renderer,
SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, MONITOR_VER_RES);
SDL_SetTextureBlendMode(m->texture, SDL_BLENDMODE_BLEND);
/*Initialize the frame buffer to gray (77 is an empirical value) */
#if MONITOR_DOUBLE_BUFFERED
SDL_UpdateTexture(m->texture, NULL, m->tft_fb_act, MONITOR_HOR_RES * sizeof(uint32_t));
#else
memset(m->tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));
#endif
m->sdl_refr_qry = true;
}
static void window_update(monitor_t * m)
{
#if MONITOR_DOUBLE_BUFFERED == 0
SDL_UpdateTexture(m->texture, NULL, m->tft_fb, MONITOR_HOR_RES * sizeof(uint32_t));
#else
if(m->tft_fb_act == NULL) return;
SDL_UpdateTexture(m->texture, NULL, m->tft_fb_act, MONITOR_HOR_RES * sizeof(uint32_t));
#endif
SDL_RenderClear(m->renderer);
/*Test: Draw a background to test transparent screens (LV_COLOR_SCREEN_TRANSP)*/
// SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
// SDL_Rect r;
// r.x = 0; r.y = 0; r.w = MONITOR_HOR_RES; r.w = MONITOR_VER_RES;
// SDL_RenderDrawRect(renderer, &r);
/*Update the renderer with the texture containing the rendered image*/
SDL_RenderCopy(m->renderer, m->texture, NULL, NULL);
SDL_RenderPresent(m->renderer);
}
#endif /*USE_MONITOR*/

View File

@ -1,57 +0,0 @@
/**
* @file monitor.h
*
*/
#ifndef MONITOR_H
#define MONITOR_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_MONITOR
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void monitor_init(void);
void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
void monitor_flush2(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
/**********************
* MACROS
**********************/
#endif /* USE_MONITOR */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* MONITOR_H */

View File

@ -1 +0,0 @@
--style=kr --convert-tabs --indent=spaces=4 --indent-switches --pad-oper --unpad-paren --align-pointer=middle --suffix=.bak --lineend=linux --min-conditional-indent=

View File

@ -1 +0,0 @@
--convert-tabs --indent=spaces=4

View File

@ -1,383 +0,0 @@
/**
* @file AD_touch.c
*
*/
#include "AD_touch.h"
#if USE_AD_TOUCH
#include LV_DRV_INDEV_INCLUDE
#include LV_DRV_DELAY_INCLUDE
#define SAMPLE_POINTS 4
#define CALIBRATIONINSET 20 // range 0 <= CALIBRATIONINSET <= 40
#define RESISTIVETOUCH_AUTO_SAMPLE_MODE
#define TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD 350 // between 0-0x03ff the lesser this value
// Current ADC values for X and Y channels
int16_t adcX = 0;
int16_t adcY = 0;
volatile unsigned int adcTC = 0;
// coefficient values
volatile long _trA;
volatile long _trB;
volatile long _trC;
volatile long _trD;
volatile int16_t xRawTouch[SAMPLE_POINTS] = {TOUCHCAL_ULX, TOUCHCAL_URX, TOUCHCAL_LRX, TOUCHCAL_LLX};
volatile int16_t yRawTouch[SAMPLE_POINTS] = {TOUCHCAL_ULY, TOUCHCAL_URY, TOUCHCAL_LRY, TOUCHCAL_LLY};
#define TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR 8
// use this scale factor to avoid working in floating point numbers
#define SCALE_FACTOR (1 << TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR)
typedef enum {
IDLE, //0
SET_X, //1
RUN_X, //2
GET_X, //3
RUN_CHECK_X, //4
CHECK_X, //5
SET_Y, //6
RUN_Y, //7
GET_Y, //8
CHECK_Y, //9
SET_VALUES, //10
GET_POT, //11
RUN_POT //12
} TOUCH_STATES;
volatile TOUCH_STATES state = IDLE;
#define CAL_X_INSET (((GetMaxX() + 1) * (CALIBRATIONINSET >> 1)) / 100)
#define CAL_Y_INSET (((GetMaxY() + 1) * (CALIBRATIONINSET >> 1)) / 100)
int stat;
int16_t temp_x, temp_y;
static int16_t TouchGetX(void);
static int16_t TouchGetRawX(void);
static int16_t TouchGetY(void);
static int16_t TouchGetRawY(void);
static int16_t TouchDetectPosition(void);
static void TouchCalculateCalPoints(void);
/********************************************************************/
void ad_touch_init(void)
{
// Initialize ADC for auto sampling mode
AD1CON1 = 0; // reset
AD1CON2 = 0; // AVdd, AVss, int every conversion, MUXA only
AD1CON3 = 0x1FFF; // 31 Tad auto-sample, Tad = 256*Tcy
AD1CON1 = 0x80E0; // Turn on A/D module, use auto-convert
ADPCFG_XPOS = RESISTIVETOUCH_ANALOG;
ADPCFG_YPOS = RESISTIVETOUCH_ANALOG;
AD1CSSL = 0; // No scanned inputs
state = SET_X; // set the state of the state machine to start the sampling
/*Load calibration data*/
xRawTouch[0] = TOUCHCAL_ULX;
yRawTouch[0] = TOUCHCAL_ULY;
xRawTouch[1] = TOUCHCAL_URX;
yRawTouch[1] = TOUCHCAL_URY;
xRawTouch[3] = TOUCHCAL_LLX;
yRawTouch[3] = TOUCHCAL_LLY;
xRawTouch[2] = TOUCHCAL_LRX;
yRawTouch[2] = TOUCHCAL_LRY;
TouchCalculateCalPoints();
}
/*Use this in lv_indev_drv*/
bool ad_touch_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static int16_t last_x = 0;
static int16_t last_y = 0;
int16_t x, y;
x = TouchGetX();
y = TouchGetY();
if((x > 0) && (y > 0)) {
data->point.x = x;
data->point.y = y;
last_x = data->point.x;
last_y = data->point.y;
data->state = LV_INDEV_STATE_PR;
} else {
data->point.x = last_x;
data->point.y = last_y;
data->state = LV_INDEV_STATE_REL;
}
return false;
}
/* Call periodically (e.g. in every 1 ms) to handle reading with ADC*/
int16_t ad_touch_handler(void)
{
static int16_t tempX, tempY;
int16_t temp;
switch(state) {
case IDLE:
adcX = 0;
adcY = 0;
break;
case SET_VALUES:
if(!TOUCH_ADC_DONE)
break;
if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD < (WORD)ADC1BUF0) {
adcX = 0;
adcY = 0;
} else {
adcX = tempX;
adcY = tempY;
}
state = SET_X;
return 1; // touch screen acquisition is done
case SET_X:
TOUCH_ADC_INPUT_SEL = ADC_XPOS;
ResistiveTouchScreen_XPlus_Config_As_Input();
ResistiveTouchScreen_YPlus_Config_As_Input();
ResistiveTouchScreen_XMinus_Config_As_Input();
ResistiveTouchScreen_YMinus_Drive_Low();
ResistiveTouchScreen_YMinus_Config_As_Output();
ADPCFG_YPOS = RESISTIVETOUCH_DIGITAL; // set to digital pin
ADPCFG_XPOS = RESISTIVETOUCH_ANALOG; // set to analog pin
TOUCH_ADC_START = 1; // run conversion
state = CHECK_X;
break;
case CHECK_X:
case CHECK_Y:
if(TOUCH_ADC_DONE == 0) {
break;
}
if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD > (WORD)ADC1BUF0) {
if(state == CHECK_X) {
ResistiveTouchScreen_YPlus_Drive_High();
ResistiveTouchScreen_YPlus_Config_As_Output();
tempX = 0;
state = RUN_X;
} else {
ResistiveTouchScreen_XPlus_Drive_High();
ResistiveTouchScreen_XPlus_Config_As_Output();
tempY = 0;
state = RUN_Y;
}
} else {
adcX = 0;
adcY = 0;
state = SET_X;
return 1; // touch screen acquisition is done
break;
}
case RUN_X:
case RUN_Y:
TOUCH_ADC_START = 1;
state = (state == RUN_X) ? GET_X : GET_Y;
// no break needed here since the next state is either GET_X or GET_Y
break;
case GET_X:
case GET_Y:
if(!TOUCH_ADC_DONE)
break;
temp = ADC1BUF0;
if(state == GET_X) {
if(temp != tempX) {
tempX = temp;
state = RUN_X;
break;
}
} else {
if(temp != tempY) {
tempY = temp;
state = RUN_Y;
break;
}
}
if(state == GET_X)
ResistiveTouchScreen_YPlus_Config_As_Input();
else
ResistiveTouchScreen_XPlus_Config_As_Input();
TOUCH_ADC_START = 1;
state = (state == GET_X) ? SET_Y : SET_VALUES;
break;
case SET_Y:
if(!TOUCH_ADC_DONE)
break;
if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD < (WORD)ADC1BUF0) {
adcX = 0;
adcY = 0;
state = SET_X;
return 1; // touch screen acquisition is done
break;
}
TOUCH_ADC_INPUT_SEL = ADC_YPOS;
ResistiveTouchScreen_XPlus_Config_As_Input();
ResistiveTouchScreen_YPlus_Config_As_Input();
ResistiveTouchScreen_XMinus_Drive_Low();
ResistiveTouchScreen_XMinus_Config_As_Output();
ResistiveTouchScreen_YMinus_Config_As_Input();
ADPCFG_YPOS = RESISTIVETOUCH_ANALOG; // set to analog pin
ADPCFG_XPOS = RESISTIVETOUCH_DIGITAL; // set to digital pin
TOUCH_ADC_START = 1; // run conversion
state = CHECK_Y;
break;
default:
state = SET_X;
return 1; // touch screen acquisition is done
}
stat = state;
temp_x = adcX;
temp_y = adcY;
return 0; // touch screen acquisition is not done
}
/**********************
* STATIC FUNCTIONS
**********************/
/********************************************************************/
static int16_t TouchGetX(void)
{
long result;
result = TouchGetRawX();
if(result > 0) {
result = (long)((((long)_trC * result) + _trD) >> TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR);
}
return ((int16_t)result);
}
/********************************************************************/
static int16_t TouchGetRawX(void)
{
#ifdef TOUCHSCREEN_RESISTIVE_SWAP_XY
return adcY;
#else
return adcX;
#endif
}
/********************************************************************/
static int16_t TouchGetY(void)
{
long result;
result = TouchGetRawY();
if(result > 0) {
result = (long)((((long)_trA * result) + (long)_trB) >> TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR);
}
return ((int16_t)result);
}
/********************************************************************/
static int16_t TouchGetRawY(void)
{
#ifdef TOUCHSCREEN_RESISTIVE_SWAP_XY
return adcX;
#else
return adcY;
#endif
}
static void TouchCalculateCalPoints(void)
{
long trA, trB, trC, trD; // variables for the coefficients
long trAhold, trBhold, trChold, trDhold;
long test1, test2; // temp variables (must be signed type)
int16_t xPoint[SAMPLE_POINTS], yPoint[SAMPLE_POINTS];
yPoint[0] = yPoint[1] = CAL_Y_INSET;
yPoint[2] = yPoint[3] = (GetMaxY() - CAL_Y_INSET);
xPoint[0] = xPoint[3] = CAL_X_INSET;
xPoint[1] = xPoint[2] = (GetMaxX() - CAL_X_INSET);
// calculate points transfer functiona
// based on two simultaneous equations solve for the
// constants
// use sample points 1 and 4
// Dy1 = aTy1 + b; Dy4 = aTy4 + b
// Dx1 = cTx1 + d; Dy4 = aTy4 + b
test1 = (long)yPoint[0] - (long)yPoint[3];
test2 = (long)yRawTouch[0] - (long)yRawTouch[3];
trA = ((long)((long)test1 * SCALE_FACTOR) / test2);
trB = ((long)((long)yPoint[0] * SCALE_FACTOR) - (trA * (long)yRawTouch[0]));
test1 = (long)xPoint[0] - (long)xPoint[2];
test2 = (long)xRawTouch[0] - (long)xRawTouch[2];
trC = ((long)((long)test1 * SCALE_FACTOR) / test2);
trD = ((long)((long)xPoint[0] * SCALE_FACTOR) - (trC * (long)xRawTouch[0]));
trAhold = trA;
trBhold = trB;
trChold = trC;
trDhold = trD;
// use sample points 2 and 3
// Dy2 = aTy2 + b; Dy3 = aTy3 + b
// Dx2 = cTx2 + d; Dy3 = aTy3 + b
test1 = (long)yPoint[1] - (long)yPoint[2];
test2 = (long)yRawTouch[1] - (long)yRawTouch[2];
trA = ((long)(test1 * SCALE_FACTOR) / test2);
trB = ((long)((long)yPoint[1] * SCALE_FACTOR) - (trA * (long)yRawTouch[1]));
test1 = (long)xPoint[1] - (long)xPoint[3];
test2 = (long)xRawTouch[1] - (long)xRawTouch[3];
trC = ((long)((long)test1 * SCALE_FACTOR) / test2);
trD = ((long)((long)xPoint[1] * SCALE_FACTOR) - (trC * (long)xRawTouch[1]));
// get the average and use the average
_trA = (trA + trAhold) >> 1;
_trB = (trB + trBhold) >> 1;
_trC = (trC + trChold) >> 1;
_trD = (trD + trDhold) >> 1;
}
#endif

View File

@ -1,120 +0,0 @@
/**
* @file AD_touch.h
*
*/
#ifndef AD_TOUCH_H
#define AD_TOUCH_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_AD_TOUCH
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#define _SUPPRESS_PLIB_WARNING
#include <plib.h>
#include "GenericTypeDefs.h"
#define DISP_ORIENTATION 0
#define DISP_HOR_RESOLUTION 320
#define DISP_VER_RESOLUTION 240
/*GetMaxX Macro*/
#if (DISP_ORIENTATION == 90) || (DISP_ORIENTATION == 270)
#define GetMaxX() (DISP_VER_RESOLUTION - 1)
#elif (DISP_ORIENTATION == 0) || (DISP_ORIENTATION == 180)
#define GetMaxX() (DISP_HOR_RESOLUTION - 1)
#endif
/*GetMaxY Macro*/
#if (DISP_ORIENTATION == 90) || (DISP_ORIENTATION == 270)
#define GetMaxY() (DISP_HOR_RESOLUTION - 1)
#elif (DISP_ORIENTATION == 0) || (DISP_ORIENTATION == 180)
#define GetMaxY() (DISP_VER_RESOLUTION - 1)
#endif
/*********************************************************************
* HARDWARE PROFILE FOR THE RESISTIVE TOUCHSCREEN
*********************************************************************/
#define TOUCH_ADC_INPUT_SEL AD1CHS
// ADC Sample Start
#define TOUCH_ADC_START AD1CON1bits.SAMP
// ADC Status
#define TOUCH_ADC_DONE AD1CON1bits.DONE
#define RESISTIVETOUCH_ANALOG 1
#define RESISTIVETOUCH_DIGITAL 0
// ADC channel constants
#define ADC_XPOS ADC_CH0_POS_SAMPLEA_AN12
#define ADC_YPOS ADC_CH0_POS_SAMPLEA_AN13
// ADC Port Control Bits
#define ADPCFG_XPOS AD1PCFGbits.PCFG12 //XR
#define ADPCFG_YPOS AD1PCFGbits.PCFG13 //YD
// X port definitions
#define ResistiveTouchScreen_XPlus_Drive_High() LATBbits.LATB12 = 1
#define ResistiveTouchScreen_XPlus_Drive_Low() LATBbits.LATB12 = 0 //LAT_XPOS
#define ResistiveTouchScreen_XPlus_Config_As_Input() TRISBbits.TRISB12 = 1 //TRIS_XPOS
#define ResistiveTouchScreen_XPlus_Config_As_Output() TRISBbits.TRISB12 = 0
#define ResistiveTouchScreen_XMinus_Drive_High() LATFbits.LATF0 = 1
#define ResistiveTouchScreen_XMinus_Drive_Low() LATFbits.LATF0 = 0 //LAT_XNEG
#define ResistiveTouchScreen_XMinus_Config_As_Input() TRISFbits.TRISF0 = 1 //TRIS_XNEG
#define ResistiveTouchScreen_XMinus_Config_As_Output() TRISFbits.TRISF0 = 0
// Y port definitions
#define ResistiveTouchScreen_YPlus_Drive_High() LATBbits.LATB13 = 1
#define ResistiveTouchScreen_YPlus_Drive_Low() LATBbits.LATB13 = 0 //LAT_YPOS
#define ResistiveTouchScreen_YPlus_Config_As_Input() TRISBbits.TRISB13 = 1 //TRIS_YPOS
#define ResistiveTouchScreen_YPlus_Config_As_Output() TRISBbits.TRISB13 = 0
#define ResistiveTouchScreen_YMinus_Drive_High() LATFbits.LATF1 = 1
#define ResistiveTouchScreen_YMinus_Drive_Low() LATFbits.LATF1 = 0 //LAT_YNEG
#define ResistiveTouchScreen_YMinus_Config_As_Input() TRISFbits.TRISF1 = 1 //TRIS_YNEG
#define ResistiveTouchScreen_YMinus_Config_As_Output() TRISFbits.TRISF1 = 0
// Default calibration points
#define TOUCHCAL_ULX 0x0348
#define TOUCHCAL_ULY 0x00CC
#define TOUCHCAL_URX 0x00D2
#define TOUCHCAL_URY 0x00CE
#define TOUCHCAL_LLX 0x034D
#define TOUCHCAL_LLY 0x0335
#define TOUCHCAL_LRX 0x00D6
#define TOUCHCAL_LRY 0x032D
void ad_touch_init(void);
bool ad_touch_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
int16_t ad_touch_handler(void);
#endif /* USE_AD_TOUCH */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* AD_TOUCH_H */

View File

@ -1,179 +0,0 @@
/**
* @file FT5406EE8.c
*
*/
/*********************
* INCLUDES
*********************/
#include "FT5406EE8.h"
#if USE_FT5406EE8
#include <stddef.h>
#include <stdbool.h>
#include LV_DRV_INDEV_INCLUDE
#include LV_DRV_DELAY_INCLUDE
/*********************
* DEFINES
*********************/
#define I2C_WR_BIT 0x00
#define I2C_RD_BIT 0x01
/*DEVICE MODES*/
#define OPERAT_MD 0x00
#define TEST_MD 0x04
#define SYS_INF_MD 0x01
/*OPERATING MODE*/
#define DEVICE_MODE 0x00
#define GEST_ID 0x01
#define TD_STATUS 0x02
#define FT5406EE8_FINGER_MAX 10
/*Register adresses*/
#define FT5406EE8_REG_DEVICE_MODE 0x00
#define FT5406EE8_REG_GEST_ID 0x01
#define FT5406EE8_REG_TD_STATUS 0x02
#define FT5406EE8_REG_YH 0x03
#define FT5406EE8_REG_YL 0x04
#define FT5406EE8_REG_XH 0x05
#define FT5406EE8_REG_XL 0x06
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool ft5406ee8_get_touch_num(void);
static bool ft5406ee8_read_finger1(int16_t * x, int16_t * y);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
*
*/
void ft5406ee8_init(void)
{
}
/**
* Get the current position and state of the touchpad
* @param data store the read data here
* @return false: because no ore data to be read
*/
bool ft5406ee8_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static int16_t x_last;
static int16_t y_last;
int16_t x;
int16_t y;
bool valid = true;
valid = ft5406ee8_get_touch_num();
if(valid == true) {
valid = ft5406ee8_read_finger1(&x, &y);
}
if(valid == true) {
x = (uint32_t)((uint32_t)x * 320) / 2048;
y = (uint32_t)((uint32_t)y * 240) / 2048;
x_last = x;
y_last = y;
} else {
x = x_last;
y = y_last;
}
data->point.x = x;
data->point.y = y;
data->state = valid == false ? LV_INDEV_STATE_REL : LV_INDEV_STATE_PR;
return false;
}
/**********************
* STATIC FUNCTIONS
**********************/
static bool ft5406ee8_get_touch_num(void)
{
bool ok = true;
uint8_t t_num = 0;
LV_DRV_INDEV_I2C_START;
LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_WR_BIT);
LV_DRV_INDEV_I2C_WR(FT5406EE8_REG_TD_STATUS)
LV_DRV_INDEV_I2C_RESTART;
LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_RD_BIT);
t_num = LV_DRV_INDEV_I2C_READ(0);
/* Error if not touched or too much finger */
if(t_num > FT5406EE8_FINGER_MAX || t_num == 0) {
ok = false;
}
return ok;
}
/**
* Read the x and y coordinated
* @param x store the x coordinate here
* @param y store the y coordinate here
* @return false: not valid point; true: valid point
*/
static bool ft5406ee8_read_finger1(int16_t * x, int16_t * y)
{
uint8_t temp_xH = 0;
uint8_t temp_xL = 0;
uint8_t temp_yH = 0;
uint8_t temp_yL = 0;
/*Read Y High and low byte*/
LV_DRV_INDEV_I2C_START;
LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_WR_BIT);
LV_DRV_INDEV_I2C_WR(FT5406EE8_REG_YH)
LV_DRV_INDEV_I2C_RESTART;
LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_RD_BIT);
temp_yH = LV_DRV_INDEV_I2C_READ(1);
temp_yL = LV_DRV_INDEV_I2C_READ(1);
/*The upper two bit must be 2 on valid press*/
if(((temp_yH >> 6) & 0xFF) != 2) {
(void) LV_DRV_INDEV_I2C_READ(0); /*Dummy read to close read sequence*/
*x = 0;
*y = 0;
return false;
}
/*Read X High and low byte*/
temp_xH = LV_DRV_INDEV_I2C_READ(1);
temp_xL = LV_DRV_INDEV_I2C_READ(0);
/*Save the result*/
*x = (temp_xH & 0x0F) << 8;
*x += temp_xL;
*y = (temp_yH & 0x0F) << 8;
*y += temp_yL;
return true;
}
#endif

View File

@ -1,56 +0,0 @@
/**
* @file FT5406EE8.h
*
*/
#ifndef FT5406EE8_H
#define FT5406EE8_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_FT5406EE8
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void ft5406ee8_init(void);
bool ft5406ee8_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/**********************
* MACROS
**********************/
#endif /* USE_FT5406EE8 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* FT5406EE8_H */

View File

@ -1,210 +0,0 @@
/**
* @file XPT2046.c
*
*/
/*********************
* INCLUDES
*********************/
#include "XPT2046.h"
#if USE_XPT2046
#include <stddef.h>
#include LV_DRV_INDEV_INCLUDE
#include LV_DRV_DELAY_INCLUDE
#include <SPI.h>
#include "XPT2046_Touchscreen.h"
/*********************
* DEFINES
*********************/
#define CMD_X_READ 0b10010000
#define CMD_Y_READ 0b11010000
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void xpt2046_corr(int16_t * x, int16_t * y);
static void xpt2046_avg(int16_t * x, int16_t * y);
/**********************
* STATIC VARIABLES
**********************/
int16_t avg_buf_x[XPT2046_AVG];
int16_t avg_buf_y[XPT2046_AVG];
uint8_t avg_last;
#if defined(STM32F407ZG)
#include "SoftSPI.h"
SoftSPI xpt2046_spi(PF11, PB2, PB0);
XPT2046_Touchscreen ts(PC13);
#else
SPIClass xpt2046_spi(PB15, PB14, PB13, PB12);
XPT2046_Touchscreen ts(PB12);
#endif
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the XPT2046
*/
void xpt2046_init(uint8_t rotation)
{
ts.begin();
ts.setRotation(rotation);
}
/**
* Get the current position and state of the touchpad
* @param data store the read data here
* @return false: because no ore data to be read
*/
bool xpt2046_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static int16_t last_x = 0;
static int16_t last_y = 0;
uint8_t buf;
int16_t x = 0;
int16_t y = 0;
// uint8_t irq = LV_DRV_INDEV_IRQ_READ;
data->state = ts.touched();
if(data->state) {
TS_Point p = ts.getPoint();
x = p.x;
y = p.y;
xpt2046_corr(&x, &y);
#if 0
// LV_DRV_INDEV_SPI_CS(0);
xpt2046_spi.beginTransaction(SPI_SETTING);
digitalWrite(PB12, LOW);
xpt2046_spi.transfer(CMD_X_READ); /*Start x read*/
buf = xpt2046_spi.transfer(0); /*Read x MSB*/
x = buf << 8;
buf = xpt2046_spi.transfer(CMD_Y_READ); /*Until x LSB converted y command can be sent*/
x += buf;
buf = xpt2046_spi.transfer(0); /*Read y MSB*/
y = buf << 8;
buf = xpt2046_spi.transfer(0); /*Read y LSB*/
y += buf;
/*Normalize Data*/
x = x >> 3;
y = y >> 3;
xpt2046_corr(&x, &y);
xpt2046_avg(&x, &y);
last_x = x;
last_y = y;
data->state = LV_INDEV_STATE_PR;
if(data->state) {
Serial.print(x);
Serial.print(" - ");
Serial.println(y);
} else {
Serial.print(".");
}
// LV_DRV_INDEV_SPI_CS(1);
digitalWrite(PB12, HIGH);
xpt2046_spi.endTransaction();
#endif
} else {
x = last_x;
y = last_y;
avg_last = 0;
data->state = LV_INDEV_STATE_REL;
}
data->point.x = x;
data->point.y = y;
if(data->state) {
Serial.print(x);
Serial.print(" - ");
Serial.println(y);
} else {
// Serial.print(".");
}
return false;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void xpt2046_corr(int16_t * x, int16_t * y)
{
#if XPT2046_XY_SWAP != 0
int16_t swap_tmp;
swap_tmp = *x;
*x = *y;
*y = swap_tmp;
#endif
if((*x) > XPT2046_X_MIN)
(*x) -= XPT2046_X_MIN;
else
(*x) = 0;
if((*y) > XPT2046_Y_MIN)
(*y) -= XPT2046_Y_MIN;
else
(*y) = 0;
(*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES) / (XPT2046_X_MAX - XPT2046_X_MIN);
(*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES) / (XPT2046_Y_MAX - XPT2046_Y_MIN);
#if XPT2046_X_INV != 0
(*x) = XPT2046_HOR_RES - (*x);
#endif
#if XPT2046_Y_INV != 0
(*y) = XPT2046_VER_RES - (*y);
#endif
}
static void xpt2046_avg(int16_t * x, int16_t * y)
{
/*Shift out the oldest data*/
uint8_t i;
for(i = XPT2046_AVG - 1; i > 0; i--) {
avg_buf_x[i] = avg_buf_x[i - 1];
avg_buf_y[i] = avg_buf_y[i - 1];
}
/*Insert the new point*/
avg_buf_x[0] = *x;
avg_buf_y[0] = *y;
if(avg_last < XPT2046_AVG) avg_last++;
/*Sum the x and y coordinates*/
int32_t x_sum = 0;
int32_t y_sum = 0;
for(i = 0; i < avg_last; i++) {
x_sum += avg_buf_x[i];
y_sum += avg_buf_y[i];
}
/*Normalize the sums*/
(*x) = (int32_t)x_sum / avg_last;
(*y) = (int32_t)y_sum / avg_last;
}
#endif

View File

@ -1,56 +0,0 @@
/**
* @file XPT2046.h
*
*/
#ifndef XPT2046_H
#define XPT2046_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_XPT2046
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void xpt2046_init(uint8_t rotation);
bool xpt2046_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/**********************
* MACROS
**********************/
#endif /* USE_XPT2046 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XPT2046_H */

View File

@ -1,75 +0,0 @@
/**
* @file XPT2046.c
*
*/
/*********************
* INCLUDES
*********************/
#include "XPT2046_alt_drv.h"
#if USE_XPT2046_ALT_DRV
#include <stddef.h>
#include LV_DRV_INDEV_INCLUDE
#include LV_DRV_DELAY_INCLUDE
#include <XPT2046_Touchscreen.h>
/*********************
* DEFINES
*********************/
#define CS_PIN PB12
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
XPT2046_Touchscreen ts(CS_PIN);
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the XPT2046
*/
void xpt2046_alt_drv_init(uint8_t rotation)
{
ts.begin();
ts.setRotation(rotation);
}
/**
* Get the current position and state of the touchpad
* @param data store the read data here
* @return false: because no more data to be read
*/
bool xpt2046_alt_drv_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
data->state = ts.touched();
if(data->state) {
TS_Point p = ts.getPoint();
data->point.x = p.x;
data->point.y = p.y;
Serial.print(p.x);
Serial.print(" - ");
Serial.println(p.y);
}
return false;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,56 +0,0 @@
/**
* @file XPT2046_alt_drv.h
*
*/
#ifndef XPT2046_ALT_DRV_H
#define XPT2046_ALT_DRV_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_XPT2046_ALT_DRV
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void xpt2046_alt_drv_init(uint8_t rotation);
bool xpt2046_alt_drv_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/**********************
* MACROS
**********************/
#endif /* USE_XPT2046_ALT_DRV */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XPT2046_ALT_DRV_H */

View File

@ -1,223 +0,0 @@
/**
* @file evdev.c
*
*/
/*********************
* INCLUDES
*********************/
#include "evdev.h"
#if USE_EVDEV != 0
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
int map(int x, int in_min, int in_max, int out_min, int out_max);
/**********************
* STATIC VARIABLES
**********************/
int evdev_fd;
int evdev_root_x;
int evdev_root_y;
int evdev_button;
int evdev_key_val;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the evdev interface
*/
void evdev_init(void)
{
evdev_fd = open(EVDEV_NAME, O_RDWR | O_NOCTTY | O_NDELAY);
if(evdev_fd == -1) {
perror("unable open evdev interface:");
return;
}
fcntl(evdev_fd, F_SETFL, O_ASYNC | O_NONBLOCK);
evdev_root_x = 0;
evdev_root_y = 0;
evdev_key_val = 0;
evdev_button = LV_INDEV_STATE_REL;
}
/**
* reconfigure the device file for evdev
* @param dev_name set the evdev device filename
* @return true: the device file set complete
* false: the device file doesn't exist current system
*/
bool evdev_set_file(char* dev_name)
{
if(evdev_fd != -1) {
close(evdev_fd);
}
evdev_fd = open(dev_name, O_RDWR | O_NOCTTY | O_NDELAY);
if(evdev_fd == -1) {
perror("unable open evdev interface:");
return false;
}
fcntl(evdev_fd, F_SETFL, O_ASYNC | O_NONBLOCK);
evdev_root_x = 0;
evdev_root_y = 0;
evdev_key_val = 0;
evdev_button = LV_INDEV_STATE_REL;
return true;
}
/**
* Get the current position and state of the evdev
* @param data store the evdev data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool evdev_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
{
struct input_event in;
while(read(evdev_fd, &in, sizeof(struct input_event)) > 0) {
if(in.type == EV_REL) {
if(in.code == REL_X)
#if EVDEV_SWAP_AXES
evdev_root_y += in.value;
#else
evdev_root_x += in.value;
#endif
else if(in.code == REL_Y)
#if EVDEV_SWAP_AXES
evdev_root_x += in.value;
#else
evdev_root_y += in.value;
#endif
} else if(in.type == EV_ABS) {
if(in.code == ABS_X)
#if EVDEV_SWAP_AXES
evdev_root_y = in.value;
#else
evdev_root_x = in.value;
#endif
else if(in.code == ABS_Y)
#if EVDEV_SWAP_AXES
evdev_root_x = in.value;
#else
evdev_root_y = in.value;
#endif
else if(in.code == ABS_MT_POSITION_X)
#if EVDEV_SWAP_AXES
evdev_root_y = in.value;
#else
evdev_root_x = in.value;
#endif
else if(in.code == ABS_MT_POSITION_Y)
#if EVDEV_SWAP_AXES
evdev_root_x = in.value;
#else
evdev_root_y = in.value;
#endif
} else if(in.type == EV_KEY) {
if(in.code == BTN_MOUSE || in.code == BTN_TOUCH) {
if(in.value == 0)
evdev_button = LV_INDEV_STATE_REL;
else if(in.value == 1)
evdev_button = LV_INDEV_STATE_PR;
} else if(drv->type == LV_INDEV_TYPE_KEYPAD) {
data->state = (in.value) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
switch(in.code) {
case KEY_BACKSPACE:
data->key = LV_KEY_BACKSPACE;
break;
case KEY_ENTER:
data->key = LV_KEY_ENTER;
break;
case KEY_UP:
data->key = LV_KEY_UP;
break;
case KEY_LEFT:
data->key = LV_KEY_PREV;
break;
case KEY_RIGHT:
data->key = LV_KEY_NEXT;
break;
case KEY_DOWN:
data->key = LV_KEY_DOWN;
break;
default:
data->key = 0;
break;
}
evdev_key_val = data->key;
evdev_button = data->state;
return false;
}
}
}
if(drv->type == LV_INDEV_TYPE_KEYPAD) {
/* No data retrieved */
data->key = evdev_key_val;
data->state = evdev_button;
return false;
}
if(drv->type != LV_INDEV_TYPE_POINTER)
return false;
/*Store the collected data*/
#if EVDEV_SCALE
data->point.x = map(evdev_root_x, 0, EVDEV_SCALE_HOR_RES, 0, lv_disp_get_hor_res(drv->disp));
data->point.y = map(evdev_root_y, 0, EVDEV_SCALE_VER_RES, 0, lv_disp_get_ver_res(drv->disp));
#endif
#if EVDEV_CALIBRATE
data->point.x = map(evdev_root_x, EVDEV_HOR_MIN, EVDEV_HOR_MAX, 0, lv_disp_get_hor_res(drv->disp));
data->point.y = map(evdev_root_y, EVDEV_VER_MIN, EVDEV_VER_MAX, 0, lv_disp_get_ver_res(drv->disp));
#else
data->point.x = evdev_root_x;
data->point.y = evdev_root_y;
#endif
data->state = evdev_button;
if(data->point.x < 0)
data->point.x = 0;
if(data->point.y < 0)
data->point.y = 0;
if(data->point.x >= lv_disp_get_hor_res(drv->disp))
data->point.x = lv_disp_get_hor_res(drv->disp) - 1;
if(data->point.y >= lv_disp_get_ver_res(drv->disp))
data->point.y = lv_disp_get_ver_res(drv->disp) - 1;
return false;
}
/**********************
* STATIC FUNCTIONS
**********************/
int map(int x, int in_min, int in_max, int out_min, int out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
#endif

View File

@ -1,73 +0,0 @@
/**
* @file evdev.h
*
*/
#ifndef EVDEV_H
#define EVDEV_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_EVDEV
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the evdev
*/
void evdev_init(void);
/**
* reconfigure the device file for evdev
* @param dev_name set the evdev device filename
* @return true: the device file set complete
* false: the device file doesn't exist current system
*/
bool evdev_set_file(char* dev_name);
/**
* Get the current position and state of the evdev
* @param data store the evdev data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool evdev_read(lv_indev_drv_t * drv, lv_indev_data_t * data);
/**********************
* MACROS
**********************/
#endif /* USE_EVDEV */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* EVDEV_H */

View File

@ -1,12 +0,0 @@
CSRCS += FT5406EE8.c
CSRCS += keyboard.c
CSRCS += mouse.c
CSRCS += mousewheel.c
CSRCS += evdev.c
CSRCS += libinput.c
CSRCS += XPT2046.c
DEPPATH += --dep-path $(LVGL_DIR)/lv_drivers/indev
VPATH += :$(LVGL_DIR)/lv_drivers/indev
CFLAGS += "-I$(LVGL_DIR)/lv_drivers/indev"

View File

@ -1,130 +0,0 @@
/**
* @file sdl_kb.c
*
*/
/*********************
* INCLUDES
*********************/
#include "keyboard.h"
#if USE_KEYBOARD
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static uint32_t keycode_to_ascii(uint32_t sdl_key);
/**********************
* STATIC VARIABLES
**********************/
static uint32_t last_key;
static lv_indev_state_t state;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the keyboard
*/
void keyboard_init(void)
{
/*Nothing to init*/
}
/**
* Get the last pressed or released character from the PC's keyboard
* @param indev_drv pointer to the related input device driver
* @param data store the read data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
(void) indev_drv; /*Unused*/
data->state = state;
data->key = keycode_to_ascii(last_key);
return false;
}
/**
* It is called periodically from the SDL thread to check a key is pressed/released
* @param event describes the event
*/
void keyboard_handler(SDL_Event * event)
{
/* We only care about SDL_KEYDOWN and SDL_KEYUP events */
switch(event->type) {
case SDL_KEYDOWN: /*Button press*/
last_key = event->key.keysym.sym; /*Save the pressed key*/
state = LV_INDEV_STATE_PR; /*Save the key is pressed now*/
break;
case SDL_KEYUP: /*Button release*/
state = LV_INDEV_STATE_REL; /*Save the key is released but keep the last key*/
break;
default:
break;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Convert the key code LV_KEY_... "codes" or leave them if they are not control characters
* @param sdl_key the key code
* @return
*/
static uint32_t keycode_to_ascii(uint32_t sdl_key)
{
/*Remap some key to LV_KEY_... to manage groups*/
switch(sdl_key) {
case SDLK_RIGHT:
case SDLK_KP_PLUS:
return LV_KEY_RIGHT;
case SDLK_LEFT:
case SDLK_KP_MINUS:
return LV_KEY_LEFT;
case SDLK_UP:
return LV_KEY_UP;
case SDLK_DOWN:
return LV_KEY_DOWN;
case SDLK_ESCAPE:
return LV_KEY_ESC;
#ifdef LV_KEY_BACKSPACE /*For backward compatibility*/
case SDLK_BACKSPACE:
return LV_KEY_BACKSPACE;
#endif
#ifdef LV_KEY_DEL /*For backward compatibility*/
case SDLK_DELETE:
return LV_KEY_DEL;
#endif
case SDLK_KP_ENTER:
case '\r':
return LV_KEY_ENTER;
default:
return sdl_key;
}
}
#endif

View File

@ -1,78 +0,0 @@
/**
* @file keyboard.h
*
*/
#ifndef KEYBOARD_H
#define KEYBOARD_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_KEYBOARD
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#ifndef MONITOR_SDL_INCLUDE_PATH
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
#endif
#include MONITOR_SDL_INCLUDE_PATH
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the keyboard
*/
void keyboard_init(void);
/**
* Get the last pressed or released character from the PC's keyboard
* @param indev_drv pointer to the related input device driver
* @param data store the read data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/**
* It is called periodically from the SDL thread to check a key is pressed/released
* @param event describes the event
*/
void keyboard_handler(SDL_Event *event);
/**********************
* MACROS
**********************/
#endif /*USE_KEYBOARD*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*KEYBOARD_H*/

View File

@ -1,175 +0,0 @@
/**
* @file libinput.c
*
*/
/*********************
* INCLUDES
*********************/
#include "libinput_drv.h"
#if USE_LIBINPUT != 0
#include <stdio.h>
#include <unistd.h>
#include <linux/limits.h>
#include <fcntl.h>
#include <errno.h>
#include <stdbool.h>
#include <poll.h>
#include <libinput.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static int open_restricted(const char *path, int flags, void *user_data);
static void close_restricted(int fd, void *user_data);
/**********************
* STATIC VARIABLES
**********************/
static int libinput_fd;
static int libinput_button;
static const int timeout = 0; // do not block
static const nfds_t nfds = 1;
static struct pollfd fds[1];
static lv_point_t most_recent_touch_point = { .x = 0, .y = 0};
static struct libinput *libinput_context;
static struct libinput_device *libinput_device;
const static struct libinput_interface interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* reconfigure the device file for libinput
* @param dev_name set the libinput device filename
* @return true: the device file set complete
* false: the device file doesn't exist current system
*/
bool libinput_set_file(char* dev_name)
{
// This check *should* not be necessary, yet applications crashes even on NULL handles.
// citing libinput.h:libinput_path_remove_device:
// > If no matching device exists, this function does nothing.
if (libinput_device) {
libinput_device = libinput_device_unref(libinput_device);
libinput_path_remove_device(libinput_device);
}
libinput_device = libinput_path_add_device(libinput_context, dev_name);
if(!libinput_device) {
perror("unable to add device to libinput context:");
return false;
}
libinput_device = libinput_device_ref(libinput_device);
if(!libinput_device) {
perror("unable to reference device within libinput context:");
return false;
}
libinput_button = LV_INDEV_STATE_REL;
return true;
}
/**
* Initialize the libinput interface
*/
void libinput_init(void)
{
libinput_device = NULL;
libinput_context = libinput_path_create_context(&interface, NULL);
if(!libinput_set_file(LIBINPUT_NAME)) {
perror("unable to add device \"" LIBINPUT_NAME "\" to libinput context:");
return;
}
libinput_fd = libinput_get_fd(libinput_context);
/* prepare poll */
fds[0].fd = libinput_fd;
fds[0].events = POLLIN;
fds[0].revents = 0;
}
/**
* Get the current position and state of the libinput
* @param indev_drv driver object itself
* @param data store the libinput data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool libinput_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
struct libinput_event *event;
struct libinput_event_touch *touch_event = NULL;
int rc = 0;
rc = poll(fds, nfds, timeout);
switch (rc){
case -1:
perror(NULL);
case 0:
goto report_most_recent_state;
default:
break;
}
libinput_dispatch(libinput_context);
while((event = libinput_get_event(libinput_context)) != NULL) {
enum libinput_event_type type = libinput_event_get_type(event);
switch (type) {
case LIBINPUT_EVENT_TOUCH_MOTION:
case LIBINPUT_EVENT_TOUCH_DOWN:
touch_event = libinput_event_get_touch_event(event);
most_recent_touch_point.x = libinput_event_touch_get_x_transformed(touch_event, LV_HOR_RES);
most_recent_touch_point.y = libinput_event_touch_get_y_transformed(touch_event, LV_VER_RES);
libinput_button = LV_INDEV_STATE_PR;
break;
case LIBINPUT_EVENT_TOUCH_UP:
libinput_button = LV_INDEV_STATE_REL;
break;
default:
break;
}
libinput_event_destroy(event);
}
report_most_recent_state:
data->point.x = most_recent_touch_point.x;
data->point.y = most_recent_touch_point.y;
data->state = libinput_button;
return false;
}
/**********************
* STATIC FUNCTIONS
**********************/
static int open_restricted(const char *path, int flags, void *user_data)
{
int fd = open(path, flags);
return fd < 0 ? -errno : fd;
}
static void close_restricted(int fd, void *user_data)
{
close(fd);
}
#endif

View File

@ -1,74 +0,0 @@
/**
* @file libinput.h
*
*/
#ifndef LVGL_LIBINPUT_H
#define LVGL_LIBINPUT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_LIBINPUT
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the libinput
*/
void libinput_init(void);
/**
* reconfigure the device file for libinput
* @param dev_name set the libinput device filename
* @return true: the device file set complete
* false: the device file doesn't exist current system
*/
bool libinput_set_file(char* dev_name);
/**
* Get the current position and state of the libinput
* @param indev_drv driver object itself
* @param data store the libinput data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool libinput_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/**********************
* MACROS
**********************/
#endif /* USE_LIBINPUT */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LVGL_LIBINPUT_H */

View File

@ -1,98 +0,0 @@
/**
* @file mouse.c
*
*/
/*********************
* INCLUDES
*********************/
#include "mouse.h"
#if USE_MOUSE != 0
/*********************
* DEFINES
*********************/
#ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static bool left_button_down = false;
static int16_t last_x = 0;
static int16_t last_y = 0;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the mouse
*/
void mouse_init(void)
{
}
/**
* Get the current position and state of the mouse
* @param indev_drv pointer to the related input device driver
* @param data store the mouse data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
(void) indev_drv; /*Unused*/
/*Store the collected data*/
data->point.x = last_x;
data->point.y = last_y;
data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
return false;
}
/**
* It will be called from the main SDL thread
*/
void mouse_handler(SDL_Event * event)
{
switch(event->type) {
case SDL_MOUSEBUTTONUP:
if(event->button.button == SDL_BUTTON_LEFT)
left_button_down = false;
break;
case SDL_MOUSEBUTTONDOWN:
if(event->button.button == SDL_BUTTON_LEFT) {
left_button_down = true;
last_x = event->motion.x / MONITOR_ZOOM;
last_y = event->motion.y / MONITOR_ZOOM;
}
break;
case SDL_MOUSEMOTION:
last_x = event->motion.x / MONITOR_ZOOM;
last_y = event->motion.y / MONITOR_ZOOM;
break;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,78 +0,0 @@
/**
* @file mouse.h
*
*/
#ifndef MOUSE_H
#define MOUSE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_MOUSE
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#ifndef MONITOR_SDL_INCLUDE_PATH
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
#endif
#include MONITOR_SDL_INCLUDE_PATH
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the mouse
*/
void mouse_init(void);
/**
* Get the current position and state of the mouse
* @param indev_drv pointer to the related input device driver
* @param data store the mouse data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/**
* It will be called from the main SDL thread
*/
void mouse_handler(SDL_Event *event);
/**********************
* MACROS
**********************/
#endif /* USE_MOUSE */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* MOUSE_H */

View File

@ -1,100 +0,0 @@
/**
* @file mousewheel.c
*
*/
/*********************
* INCLUDES
*********************/
#include "mousewheel.h"
#if USE_MOUSEWHEEL
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static int16_t enc_diff = 0;
static lv_indev_state_t state = LV_INDEV_STATE_REL;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the mousewheel
*/
void mousewheel_init(void)
{
/*Nothing to init*/
}
/**
* Get encoder (i.e. mouse wheel) ticks difference and pressed state
* @param indev_drv pointer to the related input device driver
* @param data store the read data here
* @return false: all ticks and button state are handled
*/
bool mousewheel_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
(void) indev_drv; /*Unused*/
data->state = state;
data->enc_diff = enc_diff;
enc_diff = 0;
return false; /*No more data to read so return false*/
}
/**
* It is called periodically from the SDL thread to check mouse wheel state
* @param event describes the event
*/
void mousewheel_handler(SDL_Event * event)
{
switch(event->type) {
case SDL_MOUSEWHEEL:
// Scroll down (y = -1) means positive encoder turn,
// so invert it
#ifdef __EMSCRIPTEN__
/*Escripten scales it wrong*/
if(event->wheel.y < 0) enc_diff++;
if(event->wheel.y > 0) enc_diff--;
#else
enc_diff = -event->wheel.y;
#endif
break;
case SDL_MOUSEBUTTONDOWN:
if(event->button.button == SDL_BUTTON_MIDDLE) {
state = LV_INDEV_STATE_PR;
}
break;
case SDL_MOUSEBUTTONUP:
if(event->button.button == SDL_BUTTON_MIDDLE) {
state = LV_INDEV_STATE_REL;
}
break;
default:
break;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,79 +0,0 @@
/**
* @file mousewheel.h
*
*/
#ifndef MOUSEWHEEL_H
#define MOUSEWHEEL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_MOUSEWHEEL
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#ifndef MONITOR_SDL_INCLUDE_PATH
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
#endif
#include MONITOR_SDL_INCLUDE_PATH
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the encoder
*/
void mousewheel_init(void);
/**
* Get encoder (i.e. mouse wheel) ticks difference and pressed state
* @param indev_drv pointer to the related input device driver
* @param data store the read data here
* @return false: all ticks and button state are handled
*/
bool mousewheel_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/**
* It is called periodically from the SDL thread to check a key is pressed/released
* @param event describes the event
*/
void mousewheel_handler(SDL_Event *event);
/**********************
* MACROS
**********************/
#endif /*USE_MOUSEWHEEL*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*MOUSEWHEEL_H*/

View File

@ -1,13 +0,0 @@
{
"name": "lv_drivers",
"version": "6.0.2",
"keywords": "littlevgl, lvgl, driver, display, touchpad",
"description": "Drivers for LittlevGL graphics library.",
"repository": {
"type": "git",
"url": "https://github.com/littlevgl/lv_drivers.git"
},
"build": {
"includeDir": "."
}
}

View File

@ -1,10 +0,0 @@
include $(LVGL_DIR)/lv_drivers/display/display.mk
include $(LVGL_DIR)/lv_drivers/indev/indev.mk
CSRCS += win_drv.c
DEPPATH += --dep-path $(LVGL_DIR)/lv_drivers
VPATH += :$(LVGL_DIR)/lv_drivers
CFLAGS += "-I$(LVGL_DIR)/lv_drivers"

View File

@ -1,357 +0,0 @@
/**
* @file lv_drv_conf.h
*
*/
/*
* COPY THIS FILE AS lv_drv_conf.h
*/
#if 0 /*Set it to "1" to enable the content*/
#ifndef LV_DRV_CONF_H
#define LV_DRV_CONF_H
#include "lv_conf.h"
/*********************
* DELAY INTERFACE
*********************/
#define LV_DRV_DELAY_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/
#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/
/*********************
* DISPLAY INTERFACE
*********************/
/*------------
* Common
*------------*/
#define LV_DRV_DISP_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/
#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
/*---------
* SPI
*---------*/
#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/
#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/
/*------------------
* Parallel port
*-----------------*/
#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/
#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/
#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/
#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/
#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/
/***************************
* INPUT DEVICE INTERFACE
***************************/
/*----------
* Common
*----------*/
#define LV_DRV_INDEV_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/
/*---------
* SPI
*---------*/
#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/
/*---------
* I2C
*---------*/
#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/
#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/
#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/
#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/
#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/
/*********************
* DISPLAY DRIVERS
*********************/
/*-------------------
* Monitor of PC
*-------------------*/
#ifndef USE_MONITOR
# define USE_MONITOR 0
#endif
#if USE_MONITOR
# define MONITOR_HOR_RES LV_HOR_RES
# define MONITOR_VER_RES LV_VER_RES
/* Scale window by this factor (useful when simulating small screens) */
# define MONITOR_ZOOM 1
/* Used to test true double buffering with only address changing.
* Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */
# define MONITOR_DOUBLE_BUFFERED 0
/*Eclipse: <SDL2/SDL.h> Visual Studio: <SDL.h>*/
# define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Different rendering might be used if running in a Virtual machine*/
# define MONITOR_VIRTUAL_MACHINE 0
/*Open two windows to test multi display support*/
# define MONITOR_DUAL 0
#endif
/*-----------------------------------
* Native Windows (including mouse)
*----------------------------------*/
#ifndef USE_WINDOWS
# define USE_WINDOWS 0
#endif
#define USE_WINDOWS 0
#if USE_WINDOWS
# define WINDOW_HOR_RES 480
# define WINDOW_VER_RES 320
#endif
/*----------------
* SSD1963
*--------------*/
#ifndef USE_SSD1963
# define USE_SSD1963 0
#endif
#if USE_SSD1963
# define SSD1963_HOR_RES LV_HOR_RES
# define SSD1963_VER_RES LV_VER_RES
# define SSD1963_HT 531
# define SSD1963_HPS 43
# define SSD1963_LPS 8
# define SSD1963_HPW 10
# define SSD1963_VT 288
# define SSD1963_VPS 12
# define SSD1963_FPS 4
# define SSD1963_VPW 10
# define SSD1963_HS_NEG 0 /*Negative hsync*/
# define SSD1963_VS_NEG 0 /*Negative vsync*/
# define SSD1963_ORI 0 /*0, 90, 180, 270*/
# define SSD1963_COLOR_DEPTH 16
#endif
/*----------------
* R61581
*--------------*/
#ifndef USE_R61581
# define USE_R61581 0
#endif
#if USE_R61581
# define R61581_HOR_RES LV_HOR_RES
# define R61581_VER_RES LV_VER_RES
# define R61581_HSPL 0 /*HSYNC signal polarity*/
# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/
# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/
# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */
# define R61581_VSPL 0 /*VSYNC signal polarity*/
# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/
# define R61581_VFP 8 /*Vertical Front poarch*/
# define R61581_VBP 8 /*Vertical Back poarch */
# define R61581_DPL 0 /*DCLK signal polarity*/
# define R61581_EPL 1 /*ENABLE signal polarity*/
# define R61581_ORI 0 /*0, 180*/
# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/
#endif
/*------------------------------
* ST7565 (Monochrome, low res.)
*-----------------------------*/
#ifndef USE_ST7565
# define USE_ST7565 0
#endif
#if USE_ST7565
/*No settings*/
#endif /*USE_ST7565*/
/*------------------------------------------
* UC1610 (4 gray 160*[104|128])
* (EA DOGXL160 160x104 tested)
*-----------------------------------------*/
#ifndef USE_UC1610
# define USE_UC1610 0
#endif
#if USE_UC1610
# define UC1610_HOR_RES LV_HOR_RES
# define UC1610_VER_RES LV_VER_RES
# define UC1610_INIT_CONTRAST 33 /* init contrast, values in [%] */
# define UC1610_INIT_HARD_RST 0 /* 1 : hardware reset at init, 0 : software reset */
# define UC1610_TOP_VIEW 0 /* 0 : Bottom View, 1 : Top View */
#endif /*USE_UC1610*/
/*-------------------------------------------------
* SHARP memory in pixel monochrome display series
* LS012B7DD01 (184x38 pixels.)
* LS013B7DH03 (128x128 pixels.)
* LS013B7DH05 (144x168 pixels.)
* LS027B7DH01 (400x240 pixels.) (tested)
* LS032B7DD02 (336x536 pixels.)
* LS044Q7DH01 (320x240 pixels.)
*------------------------------------------------*/
#ifndef USE_SHARP_MIP
# define USE_SHARP_MIP 0
#endif
#if USE_SHARP_MIP
# define SHARP_MIP_HOR_RES LV_HOR_RES
# define SHARP_MIP_VER_RES LV_VER_RES
# define SHARP_MIP_SOFT_COM_INVERSION 0
# define SHARP_MIP_REV_BYTE(b) /*((uint8_t) __REV(__RBIT(b)))*/ /*Architecture / compiler dependent byte bits order reverse*/
#endif /*USE_SHARP_MIP*/
/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/
#ifndef USE_FBDEV
# define USE_FBDEV 0
#endif
#if USE_FBDEV
# define FBDEV_PATH "/dev/fb0"
#endif
/*-----------------------------------------
* FreeBSD frame buffer device (/dev/fbx)
*.........................................*/
#ifndef USE_BSD_FBDEV
# define USE_BSD_FBDEV 0
#endif
#if USE_BSD_FBDEV
# define FBDEV_PATH "/dev/fb0"
#endif
/*********************
* INPUT DEVICES
*********************/
/*--------------
* XPT2046
*--------------*/
#ifndef USE_XPT2046
# define USE_XPT2046 0
#endif
#if USE_XPT2046
# define XPT2046_HOR_RES 480
# define XPT2046_VER_RES 320
# define XPT2046_X_MIN 200
# define XPT2046_Y_MIN 200
# define XPT2046_X_MAX 3800
# define XPT2046_Y_MAX 3800
# define XPT2046_AVG 4
# define XPT2046_INV 0
#endif
/*-----------------
* FT5406EE8
*-----------------*/
#ifndef USE_FT5406EE8
# define USE_FT5406EE8 0
#endif
#if USE_FT5406EE8
# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/
#endif
/*---------------
* AD TOUCH
*--------------*/
#ifndef USE_AD_TOUCH
# define USE_AD_TOUCH 0
#endif
#if USE_AD_TOUCH
/*No settings*/
#endif
/*---------------------------------------
* Mouse or touchpad on PC (using SDL)
*-------------------------------------*/
#ifndef USE_MOUSE
# define USE_MOUSE 0
#endif
#if USE_MOUSE
/*No settings*/
#endif
/*-------------------------------------------
* Mousewheel as encoder on PC (using SDL)
*------------------------------------------*/
#ifndef USE_MOUSEWHEEL
# define USE_MOUSEWHEEL 0
#endif
#if USE_MOUSEWHEEL
/*No settings*/
#endif
/*-------------------------------------------------
* Touchscreen as libinput interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_LIBINPUT
# define USE_LIBINPUT 0
#endif
#if USE_LIBINPUT
# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
#endif /*USE_LIBINPUT*/
/*-------------------------------------------------
* Mouse or touchpad as evdev interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_EVDEV
# define USE_EVDEV 0
#endif
#if USE_EVDEV
# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/
# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */
# if EVDEV_SCALE
# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */
# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */
# endif /*EVDEV_SCALE*/
# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
# if EVDEV_CALIBRATE
# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
# define EVDEV_HOR_MAX 200
# define EVDEV_VER_MIN 200
# define EVDEV_VER_MAX 3800
# endif /*EVDEV_SCALE*/
#endif /*USE_EVDEV*/
/*-------------------------------
* Keyboard of a PC (using SDL)
*------------------------------*/
#ifndef USE_KEYBOARD
# define USE_KEYBOARD 0
#endif
#if USE_KEYBOARD
/*No settings*/
#endif
#endif /*LV_DRV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -1,318 +0,0 @@
/**
* @file win_drv.c
*
*/
/*********************
* INCLUDES
*********************/
#include "win_drv.h"
#if USE_WINDOWS
#include <windows.h>
#include <windowsx.h>
#include "lvgl/lvgl.h"
#if LV_COLOR_DEPTH < 16
#error Windows driver only supports true RGB colors at this time
#endif
/**********************
* DEFINES
**********************/
#define WINDOW_STYLE (WS_OVERLAPPEDWINDOW & ~(WS_SIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME))
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void do_register(void);
static void win_drv_flush(lv_disp_t *drv, lv_area_t *area, const lv_color_t * color_p);
static void win_drv_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
static void win_drv_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
static bool win_drv_read(lv_indev_t *drv, lv_indev_data_t * data);
static void msg_handler(void *param);
static COLORREF lv_color_to_colorref(const lv_color_t color);
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
/**********************
* GLOBAL VARIABLES
**********************/
bool lv_win_exit_flag = false;
lv_disp_t *lv_windows_disp;
/**********************
* STATIC VARIABLES
**********************/
static HWND hwnd;
static uint32_t *fbp = NULL; /* Raw framebuffer memory */
static bool mouse_pressed;
static int mouse_x, mouse_y;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
const char g_szClassName[] = "LittlevGL";
HWND windrv_init(void)
{
WNDCLASSEX wc;
RECT winrect;
HICON lvgl_icon;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
lvgl_icon = (HICON) LoadImage( NULL, "lvgl_icon.bmp", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
if(lvgl_icon == NULL)
lvgl_icon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIcon = lvgl_icon;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = lvgl_icon;
if(!RegisterClassEx(&wc))
{
return NULL;
}
winrect.left = 0;
winrect.right = WINDOW_HOR_RES - 1;
winrect.top = 0;
winrect.bottom = WINDOW_VER_RES - 1;
AdjustWindowRectEx(&winrect, WINDOW_STYLE, FALSE, WS_EX_CLIENTEDGE);
OffsetRect(&winrect, -winrect.left, -winrect.top);
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"LittlevGL Simulator",
WINDOW_STYLE,
CW_USEDEFAULT, CW_USEDEFAULT, winrect.right, winrect.bottom,
NULL, NULL, GetModuleHandle(NULL), NULL);
if(hwnd == NULL)
{
return NULL;
}
ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);
lv_task_create(msg_handler, 0, LV_TASK_PRIO_HIGHEST, NULL);
lv_win_exit_flag = false;
do_register();
}
/**********************
* STATIC FUNCTIONS
**********************/
static void do_register(void)
{
/*-----------------------------
* Create a buffer for drawing
*----------------------------*/
/* LittlevGL requires a buffer where it draw the objects. The buffer's has to be greater than 1 display row
*
* There are three buffering configurations:
* 1. Create ONE buffer some rows: LittlevGL will draw the display's content here and writes it to your display
* 2. Create TWO buffer some rows: LittlevGL will draw the display's content to a buffer and writes it your display.
* You should use DMA to write the buffer's content to the display.
* It will enable LittlevGL to draw the next part of the screen to the other buffer while
* the data is being sent form the first buffer. It makes rendering and flushing parallel.
* 3. Create TWO screen buffer: Similar to 2) but the buffer have to be screen sized. When LittlevGL is ready it will give the
* whole frame to display. This way you only need to change the frame buffer's address instead of
* copying the pixels.
* */
/* Example for 1) */
static lv_disp_buf_t disp_buf_1;
static lv_color_t buf1_1[WINDOW_HOR_RES * WINDOW_VER_RES]; /*A buffer for 10 rows*/
lv_disp_buf_init(&disp_buf_1, buf1_1, NULL, WINDOW_HOR_RES * WINDOW_VER_RES); /*Initialize the display buffer*/
/*-----------------------------------
* Register the display in LittlevGL
*----------------------------------*/
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
/*Set up the functions to access to your display*/
/*Set the resolution of the display*/
disp_drv.hor_res = WINDOW_HOR_RES;
disp_drv.ver_res = WINDOW_VER_RES;
/*Used to copy the buffer's content to the display*/
disp_drv.flush_cb = win_drv_flush;
/*Set a display buffer*/
disp_drv.buffer = &disp_buf_1;
/*Finally register the driver*/
lv_windows_disp = lv_disp_drv_register(&disp_drv);
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = win_drv_read;
lv_indev_drv_register(&indev_drv);
}
static void msg_handler(void *param)
{
(void)param;
MSG msg;
BOOL bRet;
if( (bRet = PeekMessage( &msg, NULL, 0, 0, TRUE )) != 0)
{
if (bRet == -1)
{
return;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if(msg.message == WM_QUIT)
lv_win_exit_flag = true;
}
static bool win_drv_read(lv_indev_t *drv, lv_indev_data_t * data)
{
data->state = mouse_pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
data->point.x = mouse_x;
data->point.y = mouse_y;
return false;
}
static void on_paint(void)
{
HBITMAP bmp = CreateBitmap(WINDOW_HOR_RES, WINDOW_VER_RES, 1, 32, fbp);
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = SelectObject(hdcMem, bmp);
BitBlt(hdc, 0, 0, WINDOW_HOR_RES, WINDOW_VER_RES, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
DeleteObject(bmp);
}
/**
* Flush a buffer to the marked area
* @param x1 left coordinate
* @param y1 top coordinate
* @param x2 right coordinate
* @param y2 bottom coordinate
* @param color_p an array of colors
*/
static void win_drv_flush(lv_disp_t *drv, lv_area_t *area, const lv_color_t * color_p)
{
win_drv_map(area->x1, area->y1, area->x2, area->y2, color_p);
lv_disp_flush_ready(drv);
}
/**
* Put a color map to the marked area
* @param x1 left coordinate
* @param y1 top coordinate
* @param x2 right coordinate
* @param y2 bottom coordinate
* @param color_p an array of colors
*/
static void win_drv_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
{
for(int y = y1; y <= y2; y++)
{
for(int x = x1; x <= x2; x++)
{
fbp[y*WINDOW_HOR_RES+x] = lv_color_to32(*color_p);
color_p++;
}
}
InvalidateRect(hwnd, NULL, FALSE);
UpdateWindow(hwnd);
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch(msg) {
case WM_CREATE:
fbp = malloc(4*WINDOW_HOR_RES*WINDOW_VER_RES);
if(fbp == NULL)
return 1;
return 0;
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
mouse_x = GET_X_LPARAM(lParam);
mouse_y = GET_Y_LPARAM(lParam);
if(msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) {
mouse_pressed = (msg == WM_LBUTTONDOWN);
}
return 0;
case WM_CLOSE:
free(fbp);
fbp = NULL;
DestroyWindow(hwnd);
return 0;
case WM_PAINT:
on_paint();
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
static COLORREF lv_color_to_colorref(const lv_color_t color)
{
uint32_t raw_color = lv_color_to32(color);
lv_color32_t tmp;
tmp.full = raw_color;
uint32_t colorref = RGB(tmp.ch.red, tmp.ch.green, tmp.ch.blue);
return colorref;
}
#endif

View File

@ -1,60 +0,0 @@
/**
* @file fbdev.h
*
*/
#ifndef WINDRV_H
#define WINDRV_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../lv_drv_conf.h"
#endif
#endif
#if USE_WINDOWS
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#include <windows.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
extern bool lv_win_exit_flag;
extern lv_disp_t *lv_windows_disp;
HWND windrv_init(void);
/**********************
* MACROS
**********************/
#endif /*USE_WINDOWS*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*WIN_DRV_H*/

View File

@ -1,65 +0,0 @@
/**
* @file tft_espi_drv.h
*
*/
#ifndef TFT_ESPI_DRV_H
#define TFT_ESPI_DRV_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifndef LV_DRV_NO_CONF
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#endif
#if USE_TFT_ESPI
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void tft_espi_init(uint8_t rotation, bool invert_display=false);
void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p);
// void tft_espi_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
void tft_espi_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
void tft_espi_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
#if defined(TOUCH_CS)
void tft_espi_calibrate(uint16_t * calData);
void tft_espi_set_touch(uint16_t * calData);
bool tft_espi_get_touch(int16_t * touchX, int16_t * touchY, uint16_t threshold);
#endif
/**********************
* MACROS
**********************/
#endif /* USE_TFT_ESPI */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* TFT_ESPI_DRV_H */

View File

@ -21,30 +21,30 @@
**********************/
/* Create a type to store the required data about your file.*/
typedef FIL file_t;
typedef FIL file_t;
/*Similarly to `file_t` create a type for directory reading too */
typedef DIR dir_t;
typedef DIR dir_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void fs_init(void);
static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode);
static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p);
static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br);
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos);
static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p);
static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p);
static lv_fs_res_t fs_remove (lv_fs_drv_t * drv, const char *path);
static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p);
static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const char * newname);
static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p);
static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *path);
static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * dir_p, char *fn);
static lv_fs_res_t fs_dir_close (lv_fs_drv_t * drv, void * dir_p);
static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode);
static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p);
static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br);
static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw);
static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos);
static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p);
static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p);
static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path);
static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p);
static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname);
static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p);
static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path);
static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn);
static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p);
/**********************
* STATIC VARIABLES
@ -70,28 +70,28 @@ void lv_fs_if_fatfs_init(void)
*--------------------------------------------------*/
/* Add a simple drive to open images */
lv_fs_drv_t fs_drv; /*A driver descriptor*/
lv_fs_drv_init(&fs_drv);
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
lv_fs_drv_init(&fs_drv);
/*Set up fields...*/
fs_drv.file_size = sizeof(file_t);
fs_drv.letter = LV_FS_IF_FATFS;
fs_drv.open_cb = fs_open;
fs_drv.close_cb = fs_close;
fs_drv.read_cb = fs_read;
fs_drv.write_cb = fs_write;
fs_drv.seek_cb = fs_seek;
fs_drv.tell_cb = fs_tell;
fs_drv.file_size = sizeof(file_t);
fs_drv.letter = LV_FS_IF_FATFS;
fs_drv.open_cb = fs_open;
fs_drv.close_cb = fs_close;
fs_drv.read_cb = fs_read;
fs_drv.write_cb = fs_write;
fs_drv.seek_cb = fs_seek;
fs_drv.tell_cb = fs_tell;
fs_drv.free_space_cb = fs_free;
fs_drv.size_cb = fs_size;
fs_drv.remove_cb = fs_remove;
fs_drv.rename_cb = fs_rename;
fs_drv.trunc_cb = fs_trunc;
fs_drv.size_cb = fs_size;
fs_drv.remove_cb = fs_remove;
fs_drv.rename_cb = fs_rename;
fs_drv.trunc_cb = fs_trunc;
fs_drv.rddir_size = sizeof(dir_t);
fs_drv.rddir_size = sizeof(dir_t);
fs_drv.dir_close_cb = fs_dir_close;
fs_drv.dir_open_cb = fs_dir_open;
fs_drv.dir_read_cb = fs_dir_read;
fs_drv.dir_open_cb = fs_dir_open;
fs_drv.dir_read_cb = fs_dir_read;
lv_fs_drv_register(&fs_drv);
}
@ -115,25 +115,27 @@ static void fs_init(void)
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode)
static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode)
{
uint8_t flags = 0;
if(mode == LV_FS_MODE_WR) flags = FA_WRITE | FA_OPEN_ALWAYS;
else if(mode == LV_FS_MODE_RD) flags = FA_READ;
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = FA_READ | FA_WRITE | FA_OPEN_ALWAYS;
if(mode == LV_FS_MODE_WR)
flags = FA_WRITE | FA_OPEN_ALWAYS;
else if(mode == LV_FS_MODE_RD)
flags = FA_READ;
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
flags = FA_READ | FA_WRITE | FA_OPEN_ALWAYS;
FRESULT res = f_open(file_p, path, flags);
if(res == FR_OK) {
f_lseek(file_p, 0);
return LV_FS_RES_OK;
f_lseek(file_p, 0);
return LV_FS_RES_OK;
} else {
return LV_FS_RES_UNKNOWN;
return LV_FS_RES_UNKNOWN;
}
}
/**
* Close an opened file
* @param drv pointer to a driver where this function belongs
@ -141,7 +143,7 @@ static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path,
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p)
static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p)
{
f_close(file_p);
return LV_FS_RES_OK;
@ -157,11 +159,13 @@ static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br)
{
FRESULT res = f_read(file_p, buf, btr, (UINT*)br);
if(res == FR_OK) return LV_FS_RES_OK;
else return LV_FS_RES_UNKNOWN;
if(res == FR_OK)
return LV_FS_RES_OK;
else
return LV_FS_RES_UNKNOWN;
}
/**
@ -173,11 +177,13 @@ static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32
* @param br the number of real written bytes (Bytes Written). NULL if unused.
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw)
static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw)
{
FRESULT res = f_write(file_p, buf, btw, (UINT*)bw);
if(res == FR_OK) return LV_FS_RES_OK;
else return LV_FS_RES_UNKNOWN;
FRESULT res = f_write(file_p, buf, btw, (UINT*)bw);
if(res == FR_OK)
return LV_FS_RES_OK;
else
return LV_FS_RES_UNKNOWN;
}
/**
@ -188,7 +194,7 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos)
static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos)
{
f_lseek(file_p, pos);
return LV_FS_RES_OK;
@ -201,9 +207,9 @@ static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos)
* @param size pointer to a variable to store the size
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p)
{
(*size_p) = f_size(((file_t *)file_p));
(*size_p) = f_size(((file_t*)file_p));
return LV_FS_RES_OK;
}
@ -215,9 +221,9 @@ static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p)
{
*pos_p = f_tell(((file_t *)file_p));
*pos_p = f_tell(((file_t*)file_p));
return LV_FS_RES_OK;
}
@ -227,7 +233,7 @@ static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
* @param path path of the file to delete
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_remove (lv_fs_drv_t * drv, const char *path)
static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path)
{
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
@ -243,9 +249,9 @@ static lv_fs_res_t fs_remove (lv_fs_drv_t * drv, const char *path)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p)
static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p)
{
f_sync(file_p); /*If not syncronized fclose can write the truncated part*/
f_sync(file_p); /*If not syncronized fclose can write the truncated part*/
f_truncate(file_p);
return LV_FS_RES_OK;
}
@ -257,13 +263,15 @@ static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p)
* @param newname path with the new name
* @return LV_FS_RES_OK or any error from 'fs_res_t'
*/
static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const char * newname)
static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname)
{
FRESULT res = f_rename(oldname, newname);
if(res == FR_OK) return LV_FS_RES_OK;
else return LV_FS_RES_UNKNOWN;
if(res == FR_OK)
return LV_FS_RES_OK;
else
return LV_FS_RES_UNKNOWN;
}
/**
@ -274,7 +282,7 @@ static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const cha
* @param free_p pointer to store the free size [kB]
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p)
static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p)
{
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
@ -290,11 +298,13 @@ static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fr
* @param path path to a directory
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *path)
static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path)
{
FRESULT res = f_opendir(dir_p, path);
if(res == FR_OK) return LV_FS_RES_OK;
else return LV_FS_RES_UNKNOWN;
if(res == FR_OK)
return LV_FS_RES_OK;
else
return LV_FS_RES_UNKNOWN;
}
/**
@ -305,21 +315,21 @@ static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *pat
* @param fn pointer to a buffer to store the filename
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * dir_p, char *fn)
static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn)
{
FRESULT res;
FILINFO fno;
fn[0] = '\0';
FRESULT res;
FILINFO fno;
fn[0] = '\0';
do {
res = f_readdir(dir_p, &fno);
if(res != FR_OK) return LV_FS_RES_UNKNOWN;
res = f_readdir(dir_p, &fno);
if(res != FR_OK) return LV_FS_RES_UNKNOWN;
if(fno.fattrib & AM_DIR) {
fn[0] = '/';
strcpy(&fn[1], fno.fname);
}
else strcpy(fn, fno.fname);
if(fno.fattrib & AM_DIR) {
fn[0] = '/';
strcpy(&fn[1], fno.fname);
} else
strcpy(fn, fno.fname);
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
@ -332,11 +342,11 @@ static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * dir_p, char *fn)
* @param dir_p pointer to an initialized 'fs_read_dir_t' variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_close (lv_fs_drv_t * drv, void * dir_p)
static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p)
{
f_closedir(dir_p);
f_closedir(dir_p);
return LV_FS_RES_OK;
}
#endif /*LV_USE_FS_IF*/
#endif /*LV_FS_IF_FATFS*/
#endif /*LV_USE_FS_IF*/
#endif /*LV_FS_IF_FATFS*/

View File

@ -8,58 +8,62 @@
*********************/
#include "lv_fs_if.h"
#if LV_USE_FS_IF
#if LV_FS_IF_PC != '\0'
#if LV_FS_IF_PC != '\0'
#include <stdio.h>
#include <errno.h>
#include <dirent.h>
#include <unistd.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#if !defined(ARDUINO_ARCH_ESP8266) && !defined(STM32F4xx)
#include <dirent.h>
#endif
#ifdef WIN32
#include <windows.h>
#endif
/*********************
* DEFINES
*********************/
#ifndef LV_FS_PC_PATH
#ifndef WIN32
#define LV_FS_PC_PATH "/fs" /*Projet root*/
#else
#define LV_FS_PC_PATH ".\\" /*Projet root*/
#endif
#endif /*LV_FS_PATH*/
/*********************
* DEFINES
*********************/
#ifndef LV_FS_PC_PATH
#ifndef WIN32
#define LV_FS_PC_PATH "/fs" /*Projet root*/
#else
#define LV_FS_PC_PATH ".\\" /*Projet root*/
#endif
#endif /*LV_FS_PATH*/
/**********************
* TYPEDEFS
**********************/
/* Create a type to store the required data about your file. */
typedef FILE * file_t;
typedef FILE* file_t;
/*Similarly to `file_t` create a type for directory reading too */
#ifndef WIN32
typedef DIR * dir_t;
#else
/*Similarly to `file_t` create a type for directory reading too */
#if defined(WIN32)
typedef HANDLE dir_t;
#endif
#elif defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx)
typedef FILE* dir_t;
#else
typedef DIR* dir_t;
#endif
/**********************
* STATIC PROTOTYPES
**********************/
static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode);
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p);
static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br);
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos);
static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p);
static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p);
static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path);
static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p);
static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * newname);
static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p);
static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * path);
static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn);
static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p);
static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode);
static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p);
static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br);
static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw);
static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos);
static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p);
static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p);
static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path);
static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p);
static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname);
static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p);
static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path);
static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn);
static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p);
/**********************
* STATIC VARIABLES
@ -83,7 +87,7 @@ void lv_fs_if_pc_init(void)
*--------------------------------------------------*/
/* Add a simple drive to open images */
lv_fs_drv_t fs_drv; /*A driver descriptor*/
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
lv_fs_drv_init(&fs_drv);
/*Set up fields...*/
@ -121,12 +125,12 @@ void lv_fs_if_pc_init(void)
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode)
static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode)
{
(void)drv; /*Unused*/
errno = 0;
const char * flags = "";
const char* flags = "";
if(mode == LV_FS_MODE_WR)
flags = "wb";
@ -135,16 +139,16 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path,
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
flags = "rb+";
/*Make the path relative to the current directory (the projects root folder)*/
/*Make the path relative to the current directory (the projects root folder)*/
#ifndef WIN32
#ifndef WIN32
char buf[256];
sprintf(buf, LV_FS_PC_PATH "/%s", path);
printf("%s\n", buf);
#else
#else
char buf[256];
sprintf(buf, LV_FS_PC_PATH "\\%s", path);
#endif
#endif
file_t f = fopen(buf, flags);
if(f == NULL) {
@ -156,8 +160,8 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path,
/* 'file_p' is pointer to a file descriptor and
* we need to store our file descriptor here*/
file_t * fp = file_p; /*Just avoid the confusing casings*/
*fp = f;
file_t* fp = file_p; /*Just avoid the confusing casings*/
*fp = f;
return LV_FS_RES_OK;
}
@ -169,10 +173,10 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path,
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p)
{
(void)drv; /*Unused*/
file_t * fp = file_p; /*Just avoid the confusing casings*/
(void)drv; /*Unused*/
file_t* fp = file_p; /*Just avoid the confusing casings*/
fclose(*fp);
return LV_FS_RES_OK;
}
@ -187,11 +191,11 @@ static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br)
{
(void)drv; /*Unused*/
file_t * fp = file_p; /*Just avoid the confusing casings*/
*br = fread(buf, 1, btr, *fp);
(void)drv; /*Unused*/
file_t* fp = file_p; /*Just avoid the confusing casings*/
*br = fread(buf, 1, btr, *fp);
return LV_FS_RES_OK;
}
@ -204,11 +208,11 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_
* @param br the number of real written bytes (Bytes Written). NULL if unused.
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw)
static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw)
{
(void)drv; /*Unused*/
file_t * fp = file_p; /*Just avoid the confusing casings*/
*bw = fwrite(buf, 1, btw, *fp);
(void)drv; /*Unused*/
file_t* fp = file_p; /*Just avoid the confusing casings*/
*bw = fwrite(buf, 1, btw, *fp);
return LV_FS_RES_OK;
}
@ -220,10 +224,10 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos)
static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos)
{
(void)drv; /*Unused*/
file_t * fp = file_p; /*Just avoid the confusing casings*/
(void)drv; /*Unused*/
file_t* fp = file_p; /*Just avoid the confusing casings*/
fseek(*fp, pos, SEEK_SET);
return LV_FS_RES_OK;
}
@ -235,10 +239,10 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos)
* @param size pointer to a variable to store the size
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p)
{
(void)drv; /*Unused*/
file_t * fp = file_p; /*Just avoid the confusing casings*/
(void)drv; /*Unused*/
file_t* fp = file_p; /*Just avoid the confusing casings*/
uint32_t cur = ftell(*fp);
@ -258,11 +262,11 @@ static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p)
{
(void)drv; /*Unused*/
file_t * fp = file_p; /*Just avoid the confusing casings*/
*pos_p = ftell(*fp);
(void)drv; /*Unused*/
file_t* fp = file_p; /*Just avoid the confusing casings*/
*pos_p = ftell(*fp);
return LV_FS_RES_OK;
}
@ -272,7 +276,7 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
* @param path path of the file to delete
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path)
static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path)
{
(void)drv; /*Unused*/
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
@ -289,10 +293,10 @@ static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p)
static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p)
{
(void)drv; /*Unused*/
file_t * fp = file_p; /*Just avoid the confusing casings*/
(void)drv; /*Unused*/
file_t* fp = file_p; /*Just avoid the confusing casings*/
fflush(*fp); /*If not syncronized fclose can write the truncated part*/
uint32_t p = ftell(*fp);
@ -307,7 +311,7 @@ static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p)
* @param newname path with the new name
* @return LV_FS_RES_OK or any error from 'fs_res_t'
*/
static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * newname)
static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname)
{
(void)drv; /*Unused*/
static char new[512];
@ -316,12 +320,14 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char
sprintf(old, LV_FS_PC_PATH "/%s", oldname);
sprintf(new, LV_FS_PC_PATH "/%s", newname);
int r = rename(old, new);
return LV_FS_RES_UNKNOWN;
if(r == 0)
return LV_FS_RES_OK;
else
return LV_FS_RES_UNKNOWN;
// int r = rename(old, new);
// if(r == 0)
// return LV_FS_RES_OK;
// else
// return LV_FS_RES_UNKNOWN;
}
/**
@ -332,7 +338,7 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char
* @param free_p pointer to store the free size [kB]
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p)
static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p)
{
(void)drv; /*Unused*/
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
@ -342,9 +348,9 @@ static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fre
return res;
}
#ifdef WIN32
#ifdef WIN32
static char next_fn[256];
#endif
#endif
/**
* Initialize a 'fs_read_dir_t' variable for directory reading
@ -353,11 +359,14 @@ static char next_fn[256];
* @param path path to a directory
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * path)
static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path)
{
(void)drv; /*Unused*/
dir_t d;
#ifndef WIN32
#if defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx)
return LV_FS_RES_UNKNOWN;
#elif !defined(WIN32)
/*Make the path relative to the current directory (the projects root folder)*/
char buf[256];
sprintf(buf, LV_FS_PC_PATH "/%s", path);
@ -366,10 +375,10 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat
} else {
/* 'dir_p' is pointer to a file descriptor and
* we need to store our file descriptor here*/
dir_t * dp = dir_p; /*Just avoid the confusing casings*/
*dp = d;
dir_t* dp = dir_p; /*Just avoid the confusing casings*/
*dp = d;
}
#else
#else
d = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA fdata;
@ -393,10 +402,10 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat
}
} while(FindNextFileA(d, &fdata));
dir_t * dp = dir_p; /*Just avoid the confusing casings*/
*dp = d;
dir_t* dp = dir_p; /*Just avoid the confusing casings*/
*dp = d;
#endif
#endif
return LV_FS_RES_OK;
}
@ -409,17 +418,18 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat
* @param fn pointer to a buffer to store the filename
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn)
{
(void)drv; /*Unused*/
dir_t * dp = dir_p; /*Just avoid the confusing casings*/
(void)drv; /*Unused*/
dir_t* dp = dir_p; /*Just avoid the confusing casings*/
#ifndef WIN32
struct dirent * entry;
#ifdef ARDUINO_ARCH_ESP32
struct dirent* entry;
do {
entry = readdir(*dp);
if(entry) {
if(entry->d_type == DT_DIR)
sprintf(fn, "/%s", entry->d_name);
else
@ -428,7 +438,9 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
strcpy(fn, "");
}
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
#else
#endif
#ifdef WIN32
strcpy(fn, next_fn);
strcpy(next_fn, "");
@ -449,7 +461,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
}
} while(FindNextFile(*dp, &fdata));
#endif
#endif
return LV_FS_RES_OK;
}
@ -459,18 +471,21 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
* @param dir_p pointer to an initialized 'fs_read_dir_t' variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p)
static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p)
{
(void)drv; /*Unused*/
dir_t * dp = dir_p;
#ifndef WIN32
dir_t* dp = dir_p;
#if defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx)
return LV_FS_RES_UNKNOWN;
#elif !defined(WIN32)
closedir(*dp);
#else
#else
FindClose(*dp);
*dp = INVALID_HANDLE_VALUE;
#endif
#endif
return LV_FS_RES_OK;
}
#endif /*LV_USE_FS_IF*/
#endif /*LV_FS_IF_FATFS*/
#endif /*LV_USE_FS_IF*/
#endif /*LV_FS_IF_FATFS*/

View File

@ -6,33 +6,35 @@
/*********************
* INCLUDES
*********************/
#ifdef ARDUINO
#include <Arduino.h>
#include "lv_fs_if.h"
#include "lv_fs_spiffs.h"
#include "ArduinoLog.h"
#if LV_USE_FS_IF
#if LV_FS_IF_SPIFFS != '\0'
#if LV_FS_IF_SPIFFS != '\0'
#if defined(ARDUINO_ARCH_ESP32)
#if HASP_USE_SPIFFS > 0
#include "SPIFFS.h"
#define LV_FS_SPIFFS SPIFFS
#elif HASP_USE_LITTLEFS > 0
#include "LITTLEFS.h"
#define LV_FS_SPIFFS LITTLEFS
#endif
#elif defined(ARDUINO_ARCH_ESP8266)
#include "LittleFS.h"
#define LV_FS_SPIFFS LittleFS
#endif // ARDUINO_ARCH
#if defined(ARDUINO_ARCH_ESP32)
#if HASP_USE_SPIFFS > 0
#include "SPIFFS.h"
#define LV_FS_SPIFFS SPIFFS
#elif HASP_USE_LITTLEFS > 0
#include "LITTLEFS.h"
#define LV_FS_SPIFFS LITTLEFS
#endif
#elif defined(ARDUINO_ARCH_ESP8266)
#include "LittleFS.h"
#define LV_FS_SPIFFS LittleFS
#endif // ARDUINO_ARCH
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include <FS.h>
#include <Esp.h>
#endif // ARDUINO_ARCH
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include <FS.h>
#include <Esp.h>
#endif // ARDUINO_ARCH
#define TAG_LVFS 91
#define TAG_LVFS 91
/*********************
* DEFINES
@ -45,34 +47,34 @@
/* Create a type to store the required data about your file.*/
typedef File lv_spiffs_file_t;
/*Similarly to `file_t` create a type for directory reading too */
#if defined(ARDUINO_ARCH_ESP32)
/*Similarly to `file_t` create a type for directory reading too */
#if defined(ARDUINO_ARCH_ESP32)
typedef File lv_spiffs_dir_t;
#elif defined(ARDUINO_ARCH_ESP8266)
#elif defined(ARDUINO_ARCH_ESP8266)
typedef Dir lv_spiffs_dir_t;
#define FILE_READ "r"
#define FILE_WRITE "r+"
#endif
#define FILE_READ "r"
#define FILE_WRITE "r+"
#endif
/**********************
* STATIC PROTOTYPES
**********************/
static void fs_init(void);
static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode);
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p);
static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br);
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos);
static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p);
static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p);
static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path);
static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p);
static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * newname);
static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p);
static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * path);
static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn);
static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p);
static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode);
static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p);
static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br);
static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw);
static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos);
static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p);
static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p);
static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path);
static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p);
static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname);
static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p);
static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path);
static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn);
static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p);
/**********************
* STATIC VARIABLES
@ -98,7 +100,7 @@ void lv_fs_if_spiffs_init(void)
*--------------------------------------------------*/
/* Add a simple drive to open images */
lv_fs_drv_t fs_drv; /*A driver descriptor*/
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
lv_fs_drv_init(&fs_drv);
/*Set up fields...*/
@ -142,14 +144,14 @@ static void fs_init(void)
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode)
static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode)
{
(void)drv; /*Unused*/
char filename[32];
snprintf_P(filename, sizeof(filename), PSTR("/%s"), path);
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p;
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p;
if(fp == NULL) return LV_FS_RES_INV_PARAM;
LOG_VERBOSE(TAG_LVFS, F("Opening %s"), filename);
@ -184,10 +186,10 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path,
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p)
{
(void)drv; /*Unused*/
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p;
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p;
if(fp == NULL) return LV_FS_RES_INV_PARAM;
lv_spiffs_file_t file = *fp;
@ -215,10 +217,10 @@ static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br)
{
(void)drv; /*Unused*/
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p;
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p;
if(fp == NULL) return LV_FS_RES_INV_PARAM;
lv_spiffs_file_t file = *fp;
@ -230,7 +232,7 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_
} else {
// LOG_VERBOSE(TAG_LVFS, F("Reading %u bytes from %s at position %u"), btr, file.name(), file.position());
uint32_t len = 0;
char * chp = (char *)buf;
char* chp = (char*)buf;
if(chp != NULL && btr > 0)
len = file.readBytes(chp, btr);
else
@ -255,10 +257,10 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_
* @param br the number of real written bytes (Bytes Written). NULL if unused.
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw)
static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw)
{
(void)drv; /*Unused*/
lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p;
lv_spiffs_file_t file = *(lv_spiffs_file_t*)file_p;
// File file = fp;
if(!file) {
@ -266,7 +268,7 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
return LV_FS_RES_NOT_EX;
} else {
*bw = (uint32_t)file.write((byte *)buf, btw);
*bw = (uint32_t)file.write((byte*)buf, btw);
return LV_FS_RES_OK;
}
}
@ -279,10 +281,10 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos)
static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos)
{
(void)drv; /*Unused*/
lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p;
lv_spiffs_file_t file = *(lv_spiffs_file_t*)file_p;
// File file = fp;
if(!file) {
@ -302,10 +304,10 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos)
* @param size pointer to a variable to store the size
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p)
{
(void)drv; /*Unused*/
lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p;
lv_spiffs_file_t file = *(lv_spiffs_file_t*)file_p;
// File file = fp;
if(!file) {
@ -326,10 +328,10 @@ static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p)
{
(void)drv; /*Unused*/
lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p;
lv_spiffs_file_t file = *(lv_spiffs_file_t*)file_p;
// File file = fp;
if(!file) {
@ -348,7 +350,7 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
* @param path path of the file to delete
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path)
static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path)
{
(void)drv; /*Unused*/
@ -373,7 +375,7 @@ static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p)
static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p)
{
return LV_FS_RES_NOT_IMP;
}
@ -385,7 +387,7 @@ static lv_fs_res_t fs_trunc(lv_fs_drv_t * drv, void * file_p)
* @param newname path with the new name
* @return LV_FS_RES_OK or any error from 'fs_res_t'
*/
static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char * newname)
static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname)
{
(void)drv; /*Unused*/
char fromname[32];
@ -409,23 +411,23 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char
* @param free_p pointer to store the free size [kB]
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p)
static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p)
{
(void)drv; /*Unused*/
#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266)
FSInfo fs_info;
LV_FS_SPIFFS.info(fs_info);
*total_p = (uint32_t)fs_info.totalBytes;
*free_p = (uint32_t)fs_info.totalBytes - fs_info.usedBytes;
return LV_FS_RES_OK;
#elif defined(ARDUINO_ARCH_ESP32)
#elif defined(ARDUINO_ARCH_ESP32)
*total_p = (uint32_t)LV_FS_SPIFFS.totalBytes();
*free_p = (uint32_t)LV_FS_SPIFFS.totalBytes() - LV_FS_SPIFFS.usedBytes();
return LV_FS_RES_OK;
#endif
#endif
return LV_FS_RES_NOT_IMP;
}
@ -437,23 +439,23 @@ static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fre
* @param path path to a directory
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * path)
static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path)
{
lv_spiffs_dir_t dir;
#if defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP32)
dir = LV_FS_SPIFFS.open(path);
if(!dir) {
return LV_FS_RES_UNKNOWN;
}
#endif
#endif
#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266)
dir = LV_FS_SPIFFS.openDir(path);
#endif
#endif
lv_spiffs_dir_t * dp = (lv_spiffs_dir_t *)dir_p; /*Just avoid the confusing casings*/
*dp = dir;
lv_spiffs_dir_t* dp = (lv_spiffs_dir_t*)dir_p; /*Just avoid the confusing casings*/
*dp = dir;
return LV_FS_RES_OK;
}
@ -465,11 +467,11 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat
* @param fn pointer to a buffer to store the filename
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn)
{
lv_spiffs_dir_t dir = *(lv_spiffs_dir_t *)dir_p; /*Convert type*/
lv_spiffs_dir_t dir = *(lv_spiffs_dir_t*)dir_p; /*Convert type*/
#if defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP32)
File file = dir.openNextFile();
if(file) {
strcpy(fn, file.name());
@ -477,16 +479,16 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
} else {
return LV_FS_RES_UNKNOWN;
}
#endif
#endif
#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266)
if(dir.next()) {
strcpy(fn, dir.fileName().c_str());
return LV_FS_RES_OK;
} else {
return LV_FS_RES_UNKNOWN;
}
#endif
#endif
return LV_FS_RES_NOT_IMP;
}
@ -497,10 +499,12 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
* @param dir_p pointer to an initialized 'fs_read_dir_t' variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p)
static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p)
{
return LV_FS_RES_OK;
}
#endif /*LV_USE_FS_IF*/
#endif /*LV_FS_IF_SPIFFS*/
#endif /*LV_USE_FS_IF*/
#endif /*LV_FS_IF_SPIFFS*/
#endif /*ARDUINO*/

View File

@ -15,7 +15,7 @@ Obtain or create a font file:
lv_zifont_init();
static lv_font_t font1;
lv_zifont_font_init(&font1, "./notosans_32.zi", 0);
lv_zifont_font_init(&font1, "/notosans_32.zi", 0);
static lv_style_t ft_style;
lv_style_copy(&ft_style, &lv_style_plain);

View File

@ -1,6 +1,9 @@
/*********************
* INCLUDES
*********************/
#if !(defined(WINDOWS) || defined(POSIX))
#include <Arduino.h>
#include <stdio.h>
@ -52,8 +55,8 @@ enum zifont_codepage_t8_t { ASCII = 0x01, ISO_8859_1 = 0x03, UTF_8 = 0x18 };
/**********************
* STATIC PROTOTYPES
**********************/
const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t unicode_letter);
bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out,
const uint8_t* IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t* font, uint32_t unicode_letter);
bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t* font, lv_font_glyph_dsc_t* dsc_out,
uint32_t unicode_letter, uint32_t unicode_letter_next);
/**********************
@ -70,7 +73,7 @@ lv_zifont_char_t lastCharInfo; // Holds the last Glyph DSC
#define CHAR_CACHE_SIZE 95
// static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache
#endif
static uint8_t * charBitmap_p;
static uint8_t* charBitmap_p;
/**********************
* MACROS
@ -80,18 +83,19 @@ static uint8_t * charBitmap_p;
* GLOBAL FUNCTIONS
**********************/
static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos);
static void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos);
static void IRAM_ATTR blackAdd(uint8_t* charBitmap_p, uint16_t pos);
static void IRAM_ATTR colorsAdd(uint8_t* charBitmap_p, uint8_t color1, uint16_t pos);
// static uint16_t unicode2codepoint(uint32_t unicode, uint8_t codepage);
// static void printBuffer(uint8_t * charBitmap_p, uint8_t w, uint8_t h);
int lv_zifont_init(void)
{
// FS.begin(true);
// charBitmap_p = (uint8_t *)lv_mem_alloc(32 * 32);
return LV_RES_OK; // OK
}
static inline bool openFont(File & file, const char * filename)
static inline bool openFont(File& file, const char* filename)
{
if(*filename != '/') return false;
@ -100,6 +104,7 @@ static inline bool openFont(File & file, const char * filename)
LOG_ERROR(TAG_FONT, F("Opening font: %s"), filename);
return false;
}
// LOG_TRACE(TAG_FONT, F("Opening font: %s"), filename);
return file;
}
@ -107,7 +112,7 @@ static inline bool initCharacterFrame(size_t size)
{
if(size > _lv_mem_get_size(charBitmap_p)) {
lv_mem_free(charBitmap_p);
charBitmap_p = (uint8_t *)lv_mem_alloc(size);
charBitmap_p = (uint8_t*)lv_mem_alloc(size);
LOG_WARNING(TAG_FONT, F("Pixel buffer is %d bytes"), _lv_mem_get_size(charBitmap_p));
}
@ -120,29 +125,34 @@ static inline bool initCharacterFrame(size_t size)
}
}
int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size)
int lv_zifont_font_init(lv_font_t** font, const char* font_path, uint16_t size)
{
charInBuffer = 0; // invalidate any previous cache
LOG_TRACE(TAG_FONT, F("File %s - Line %d - lv_zifont_font_init"), __FILE__, __LINE__);
if(!*font) {
*font = (lv_font_t *)lv_mem_alloc(sizeof(lv_font_t));
LOG_TRACE(TAG_FONT, F("File %s - Line %d - init font"), __FILE__, __LINE__);
*font = (lv_font_t*)lv_mem_alloc(sizeof(lv_font_t));
LV_ASSERT_MEM(*font);
_lv_memset_00(*font, sizeof(lv_font_t)); // lv_mem_alloc might be dirty
}
lv_font_fmt_zifont_dsc_t * dsc;
lv_font_fmt_zifont_dsc_t* dsc;
if(!(*font)->dsc) {
dsc = (lv_font_fmt_zifont_dsc_t *)lv_mem_alloc(sizeof(lv_font_fmt_zifont_dsc_t));
LOG_TRACE(TAG_FONT, F("File %s - Line %d - init font dsc"), __FILE__, __LINE__);
dsc = (lv_font_fmt_zifont_dsc_t*)lv_mem_alloc(sizeof(lv_font_fmt_zifont_dsc_t));
LV_ASSERT_MEM(dsc);
_lv_memset_00(dsc, sizeof(lv_font_fmt_zifont_dsc_t)); // lv_mem_alloc might be dirty
dsc->ascii_glyph_dsc = NULL;
} else {
dsc = (lv_font_fmt_zifont_dsc_t *)(*font)->dsc;
LOG_TRACE(TAG_FONT, F("File %s - Line %d - reuse font dsc"), __FILE__, __LINE__);
dsc = (lv_font_fmt_zifont_dsc_t*)(*font)->dsc;
}
LV_ASSERT_MEM(dsc);
if(!dsc) return ZIFONT_ERROR_OUT_OF_MEMORY;
/* Initialize Last Glyph DSC */
dsc->last_glyph_dsc = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t));
dsc->last_glyph_dsc = (lv_zifont_char_t*)lv_mem_alloc(sizeof(lv_zifont_char_t));
_lv_memset_00(dsc->last_glyph_dsc, sizeof(lv_zifont_char_t)); // lv_mem_alloc might be dirty
if(dsc->last_glyph_dsc == NULL) return ZIFONT_ERROR_OUT_OF_MEMORY;
@ -155,7 +165,9 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
/* Read file header as dsc */
zi_font_header_t header;
size_t readSize = file.readBytes((char *)&header, sizeof(zi_font_header_t));
size_t readSize = file.readBytes((char*)&header, sizeof(zi_font_header_t));
LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__);
/* Check that we read the correct size */
if(readSize != sizeof(zi_font_header_t)) {
@ -164,6 +176,8 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
return ZIFONT_ERROR_READING_DATA;
}
LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__);
/* Check ziFile Header Format */
if(header.Password != 4 || header.Version != 5) {
LOG_ERROR(TAG_FONT, F("Unknown font file format"));
@ -171,6 +185,8 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
return ZIFONT_ERROR_UNKNOWN_HEADER;
}
LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__);
dsc->CharHeight = header.CharHeight;
dsc->CharWidth = header.CharWidth;
dsc->Maximumnumchars = header.Maximumnumchars;
@ -179,20 +195,33 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
dsc->Startdataaddress = header.Startdataaddress + header.Descriptionlength;
dsc->Fontdataadd8byte = header.Fontdataadd8byte;
if(!dsc->ascii_glyph_dsc) {
dsc->ascii_glyph_dsc = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE);
LOG_TRACE(TAG_FONT, F("File %s - Line %d - %d"), __FILE__, __LINE__, dsc->ascii_glyph_dsc);
if(dsc->ascii_glyph_dsc == NULL) {
LOG_TRACE(TAG_FONT, F("File %s - Line %d - ascii_glyph_dsc init"), __FILE__, __LINE__);
dsc->ascii_glyph_dsc = (lv_zifont_char_t*)lv_mem_alloc(sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE);
LV_ASSERT_MEM(dsc->ascii_glyph_dsc);
_lv_memset_00(dsc->ascii_glyph_dsc, sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE); // lv_mem_alloc might be dirty
}
LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__);
if(dsc->ascii_glyph_dsc == NULL) {
file.close();
return ZIFONT_ERROR_OUT_OF_MEMORY;
}
LOG_TRACE(TAG_FONT, F("File %s - Line %d - Seerkset: %d"), __FILE__, __LINE__, dsc->Startdataaddress);
/* read charmap into cache */
file.seek(0 * sizeof(zi_font_header_t) + dsc->Startdataaddress, SeekSet);
LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__);
//* read and fill charmap cache
readSize = file.readBytes((char *)dsc->ascii_glyph_dsc, sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE);
readSize = file.readBytes((char*)dsc->ascii_glyph_dsc, sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE);
LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__);
//* Check that we read the correct size
if(readSize != sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE) {
@ -233,9 +262,11 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
/* header data struct */ /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
(*font)->subpx = 0;
if((*font)->user_data != (char *)font_path) {
LOG_TRACE(TAG_FONT, F("File %s - Line %d"), __FILE__, __LINE__);
if((*font)->user_data != (char*)font_path) {
if((*font)->user_data) free((*font)->user_data);
(*font)->user_data = (char *)font_path;
(*font)->user_data = (char*)font_path;
}
return ZIFONT_NO_ERROR;
@ -251,7 +282,7 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t unicode_letter)
const uint8_t* IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t* font, uint32_t unicode_letter)
{
/* Bitmap still in buffer */
if(charInBuffer == unicode_letter && charBitmap_p) {
@ -260,8 +291,8 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font,
return charBitmap_p;
}
lv_font_fmt_zifont_dsc_t * fdsc = (lv_font_fmt_zifont_dsc_t *)font->dsc; /* header data struct */
lv_zifont_char_t * charInfo;
lv_font_fmt_zifont_dsc_t* fdsc = (lv_font_fmt_zifont_dsc_t*)font->dsc; /* header data struct */
lv_zifont_char_t* charInfo;
/* Space */
if(unicode_letter == 0x20) {
@ -286,7 +317,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font,
charmap_position = 25 + sizeof(zi_font_header_t);
glyphID = unicode_letter - 0xf000; // start of fontawesome
} else {
strcpy(filename, (char *)font->user_data);
strcpy(filename, (char*)font->user_data);
charmap_position = fdsc->Startdataaddress;
glyphID = unicode_letter - 0x20; // simple unicode to ascii - space is charNum=0
}
@ -300,11 +331,11 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font,
} else {
Serial.print("%");
/* Read Character Table */
charInfo = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t));
charInfo = (lv_zifont_char_t*)lv_mem_alloc(sizeof(lv_zifont_char_t));
// lv_memset(charInfo, 0x00, sizeof(lv_zifont_char_t)); // lv_mem_alloc might be dirty
uint32_t char_position = glyphID * sizeof(lv_zifont_char_t) + charmap_position;
file.seek(char_position, SeekSet);
size_t readSize = file.readBytes((char *)charInfo, sizeof(lv_zifont_char_t));
size_t readSize = file.readBytes((char*)charInfo, sizeof(lv_zifont_char_t));
/* Check that we read the correct size */
if(readSize != sizeof(lv_zifont_char_t)) {
@ -438,7 +469,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font,
* @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out`
*/
bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out,
bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t* font, lv_font_glyph_dsc_t* dsc_out,
uint32_t unicode_letter, uint32_t unicode_letter_next)
{
/* Only ascii characteres supported for now */
@ -449,7 +480,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_
// if(unicode_letter > 0xff) Serial.printf("Char# %u\n", unicode_letter);
// ulong startMillis = millis();
lv_font_fmt_zifont_dsc_t * fdsc = (lv_font_fmt_zifont_dsc_t *)font->dsc; /* header data struct */
lv_font_fmt_zifont_dsc_t* fdsc = (lv_font_fmt_zifont_dsc_t*)font->dsc; /* header data struct */
uint16_t glyphID;
File file;
@ -479,7 +510,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_
snprintf_P(filename, sizeof(filename), PSTR("/fontawesome%u.zi"), fdsc->CharHeight);
if(!openFont(file, filename)) return false;
} else {
if(!openFont(file, (char *)font->user_data)) return false;
if(!openFont(file, (char*)font->user_data)) return false;
}
/* read 10 bytes charmap */
@ -487,7 +518,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_
lv_zifont_char_t myCharIndex;
uint32_t char_position = glyphID * sizeof(lv_zifont_char_t) + charmap_position;
file.seek(char_position, SeekSet);
size_t readSize = file.readBytes((char *)&myCharIndex, sizeof(lv_zifont_char_t));
size_t readSize = file.readBytes((char*)&myCharIndex, sizeof(lv_zifont_char_t));
file.close();
/* Check that we read the correct size */
@ -533,7 +564,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_
return true;
}
static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos)
static void IRAM_ATTR blackAdd(uint8_t* charBitmap_p, uint16_t pos)
{
uint8_t col = pos & 0x0001; // remainder
uint16_t map_p = pos >> 1; // devide by 2
@ -545,7 +576,7 @@ static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos)
}
}
static inline void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos)
static inline void IRAM_ATTR colorsAdd(uint8_t* charBitmap_p, uint8_t color1, uint16_t pos)
{
uint32_t col = pos & 0x0001; // remainder
uint32_t map_p = pos >> 1; // devide by 2
@ -557,6 +588,8 @@ static inline void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, u
}
}
#endif
/*
void printPixel(uint8_t pixel)
{

View File

@ -34,14 +34,13 @@ extra_default_envs =
; Common environment settings
;***************************************************
[env]
framework = arduino
upload_speed = 921600
monitor_speed = 115200
build_flags =
-D PIOENV=\"${PIOENV}\"
;-Os ; Code Size Optimization
-Og ; Code Debug Optimization
-Os ; Code Size Optimization
;-Og ; Code Debug Optimization
;-w ; Suppress warnings
-D CORE_DEBUG_LEVEL=0 ; 0=Silent, 1=Errors, 2=Warnings
-I include ; include lv_conf.h and hasp_conf.h
@ -49,11 +48,10 @@ build_flags =
-D LV_CONF_INCLUDE_SIMPLE ; for lvgl
-D LV_LVGL_H_INCLUDE_SIMPLE ; for lv_drivers
-D LV_COMP_CONF_INCLUDE_SIMPLE ; for components
; -- littlevgl build options ------------------------------
; -- ESP build options ------------------------------------
-D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files
; -- ArduinoJson build options ----------------------------
-D ARDUINOJSON_DECODE_UNICODE=1 ; for utf-8 symbols
-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
; -- StreamUtils build options ----------------------------
-D STREAMUTILS_ENABLE_EEPROM=1 ; for STM32, it also supports EEPROM
@ -63,21 +61,20 @@ build_flags =
-D HASP_VER_MIN=4
-D HASP_VER_REV=0
-D HASP_LOG_LEVEL=9
-D HASP_USE_CONFIG=1 ; Native application, not library
${override.build_flags}
; -- Shared library dependencies in all environments
; Warning : don't put comments after github links => causes infinite download loop
lib_deps =
bxparks/AceButton@^1.8.2 ; GPIO button library
bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser
bblanchon/ArduinoJson@^6.17.3 ; Json(l) parser
bblanchon/StreamUtils@1.6.0 ; for EEPromStream
knolleary/PubSubClient@^2.8.0 ; MQTT client
git+https://github.com/fvanroie/ConsoleInput.git
;git+https://github.com/andrethomas/TasmotaSlave.git
;git+https://github.com/fvanroie/lv_components.git
git+https://github.com/lvgl/lvgl.git
;lvgl/lvgl @ ^7.7.2 ; from PIO library
;git+https://github.com/lvgl/lvgl.git
lvgl/lvgl @^7.11.0 ; from PIO library
;bodmer/TFT_eSPI @ 2.3.4 ; Tft SPI drivers EXACT version 2.3.5 has compile error
git+https://github.com/Bodmer/TFT_eSPI.git
; ------ Unused / Test libraries
@ -89,10 +86,25 @@ lib_deps =
src_filter = +<*> -<.git/> -<examples/> -<test/> -<tests/> -<stm32f4/> -<lv_font_montserrat_*.c>
extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py
; -- Platform specific build flags
[esp32]
framework = arduino
platform = espressif32
board_upload.flash_size=4MB
board_upload.maximum_size = 4194304
board_build.partitions = user_setups/esp32/partition_app1704k_spiffs720k.csv
; ----- crash reporter
monitor_filters = esp32_exception_decoder
; ----- debugger
check_tool = cppcheck
check_flags = --enable=all
debug_tool = esp-prog
debug_init_break = tbreak setup
build_flags =
${env.build_flags}
-D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer
@ -101,13 +113,16 @@ build_flags =
-D NO_GLOBAL_HTTPUPDATE ; dont instantiate httpUpdate
; -- lvgl build options -----------------------------
-D LV_MEM_SIZE=61440U ; 60kB lvgl memory
; -- ArduinoJson build options ----------------------------
-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
; -- tft_espi build options ------------------------
;-D USE_DMA_TO_TFT
; -- hasp-lvgl build options ------------------------
;-D HASP_USE_TELNET=1
-D HASP_USE_TELNET=1
;-D HASP_USE_SPIFFS=1
-D HASP_USE_LITTLEFS=1
;-D HASP_USE_EEPROM=1
-D HASP_USE_CONFIG=1 ; Native application, not library
; -- LittleFS build options ------------------------
-D CONFIG_LITTLEFS_FOR_IDF_3_2
@ -130,10 +145,10 @@ ps_ram =
-mfix-esp32-psram-cache-issue
extra_scripts =
${env.extra_scripts}
tools/copy_partitions.py
tools/esp_merge_bin.py
tools/analyze_elf.py
; ${env.extra_scripts}
; tools/copy_partitions.py
; -- The ESP32 has 2 SPI Hardware Busses available to use:
vspi =
@ -146,23 +161,40 @@ hspi =
-D TFT_SCLK=14
[esp8266]
framework = arduino
platform = espressif8266
board_build.f_flash = 40000000L
board_build.flash_mode = dout
board_build.ldscript = eagle.flash.4m2m.ld ; 2Mb Spiffs
board_build.f_cpu = 160000000L ; set frequency to 160MHz
; ----- crash reporter
monitor_filters = esp8266_exception_decoder
build_flags=
-D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer
-D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages
-D HASP_CONSOLE_BUFFER=160 ; maximum length of a console/telnet command
-D ATOMIC_FS_UPDATE ; enabled compressed ota updates
-D NO_GLOBAL_HTTPUPDATE ; dont instantiate httpUpdate
-D HTTP_UPLOAD_BUFLEN=512 ; lower http upload buffer
-D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages
-D HASP_CONSOLE_BUFFER=160 ; maximum length of a console/telnet command
-D ATOMIC_FS_UPDATE ; enabled compressed ota updates
-D NO_GLOBAL_HTTPUPDATE ; dont instantiate httpUpdate
; -- lwIP Variant -----------------------------------
;-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
; -- lvgl build options -----------------------------
-D LV_MEM_SIZE=12288U ; 12kB lvgl memory
-D LV_MEM_SIZE=12288U ; 12kB lvgl memory
; -- ArduinoJson build options ----------------------------
-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
-D ARDUINOJSON_ENABLE_STD_STRING=1 ; for std::string
; -- hasp-lvgl build options ------------------------
;-D HASP_USE_TELNET=1
-D HASP_USE_TELNET=1
;-D HASP_USE_SPIFFS=1
-D HASP_USE_LITTLEFS=1
-D HASP_USE_EEPROM=1
-D HASP_USE_ETHERNET=0
-D HASP_USE_CONFIG=1 ; Native application, not library
extra_scripts = tools/copy_fw.py ; tools/pre:extra_script.py
lib_ignore =
ESP32 BLE Arduino
@ -173,49 +205,28 @@ lib_ignore =
lib_deps =
[stm32f4]
framework = arduino
platform = ststm32
build_flags=
-I include/stm32f4
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
-D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command
-D IRAM_ATTR= ; No IRAM_ATTR available on STM32
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
-D HASP_CONSOLE_BUFFER=220 ; maximum length of a console/telnet command
-D IRAM_ATTR= ; No IRAM_ATTR available on STM32
-D ICACHE_RAM_ATTR=
-D STM32
-D ARDUINOJSON_DECODE_UNICODE=1 ; for utf-8 symbols
-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
-D STREAMUTILS_USE_EEPROM_UPDATE=1 ; update cell only when changed
; -- lvgl build options -----------------------------
-D LV_MEM_SIZE=20480U ; 20kB lvgl memory
-D HASP_USE_SYSLOG=0 ; Needs UDP
-D LV_MEM_SIZE=20480U ; 20kB lvgl memory
-D HASP_USE_SYSLOG=0 ; Needs UDP
-D HASP_USE_SPIFFS=0
-D HASP_USE_LITTLEFS=0
-D HASP_USE_CONFIG=1 ; Native application, not library
lib_deps =
; sstaub/Ticker @ ^3.2.0
stm32duino/STM32duino LwIP @ ^2.1.2
;https://github.com/stm32duino/LwIP.git
;***************************************************
; Native build
;***************************************************
;[env:native]
;platform = native
;build_flags =
; -D LV_CONF_INCLUDE_SIMPLE
; ; -I src Required to find lv_conf.h
; -I src
; -I drivers/sdl2
; -lSDL2
; ; SDL drivers options
; -D LV_LVGL_H_INCLUDE_SIMPLE
; -D LV_DRV_NO_CONF
; -D USE_MONITOR
; -D MONITOR_ZOOM=2
; -D USE_MOUSE
; -D USE_MOUSEWHEEL
; -D USE_KEYBOARD
;lib_deps =
; ;lvgl=https://github.com/littlevgl/lvgl/archive/master.zip
; ;lvgl@^6.1.0
; ;lv_drivers=https://github.com/littlevgl/lv_drivers/archive/master.zip
; lv_drivers@^6.0.2
;src_filter = +<*> +<../drivers/sdl2>

View File

@ -6,14 +6,17 @@
[platformio]
extra_configs =
; Uncomment or edit the lines to show more User Setups in the PIO sidebar
; user_setups/darwin_sdl/*.ini
; user_setups/esp32/*.ini
; user_setups/esp8266/*.ini
; user_setups/linux_sdl/*.ini
; user_setups/stm32f4xx/*.ini
; user_setups/win32/*.ini
[override]
; -- Hasp config options --------------------------------------
build_flags =
; -- Uncomment the next line to use the file src/user_config_override.h settings
; -- Uncomment the next line to use the file include/user_config_override.h settings
; -DUSE_CONFIG_OVERRIDE
;region -- Default Build Environments : Used when Build All ---
@ -21,15 +24,16 @@ extra_default_envs =
; Comment unneeded environments or create extra
; d1-mini-esp32_ili9341
; d1-mini-esp8266_ili9341
; lolind32pro-lolintft24
; esp32dev-mrb3511
; esp12e-st7735
; d132-unoshield
; nodemcu32s-raspi
; esp12e-st7735
; esp32dev-mrb3511
; esp32dev-ili9488
; lanbon_l8
; wt32-sc01
; lolin-d32-pro_ili9341
; my_custom_build
; nodemcu32s-raspi
; wt32-sc01
; ttgo_esp32_poe-ili9341
;endregion
;region -- Define your local COM ports for each environment ---
@ -52,36 +56,43 @@ upload_port = 192.168.4.4 ; IP of the ESP
upload_protocol = espota ; Use ArduinoOTA after flashing over serial
upload_flags = --port=3232 ; --auth=haspadmin ; OTA password
[env:ttgo_esp32_poe-lolintft24]
[env:ttgo_esp32_poe-ili9341]
monitor_port = COM9 ; Change to the correct port
;upload_port = ${env:ttgo_esp32_poe-lolintft24.monitor_port}
;upload_port = ${env:ttgo_esp32_poe-ili9341.monitor_port}
upload_port = 192.168.4.5 ; IP of the ESP
upload_protocol = espota ; Use ArduinoOTA after flashing over serial
upload_flags = --port=3232 ; --auth=haspadmin ; OTA password
[env:lolind32pro-lolintft24]
monitor_port = COM3 ; Change to the correct port
upload_port = ${env:lolind32pro-lolintft24.monitor_port}
[env:lolin-d32-pro_ili9341]
monitor_port = COM5 ; Change to the correct port
upload_port = ${env:lolin-d32-pro_ili9341.monitor_port}
;endregion
;region -- Custom Environment configuration example -----------------
[env:my_custom_build]
platform = espressif32
extends = esp32
board = nodemcu-32s
monitor_port = COM3
upload_port = ${env:my_custom_build.monitor_port}
upload_port = COM12 ; To change the port, use platform_override.ini
monitor_port = COM12 ; To change the port, use platform_override.ini
board_build.partitions = user_setups/esp32/partition_app1536k_spiffs1024k.csv ; default.csv
debug_tool = esp-prog
debug_init_break = tbreak setup
build_flags =
${env.build_flags}
${esp32.build_flags}
;region -- TFT_eSPI build options -----------------------------------
${lcd.raspberrypi}
${lcd.lolin24}
${esp32.vspi}
-D TFT_CS=5
-D TFT_DC=4
-D TFT_RST=32
-D TFT_BCKL=-1 ; None, configurable via web UI (e.g. 21)
-D TOUCH_CS=22
-D TFT_DC=5
-D TFT_CS=26
-D TFT_RST=-1 ; RST
-D TFT_BCKL=22 ; None, configurable via web UI (e.g. 21)
-D TOUCH_CS=17 ; (can also be 22 or 16)
; -- Options ----------------------------------------
-D HASP_USE_TELNET=1
;endregion
;endregion

View File

@ -1,9 +1,2 @@
#include "device.h"
#if defined(LANBONL8)
#warning Lanbon L8
#elif defined(M5STACK)
#warning M5 Stack
#else
dev::BaseDevice haspDevice;
#endif
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */

View File

@ -1,14 +1,50 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_H
#define HASP_DEVICE_H
#ifdef ARDUINO
#include "Arduino.h"
#endif
#if defined(WINDOWS) || defined(POSIX)
#include <cstdint>
#endif
#if defined(POSIX)
#include <stddef.h>
#endif
#ifdef WINDOWS
#include "Windows.h"
#endif
namespace dev {
class BaseDevice {
public:
virtual void pre_setup()
bool has_battery = false;
bool has_backligth_control = true;
virtual void reboot()
{}
virtual const char* get_hostname()
{
return "";
}
virtual void set_hostname(const char*)
{}
virtual const char* get_core_version()
{
return "";
}
virtual const char* get_chip_model()
{
return "";
}
virtual void init()
{}
virtual void show_info()
{}
virtual void post_setup()
{}
@ -16,20 +52,64 @@ class BaseDevice {
{}
virtual void loop_5s()
{}
virtual void set_backlight_pin(uint8_t pin)
{}
virtual void set_backlight_level(uint8_t level)
{}
virtual uint8_t get_backlight_level()
{
return -1;
}
virtual void set_backlight_power(bool power)
{}
virtual bool get_backlight_power()
{
return true;
}
virtual size_t get_free_max_block()
{
return 0;
}
virtual size_t get_free_heap()
{
return 0;
}
virtual uint8_t get_heap_fragmentation()
{
return 0;
}
virtual uint16_t get_cpu_frequency()
{
return 0;
}
virtual bool is_system_pin(uint8_t pin)
{
return false;
}
};
} // namespace dev
using dev::BaseDevice;
#if defined(ESP32)
#warning Building for ESP32 Devices
#include "esp32/esp32.h"
#elif defined(ESP8266)
#warning Building for ESP8266 Devices
#include "esp8266/esp8266.h"
#elif defined(STM32F4)
#warning Building for STM32F4xx Devices
#include "stm32f4/stm32f4.h"
#elif defined(WINDOWS)
#warning Building for Win32 Devices
#include "win32/hasp_win32.h"
#elif defined(POSIX)
#warning Building for Posix Devices
#include "posix/hasp_posix.h"
#include "lanbonl8.h"
#include "m5stackcore2.h"
#if defined(LANBONL8)
#warning Lanbon L8
#elif defined(M5STACK)
#warning M5 Stack
#else
#warning Building for Generic Devices
using dev::BaseDevice;
extern dev::BaseDevice haspDevice;
#endif
#endif
#endif

170
src/dev/esp32/esp32.cpp Normal file
View File

@ -0,0 +1,170 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if defined(ESP32)
#include "Arduino.h"
#include <Esp.h>
#include "esp_system.h"
#include "../device.h"
#include "esp32.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "hasp_conf.h"
#include "hasp_debug.h"
#include "hasp/hasp_utilities.h"
#define BACKLIGHT_CHANNEL 0
namespace dev {
void Esp32Device::reboot()
{
ESP.restart();
}
void Esp32Device::show_info()
{
LOG_VERBOSE(TAG_DEV, F("Processor : ESP32"));
LOG_VERBOSE(TAG_DEV, F("CPU freq. : %i MHz"), get_cpu_frequency());
// LOG_VERBOSE(TAG_DEV, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
}
const char* Esp32Device::get_hostname()
{
return _hostname.c_str();
}
void Esp32Device::set_hostname(const char* hostname)
{
_hostname = hostname;
}
const char* Esp32Device::get_core_version()
{
return esp_get_idf_version(); // == ESP.getSdkVersion();
}
const char* Esp32Device::get_chip_model()
{
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
// model = chip_info.cores;
// model += F("core ");
switch(chip_info.model) {
case CHIP_ESP32:
return "ESP32";
#ifdef CHIP_ESP32S2
case CHIP_ESP32S2:
return "ESP32-S2";
#endif
#ifdef CHIP_ESP32S3
case CHIP_ESP32S3:
return "ESP32-S3";
#endif
default:
return "Unknown ESP32";
}
// model += F(" rev");
// model += chip_info.revision;
}
void Esp32Device::set_backlight_pin(uint8_t pin)
{
_backlight_pin = pin;
/* Setup Backlight Control Pin */
if(pin < GPIO_NUM_MAX) {
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
ledcSetup(BACKLIGHT_CHANNEL, 20000, 12);
ledcAttachPin(pin, BACKLIGHT_CHANNEL);
update_backlight();
} else {
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin not set"));
}
}
void Esp32Device::set_backlight_level(uint8_t level)
{
_backlight_level = level >= 0 ? level : 0;
_backlight_level = _backlight_level <= 100 ? _backlight_level : 100;
update_backlight();
}
uint8_t Esp32Device::get_backlight_level()
{
return _backlight_level;
}
void Esp32Device::set_backlight_power(bool power)
{
_backlight_power = power;
update_backlight();
}
bool Esp32Device::get_backlight_power()
{
return _backlight_power != 0;
}
void Esp32Device::update_backlight()
{
if(_backlight_pin < GPIO_NUM_MAX) {
uint32_t duty = _backlight_power ? map(_backlight_level, 0, 100, 0, 4095) : 0;
ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value
}
}
size_t Esp32Device::get_free_max_block()
{
return ESP.getMaxAllocHeap();
}
size_t Esp32Device::get_free_heap()
{
return ESP.getFreeHeap();
}
uint8_t Esp32Device::get_heap_fragmentation()
{
uint32_t free = ESP.getFreeHeap();
if(free) {
return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)free);
} else {
return 100; // no free memory
}
}
uint16_t Esp32Device::get_cpu_frequency()
{
return ESP.getCpuFreqMHz();
}
bool Esp32Device::is_system_pin(uint8_t pin)
{
if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash
if((pin == 37) || (pin == 38)) return true; // unavailable
if(psramFound()) {
if((pin == 16) || (pin == 17)) return true; // PSRAM
}
return false;
}
} // namespace dev
#if defined(LANBONL8)
#warning Building for Lanbon L8
#include "dev/esp32/lanbonl8.h"
#elif defined(M5STACK)
#warning Building for M5Stack core2
#include "dev/esp32/m5stackcore2.h"
#else
dev::Esp32Device haspDevice;
#endif
#endif // ESP32

72
src/dev/esp32/esp32.h Normal file
View File

@ -0,0 +1,72 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_ESP32_H
#define HASP_DEVICE_ESP32_H
#include "../device.h"
#if defined(ESP32)
namespace dev {
class Esp32Device : public BaseDevice {
public:
Esp32Device()
{
_hostname = "plate";
_backlight_power = 1;
_backlight_level = 100;
#ifdef TFT_BCKL
_backlight_pin = TFT_BCKL;
#else
_backlight_pin = -1;
#endif
}
void reboot() override;
void show_info() override;
const char* get_hostname();
void set_hostname(const char*);
const char* get_core_version();
const char* get_chip_model();
void set_backlight_pin(uint8_t pin) override;
void set_backlight_level(uint8_t val) override;
uint8_t get_backlight_level() override;
void set_backlight_power(bool power) override;
bool get_backlight_power() override;
size_t get_free_max_block() override;
size_t get_free_heap() override;
uint8_t get_heap_fragmentation() override;
uint16_t get_cpu_frequency() override;
bool is_system_pin(uint8_t pin) override;
private:
std::string _hostname;
uint8_t _backlight_pin;
uint8_t _backlight_level;
uint8_t _backlight_power;
void update_backlight();
};
} // namespace dev
#if defined(LANBONL8)
#warning Building for Lanbon L8
#include "lanbonl8.h"
#elif defined(M5STACK)
#warning Building for M5Stack core2
#include "m5stackcore2.h"
#else
using dev::Esp32Device;
extern dev::Esp32Device haspDevice;
#endif
#endif // ESP32
#endif // HASP_DEVICE_ESP32_H

View File

@ -1,13 +1,23 @@
#include "Arduino.h"
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#include "lanbonl8.h"
#if defined(LANBONL8)
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "Arduino.h"
#include "dev/esp32/esp32.h"
#define REF_VOLTAGE 1100
esp_adc_cal_characteristics_t * adc_chars =
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "hasp_conf.h"
#include "hasp_debug.h"
#define BACKLIGHT_CHANNEL 0
#define REF_VOLTAGE 1100
esp_adc_cal_characteristics_t* adc_chars =
new esp_adc_cal_characteristics_t; // adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
namespace dev {
@ -41,7 +51,7 @@ static void print_char_val_type(esp_adc_cal_value_t val_type)
}
}
void LanbonL8::pre_setup()
void LanbonL8::init()
{
// Check if Two Point or Vref are burned into eFuse
check_efuse();
@ -54,20 +64,8 @@ void LanbonL8::pre_setup()
print_char_val_type(val_type);
}
void LanbonL8::post_setup()
{}
void LanbonL8::loop()
{}
void LanbonL8::loop_5s()
{
double voltage = esp_adc_cal_raw_to_voltage(analogRead(39), adc_chars);
Serial.print(adc1_get_raw(ADC1_CHANNEL_3));
Serial.print(" - ");
Serial.println(voltage);
}
} // namespace dev
dev::LanbonL8 haspDevice;
#endif

View File

@ -1,27 +1,23 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_LANBONL8_H
#define HASP_DEVICE_LANBONL8_H
#include "device.h"
#include "esp32.h"
#if defined(LANBONL8)
namespace dev {
class LanbonL8 : public BaseDevice {
class LanbonL8 : public Esp32Device {
public:
void pre_setup() override;
void post_setup() override;
void loop() override;
void loop_5s() override;
void init();
};
} // namespace dev
using dev::LanbonL8;
extern dev::LanbonL8 haspDevice;
#endif

View File

@ -1,13 +1,17 @@
#include "device.h"
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#include "m5stackcore2.h"
#if defined(M5STACK)
#include "AXP192.h" // Power Mgmt
#include "AXP192.h" // Power Mgmt
#include "dev/esp32/esp32.h"
// AXP192 Axp;
namespace dev {
void M5StackCore2::pre_setup(void)
void M5StackCore2::init(void)
{
AXP192 Axp;
Wire.begin(TOUCH_SDA, TOUCH_SCL);
@ -39,15 +43,8 @@ void M5StackCore2::pre_setup(void)
Axp.SetLed(1);
}
void M5StackCore2::post_setup(void)
{}
void M5StackCore2::loop(void)
{}
void M5StackCore2::loop_5s(void)
{}
} // namespace dev
dev::M5StackCore2 haspDevice;
#endif

View File

@ -1,4 +1,4 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_M5STACKCORE2_H
@ -6,16 +6,13 @@
#if defined(M5STACK)
#include "device.h"
#include "esp32.h"
namespace dev {
class M5StackCore2 : public BaseDevice {
class M5StackCore2 : public Esp32Device {
public:
void pre_setup() override;
void post_setup() override;
void loop() override;
void loop_5s() override;
void init() override;
};
} // namespace dev

123
src/dev/esp8266/esp8266.cpp Normal file
View File

@ -0,0 +1,123 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if defined(ESP8266)
#include "Arduino.h"
#include <Esp.h>
#include "esp8266.h"
#include "hasp_conf.h"
#include "hasp_debug.h"
#include "hasp/hasp_utilities.h"
#define BACKLIGHT_CHANNEL 0
namespace dev {
void Esp8266Device::reboot()
{
ESP.restart();
}
void Esp8266Device::show_info()
{
LOG_VERBOSE(TAG_DEV, F("Processor : ESP8266"));
LOG_VERBOSE(TAG_DEV, F("CPU freq. : %i MHz"), get_cpu_frequency());
LOG_VERBOSE(TAG_DEV, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
}
const char* Esp8266Device::get_hostname()
{
return _hostname.c_str();
}
void Esp8266Device::set_hostname(const char* hostname)
{
_hostname = hostname;
}
const char* Esp8266Device::get_core_version()
{
return _core_version.c_str();
}
const char* Esp8266Device::get_chip_model()
{
return "ESP8266";
}
void Esp8266Device::set_backlight_pin(uint8_t pin)
{
_backlight_pin = pin;
/* Setup Backlight Control Pin */
if(pin >= 0) {
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
pinMode(_backlight_pin, OUTPUT);
update_backlight();
}
}
void Esp8266Device::set_backlight_level(uint8_t level)
{
_backlight_level = level >= 0 ? level : 0;
_backlight_level = _backlight_level <= 100 ? _backlight_level : 100;
update_backlight();
}
uint8_t Esp8266Device::get_backlight_level()
{
return _backlight_level;
}
void Esp8266Device::set_backlight_power(bool power)
{
_backlight_power = power;
update_backlight();
}
bool Esp8266Device::get_backlight_power()
{
return _backlight_power != 0;
}
void Esp8266Device::update_backlight()
{
if(_backlight_pin == -1) return;
analogWrite(_backlight_pin, _backlight_power ? map(_backlight_level, 0, 100, 0, 1023) : 0);
}
size_t Esp8266Device::get_free_max_block()
{
return ESP.getMaxFreeBlockSize();
}
size_t Esp8266Device::get_free_heap(void)
{
return ESP.getFreeHeap();
}
uint8_t Esp8266Device::get_heap_fragmentation()
{
return ESP.getHeapFragmentation();
}
uint16_t Esp8266Device::get_cpu_frequency()
{
return ESP.getCpuFreqMHz();
}
bool Esp8266Device::is_system_pin(uint8_t pin)
{
if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash
if((pin >= 12) && (pin <= 14)) return true; // HSPI
return false;
}
} // namespace dev
dev::Esp8266Device haspDevice;
#endif // ESP8266

69
src/dev/esp8266/esp8266.h Normal file
View File

@ -0,0 +1,69 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_ESP8266_H
#define HASP_DEVICE_ESP8266_H
#include "hasp_conf.h"
#include "dev/device.h"
#if defined(ESP8266)
namespace dev {
class Esp8266Device : public BaseDevice {
public:
Esp8266Device()
{
_hostname = "plate";
_backlight_power = 1;
_backlight_level = 100;
_core_version = ESP.getCoreVersion().c_str();
#ifdef TFT_BCKL
_backlight_pin = TFT_BCKL;
#else
_backlight_pin = -1;
#endif
}
void reboot() override;
void show_info() override;
const char* get_hostname();
void set_hostname(const char*);
const char* get_core_version();
const char* get_chip_model();
void set_backlight_pin(uint8_t pin) override;
void set_backlight_level(uint8_t val) override;
uint8_t get_backlight_level() override;
void set_backlight_power(bool power) override;
bool get_backlight_power() override;
size_t get_free_max_block() override;
size_t get_free_heap() override;
uint8_t get_heap_fragmentation() override;
uint16_t get_cpu_frequency() override;
bool is_system_pin(uint8_t pin) override;
private:
std::string _hostname;
std::string _core_version;
uint8_t _backlight_pin;
uint8_t _backlight_level;
uint8_t _backlight_power;
void update_backlight();
};
} // namespace dev
using dev::Esp8266Device;
extern dev::Esp8266Device haspDevice;
#endif // ESP8266
#endif // HASP_DEVICE_ESP8266_H

View File

@ -0,0 +1,157 @@
#if defined(POSIX)
#include <cstdint>
#include <sys/utsname.h>
#include "hasp_posix.h"
#include "hasp_conf.h"
#include "hasp/hasp_utilities.h"
#include "hasp_debug.h"
#include "display/monitor.h"
// extern monitor_t monitor;
namespace dev {
PosixDevice::PosixDevice()
{
struct utsname uts;
if(uname(&uts) < 0) {
LOG_ERROR(0, "uname() error");
_hostname = "localhost";
_core_version = "unknown";
_chip_model = "unknown";
} else {
// LOG_VERBOSE(0,"Sysname: %s", uts.sysname);
// LOG_VERBOSE(0,"Nodename: %s", uts.nodename);
// LOG_VERBOSE(0,"Release: %s", uts.release);
// LOG_VERBOSE(0,"Version: %s", uts.version);
// LOG_VERBOSE(0,"Machine: %s", uts.machine);
char version[128];
snprintf(version, sizeof(version), "%s %s", uts.sysname, uts.release);
_core_version = version;
_chip_model = uts.machine;
_hostname = uts.nodename;
}
_backlight_power = 1;
_backlight_level = 100;
}
void PosixDevice::reboot()
{}
void PosixDevice::show_info()
{
struct utsname uts;
if(uname(&uts) < 0) {
LOG_ERROR(0, "uname() error");
} else {
LOG_VERBOSE(0, "Sysname: %s", uts.sysname);
LOG_VERBOSE(0, "Nodename: %s", uts.nodename);
LOG_VERBOSE(0, "Release: %s", uts.release);
LOG_VERBOSE(0, "Version: %s", uts.version);
LOG_VERBOSE(0, "Machine: %s", uts.machine);
}
LOG_VERBOSE(0, "Processor : %s", "unknown");
LOG_VERBOSE(0, "CPU freq. : %i MHz", 0);
}
const char* PosixDevice::get_hostname()
{
return _hostname.c_str();
}
void PosixDevice::set_hostname(const char* hostname)
{
_hostname = hostname;
monitor_title(hostname);
// SDL_SetWindowTitle(monitor.window, hostname);
}
const char* PosixDevice::get_core_version()
{
return _core_version.c_str();
}
const char* PosixDevice::get_chip_model()
{
return _chip_model.c_str();
}
void PosixDevice::set_backlight_pin(uint8_t pin)
{
// PosixDevice::backlight_pin = pin;
}
void PosixDevice::set_backlight_level(uint8_t level)
{
uint8_t new_level = level >= 0 ? level : 0;
new_level = new_level <= 100 ? new_level : 100;
if(_backlight_level != new_level) {
_backlight_level = new_level;
update_backlight();
}
}
uint8_t PosixDevice::get_backlight_level()
{
return _backlight_level;
}
void PosixDevice::set_backlight_power(bool power)
{
_backlight_power = power;
update_backlight();
}
bool PosixDevice::get_backlight_power()
{
return _backlight_power != 0;
}
void PosixDevice::update_backlight()
{
uint8_t level = _backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0;
monitor_backlight(level);
// SDL_SetTextureColorMod(monitor.texture, level, level, level);
// window_update(&monitor);
// monitor.sdl_refr_qry = true;
// monitor_sdl_refr(NULL);
// const lv_area_t area = {1,1,0,0};
// monitor_flush(NULL,&area,NULL);
}
size_t PosixDevice::get_free_max_block()
{
return 0;
}
size_t PosixDevice::get_free_heap(void)
{
return 0;
}
uint8_t PosixDevice::get_heap_fragmentation()
{
return 0;
}
uint16_t PosixDevice::get_cpu_frequency()
{
return 0;
}
bool PosixDevice::is_system_pin(uint8_t pin)
{
return false;
}
} // namespace dev
dev::PosixDevice haspDevice;
#endif // POSIX

View File

@ -0,0 +1,74 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_POSIX_H
#define HASP_DEVICE_POSIX_H
#include <cstdint>
#include <cstddef>
extern "C" {
#include <inttypes.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/utsname.h>
}
#include "hasp_conf.h"
#include "../device.h"
#if defined(POSIX)
static inline void itoa(int i, char* out, int unused_)
{
(void)unused_;
sprintf(out, "%d", i);
}
namespace dev {
class PosixDevice : public BaseDevice {
public:
PosixDevice();
void reboot() override;
void show_info() override;
const char* get_hostname();
void set_hostname(const char*);
const char* get_core_version();
const char* get_chip_model();
void set_backlight_pin(uint8_t pin);
void set_backlight_level(uint8_t val);
uint8_t get_backlight_level();
void set_backlight_power(bool power);
bool get_backlight_power();
size_t get_free_max_block();
size_t get_free_heap();
uint8_t get_heap_fragmentation();
uint16_t get_cpu_frequency();
bool is_system_pin(uint8_t pin) override;
private:
std::string _hostname;
std::string _core_version;
std::string _chip_model;
uint8_t _backlight_pin;
uint8_t _backlight_level;
uint8_t _backlight_power;
void update_backlight();
};
} // namespace dev
using dev::PosixDevice;
extern dev::PosixDevice haspDevice;
#endif // POSIX
#endif // HASP_DEVICE_POSIX_H

134
src/dev/stm32f4/stm32f4.cpp Normal file
View File

@ -0,0 +1,134 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if defined(STM32F4xx)
#include "Arduino.h"
#include "stm32f4.h"
#include "hasp_conf.h"
#include "hasp_debug.h"
#include "hasp/hasp_utilities.h"
#define BACKLIGHT_CHANNEL 0
namespace dev {
void Stm32f4Device::reboot()
{
// ESP.restart();
}
void Stm32f4Device::show_info()
{
LOG_VERBOSE(TAG_DEV, F("Processor : STM32F4xx"));
// LOG_VERBOSE(TAG_DEV, F("CPU freq. : %i MHz"), get_cpu_frequency());
// LOG_VERBOSE(TAG_DEV, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
}
const char* Stm32f4Device::get_hostname()
{
return _hostname.c_str();
}
void Stm32f4Device::set_hostname(const char* hostname)
{
_hostname = hostname;
}
const char* Stm32f4Device::get_core_version()
{
// return ESP.getCoreVersion().c_str();
}
void Stm32f4Device::set_backlight_pin(uint8_t pin)
{
_backlight_pin = pin;
/* Setup Backlight Control Pin */
if(pin >= 0) {
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
pinMode(_backlight_pin, OUTPUT);
update_backlight();
}
}
const char* Stm32f4Device::get_chip_model()
{
#if defined(STM32F407ZG)
return "STM32F407ZG";
#elif defined(STM32F407ZE)
return "STM32F407ZE";
#elif defined(STM32F407VE)
return "STM32F407VE";
#elif defined(STM32F407VG)
return "STM32F407VG";
#elif defined(STM32F4xx) || defined(ARDUINO_ARCH_STM32F4)
return "STM32F4";
#else
return "Unknown STM32";
#endif
}
void Stm32f4Device::set_backlight_level(uint8_t level)
{
_backlight_level = level >= 0 ? level : 0;
_backlight_level = _backlight_level <= 100 ? _backlight_level : 100;
update_backlight();
}
uint8_t Stm32f4Device::get_backlight_level()
{
return _backlight_level;
}
void Stm32f4Device::set_backlight_power(bool power)
{
_backlight_power = power;
update_backlight();
}
bool Stm32f4Device::get_backlight_power()
{
return _backlight_power != 0;
}
void Stm32f4Device::update_backlight()
{
if(_backlight_pin == -1) return;
// analogWrite(_backlight_pin, _backlight_power ? map(_backlight_level, 0, 100, 0, 1023) : 0);
}
size_t Stm32f4Device::get_free_max_block()
{
// return ESP.getMaxFreeBlockSize();
}
size_t Stm32f4Device::get_free_heap(void)
{
// return ESP.getFreeHeap();
}
uint8_t Stm32f4Device::get_heap_fragmentation()
{
// return ESP.getHeapFragmentation();
}
uint16_t Stm32f4Device::get_cpu_frequency()
{
// return ESP.getCpuFreqMHz();
}
bool Stm32f4Device::is_system_pin(uint8_t pin)
{
// if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash
// if((pin >= 12) && (pin <= 14)) return true; // HSPI
return false;
}
} // namespace dev
dev::Stm32f4Device haspDevice;
#endif // STM32F4xx

67
src/dev/stm32f4/stm32f4.h Normal file
View File

@ -0,0 +1,67 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_STM32F4_H
#define HASP_DEVICE_STM32F4_H
#include "hasp_conf.h"
#include "dev/device.h"
#if defined(STM32F4xx)
namespace dev {
class Stm32f4Device : public BaseDevice {
public:
Stm32f4Device()
{
_hostname = "plate";
_backlight_power = 1;
_backlight_level = 100;
#ifdef TFT_BCKL
_backlight_pin = TFT_BCKL;
#else
_backlight_pin = -1;
#endif
}
void reboot() override;
void show_info() override;
const char* get_hostname();
void set_hostname(const char*);
const char* get_core_version();
const char* get_chip_model();
void set_backlight_pin(uint8_t pin) override;
void set_backlight_level(uint8_t val) override;
uint8_t get_backlight_level() override;
void set_backlight_power(bool power) override;
bool get_backlight_power() override;
size_t get_free_max_block() override;
size_t get_free_heap() override;
uint8_t get_heap_fragmentation() override;
uint16_t get_cpu_frequency() override;
bool is_system_pin(uint8_t pin) override;
private:
std::string _hostname;
uint8_t _backlight_pin;
uint8_t _backlight_level;
uint8_t _backlight_power;
void update_backlight();
};
} // namespace dev
using dev::Stm32f4Device;
extern dev::Stm32f4Device haspDevice;
#endif // STM32F4xx
#endif // HASP_DEVICE_STM32F4_H

View File

@ -0,0 +1,134 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if defined(WINDOWS)
#include <cstdint>
#include "Windows.h"
#include "hasp_win32.h"
#include "hasp_conf.h"
#include "hasp/hasp_utilities.h"
#include "hasp_debug.h"
#include "display/monitor.h"
namespace dev {
static inline void native_cpuid(unsigned int* eax, unsigned int* ebx, unsigned int* ecx, unsigned int* edx)
{
/* ecx is often an input as well as an output. */
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "0"(*eax), "2"(*ecx) : "memory");
}
void Win32Device::reboot()
{}
void Win32Device::show_info()
{
unsigned int eax, ebx, ecx, edx;
eax = 0;
native_cpuid(&eax, &ebx, &ecx, &edx);
// printf("EAX: %08X EBX: %08X ECX: %08X EDX: %08X\n", eax, ebx, ecx, edx);
char vendor[13];
memcpy(vendor, &ebx, 4);
memcpy(vendor + 4, &edx, 4);
memcpy(vendor + 8, &ecx, 4);
vendor[12] = '\0';
LOG_VERBOSE(0, F("Processor : %s"), vendor);
LOG_VERBOSE(0, F("CPU freq. : %i MHz"), get_cpu_frequency());
}
const char* Win32Device::get_hostname()
{
return _hostname.c_str();
}
void Win32Device::set_hostname(const char* hostname)
{
_hostname = hostname;
monitor_title(hostname);
// SDL_SetWindowTitle(monitor.window, hostname);
}
const char* Win32Device::get_core_version()
{
return _core_version.c_str();
}
const char* Win32Device::get_chip_model()
{
return "SDL2";
}
void Win32Device::set_backlight_pin(uint8_t pin)
{
// Win32Device::_backlight_pin = pin;
}
void Win32Device::set_backlight_level(uint8_t level)
{
uint8_t new_level = level >= 0 ? level : 0;
new_level = new_level <= 100 ? new_level : 100;
if(_backlight_level != new_level) {
_backlight_level = new_level;
update_backlight();
}
}
uint8_t Win32Device::get_backlight_level()
{
return _backlight_level;
}
void Win32Device::set_backlight_power(bool power)
{
_backlight_power = power;
update_backlight();
}
bool Win32Device::get_backlight_power()
{
return _backlight_power != 0;
}
void Win32Device::update_backlight()
{
uint8_t level = _backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0;
monitor_backlight(level);
}
size_t Win32Device::get_free_max_block()
{
return 0;
}
size_t Win32Device::get_free_heap(void)
{
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
return status.ullAvailPhys;
}
uint8_t Win32Device::get_heap_fragmentation()
{
return 0;
}
uint16_t Win32Device::get_cpu_frequency()
{
return 0;
}
bool Win32Device::is_system_pin(uint8_t pin)
{
return false;
}
} // namespace dev
dev::Win32Device haspDevice;
#endif // WINDOWS

View File

@ -0,0 +1,93 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_WINDOWS_H
#define HASP_DEVICE_WINDOWS_H
#include <cstdint>
#include <string>
#include "Windows.h"
#include "hasp_conf.h"
#include "../device.h"
#if defined(WINDOWS)
namespace dev {
class Win32Device : public BaseDevice {
public:
Win32Device()
{
char buffer[MAX_COMPUTERNAME_LENGTH + 1];
DWORD length = sizeof(buffer);
if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNameNetBIOS, buffer, &length)) {
_hostname = buffer;
} else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNameDnsHostname, buffer, &length)) {
_hostname = buffer;
} else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNamePhysicalDnsHostname, buffer, &length)) {
_hostname = buffer;
} else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNamePhysicalDnsDomain, buffer, &length)) {
_hostname = buffer;
} else {
_hostname = "localhost";
}
// Get the Windows version.
DWORD dwBuild = 0;
DWORD dwVersion = GetVersion();
DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
DWORD dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
if(dwVersion < 0x80000000) dwBuild = (DWORD)(HIWORD(dwVersion));
char version[128];
snprintf(version, sizeof(version), "Windows %d.%d-%d", dwMajorVersion, dwMinorVersion, dwBuild);
_core_version = version;
// _backlight_pin = -1;
_backlight_power = 1;
_backlight_level = 100;
}
void reboot() override;
void show_info() override;
const char* get_hostname();
void set_hostname(const char*);
const char* get_core_version();
const char* get_chip_model();
void set_backlight_pin(uint8_t pin);
void set_backlight_level(uint8_t val);
uint8_t get_backlight_level();
void set_backlight_power(bool power);
bool get_backlight_power();
size_t get_free_max_block();
size_t get_free_heap();
uint8_t get_heap_fragmentation();
uint16_t get_cpu_frequency();
bool is_system_pin(uint8_t pin) override;
private:
std::string _hostname;
std::string _core_version;
uint8_t _backlight_pin;
uint8_t _backlight_level;
uint8_t _backlight_power;
void update_backlight();
};
} // namespace dev
using dev::Win32Device;
extern dev::Win32Device haspDevice;
#endif // WINDOWS
#endif // HASP_DEVICE_WINDOWS_H

View File

@ -1,26 +0,0 @@
#include "hasp_drv_display.h"
void drv_display_init(lv_disp_drv_t * disp_drv, uint8_t rotation, bool invert_display)
{
/* TFT init */
#if defined(USE_FSMC)
fsmc_ili9341_init(rotation, invert_display);
disp_drv->flush_cb = fsmc_ili9341_flush; // Normal callback when flushing
// xpt2046_init(rotation);
#else
tft_espi_init(rotation, invert_display);
disp_drv->flush_cb = tft_espi_flush; // Normal callback when flushing
#endif
}
/* Callback used for screenshots only: */
/* indirect callback to flush screenshot data to the screen */
void drv_display_flush_cb(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
{
#if defined(USE_FSMC)
fsmc_ili9341_flush(disp, area, color_p);
#else
tft_espi_flush(disp, area, color_p);
#endif
}

Some files were not shown because too many files have changed in this diff Show More