From 8400dd00431f423a8b68a054e32f75c764b76df3 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Wed, 5 Jun 2024 09:55:21 +0000 Subject: [PATCH] chore: autoformatting --- radio/src/gui/colorlcd/function_switches.cpp | 208 +++++------ radio/src/gui/colorlcd/function_switches.h | 38 +-- .../gui/colorlcd/radio_diagcustswitches.cpp | 59 ++-- .../src/gui/colorlcd/radio_diagcustswitches.h | 14 +- radio/src/targets/horus/cst8xx_driver.cpp | 119 ++++--- radio/src/targets/horus/cst8xx_driver.h | 21 +- radio/src/targets/horus/hal.h | 1 - .../src/targets/horus/lcd_st7796s_driver.cpp | 322 +++++++++--------- radio/src/targets/horus/lcd_st7796s_driver.h | 61 ++-- 9 files changed, 436 insertions(+), 407 deletions(-) diff --git a/radio/src/gui/colorlcd/function_switches.cpp b/radio/src/gui/colorlcd/function_switches.cpp index 14516b4dab1..413aeaafd01 100644 --- a/radio/src/gui/colorlcd/function_switches.cpp +++ b/radio/src/gui/colorlcd/function_switches.cpp @@ -22,54 +22,57 @@ #if defined(FUNCTION_SWITCHES) #include "function_switches.h" -#include "opentx.h" +#include "opentx.h" #include "strhelpers.h" #include "switches.h" -#define SET_DIRTY() storageDirty(EE_MODEL) +#define SET_DIRTY() storageDirty(EE_MODEL) static const lv_coord_t line_col_dsc1[] = {LV_GRID_CONTENT, - LV_GRID_TEMPLATE_LAST}; + LV_GRID_TEMPLATE_LAST}; + +static const lv_coord_t line_col_dsc2[] = { + LV_GRID_FR(10), LV_GRID_FR(10), LV_GRID_FR(10), + LV_GRID_FR(12), LV_GRID_FR(8), LV_GRID_TEMPLATE_LAST}; -static const lv_coord_t line_col_dsc2[] = {LV_GRID_FR(10), LV_GRID_FR(10), LV_GRID_FR(10), LV_GRID_FR(12), LV_GRID_FR(8), - LV_GRID_TEMPLATE_LAST}; - static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; -static const char* _fct_sw_start[] = { STR_CHAR_DOWN, STR_CHAR_UP, STR_LAST }; +static const char* _fct_sw_start[] = {STR_CHAR_DOWN, STR_CHAR_UP, STR_LAST}; -const std::string edgetx_fs_manual_url = "https://edgetx.gitbook.io/edgetx-user-manual/b-and-w-radios/model-select/setup#function-switches"; +const std::string edgetx_fs_manual_url = + "https://edgetx.gitbook.io/edgetx-user-manual/b-and-w-radios/model-select/" + "setup#function-switches"; class FunctionSwitch : public Window { public: FunctionSwitch(Window* parent, uint8_t sw) : - Window(parent, {0, 0, LCD_W - PAD_SMALL * 2, 36}), - switchIndex(sw) + Window(parent, {0, 0, LCD_W - PAD_SMALL * 2, 36}), switchIndex(sw) { padAll(PAD_TINY); std::string s(STR_CHAR_SWITCH); s += switchGetName(switchIndex + switchGetMaxSwitches()); - new StaticText(this, {8, 6, SW_W, PAGE_LINE_HEIGHT}, s, COLOR_THEME_PRIMARY1); - - new ModelTextEdit(this, {NM_X, 0, NM_W, 32}, g_model.switchNames[switchIndex], LEN_SWITCH_NAME); - - auto choice = new Choice(this, {TP_X, 0, TP_W, 32}, STR_SWTYPES, SWITCH_NONE, SWITCH_2POS, - [=]() { - return FSWITCH_CONFIG(switchIndex); - }, - [=](int val) { - FSWITCH_SET_CONFIG(switchIndex, val); - if (val == SWITCH_TOGGLE) { - FSWITCH_SET_STARTUP(switchIndex, FS_START_PREVIOUS); - startChoice->setValue(startChoice->getIntValue()); - } - SET_DIRTY(); - }); + new StaticText(this, {8, 6, SW_W, PAGE_LINE_HEIGHT}, s, + COLOR_THEME_PRIMARY1); + + new ModelTextEdit(this, {NM_X, 0, NM_W, 32}, + g_model.switchNames[switchIndex], LEN_SWITCH_NAME); + + auto choice = new Choice( + this, {TP_X, 0, TP_W, 32}, STR_SWTYPES, SWITCH_NONE, SWITCH_2POS, + [=]() { return FSWITCH_CONFIG(switchIndex); }, + [=](int val) { + FSWITCH_SET_CONFIG(switchIndex, val); + if (val == SWITCH_TOGGLE) { + FSWITCH_SET_STARTUP(switchIndex, FS_START_PREVIOUS); + startChoice->setValue(startChoice->getIntValue()); + } + SET_DIRTY(); + }); choice->setAvailableHandler([=](int typ) -> bool { int group = FSWITCH_GROUP(switchIndex); if (group > 0 && IS_FSWITCH_GROUP_ON(group) && typ == SWITCH_TOGGLE) @@ -77,40 +80,41 @@ class FunctionSwitch : public Window return true; }); - groupChoice = new Choice(this, {GR_X, 0, GR_W, 32}, STR_FUNCTION_SWITCH_GROUPS, 0, 3, - [=]() { - return FSWITCH_GROUP(switchIndex); - }, - [=](int group) { - int oldGroup = FSWITCH_GROUP(switchIndex); - if (groupHasSwitchOn(group)) - setFSLogicalState(switchIndex, 0); - FSWITCH_SET_GROUP(switchIndex, group); - if (group > 0) { - FSWITCH_SET_STARTUP(switchIndex, groupDefaultSwitch(group) == -1 ? FS_START_PREVIOUS : FS_START_OFF); - if (FSWITCH_CONFIG(switchIndex) == SWITCH_TOGGLE && IS_FSWITCH_GROUP_ON(group)) - FSWITCH_SET_CONFIG(switchIndex, SWITCH_2POS); - setGroupSwitchState(group, switchIndex); - } else { - FSWITCH_SET_STARTUP(switchIndex, FS_START_PREVIOUS); - } - setGroupSwitchState(oldGroup); - SET_DIRTY(); - }); + groupChoice = new Choice( + this, {GR_X, 0, GR_W, 32}, STR_FUNCTION_SWITCH_GROUPS, 0, 3, + [=]() { return FSWITCH_GROUP(switchIndex); }, + [=](int group) { + int oldGroup = FSWITCH_GROUP(switchIndex); + if (groupHasSwitchOn(group)) setFSLogicalState(switchIndex, 0); + FSWITCH_SET_GROUP(switchIndex, group); + if (group > 0) { + FSWITCH_SET_STARTUP(switchIndex, groupDefaultSwitch(group) == -1 + ? FS_START_PREVIOUS + : FS_START_OFF); + if (FSWITCH_CONFIG(switchIndex) == SWITCH_TOGGLE && + IS_FSWITCH_GROUP_ON(group)) + FSWITCH_SET_CONFIG(switchIndex, SWITCH_2POS); + setGroupSwitchState(group, switchIndex); + } else { + FSWITCH_SET_STARTUP(switchIndex, FS_START_PREVIOUS); + } + setGroupSwitchState(oldGroup); + SET_DIRTY(); + }); groupChoice->setAvailableHandler([=](int group) -> bool { - if (FSWITCH_CONFIG(switchIndex) == SWITCH_TOGGLE && group && IS_FSWITCH_GROUP_ON(group)) + if (FSWITCH_CONFIG(switchIndex) == SWITCH_TOGGLE && group && + IS_FSWITCH_GROUP_ON(group)) return false; return true; }); - startChoice = new Choice(this, {ST_X, 0, ST_W, 32}, _fct_sw_start, 0, 2, - [=]() { - return FSWITCH_STARTUP(switchIndex); - }, - [=](int val) { - FSWITCH_SET_STARTUP(switchIndex, val); - SET_DIRTY(); - }); + startChoice = new Choice( + this, {ST_X, 0, ST_W, 32}, _fct_sw_start, 0, 2, + [=]() { return FSWITCH_STARTUP(switchIndex); }, + [=](int val) { + FSWITCH_SET_STARTUP(switchIndex, val); + SET_DIRTY(); + }); setState(); } @@ -132,7 +136,8 @@ class FunctionSwitch : public Window void setState() { - if (FSWITCH_CONFIG(switchIndex) != SWITCH_2POS || FSWITCH_GROUP(switchIndex) > 0) { + if (FSWITCH_CONFIG(switchIndex) != SWITCH_2POS || + FSWITCH_GROUP(switchIndex) > 0) { lv_obj_add_flag(startChoice->getLvObj(), LV_OBJ_FLAG_HIDDEN); } else { lv_obj_clear_flag(startChoice->getLvObj(), LV_OBJ_FLAG_HIDDEN); @@ -155,45 +160,51 @@ class SwitchGroup : public Window { public: SwitchGroup(Window* parent, uint8_t group) : - Window(parent, {0, 0, LCD_W - PAD_SMALL * 2, 36}), - groupIndex(group) + Window(parent, {0, 0, LCD_W - PAD_SMALL * 2, 36}), groupIndex(group) { padAll(PAD_TINY); - new StaticText(this, {0, 6, NM_W, PAGE_LINE_HEIGHT}, STR_FUNCTION_SWITCH_GROUPS[groupIndex], COLOR_THEME_PRIMARY1); - - auto btn = new TextButton(this, {AO_X, 0, AO_W, 32}, STR_GROUP_ALWAYS_ON, [=]() -> int8_t { - int groupAlwaysOn = IS_FSWITCH_GROUP_ON(groupIndex); - groupAlwaysOn ^= 1; - SET_FSWITCH_GROUP_ON(groupIndex, groupAlwaysOn); - setGroupSwitchState(groupIndex); - startChoice->setValue(startChoice->getIntValue()); - SET_DIRTY(); - return groupAlwaysOn; - }); + new StaticText(this, {0, 6, NM_W, PAGE_LINE_HEIGHT}, + STR_FUNCTION_SWITCH_GROUPS[groupIndex], + COLOR_THEME_PRIMARY1); + + auto btn = new TextButton( + this, {AO_X, 0, AO_W, 32}, STR_GROUP_ALWAYS_ON, [=]() -> int8_t { + int groupAlwaysOn = IS_FSWITCH_GROUP_ON(groupIndex); + groupAlwaysOn ^= 1; + SET_FSWITCH_GROUP_ON(groupIndex, groupAlwaysOn); + setGroupSwitchState(groupIndex); + startChoice->setValue(startChoice->getIntValue()); + SET_DIRTY(); + return groupAlwaysOn; + }); btn->check(IS_FSWITCH_GROUP_ON(groupIndex)); - new StaticText(this, {SL_X, 6, SL_W, PAGE_LINE_HEIGHT}, STR_SWITCH_STARTUP, COLOR_THEME_PRIMARY1); - - startChoice = new Choice(this, {ST_X, 0, ST_W, 32}, STR_FSSWITCHES, 0, NUM_FUNCTIONS_SWITCHES + 1, - [=]() { - return groupDefaultSwitch(groupIndex) + 1; - }, - [=](int sw) { - for (int i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) { - if (FSWITCH_GROUP(i) == groupIndex) { - FSWITCH_SET_STARTUP(i, sw ? FS_START_OFF : FS_START_PREVIOUS); - } - } - if (sw > 0 && sw <= NUM_FUNCTIONS_SWITCHES) { - FSWITCH_SET_STARTUP(sw - 1, FS_START_ON); - } - SET_DIRTY(); - }); + new StaticText(this, {SL_X, 6, SL_W, PAGE_LINE_HEIGHT}, STR_SWITCH_STARTUP, + COLOR_THEME_PRIMARY1); + + startChoice = new Choice( + this, {ST_X, 0, ST_W, 32}, STR_FSSWITCHES, 0, + NUM_FUNCTIONS_SWITCHES + 1, + [=]() { return groupDefaultSwitch(groupIndex) + 1; }, + [=](int sw) { + for (int i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) { + if (FSWITCH_GROUP(i) == groupIndex) { + FSWITCH_SET_STARTUP(i, sw ? FS_START_OFF : FS_START_PREVIOUS); + } + } + if (sw > 0 && sw <= NUM_FUNCTIONS_SWITCHES) { + FSWITCH_SET_STARTUP(sw - 1, FS_START_ON); + } + SET_DIRTY(); + }); startChoice->setAvailableHandler([=](int sw) -> bool { - return (sw == 0) || (sw == NUM_FUNCTIONS_SWITCHES + 1 && !IS_FSWITCH_GROUP_ON(groupIndex)) || (FSWITCH_GROUP(sw - 1) == groupIndex); + return (sw == 0) || + (sw == NUM_FUNCTIONS_SWITCHES + 1 && + !IS_FSWITCH_GROUP_ON(groupIndex)) || + (FSWITCH_GROUP(sw - 1) == groupIndex); }); -} + } static constexpr coord_t NM_W = 100; static constexpr coord_t AO_X = NM_W + 2; @@ -221,17 +232,19 @@ ModelFunctionSwitches::ModelFunctionSwitches() : Page(ICON_MODEL_SETUP) auto line = body->newLine(grid2); new StaticText(line, rect_t{}, STR_SWITCHES, COLOR_THEME_PRIMARY1); - new StaticText(line, rect_t{}, STR_NAME, COLOR_THEME_PRIMARY1|FONT(XS)); - new StaticText(line, rect_t{}, STR_SWITCH_TYPE, COLOR_THEME_PRIMARY1|FONT(XS)); - new StaticText(line, rect_t{}, STR_GROUP, COLOR_THEME_PRIMARY1|FONT(XS)); - new StaticText(line, rect_t{}, STR_SWITCH_STARTUP, COLOR_THEME_PRIMARY1|FONT(XS)); + new StaticText(line, rect_t{}, STR_NAME, COLOR_THEME_PRIMARY1 | FONT(XS)); + new StaticText(line, rect_t{}, STR_SWITCH_TYPE, + COLOR_THEME_PRIMARY1 | FONT(XS)); + new StaticText(line, rect_t{}, STR_GROUP, COLOR_THEME_PRIMARY1 | FONT(XS)); + new StaticText(line, rect_t{}, STR_SWITCH_STARTUP, + COLOR_THEME_PRIMARY1 | FONT(XS)); for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) { new FunctionSwitch(body, i); } for (uint8_t i = 1; i <= 3; i += 1) { - groupLines[i-1] = new SwitchGroup(body, i); + groupLines[i - 1] = new SwitchGroup(body, i); } line = body->newLine(grid1); @@ -242,14 +255,17 @@ ModelFunctionSwitches::ModelFunctionSwitches() : Page(ICON_MODEL_SETUP) line->padBottom(10); line->padLeft((width() - 150) / 2); - auto qr = lv_qrcode_create(line->getLvObj(), 150, makeLvColor(COLOR_THEME_SECONDARY1), makeLvColor(COLOR_THEME_SECONDARY3)); - lv_qrcode_update(qr, edgetx_fs_manual_url.c_str(), edgetx_fs_manual_url.length()); + auto qr = lv_qrcode_create(line->getLvObj(), 150, + makeLvColor(COLOR_THEME_SECONDARY1), + makeLvColor(COLOR_THEME_SECONDARY3)); + lv_qrcode_update(qr, edgetx_fs_manual_url.c_str(), + edgetx_fs_manual_url.length()); } void ModelFunctionSwitches::setState() { for (int i = 0; i < 3; i += 1) - if (firstSwitchInGroup(i+1) < 0) + if (firstSwitchInGroup(i + 1) < 0) lv_obj_add_flag(groupLines[i]->getLvObj(), LV_OBJ_FLAG_HIDDEN); else lv_obj_clear_flag(groupLines[i]->getLvObj(), LV_OBJ_FLAG_HIDDEN); diff --git a/radio/src/gui/colorlcd/function_switches.h b/radio/src/gui/colorlcd/function_switches.h index 9762016783c..768ef684f9e 100644 --- a/radio/src/gui/colorlcd/function_switches.h +++ b/radio/src/gui/colorlcd/function_switches.h @@ -1,23 +1,23 @@ /* -* Copyright (C) EdgeTX -* -* Based on code named -* opentx - https://github.com/opentx/opentx -* th9x - http://code.google.com/p/th9x -* er9x - http://code.google.com/p/er9x -* gruvin9x - http://code.google.com/p/gruvin9x -* -* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -*/ + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #pragma once diff --git a/radio/src/gui/colorlcd/radio_diagcustswitches.cpp b/radio/src/gui/colorlcd/radio_diagcustswitches.cpp index 94a9dfcbb7e..4e0dd66501a 100644 --- a/radio/src/gui/colorlcd/radio_diagcustswitches.cpp +++ b/radio/src/gui/colorlcd/radio_diagcustswitches.cpp @@ -21,10 +21,11 @@ #if defined(FUNCTION_SWITCHES) -#include "opentx.h" #include "radio_diagcustswitches.h" -#include "libopenui.h" + #include "board.h" +#include "libopenui.h" +#include "opentx.h" class RadioCustSwitchesDiagsWindow : public Window { @@ -32,40 +33,54 @@ class RadioCustSwitchesDiagsWindow : public Window static constexpr coord_t FS_2ND_COLUMN = 160; static constexpr coord_t FS_3RD_COLUMN = 260; - public: - RadioCustSwitchesDiagsWindow(Window * parent, const rect_t &rect) : - Window(parent, rect) - { - new StaticText(this, {FS_1ST_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, "Phys"); - new StaticText(this, {FS_2ND_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, "Log"); - new StaticText(this, {FS_3RD_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, "Led"); - for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) { - coord_t y = 2 * FH + i * FH; - new StaticText(this, {10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, STR_CHAR_SWITCH); - new StaticText(this, {25, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, switchGetName(i+switchGetMaxSwitches())); - new DynamicText(this, {FS_1ST_COLUMN + 10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, [=]() { return getFSPhysicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; }); - new DynamicText(this, {FS_2ND_COLUMN + 10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, [=]() { return getFSLogicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; }); - new DynamicText(this, {FS_3RD_COLUMN + 5, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, [=]() { return STR_OFFON[getFSLedState(i)]; }); - } + public: + RadioCustSwitchesDiagsWindow(Window *parent, const rect_t &rect) : + Window(parent, rect) + { + new StaticText(this, {FS_1ST_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, + "Phys"); + new StaticText(this, {FS_2ND_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, + "Log"); + new StaticText(this, {FS_3RD_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, + "Led"); + for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) { + coord_t y = 2 * FH + i * FH; + new StaticText(this, {10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, + STR_CHAR_SWITCH); + new StaticText(this, {25, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, + switchGetName(i + switchGetMaxSwitches())); + new DynamicText( + this, {FS_1ST_COLUMN + 10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, + [=]() { + return getFSPhysicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; + }); + new DynamicText( + this, {FS_2ND_COLUMN + 10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, + [=]() { return getFSLogicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; }); + new DynamicText(this, + {FS_3RD_COLUMN + 5, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, + [=]() { return STR_OFFON[getFSLedState(i)]; }); } + } - protected: + protected: }; -void RadioCustSwitchesDiagsPage::buildHeader(Window * window) +void RadioCustSwitchesDiagsPage::buildHeader(Window *window) { header->setTitle(STR_RADIO_SETUP); header->setTitle2(STR_MENU_FSWITCH); } -void RadioCustSwitchesDiagsPage::buildBody(Window * window) +void RadioCustSwitchesDiagsPage::buildBody(Window *window) { body->padAll(PAD_ZERO); - new RadioCustSwitchesDiagsWindow(window, {0, 0, window->width(), window->height()}); + new RadioCustSwitchesDiagsWindow(window, + {0, 0, window->width(), window->height()}); } RadioCustSwitchesDiagsPage::RadioCustSwitchesDiagsPage() : - Page(ICON_MODEL_SETUP) + Page(ICON_MODEL_SETUP) { buildHeader(header); buildBody(body); diff --git a/radio/src/gui/colorlcd/radio_diagcustswitches.h b/radio/src/gui/colorlcd/radio_diagcustswitches.h index a1da5647a32..6f3ed471163 100644 --- a/radio/src/gui/colorlcd/radio_diagcustswitches.h +++ b/radio/src/gui/colorlcd/radio_diagcustswitches.h @@ -21,12 +21,12 @@ #include "page.h" -class RadioCustSwitchesDiagsPage: public Page { - public: - explicit RadioCustSwitchesDiagsPage(); +class RadioCustSwitchesDiagsPage : public Page +{ + public: + explicit RadioCustSwitchesDiagsPage(); - protected: - void buildHeader(Window * window); - void buildBody(Window * window); + protected: + void buildHeader(Window* window); + void buildBody(Window* window); }; - diff --git a/radio/src/targets/horus/cst8xx_driver.cpp b/radio/src/targets/horus/cst8xx_driver.cpp index 4385801ed6c..f0745d42825 100644 --- a/radio/src/targets/horus/cst8xx_driver.cpp +++ b/radio/src/targets/horus/cst8xx_driver.cpp @@ -19,52 +19,45 @@ * GNU General Public License for more details. */ +#include "cst8xx_driver.h" + +#include "debug.h" +#include "delays_driver.h" +#include "hal.h" #include "hal/gpio.h" +#include "rtos.h" +#include "stm32_exti_driver.h" #include "stm32_gpio.h" -#include "stm32_hal_ll.h" +#include "stm32_gpio_driver.h" #include "stm32_hal.h" +#include "stm32_hal_ll.h" #include "stm32_i2c_driver.h" -#include "stm32_gpio_driver.h" -#include "stm32_exti_driver.h" - -#include "rtos.h" - -#include "hal.h" #include "timers_driver.h" -#include "delays_driver.h" -#include "cst8xx_driver.h" - -#include "debug.h" volatile static bool touchEventOccured; -#define TOUCH_CST836U_I2C_ADDRESS (0x15) +#define TOUCH_CST836U_I2C_ADDRESS (0x15) static tc_handle_TypeDef tc_handle = {0, 0}; tmr10ms_t downTime = 0; tmr10ms_t tapTime = 0; short tapCount = 0; -#define TAP_TIME 250 //ms +#define TAP_TIME 250 // ms static TouchState internalTouchState = {}; -static void _cst836u_exti_isr(void) -{ - touchEventOccured = true; -} +static void _cst836u_exti_isr(void) { touchEventOccured = true; } static void TouchAFExtiConfig(void) { __HAL_RCC_SYSCFG_CLK_ENABLE(); LL_SYSCFG_SetEXTISource(TOUCH_INT_EXTI_Port, TOUCH_INT_EXTI_SysCfgLine); - stm32_exti_enable(TOUCH_INT_EXTI_Line, - LL_EXTI_TRIGGER_FALLING, - _cst836u_exti_isr); + stm32_exti_enable(TOUCH_INT_EXTI_Line, LL_EXTI_TRIGGER_FALLING, + _cst836u_exti_isr); } - void initTouchI2C(void) { TRACE("CST836U I2C Init"); @@ -75,14 +68,13 @@ void initTouchI2C(void) } } -#define I2C_TIMEOUT_MAX 5 // 5 ms +#define I2C_TIMEOUT_MAX 5 // 5 ms -bool touch_i2c_read(uint8_t addr, uint8_t reg, uint8_t * data, uint8_t len) +bool touch_i2c_read(uint8_t addr, uint8_t reg, uint8_t* data, uint8_t len) { - if(stm32_i2c_master_tx(TOUCH_I2C_BUS, addr, ®, 1, 3) < 0) - return false; + if (stm32_i2c_master_tx(TOUCH_I2C_BUS, addr, ®, 1, 3) < 0) return false; delay_us(5); - if(stm32_i2c_master_rx(TOUCH_I2C_BUS, addr, data, len, I2C_TIMEOUT_MAX) < 0) + if (stm32_i2c_master_rx(TOUCH_I2C_BUS, addr, data, len, I2C_TIMEOUT_MAX) < 0) return false; return true; @@ -99,7 +91,8 @@ static uint8_t TS_IO_Read(uint8_t addr, uint8_t reg) return result; } -static uint16_t TS_IO_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t * buffer, uint16_t length) +static uint16_t TS_IO_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t* buffer, + uint16_t length) { uint8_t tryCount = 3; while (!touch_i2c_read(addr, reg, buffer, length)) { @@ -109,14 +102,19 @@ static uint16_t TS_IO_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t * buffer, return 1; } - static void touch_cst836u_debug_info(void) { #if defined(DEBUG) - TRACE("cst836u: fw ver 0x%02X %02X", TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_FW_VERSION_H_REG), TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_FW_VERSION_L_REG)); - TRACE("cst836u: module version 0x%02X", TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_MODULE_VERSION_REG)); - TRACE("cst836u: project name 0x%02X", TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_PROJECT_NAME_REG)); - TRACE("cst836u: chip type 0x%02X 0x%02X", TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_CHIP_TYPE_H_REG), TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_CHIP_TYPE_L_REG)); + TRACE("cst836u: fw ver 0x%02X %02X", + TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_FW_VERSION_H_REG), + TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_FW_VERSION_L_REG)); + TRACE("cst836u: module version 0x%02X", + TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_MODULE_VERSION_REG)); + TRACE("cst836u: project name 0x%02X", + TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_PROJECT_NAME_REG)); + TRACE("cst836u: chip type 0x%02X 0x%02X", + TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_CHIP_TYPE_H_REG), + TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_CHIP_TYPE_L_REG)); #endif } @@ -129,31 +127,33 @@ static void touch_cst836u_debug_info(void) * @param Y: Pointer to Y position value * @retval None. */ -static void cst836u_TS_GetXY(uint16_t * X, uint16_t * Y, uint32_t * event) +static void cst836u_TS_GetXY(uint16_t* X, uint16_t* Y, uint32_t* event) { uint8_t regAddress = 0; uint8_t dataxy[4]; if (tc_handle.currActiveTouchIdx < tc_handle.currActiveTouchNb) { switch (tc_handle.currActiveTouchIdx) { - case 0 : + case 0: regAddress = CST836U_TOUCH1_XH_REG; break; - case 1 : + case 1: regAddress = CST836U_TOUCH2_XH_REG; break; - default : + default: break; } /* Read X and Y positions */ - TS_IO_ReadMultiple(TOUCH_CST836U_I2C_ADDRESS, regAddress, dataxy, sizeof(dataxy)); + TS_IO_ReadMultiple(TOUCH_CST836U_I2C_ADDRESS, regAddress, dataxy, + sizeof(dataxy)); /* Send back ready X position to caller */ *X = ((dataxy[0] & CST836U_MSB_MASK) << 8) | dataxy[1]; /* Send back ready Y position to caller */ *Y = ((dataxy[2] & CST836U_MSB_MASK) << 8) | dataxy[3]; - *event = (dataxy[0] & CST836U_TOUCH_EVT_FLAG_MASK) >> CST836U_TOUCH_EVT_FLAG_SHIFT; + *event = (dataxy[0] & CST836U_TOUCH_EVT_FLAG_MASK) >> + CST836U_TOUCH_EVT_FLAG_SHIFT; /* uint32_t weight; uint32_t area; @@ -164,8 +164,8 @@ static void cst836u_TS_GetXY(uint16_t * X, uint16_t * Y, uint32_t * event) /** * @brief Return if there is touches detected or not. - * Try to detect new touches and forget the old ones (reset internal global - * variables). + * Try to detect new touches and forget the old ones (reset internal + * global variables). * @param DeviceAddr: Device address on communication Bus. * @retval : Number of active touches detected (can be 0, 1 or 2). */ @@ -216,35 +216,32 @@ void handleTouch() internalTouchState.x = touchX; internalTouchState.y = touchY; - if (internalTouchState.event == TE_NONE || internalTouchState.event == TE_UP || internalTouchState.event == TE_SLIDE_END) { + if (internalTouchState.event == TE_NONE || + internalTouchState.event == TE_UP || + internalTouchState.event == TE_SLIDE_END) { internalTouchState.startX = internalTouchState.x; internalTouchState.startY = internalTouchState.y; internalTouchState.event = TE_DOWN; - } - else if (internalTouchState.event == TE_DOWN) { - if (dx >= SLIDE_RANGE || dx <= -SLIDE_RANGE || dy >= SLIDE_RANGE || dy <= -SLIDE_RANGE) { + } else if (internalTouchState.event == TE_DOWN) { + if (dx >= SLIDE_RANGE || dx <= -SLIDE_RANGE || dy >= SLIDE_RANGE || + dy <= -SLIDE_RANGE) { internalTouchState.event = TE_SLIDE; - internalTouchState.deltaX = (short) dx; - internalTouchState.deltaY = (short) dy; - } - else { + internalTouchState.deltaX = (short)dx; + internalTouchState.deltaY = (short)dy; + } else { internalTouchState.event = TE_DOWN; internalTouchState.deltaX = 0; internalTouchState.deltaY = 0; } - } - else if (internalTouchState.event == TE_SLIDE) { - internalTouchState.event = TE_SLIDE; //no change - internalTouchState.deltaX = (short) dx; - internalTouchState.deltaY = (short) dy; + } else if (internalTouchState.event == TE_SLIDE) { + internalTouchState.event = TE_SLIDE; // no change + internalTouchState.deltaX = (short)dx; + internalTouchState.deltaY = (short)dy; } } } -bool touchPanelEventOccured() -{ - return touchEventOccured; -} +bool touchPanelEventOccured() { return touchEventOccured; } TouchState touchPanelRead() { @@ -284,12 +281,10 @@ TouchState touchPanelRead() TouchState ret = internalTouchState; internalTouchState.deltaX = 0; internalTouchState.deltaY = 0; - if(internalTouchState.event == TE_UP || internalTouchState.event == TE_SLIDE_END) + if (internalTouchState.event == TE_UP || + internalTouchState.event == TE_SLIDE_END) internalTouchState.event = TE_NONE; return ret; } -TouchState getInternalTouchState() -{ - return internalTouchState; -} +TouchState getInternalTouchState() { return internalTouchState; } diff --git a/radio/src/targets/horus/cst8xx_driver.h b/radio/src/targets/horus/cst8xx_driver.h index cf1e9bb33b6..086d73d00c2 100644 --- a/radio/src/targets/horus/cst8xx_driver.h +++ b/radio/src/targets/horus/cst8xx_driver.h @@ -45,12 +45,12 @@ extern "C" { /* Set Multi-touch as non supported */ #ifndef TS_MULTI_TOUCH_SUPPORTED - #define TS_MULTI_TOUCH_SUPPORTED 0 +#define TS_MULTI_TOUCH_SUPPORTED 0 #endif /* Set Auto-calibration as non supported */ #ifndef TS_AUTO_CALIBRATION_SUPPORTED - #define TS_AUTO_CALIBRATION_SUPPORTED 0 +#define TS_AUTO_CALIBRATION_SUPPORTED 0 #endif /* Macros --------------------------------------------------------------------*/ @@ -58,8 +58,7 @@ extern "C" { /** @typedef ft6x06_handle_TypeDef * ft6x06 Handle definition. */ -typedef struct -{ +typedef struct { /* field holding the current number of simultaneous active touches */ uint8_t currActiveTouchNb; @@ -67,7 +66,7 @@ typedef struct uint8_t currActiveTouchIdx; } tc_handle_TypeDef; - +/* clang-format off */ #define CST836U_WORK_MODE_REG 0x00 #define CST836U_PROXIMITY_ID_REG 0x01 #define CST836U_TOUCH_NUM_REG 0x02 @@ -98,13 +97,13 @@ typedef struct #define CST836U_MSB_MASK 0x0F -#define CST836U_TOUCH_EVT_FLAG_SHIFT 6 -#define CST836U_TOUCH_EVT_FLAG_MASK (3 << CST836U_TOUCH_EVT_FLAG_SHIFT) -#define CST836U_TOUCH_EVT_FLAG_CONTACT 0x02 - -extern void TouchInit( void ); -extern void TouchDriver( void ); +#define CST836U_TOUCH_EVT_FLAG_SHIFT 6 +#define CST836U_TOUCH_EVT_FLAG_MASK (3 << CST836U_TOUCH_EVT_FLAG_SHIFT) +#define CST836U_TOUCH_EVT_FLAG_CONTACT 0x02 +/* clang-format on */ +extern void TouchInit(void); +extern void TouchDriver(void); #ifdef __cplusplus } diff --git a/radio/src/targets/horus/hal.h b/radio/src/targets/horus/hal.h index f74842aad8c..86b1b4fc668 100644 --- a/radio/src/targets/horus/hal.h +++ b/radio/src/targets/horus/hal.h @@ -568,7 +568,6 @@ #define LED_BLUE_GPIO GPIO_PIN(GPIOE, 5) // PE.05 #endif - // Customisable switches leds #if defined(RADIO_T15) #define FSLED_GPIO_1 GPIO_PIN(GPIOA, 15) //PA.15 diff --git a/radio/src/targets/horus/lcd_st7796s_driver.cpp b/radio/src/targets/horus/lcd_st7796s_driver.cpp index 93b1ebfd780..3d9b12af083 100644 --- a/radio/src/targets/horus/lcd_st7796s_driver.cpp +++ b/radio/src/targets/horus/lcd_st7796s_driver.cpp @@ -19,24 +19,25 @@ * GNU General Public License for more details. */ -#include "stm32_hal_ll.h" -#include "stm32_hal.h" -#include "opentx_types.h" +#include "lcd_st7796s_driver.h" + +#include "board.h" +#include "debug.h" +#include "delays_driver.h" #include "dma2d.h" #include "hal.h" -#include "delays_driver.h" -#include "debug.h" #include "lcd.h" -#include "lcd_st7796s_driver.h" -#include "board.h" +#include "opentx_types.h" +#include "stm32_hal.h" +#include "stm32_hal_ll.h" static LTDC_HandleTypeDef hltdc; static void* initialFrameBuffer = nullptr; static volatile uint8_t _frame_addr_reloaded = 0; -static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer, - const rect_t ©_area) +static void startLcdRefresh(lv_disp_drv_t* disp_drv, uint16_t* buffer, + const rect_t& copy_area) { (void)disp_drv; (void)copy_area; @@ -50,12 +51,13 @@ static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer, // wait for reload // TODO: replace through some smarter mechanism without busy wait - while(_frame_addr_reloaded == 0); + while (_frame_addr_reloaded == 0); } uint32_t lcdPixelClock; -static void LCD_AF_GPIOConfig(void) { +static void LCD_AF_GPIOConfig(void) +{ /* ----------------------------------------------------------------------------- LCD_CLK <-> PG.07 | LCD_HSYNC <-> PI.12 | LCD_R3 <-> PJ.02 | LCD_G5 <-> PK.00 @@ -73,66 +75,70 @@ static void LCD_AF_GPIOConfig(void) { LL_GPIO_StructInit(&GPIO_InitStructure); // GPIOG configuration - GPIO_InitStructure.Pin = LL_GPIO_PIN_7; - GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStructure.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStructure.Pin = LL_GPIO_PIN_7; + GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStructure.Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStructure.Pull = LL_GPIO_PULL_NO; - GPIO_InitStructure.Alternate = LL_GPIO_AF_14; // AF LTDC + GPIO_InitStructure.Pull = LL_GPIO_PULL_NO; + GPIO_InitStructure.Alternate = LL_GPIO_AF_14; // AF LTDC LL_GPIO_Init(GPIOG, &GPIO_InitStructure); - + // GPIOI configuration - GPIO_InitStructure.Pin = LL_GPIO_PIN_12 | LL_GPIO_PIN_13; + GPIO_InitStructure.Pin = LL_GPIO_PIN_12 | LL_GPIO_PIN_13; LL_GPIO_Init(GPIOI, &GPIO_InitStructure); // GPIOJ configuration - GPIO_InitStructure.Pin = LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_9 | LL_GPIO_PIN_10 | LL_GPIO_PIN_11 | LL_GPIO_PIN_15; + GPIO_InitStructure.Pin = LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | + LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_9 | + LL_GPIO_PIN_10 | LL_GPIO_PIN_11 | LL_GPIO_PIN_15; LL_GPIO_Init(GPIOJ, &GPIO_InitStructure); // GPIOK configuration - GPIO_InitStructure.Pin = LL_GPIO_PIN_0 | LL_GPIO_PIN_1 | LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_7; + GPIO_InitStructure.Pin = LL_GPIO_PIN_0 | LL_GPIO_PIN_1 | LL_GPIO_PIN_2 | + LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5 | + LL_GPIO_PIN_6 | LL_GPIO_PIN_7; LL_GPIO_Init(GPIOK, &GPIO_InitStructure); } -static void lcdSpiConfig(void) { +static void lcdSpiConfig(void) +{ LL_GPIO_InitTypeDef GPIO_InitStructure; LL_GPIO_StructInit(&GPIO_InitStructure); - GPIO_InitStructure.Pin = LCD_SPI_SCK_GPIO_PIN | LCD_SPI_MOSI_GPIO_PIN; - GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStructure.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStructure.Pin = LCD_SPI_SCK_GPIO_PIN | LCD_SPI_MOSI_GPIO_PIN; + GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStructure.Mode = LL_GPIO_MODE_OUTPUT; GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStructure.Pull = LL_GPIO_PULL_NO; + GPIO_InitStructure.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(LCD_SPI_GPIO, &GPIO_InitStructure); - GPIO_InitStructure.Pin = LCD_SPI_CS_GPIO_PIN; - GPIO_InitStructure.Pull = LL_GPIO_PULL_UP; + GPIO_InitStructure.Pin = LCD_SPI_CS_GPIO_PIN; + GPIO_InitStructure.Pull = LL_GPIO_PULL_UP; LL_GPIO_Init(LCD_SPI_GPIO, &GPIO_InitStructure); - GPIO_InitStructure.Pin = LCD_NRST_GPIO_PIN; + GPIO_InitStructure.Pin = LCD_NRST_GPIO_PIN; LL_GPIO_Init(LCD_NRST_GPIO, &GPIO_InitStructure); /* Set the chip select pin always low */ LCD_CS_LOW(); } -void lcdDelay() { - delay_01us(1); -} +void lcdDelay() { delay_01us(1); } -static void lcdReset() { +static void lcdReset() +{ LCD_NRST_HIGH(); delay_ms(1); - LCD_NRST_LOW(); // RESET(); + LCD_NRST_LOW(); // RESET(); delay_ms(100); LCD_NRST_HIGH(); delay_ms(100); } -static void lcdWriteByte(uint8_t data_enable, uint8_t byte) { - +static void lcdWriteByte(uint8_t data_enable, uint8_t byte) +{ LCD_SCK_LOW(); if (data_enable) { @@ -163,167 +169,166 @@ static void lcdWriteByte(uint8_t data_enable, uint8_t byte) { LCD_SCK_LOW(); } - -void lcdWriteCommand(uint8_t command) { +void lcdWriteCommand(uint8_t command) +{ LCD_CS_LOW(); lcdWriteByte(0, command); LCD_CS_HIGH(); lcdDelay(); } -void lcdWriteData(uint8_t data) { +void lcdWriteData(uint8_t data) +{ LCD_CS_LOW(); lcdWriteByte(1, data); LCD_CS_HIGH(); lcdDelay(); } -void LCD_ST7796S_On(void) { - lcdWriteCommand(0x29); -} +void LCD_ST7796S_On(void) { lcdWriteCommand(0x29); } -void LCD_ST7796S_Init(void) { +void LCD_ST7796S_Init(void) +{ delay_ms(120); - lcdWriteCommand( 0x11 ); + lcdWriteCommand(0x11); delay_ms(120); - lcdWriteCommand( 0xF0 ); - lcdWriteData( 0xC3 ); + lcdWriteCommand(0xF0); + lcdWriteData(0xC3); - lcdWriteCommand( 0xF0 ); - lcdWriteData( 0x96 ); + lcdWriteCommand(0xF0); + lcdWriteData(0x96); - lcdWriteCommand( 0x36 ); - lcdWriteData( 0x28 ); + lcdWriteCommand(0x36); + lcdWriteData(0x28); - lcdWriteCommand( 0x2A ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x01 ); - lcdWriteData( 0xDF ); - lcdWriteCommand( 0x2B ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x01 ); - lcdWriteData( 0x3F ); + lcdWriteCommand(0x2A); + lcdWriteData(0x00); + lcdWriteData(0x00); + lcdWriteData(0x01); + lcdWriteData(0xDF); + lcdWriteCommand(0x2B); + lcdWriteData(0x00); + lcdWriteData(0x00); + lcdWriteData(0x01); + lcdWriteData(0x3F); - lcdWriteCommand( 0x3A ); + lcdWriteCommand(0x3A); #if defined(RADIO_T15) - lcdWriteData( 0x55 ); + lcdWriteData(0x55); #else - lcdWriteData( 0x66 ); + lcdWriteData(0x66); #endif - lcdWriteCommand( 0x34 ); + lcdWriteCommand(0x34); - //SET RGB STRAT - lcdWriteCommand (0xB0 ); //SET HS VS DE CLK 上升还是下降有效 - lcdWriteData( 0x80 ); + // SET RGB STRAT + lcdWriteCommand(0xB0); // SET HS VS DE CLK 上升还是下降有效 + lcdWriteData(0x80); - lcdWriteCommand( 0xB4 ); - lcdWriteData( 0x01 ); + lcdWriteCommand(0xB4); + lcdWriteData(0x01); - lcdWriteCommand( 0xB6 ); + lcdWriteCommand(0xB6); // lcdWriteData( 0x20 ); // lcdWriteData( 0x02 ); // lcdWriteData( 0x3B ); - lcdWriteData( 0x20 ); - lcdWriteData( 0x02 ); - lcdWriteData( 0x3B ); - //SET RGB END - - lcdWriteCommand( 0xB7); - lcdWriteData( 0xC6); - - lcdWriteCommand( 0xB9 ); - lcdWriteData( 0x02 ); - lcdWriteData( 0xE0 ); - - lcdWriteCommand( 0xC0 ); - lcdWriteData( 0x80 ); - lcdWriteData( 0x65 ); - - lcdWriteCommand( 0xC1 ); - lcdWriteData( 0x0D ); - - lcdWriteCommand( 0xC2 ); - lcdWriteData( 0xA7 ); - - lcdWriteCommand( 0xC5 ); - lcdWriteData( 0x14 ); - - lcdWriteCommand( 0xE8 ); - lcdWriteData( 0x40 ); - lcdWriteData( 0x8A ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x29 ); - lcdWriteData( 0x19 ); - lcdWriteData( 0xA5 ); - lcdWriteData( 0x33 ); - - lcdWriteCommand( 0xE0 ); - lcdWriteData( 0xD0 ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x04 ); - lcdWriteData( 0x05 ); - lcdWriteData( 0x04 ); - lcdWriteData( 0x21 ); - lcdWriteData( 0x25 ); - lcdWriteData( 0x43 ); - lcdWriteData( 0x3F ); - lcdWriteData( 0x37 ); - lcdWriteData( 0x13 ); - lcdWriteData( 0x13 ); - lcdWriteData( 0x29 ); - lcdWriteData( 0x32 ); - - lcdWriteCommand( 0xE1 ); - lcdWriteData( 0xD0 ); - lcdWriteData( 0x04 ); - lcdWriteData( 0x06 ); - lcdWriteData( 0x09 ); - lcdWriteData( 0x06 ); - lcdWriteData( 0x03 ); - lcdWriteData( 0x25 ); - lcdWriteData( 0x32 ); - lcdWriteData( 0x3E ); - lcdWriteData( 0x18 ); - lcdWriteData( 0x15 ); - lcdWriteData( 0x15 ); - lcdWriteData( 0x2B ); - lcdWriteData( 0x30 ); - - lcdWriteCommand( 0xF0 ); - lcdWriteData( 0x3C ); - - lcdWriteCommand( 0xF0 ); - lcdWriteData( 0x69 ); + lcdWriteData(0x20); + lcdWriteData(0x02); + lcdWriteData(0x3B); + // SET RGB END + + lcdWriteCommand(0xB7); + lcdWriteData(0xC6); + + lcdWriteCommand(0xB9); + lcdWriteData(0x02); + lcdWriteData(0xE0); + + lcdWriteCommand(0xC0); + lcdWriteData(0x80); + lcdWriteData(0x65); + + lcdWriteCommand(0xC1); + lcdWriteData(0x0D); + + lcdWriteCommand(0xC2); + lcdWriteData(0xA7); + + lcdWriteCommand(0xC5); + lcdWriteData(0x14); + + lcdWriteCommand(0xE8); + lcdWriteData(0x40); + lcdWriteData(0x8A); + lcdWriteData(0x00); + lcdWriteData(0x00); + lcdWriteData(0x29); + lcdWriteData(0x19); + lcdWriteData(0xA5); + lcdWriteData(0x33); + + lcdWriteCommand(0xE0); + lcdWriteData(0xD0); + lcdWriteData(0x00); + lcdWriteData(0x04); + lcdWriteData(0x05); + lcdWriteData(0x04); + lcdWriteData(0x21); + lcdWriteData(0x25); + lcdWriteData(0x43); + lcdWriteData(0x3F); + lcdWriteData(0x37); + lcdWriteData(0x13); + lcdWriteData(0x13); + lcdWriteData(0x29); + lcdWriteData(0x32); + + lcdWriteCommand(0xE1); + lcdWriteData(0xD0); + lcdWriteData(0x04); + lcdWriteData(0x06); + lcdWriteData(0x09); + lcdWriteData(0x06); + lcdWriteData(0x03); + lcdWriteData(0x25); + lcdWriteData(0x32); + lcdWriteData(0x3E); + lcdWriteData(0x18); + lcdWriteData(0x15); + lcdWriteData(0x15); + lcdWriteData(0x2B); + lcdWriteData(0x30); + + lcdWriteCommand(0xF0); + lcdWriteData(0x3C); + + lcdWriteCommand(0xF0); + lcdWriteData(0x69); delay_ms(120); #if defined(RADIO_T15) - if (hardwareOptions.pcbrev == PCBREV_T15_IPS) - lcdWriteCommand( 0x21 ); + if (hardwareOptions.pcbrev == PCBREV_T15_IPS) lcdWriteCommand(0x21); #endif LCD_ST7796S_On(); } -void LCD_ST7796S_Off(void) { - lcdWriteCommand(0x28); -} +void LCD_ST7796S_Off(void) { lcdWriteCommand(0x28); } -void LCD_Init_LTDC() { +void LCD_Init_LTDC() +{ hltdc.Instance = LTDC; /* Configure PLLSAI prescalers for LCD */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * lcdPixelclock * 16 = XX Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLL_LTDC = PLLSAI_VCO/4 = YY Mhz */ - /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = YY/4 = lcdPixelClock Mhz */ - uint32_t clock = (lcdPixelClock*16) / 1000000; // clock*16 in MHz + /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = YY/4 = lcdPixelClock + * Mhz */ + uint32_t clock = (lcdPixelClock * 16) / 1000000; // clock*16 in MHz RCC_PeriphCLKInitTypeDef clkConfig; clkConfig.PeriphClockSelection = RCC_PERIPHCLK_LTDC; clkConfig.PLLSAI.PLLSAIN = clock; @@ -332,7 +337,8 @@ void LCD_Init_LTDC() { clkConfig.PLLSAIDivR = RCC_PLLSAIDIVR_4; HAL_RCCEx_PeriphCLKConfig(&clkConfig); - /* LTDC Configuration *********************************************************/ + /* LTDC Configuration + * *********************************************************/ /* Polarity configuration */ /* Initialize the horizontal synchronization polarity as active low */ hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL; @@ -370,13 +376,14 @@ void LCD_Init_LTDC() { // Configure IRQ (line) NVIC_SetPriority(LTDC_IRQn, LTDC_IRQ_PRIO); NVIC_EnableIRQ(LTDC_IRQn); - + // Trigger on last line HAL_LTDC_ProgramLineEvent(&hltdc, LCD_W); __HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI); } -void LCD_LayerInit() { +void LCD_LayerInit() +{ auto& layer = hltdc.LayerCfg[0]; /* Windowing configuration */ @@ -387,7 +394,7 @@ void LCD_LayerInit() { /* Pixel Format configuration*/ layer.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; - + /* Alpha constant (255 totally opaque) */ layer.Alpha = 255; @@ -404,7 +411,8 @@ void LCD_LayerInit() { layer.ImageWidth = LCD_H; layer.ImageHeight = LCD_W; - /* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */ + /* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ + * Offset */ layer.FBStartAdress = (intptr_t)initialFrameBuffer; /* Initialize LTDC layer 1 */ @@ -414,14 +422,12 @@ void LCD_LayerInit() { HAL_LTDC_EnableDither(&hltdc); } -extern "C" -void lcdSetInitalFrameBuffer(void* fbAddress) +extern "C" void lcdSetInitalFrameBuffer(void* fbAddress) { initialFrameBuffer = fbAddress; } -extern "C" -void lcdInit(void) +extern "C" void lcdInit(void) { /* Configure the LCD SPI+RESET pins */ lcdSpiConfig(); diff --git a/radio/src/targets/horus/lcd_st7796s_driver.h b/radio/src/targets/horus/lcd_st7796s_driver.h index 07afb5b38b8..678b0ca6d0e 100644 --- a/radio/src/targets/horus/lcd_st7796s_driver.h +++ b/radio/src/targets/horus/lcd_st7796s_driver.h @@ -21,44 +21,43 @@ #pragma once -#define HBP ( 24 ) -#define VBP ( 10 ) +#define HBP (24) +#define VBP (10) -#define HSW ( 4 ) -#define VSH ( 2 ) +#define HSW (4) +#define VSH (2) -#define HFP ( 140 - HBP ) -#define VFP ( 22 - VBP ) +#define HFP (140 - HBP) +#define VFP (22 - VBP) +#define SET_IO_INPUT(PORT, PIN) \ + LL_GPIO_SetPinMode(PORT, PIN, LL_GPIO_MODE_INPUT) +#define SET_IO_OUTPUT(PORT, PIN) \ + LL_GPIO_SetPinMode(PORT, PIN, LL_GPIO_MODE_OUTPUT) -#define SET_IO_INPUT( PORT, PIN ) LL_GPIO_SetPinMode( PORT, PIN, LL_GPIO_MODE_INPUT ) -#define SET_IO_OUTPUT( PORT, PIN ) LL_GPIO_SetPinMode( PORT, PIN, LL_GPIO_MODE_OUTPUT ) +#define LCD_NRST_HIGH() LL_GPIO_SetOutputPin(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN) +#define LCD_NRST_LOW() LL_GPIO_ResetOutputPin(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN) -#define LCD_NRST_HIGH() LL_GPIO_SetOutputPin(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN) -#define LCD_NRST_LOW() LL_GPIO_ResetOutputPin(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN) +#define LCD_CS_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_CS_GPIO_PIN) +#define LCD_CS_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_CS_GPIO_PIN) -#define LCD_CS_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_CS_GPIO_PIN) -#define LCD_CS_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_CS_GPIO_PIN) - -#define LCD_SCK_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN) -#define LCD_SCK_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN) - -#define LCD_MOSI_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN) -#define LCD_MOSI_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN) - -#define LCD_MOSI_AS_INPUT() SET_IO_INPUT( LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN ) -#define LCD_MOSI_AS_OUTPUT() SET_IO_OUTPUT( LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN ) - -#define LCD_READ_DATA_PIN() LL_GPIO_IsInputPinSet(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN) - - -#define HORIZONTAL_SYNC_WIDTH ( 4 ) -#define HORIZONTAL_BACK_PORCH ( 24 ) -#define HORIZONTAL_FRONT_PORCH ( 140 - HORIZONTAL_BACK_PORCH ) -#define VERTICAL_SYNC_HEIGHT ( 2 ) -#define VERTICAL_BACK_PORCH ( 10 ) -#define VERTICAL_FRONT_PORCH ( 22 - VERTICAL_BACK_PORCH ) +#define LCD_SCK_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN) +#define LCD_SCK_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN) +#define LCD_MOSI_HIGH() \ + LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN) +#define LCD_MOSI_LOW() \ + LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN) +#define LCD_MOSI_AS_INPUT() SET_IO_INPUT(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN) +#define LCD_MOSI_AS_OUTPUT() SET_IO_OUTPUT(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN) +#define LCD_READ_DATA_PIN() \ + LL_GPIO_IsInputPinSet(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN) +#define HORIZONTAL_SYNC_WIDTH (4) +#define HORIZONTAL_BACK_PORCH (24) +#define HORIZONTAL_FRONT_PORCH (140 - HORIZONTAL_BACK_PORCH) +#define VERTICAL_SYNC_HEIGHT (2) +#define VERTICAL_BACK_PORCH (10) +#define VERTICAL_FRONT_PORCH (22 - VERTICAL_BACK_PORCH)