From 8476537ace0f496720e17b8a5cd16cc1205a121f Mon Sep 17 00:00:00 2001 From: godmial Date: Tue, 24 Dec 2024 15:24:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=AB=8B=E5=88=9B=E5=AE=98?= =?UTF-8?q?=E6=96=B9RGB=E5=B1=8F=E5=B9=95=E6=89=A9=E5=B1=95=E6=9D=BF?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/gd32/arm/.clang-format | 242 ++++ bsp/gd32/arm/gd32470z-lckfb/board/Kconfig | 31 + .../GD/GD32F4xx/Source/system_gd32f4xx.c | 4 +- .../GD32F4xx_Firmware_Library/SConscript | 6 + .../arm/libraries/gd32_drivers/SConscript | 8 + bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.c | 1135 +++++++++++++++++ bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.h | 101 ++ .../arm/libraries/gd32_drivers/drv_touch.c | 399 ++++++ .../arm/libraries/gd32_drivers/drv_touch.h | 96 ++ bsp/gd32/arm/libraries/gd32_drivers/font.h | 191 +++ .../libc/compilers/common/include/dirent.h | 2 +- 11 files changed, 2212 insertions(+), 3 deletions(-) create mode 100644 bsp/gd32/arm/.clang-format create mode 100644 bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.c create mode 100644 bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.h create mode 100644 bsp/gd32/arm/libraries/gd32_drivers/drv_touch.c create mode 100644 bsp/gd32/arm/libraries/gd32_drivers/drv_touch.h create mode 100644 bsp/gd32/arm/libraries/gd32_drivers/font.h diff --git a/bsp/gd32/arm/.clang-format b/bsp/gd32/arm/.clang-format new file mode 100644 index 0000000000..aa43aae1f3 --- /dev/null +++ b/bsp/gd32/arm/.clang-format @@ -0,0 +1,242 @@ +# Available style options are described in https://clang.llvm.org/docs/ClangFormatStyleOptions.html +# +# An easy way to create the .clang-format file is: +# +# clang-format -style=llvm -dump-config > .clang-format +# +--- +Language: Cpp +BasedOnStyle: LLVM +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: Right +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: true + PadOperators: true +AlignConsecutiveBitFields: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: true + PadOperators: true +AlignConsecutiveDeclarations: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 1 +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterExternBlock: false + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: false + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAfterAttributes: Never +BreakAfterJavaFieldAnnotations: false +BreakArrays: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Custom +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +BreakInheritanceList: AfterColon +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: "^ IWYU pragma:" +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: ".*" + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: "(Test)?$" +IncludeIsMainSourceRegex: "" +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: NoIndent +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: true +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: true +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: "" +MacroBlockEnd: "" +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 1000 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 1000 +PointerAlignment: Right +PPIndentWidth: 4 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: false +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: Never +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Both +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +--- + diff --git a/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig b/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig index ef50f68b40..cd5f59c7cd 100644 --- a/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig +++ b/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig @@ -385,6 +385,37 @@ endmenu menu "Board extended module Drivers" + menuconfig BSP_USING_LCD + bool "Enable LCD" + select RT_USING_LCD + default n + if BSP_USING_LCD + + config BSP_USING_TLI + bool "Enable TLI" + default y + + config BSP_USING_SDRAM + bool "Enable SDRAM" + select RT_USING_SDRAM + default y + + config BSP_USING_TOUCH + bool "Enable TOUCH" + select RT_USING_TOUCH + default n + + config BSP_USING_GPU + bool "Enable GPU" + select RT_USING_GPU + default y + + config BSP_USING_LCD_EXAMPLE + bool "Enable LCD EXAMPLE" + select RT_USING_LCD_EXAMPLE + default n + endif + endmenu endmenu diff --git a/bsp/gd32/arm/libraries/GD32F4xx_Firmware_Library/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c b/bsp/gd32/arm/libraries/GD32F4xx_Firmware_Library/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c index 51fd50c2f2..7164c044f9 100644 --- a/bsp/gd32/arm/libraries/GD32F4xx_Firmware_Library/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c +++ b/bsp/gd32/arm/libraries/GD32F4xx_Firmware_Library/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c @@ -51,10 +51,10 @@ //#define __SYSTEM_CLOCK_168M_PLL_25M_HXTAL (uint32_t)(168000000) //#define __SYSTEM_CLOCK_200M_PLL_IRC16M (uint32_t)(200000000) //#define __SYSTEM_CLOCK_200M_PLL_8M_HXTAL (uint32_t)(200000000) -#define __SYSTEM_CLOCK_200M_PLL_25M_HXTAL (uint32_t)(200000000) +// #define __SYSTEM_CLOCK_200M_PLL_25M_HXTAL (uint32_t)(200000000) //#define __SYSTEM_CLOCK_240M_PLL_IRC16M (uint32_t)(240000000) //#define __SYSTEM_CLOCK_240M_PLL_8M_HXTAL (uint32_t)(240000000) -//#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000) +#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000) #ifdef LCKFB_SKYSTART_GD32F407V #undef __SYSTEM_CLOCK_200M_PLL_25M_HXTAL diff --git a/bsp/gd32/arm/libraries/GD32F4xx_Firmware_Library/SConscript b/bsp/gd32/arm/libraries/GD32F4xx_Firmware_Library/SConscript index 8639928ed4..af8a3475a4 100644 --- a/bsp/gd32/arm/libraries/GD32F4xx_Firmware_Library/SConscript +++ b/bsp/gd32/arm/libraries/GD32F4xx_Firmware_Library/SConscript @@ -52,6 +52,12 @@ if GetDepend(['RT_USING_SDIO']): if GetDepend(['BSP_USING_SDRAM']): src += ['GD32F4xx_standard_peripheral/Source/gd32f4xx_fmc.c'] src += ['GD32F4xx_standard_peripheral/Source/gd32f4xx_exmc.c'] + +if GetDepend(['BSP_USING_TLI']): + src += ['GD32F4xx_standard_peripheral/Source/gd32f4xx_tli.c'] + +if GetDepend(['BSP_USING_GPU']): + src += ['GD32F4xx_standard_peripheral/Source/gd32f4xx_ipa.c'] path = [ cwd + '/CMSIS/GD/GD32F4xx/Include', diff --git a/bsp/gd32/arm/libraries/gd32_drivers/SConscript b/bsp/gd32/arm/libraries/gd32_drivers/SConscript index 608897aaec..73eb40ae3f 100644 --- a/bsp/gd32/arm/libraries/gd32_drivers/SConscript +++ b/bsp/gd32/arm/libraries/gd32_drivers/SConscript @@ -59,6 +59,14 @@ if GetDepend('RT_USING_PWM'): # add sdram drivers. if GetDepend('BSP_USING_SDRAM'): src += ['drv_sdram.c'] + +# add lcd drivers. +if GetDepend('BSP_USING_LCD'): + src += ['drv_lcd.c'] + +# add touch drivers. +if GetDepend('BSP_USING_TOUCH'): + src += ['drv_touch.c'] path = [cwd] diff --git a/bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.c b/bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.c new file mode 100644 index 0000000000..0b8941e602 --- /dev/null +++ b/bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.c @@ -0,0 +1,1135 @@ +#include +#include "gd32f4xx.h" +#include "drv_lcd.h" +#include "gd32f4xx_tli.h" +#include "drv_touch.h" +#include "font.h" + +/******************************************************************************* + * Definitions + ******************************************************************************/ + + +#if defined(__CC_ARM) || defined(__ARMCC_VERSION) +//Keil MDK 编译器 +uint16_t ltdc_lcd_framebuf0[800][480] __attribute__((at(LCD_FRAME_BUF_ADDR))); +#elif defined(__GNUC__) +// GCC 编译器 (如 RT-Thread 使用的 GCC) +uint16_t ltdc_lcd_framebuf0[10][10]; +#endif + +static void tli_gpio_config(void); +static void tli_config(void); +static void ipa_config(void); +static void lcd_disp_en_config(void); +static void lcd_disp_off(void); +static void lcd_disp_on(void); + +void lcd_disp_config(void) +{ + lcd_disp_en_config(); + lcd_disp_off(); + + /* configure the GPIO of TLI */ + tli_gpio_config(); + lcd_disp_on(); + + tli_config(); + tli_layer_enable(LAYER0); + tli_reload_config(TLI_FRAME_BLANK_RELOAD_EN); + tli_enable(); + ipa_config(); +} + +static void tli_config(void) +{ + tli_parameter_struct tli_init_struct; + tli_layer_parameter_struct tli_layer_init_struct; + + rcu_periph_clock_enable(RCU_TLI); + tli_gpio_config(); + /* configure PLLSAI to generate TLI clock */ + // if(ERROR == rcu_pllsai_config(216, 2, 3)){ + if (ERROR == rcu_pllsai_config(192, 2, 3)) + { + while (1); + } + rcu_tli_clock_div_config(RCU_PLLSAIR_DIV2); + + rcu_osci_on(RCU_PLLSAI_CK); + + if (ERROR == rcu_osci_stab_wait(RCU_PLLSAI_CK)) + { + while (1); + } + + /* configure TLI parameter struct */ + tli_init_struct.signalpolarity_hs = TLI_HSYN_ACTLIVE_LOW; + tli_init_struct.signalpolarity_vs = TLI_VSYN_ACTLIVE_LOW; + tli_init_struct.signalpolarity_de = TLI_DE_ACTLIVE_LOW; + tli_init_struct.signalpolarity_pixelck = TLI_PIXEL_CLOCK_TLI; + /* LCD display timing configuration */ + tli_init_struct.synpsz_hpsz = HORIZONTAL_SYNCHRONOUS_PULSE - 1; + tli_init_struct.synpsz_vpsz = VERTICAL_SYNCHRONOUS_PULSE - 1; + tli_init_struct.backpsz_hbpsz = HORIZONTAL_SYNCHRONOUS_PULSE + HORIZONTAL_BACK_PORCH - 1; + tli_init_struct.backpsz_vbpsz = VERTICAL_SYNCHRONOUS_PULSE + VERTICAL_BACK_PORCH - 1; + tli_init_struct.activesz_hasz = HORIZONTAL_SYNCHRONOUS_PULSE + HORIZONTAL_BACK_PORCH + ACTIVE_WIDTH - 1; + tli_init_struct.activesz_vasz = VERTICAL_SYNCHRONOUS_PULSE + VERTICAL_BACK_PORCH + ACTIVE_HEIGHT - 1; + tli_init_struct.totalsz_htsz = HORIZONTAL_SYNCHRONOUS_PULSE + HORIZONTAL_BACK_PORCH + ACTIVE_WIDTH + HORIZONTAL_FRONT_PORCH - 1; + tli_init_struct.totalsz_vtsz = VERTICAL_SYNCHRONOUS_PULSE + VERTICAL_BACK_PORCH + ACTIVE_HEIGHT + VERTICAL_FRONT_PORCH - 1; + /* configure LCD background R,G,B values */ + tli_init_struct.backcolor_red = 0xFF; + tli_init_struct.backcolor_green = 0xFF; + tli_init_struct.backcolor_blue = 0xFF; + tli_init(&tli_init_struct); + +#if 1 + /* TLI layer0 configuration */ + /* TLI window size configuration */ + tli_layer_init_struct.layer_window_leftpos = HORIZONTAL_SYNCHRONOUS_PULSE + HORIZONTAL_BACK_PORCH; + tli_layer_init_struct.layer_window_rightpos = (ACTIVE_WIDTH + HORIZONTAL_SYNCHRONOUS_PULSE + HORIZONTAL_BACK_PORCH - 1); + tli_layer_init_struct.layer_window_toppos = VERTICAL_SYNCHRONOUS_PULSE + VERTICAL_BACK_PORCH; + tli_layer_init_struct.layer_window_bottompos = (ACTIVE_HEIGHT + VERTICAL_SYNCHRONOUS_PULSE + VERTICAL_BACK_PORCH - 1); + /* TLI window pixel format configuration */ + tli_layer_init_struct.layer_ppf = LAYER_PPF_RGB565; + /* TLI window specified alpha configuration */ + tli_layer_init_struct.layer_sa = 255; + /* TLI layer default alpha R,G,B value configuration */ + tli_layer_init_struct.layer_default_blue = 0x00; + tli_layer_init_struct.layer_default_green = 0x00; + tli_layer_init_struct.layer_default_red = 0x00; + tli_layer_init_struct.layer_default_alpha = 0x00; + /* TLI window blend configuration */ + tli_layer_init_struct.layer_acf1 = LAYER_ACF1_SA; + tli_layer_init_struct.layer_acf2 = LAYER_ACF2_SA; + /* TLI layer frame buffer base address configuration */ + tli_layer_init_struct.layer_frame_bufaddr = (uint32_t)ltdc_lcd_framebuf0; + tli_layer_init_struct.layer_frame_line_length = ((ACTIVE_WIDTH * 2) + 3); + tli_layer_init_struct.layer_frame_buf_stride_offset = (ACTIVE_WIDTH * 2); + tli_layer_init_struct.layer_frame_total_line_number = ACTIVE_HEIGHT; + tli_layer_init(LAYER0, &tli_layer_init_struct); + tli_dither_config(TLI_DITHER_ENABLE); +#endif +} + +/*! + \brief IPA initialize and configuration + \param[in] none + \param[out] none + \retval none +*/ +static void ipa_config(void) +{ + rcu_periph_clock_enable(RCU_IPA); + nvic_irq_enable(IPA_IRQn, 0, 2); +} + +static void tli_gpio_config(void) +{ + /* enable the periphral clock */ + rcu_periph_clock_enable(RCU_GPIOA); + rcu_periph_clock_enable(RCU_GPIOB); + rcu_periph_clock_enable(RCU_GPIOC); + rcu_periph_clock_enable(RCU_GPIOD); + rcu_periph_clock_enable(RCU_GPIOF); + rcu_periph_clock_enable(RCU_GPIOG); + + /* configure HSYNC(PC6), VSYNC(PA4), PCLK(PG7), DE(PF10) */ + /* configure LCD_R7(PG6), LCD_R6(PA8), LCD_R5(PA12), LCD_R4(PA11), LCD_R3(PB0), + LCD_G7(PD3), LCD_G6(PC7), LCD_G5(PB11), LCD_G4(PB10), LCD_G3(PG10), LCD_G2(PA6), + LCD_B7(PB9), LCD_B6(PB8), LCD_B5(PA3), LCD_B4(PG12), LCD_B3(PG11) */ + gpio_af_set(GPIOA, GPIO_AF_14, GPIO_PIN_3); + gpio_af_set(GPIOA, GPIO_AF_14, GPIO_PIN_4); + gpio_af_set(GPIOA, GPIO_AF_14, GPIO_PIN_6); + gpio_af_set(GPIOA, GPIO_AF_14, GPIO_PIN_8); + gpio_af_set(GPIOA, GPIO_AF_14, GPIO_PIN_11); + gpio_af_set(GPIOA, GPIO_AF_14, GPIO_PIN_12); + + gpio_af_set(GPIOB, GPIO_AF_9, GPIO_PIN_0); + gpio_af_set(GPIOB, GPIO_AF_14, GPIO_PIN_8); + gpio_af_set(GPIOB, GPIO_AF_14, GPIO_PIN_9); + gpio_af_set(GPIOB, GPIO_AF_14, GPIO_PIN_10); + gpio_af_set(GPIOB, GPIO_AF_14, GPIO_PIN_11); + + gpio_af_set(GPIOC, GPIO_AF_14, GPIO_PIN_6); + gpio_af_set(GPIOC, GPIO_AF_14, GPIO_PIN_7); + + gpio_af_set(GPIOD, GPIO_AF_14, GPIO_PIN_3); + + gpio_af_set(GPIOF, GPIO_AF_14, GPIO_PIN_10); + + gpio_af_set(GPIOG, GPIO_AF_14, GPIO_PIN_6); + gpio_af_set(GPIOG, GPIO_AF_14, GPIO_PIN_7); + gpio_af_set(GPIOG, GPIO_AF_9, GPIO_PIN_10); + gpio_af_set(GPIOG, GPIO_AF_14, GPIO_PIN_11); + gpio_af_set(GPIOG, GPIO_AF_9, GPIO_PIN_12); + + gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_8 | GPIO_PIN_11 | GPIO_PIN_12); + gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_8 | GPIO_PIN_11 | GPIO_PIN_12); + + gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_0 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11); + gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11); + + gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6 | GPIO_PIN_7); + gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6 | GPIO_PIN_7); + + gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_3); + gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3); + + gpio_mode_set(GPIOF, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_10); + gpio_output_options_set(GPIOF, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10); + + gpio_mode_set(GPIOG, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12); + gpio_output_options_set(GPIOG, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12); +} + +/*! + \brief configure DISP ON/OFF GPIO + \param[in] none + \param[out] none + \retval none +*/ +static void lcd_disp_en_config(void) +{ + /* enable the periphral clock */ + rcu_periph_clock_enable(RCU_GPIOD); + gpio_mode_set(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_13); + gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13); +} + +/*! + \brief DISP GPIO OFF + \param[in] none + \param[out] none + \retval none +*/ +static void lcd_disp_off(void) +{ + gpio_bit_reset(GPIOD, GPIO_PIN_13); +} + +/*! + \brief DISP GPIO ON + \param[in] none + \param[out] none + \retval none +*/ +static void lcd_disp_on(void) +{ + gpio_bit_set(GPIOD, GPIO_PIN_13); +} + + +/********************************************************** + * 函 数 名 称:tli_draw_point + * 函 数 功 能:画点 + * 传 入 参 数:(x,y):起点坐标 + * color:点的颜色 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_draw_point(uint16_t x, uint16_t y, uint16_t color) +{ + *(ltdc_lcd_framebuf0[0] + (LCD_WIDTH * y + x)) = color; +} + +/********************************************************** + * 函 数 名 称:tli_draw_line + * 函 数 功 能:画线 + * 传 入 参 数:(sx,sy):起点坐标 + * (ex,ey):终点坐标 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_draw_line(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color) +{ + uint16_t t; + int xerr = 0, yerr = 0, delta_x, delta_y, distance; + int incx, incy, uRow, uCol; + + delta_x = ex - sx; //计算坐标增量 + delta_y = ey - sy; + uRow = sx; + uCol = sy; + if (delta_x > 0) + incx = 1; //设置单步方向 + else if (delta_x == 0) + incx = 0; //垂直线 + else + { + incx = -1; + delta_x = -delta_x; + } + if (delta_y > 0) + incy = 1; + else if (delta_y == 0) + incy = 0; //水平线 + else + { + incy = -1; + delta_y = -delta_y; + } + if (delta_x > delta_y) + distance = delta_x; //选取基本增量坐标轴 + else + distance = delta_y; + for (t = 0; t <= distance + 1; t++) //画线输出 + { + tli_draw_point(uRow, uCol, color); //画点 + xerr += delta_x; + yerr += delta_y; + if (xerr > distance) + { + xerr -= distance; + uRow += incx; + } + if (yerr > distance) + { + yerr -= distance; + uCol += incy; + } + } +} +/********************************************************** + * 函 数 名 称:tli_draw_Rectangle + * 函 数 功 能:画矩形填充 + * 传 入 参 数:(sx,sy) :起点坐标 + * (sx,sy) :终点坐标 + * color:笔画颜色 +* fill:填充标志 =1填充颜色 =0不填充 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_draw_Rectangle(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color, uint16_t fill) +{ + int i = 0, j = 0; + if (fill) + { + for (i = sx; i < ex; i++) + { + for (j = sy; j < ey; j++) + { + tli_draw_point(i, j, color); + } + } + } + else + { + tli_draw_line(sx, sy, ex, sy, color); + tli_draw_line(sx, sy, sx, ey, color); + tli_draw_line(sx, ey, ex, ey, color); + tli_draw_line(ex, sy, ex, ey, color); + } +} + +/********************************************************** + * 函 数 名 称:_draw_circle_8 + * 函 数 功 能:8对称性画圆算法(内部调用) + * 传 入 参 数: (xc,yc):圆中心坐标 + (x,y):光标相对于圆心的坐标 + * c:点的颜色 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:内部调用 +**********************************************************/ +static void _draw_circle_8(int xc, int yc, int x, int y, uint16_t c) +{ + tli_draw_point(xc + x, yc + y, c); + + tli_draw_point(xc - x, yc + y, c); + + tli_draw_point(xc + x, yc - y, c); + + tli_draw_point(xc - x, yc - y, c); + + tli_draw_point(xc + y, yc + x, c); + + tli_draw_point(xc - y, yc + x, c); + + tli_draw_point(xc + y, yc - x, c); + + tli_draw_point(xc - y, yc - x, c); +} + +/********************************************************** + * 函 数 名 称:tli_draw_circle + * 函 数 功 能:在指定位置画一个指定大小的圆 + * 传 入 参 数: (xc,yc) :圆中心坐标 + * c:填充的颜色 + * r:圆半径 + * fill:填充判断标志,1-填充,0-不填充 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_draw_circle(int xc, int yc, uint16_t c, int r, int fill) +{ + int x = 0, y = r, yi, d; + + d = 3 - 2 * r; + + if (fill) + { + // 如果填充(画实心圆) + while (x <= y) + { + for (yi = x; yi <= y; yi++) + _draw_circle_8(xc, yc, x, yi, c); + + if (d < 0) + { + d = d + 4 * x + 6; + } + else + { + d = d + 4 * (x - y) + 10; + y--; + } + x++; + } + } + else + { + // 如果不填充(画空心圆) + while (x <= y) + { + _draw_circle_8(xc, yc, x, y, c); + if (d < 0) + { + d = d + 4 * x + 6; + } + else + { + d = d + 4 * (x - y) + 10; + y--; + } + x++; + } + } +} + +/********************************************************** + * 函 数 名 称:_swap + * 函 数 功 能:数据交换 + * 传 入 参 数:a=交换方1 b=交换方2 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:仅内部使用 +**********************************************************/ +static void _swap(uint16_t *a, uint16_t *b) +{ + uint16_t tmp; + tmp = *a; + *a = *b; + *b = tmp; +} + +/********************************************************** + * 函 数 名 称:tli_draw_triange + * 函 数 功 能:画三角形 + * 传 入 参 数:(x0,y0):第一个边角的坐标 + * (x1,y1):顶点的坐标 + * (x2,y2):第二个边角的坐标 + * color:三角形颜色 + * fill:填充判断标志,1-填充,0-不填充 + * 函 数 返 回: + * 作 者:LCKFB + * 备 注: +**********************************************************/ + +void tli_draw_triange(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color, uint16_t fill) +{ + uint16_t a, b, y, last; + int dx01, dy01, dx02, dy02, dx12, dy12; + long sa = 0; + long sb = 0; + + if (fill == 0) + { + tli_draw_line(x0, y0, x1, y1, color); + tli_draw_line(x1, y1, x2, y2, color); + tli_draw_line(x2, y2, x0, y0, color); + } + else + { + if (y0 > y1) + { + _swap(&y0, &y1); + _swap(&x0, &x1); + } + if (y1 > y2) + { + _swap(&y2, &y1); + _swap(&x2, &x1); + } + if (y0 > y1) + { + _swap(&y0, &y1); + _swap(&x0, &x1); + } + if (y0 == y2) + { + a = b = x0; + if (x1 < a) + { + a = x1; + } + else if (x1 > b) + { + b = x1; + } + if (x2 < a) + { + a = x2; + } + else if (x2 > b) + { + b = x2; + } + tli_draw_Rectangle(a, y0, b, y0, color, 0); + return; + } + dx01 = x1 - x0; + dy01 = y1 - y0; + dx02 = x2 - x0; + dy02 = y2 - y0; + dx12 = x2 - x1; + dy12 = y2 - y1; + + if (y1 == y2) + { + last = y1; + } + else + { + last = y1 - 1; + } + for (y = y0; y <= last; y++) + { + a = x0 + sa / dy01; + b = x0 + sb / dy02; + sa += dx01; + sb += dx02; + if (a > b) + { + _swap(&a, &b); + } + tli_draw_Rectangle(a, y, b, y, color, 0); + } + sa = dx12 * (y - y1); + sb = dx02 * (y - y0); + for (; y <= y2; y++) + { + a = x1 + sa / dy12; + b = x0 + sb / dy02; + sa += dx12; + sb += dx02; + if (a > b) + { + _swap(&a, &b); + } + + tli_draw_Rectangle(a, y, b, y, color, 0); + } + } +} + + +/********************************************************** + * 函 数 名 称:point_enlargement + * 函 数 功 能:将一个点放大 + * 传 入 参 数:(x,y):点的起始坐标 + * color:点的颜色 + * magnify:点的放大倍数 最小为1 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void point_enlargement(uint16_t x, uint16_t y, uint16_t color, char magnify) +{ + tli_draw_Rectangle(x - magnify, y - magnify, x, y, color, 1); + + tli_draw_Rectangle(x, y - magnify, x + magnify, y, color, 1); + + tli_draw_Rectangle(x - magnify, y, x, y + magnify, color, 1); + + tli_draw_Rectangle(x, y, x + magnify, y + magnify, color, 1); +} + +/********************************************************** + * 函 数 名 称:LCD_ShowChar + * 函 数 功 能:显示一个字符 + * 传 入 参 数:(x,y):字符显示的起点坐标 + fc:笔画颜色 + bc:背景颜色 + num:显示的字符 + size:字符放大倍数 最小为1 + mode:是否叠加显示 0=非叠加方式 1=叠加方式 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:以16x8大小的字符作为放大模板 +**********************************************************/ +void tli_show_char(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t num, uint8_t size, uint8_t mode) +{ + uint8_t temp; + uint8_t pos, t; + uint16_t x0 = 0; + uint16_t y0 = 0; + num = num - ' '; //得到偏移后的值 + + for (pos = 0; pos < 16; pos++) + { + temp = asc2_1608[num][pos]; //调用1608字体 + for (t = 0; t < 16 / 2; t++) + { + if (!mode) + { + if (temp & 0x01) + point_enlargement(x + x0, y + y0, fc, size); //画一个点 + else + point_enlargement(x + x0, y + y0, bc, size); //画一个点 + } + else + { + if (temp & 0x01) point_enlargement(x + x0, y + y0, fc, size); //画一个点 + } + temp >>= 1; + x0 = x0 + size; + } + x0 = 0; + y0 = y0 + size; + } +} + +/********************************************************** + * 函 数 名 称:tli_Show_String + * 函 数 功 能:显示字符串 + * 传 入 参 数:(x,y):起始坐标 + * fc:笔画颜色 + * bc:背景颜色 + * size:字符放大倍数(以16作为基数放大 16*size 16*size 16*size) + * p:显示的字符串 + * mode:是否叠加显示 0=非叠加方式 1=叠加方式 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_show_string(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t size, uint8_t *p, uint8_t mode) +{ + while ((*p <= '~') && (*p >= ' ')) //判断是不是非法字符 + { + if (x > (LCD_WIDTH - 1) || y > (LCD_HEIGHT - 1)) return; + + tli_show_char(x, y, fc, bc, *p, size, mode); + x += 16 * size / 2; + p++; + } +} + + +/********************************************************** + * 函 数 名 称:tli_show_font16 + * 函 数 功 能:显示单个16*16大小的字体 + * 传 入 参 数:(x,y):字体显示的起始坐标 + * fc:字体笔画颜色 + * bc:字体背景颜色 + * s:字体索引 + * mode:是否叠加显示 0=非叠加方式 1=叠加方式 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_show_font16(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s, uint8_t mode) +{ + uint8_t i, j; + uint16_t k; + uint16_t HZnum; + uint16_t x0 = x; + HZnum = sizeof(tfont16) / sizeof(typFNT_GB16); //自动统计汉字数目 + + for (k = 0; k < HZnum; k++) + { + if ((tfont16[k].Index[0] == *(s)) && (tfont16[k].Index[1] == *(s + 1))) + { + for (i = 0; i < 16 * 2; i++) + { + for (j = 0; j < 8; j++) + { + if (!mode) + { + if (tfont16[k].Msk[i] & (0x80 >> j)) + tli_draw_point(x, y, fc); //画一个点 + else + tli_draw_point(x, y, bc); //画一个点 + } + else + { + if (tfont16[k].Msk[i] & (0x80 >> j)) tli_draw_point(x, y, fc); //画一个点 + } + x++; + if ((x - x0) == 16) + { + x = x0; + y++; + break; + } + } + } + } + continue; //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响 + } +} + +/********************************************************** + * 函 数 名 称:tli_show_font24 + * 函 数 功 能:显示单个24*24大小的字体 + * 传 入 参 数:(x,y):字体显示的起始坐标 + * fc:字体笔画颜色 + * bc:字体背景颜色 + * s:字体索引 + * mode:是否叠加显示 0=非叠加方式 1=叠加方式 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_show_font24(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s, uint8_t mode) +{ + uint8_t i, j; + uint16_t k; + uint16_t HZnum; + uint16_t x0 = x; + HZnum = sizeof(tfont24) / sizeof(typFNT_GB24); //自动统计汉字数目 + + for (k = 0; k < HZnum; k++) + { + if ((tfont24[k].Index[0] == *(s)) && (tfont24[k].Index[1] == *(s + 1))) + { + for (i = 0; i < 24 * 3; i++) + { + for (j = 0; j < 8; j++) + { + if (!mode) + { + if (tfont24[k].Msk[i] & (0x80 >> j)) + tli_draw_point(x, y, fc); //画一个点 + else + tli_draw_point(x, y, bc); //画一个点 + } + else + { + if (tfont24[k].Msk[i] & (0x80 >> j)) tli_draw_point(x, y, fc); //画一个点 + } + x++; + if ((x - x0) == 24) + { + x = x0; + y++; + break; + } + } + } + } + continue; //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响 + } +} + + +/********************************************************** + * 函 数 名 称:tli_show_font32 + * 函 数 功 能:显示单个32*32大小的字体 + * 传 入 参 数:(x,y):字体显示的起始坐标 + * fc:字体笔画颜色 + * bc:字体背景颜色 + * s:字体索引 + * mode:是否叠加显示 0=非叠加方式 1=叠加方式 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_show_font32(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s, uint8_t mode) +{ + uint8_t i, j; + uint16_t k; + uint16_t HZnum; + uint16_t x0 = x; + HZnum = sizeof(tfont32) / sizeof(typFNT_GB32); //自动统计汉字数目 + for (k = 0; k < HZnum; k++) + { + if ((tfont32[k].Index[0] == *(s)) && (tfont32[k].Index[1] == *(s + 1))) + { + for (i = 0; i < 32 * 4; i++) + { + for (j = 0; j < 8; j++) + { + if (!mode) + { + if (tfont32[k].Msk[i] & (0x80 >> j)) + tli_draw_point(x, y, fc); //画一个点 + else + tli_draw_point(x, y, bc); //画一个点 + } + else + { + if (tfont32[k].Msk[i] & (0x80 >> j)) tli_draw_point(x, y, fc); //画一个点 + } + x++; + if ((x - x0) == 32) + { + x = x0; + y++; + break; + } + } + } + } + continue; //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响 + } +} + + +/********************************************************** + * 函 数 名 称:tli_show_Chinese_string + * 函 数 功 能:显示中文字符串 + * 传 入 参 数:(x,y):字符串显示的起始坐标 + * fc:字符串笔画颜色 + * bc:字符串背景颜色 + * str:字符串 + * size:字符串大小 16,24,32 + * mode:是否叠加显示 0=非叠加方式 1=叠加方式 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:显示的中文请确保有其字模,可去font.h查看 +**********************************************************/ +void tli_show_Chinese_string(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint8_t size, uint8_t mode) +{ + while (*str != 0) //数据未结束 + { + if (x > (LCD_WIDTH - size) || y > (LCD_HEIGHT - size)) return; + + if (size == 32) + tli_show_font32(x, y, fc, bc, str, mode); + else if (size == 24) + tli_show_font24(x, y, fc, bc, str, mode); + else + tli_show_font16(x, y, fc, bc, str, mode); + + str += 2; + x += size; //下一个汉字偏移 + } +} +/********************************************************** + * 函 数 名 称:tli_show_picture + * 函 数 功 能:显示图片 + * 传 入 参 数:(x,y):显示图片的起点坐标 + * w:图片宽度 + * h:图片高度 + * pic:图片地址 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void tli_show_picture(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const unsigned char pic[]) +{ + uint16_t i, j; + uint32_t k = 0; + uint16_t x0 = x, y0 = y; + for (i = y; i < h + y0; i++) + { + for (j = x; j < w + x0; j++) + { + tli_draw_point(j, i, pic[k * 2] << 8 | pic[k * 2 + 1]); + k++; + } + } +} + + +/********************************************************** + * 函 数 名 称:tli_show_button + * 函 数 功 能:绘制一个填充的圆角按钮 + * 传 入 参 数:(x,y):按钮的左上角的起始位置 + * width:按钮宽度 + * height:按钮高度 + * radius:按钮的4个圆角半径 + * color:按钮填充颜色 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:要求w >= 2*(r+1); h >= 2*(r+1); radius > h/2 +**********************************************************/ +void tli_show_button(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t radius, uint16_t color) +{ + int i = 0; + int j = 0; + + //如果小于则绘制出来的结果不好看 + if (radius >= (height / 2)) return; + + // 绘制四个圆角 + tli_draw_circle(x + radius, y + radius, color, radius, 1); + tli_draw_circle(x + width - radius - 1, y + radius, color, radius, 1); + tli_draw_circle(x + radius, y + height - radius - 1, color, radius, 1); + tli_draw_circle(x + width - radius - 1, y + height - radius - 1, color, radius, 1); + + // 绘制边框线 + tli_draw_line(x + radius, y, x + width - radius - 1, y, color); + tli_draw_line(x + radius, y + height - 1, x + width - radius - 1, y + height - 1, color); + tli_draw_line(x, y + radius, x, y + height - radius - 1, color); + tli_draw_line(x + width - 1, y + radius, x + width - 1, y + height - radius - 1, color); + + //绘制内部颜色填充 + tli_draw_Rectangle(x + radius, y + radius, x + width - radius, y + height - radius, color, 1); + tli_draw_Rectangle(x + radius, y, x + width - radius, y + radius, color, 1); + tli_draw_Rectangle(x, y + radius, x + width, y + height - radius, color, 1); + tli_draw_Rectangle(x + radius, y + height - radius, x + width - radius, y + height, color, 1); +} + +/********************************************************** + * 函 数 名 称:tli_show_switch + * 函 数 功 能:绘制一个开关 + * 传 入 参 数:(x,y):开关左上角的起始位置 + * width:开关的宽度 + * height:开关的高度 + * on_color:开关打开之后的颜色 + * off_color:开关关闭之后的颜色 + * sw:开关的状态 =1打开 =0关闭 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:要求w >= 2*(height/2+1); 不符合要求则无法绘制 +**********************************************************/ +void tli_show_switch(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t on_color, uint16_t off_color, char sw) +{ + int radius = height / 2 - 1; + + if (width < 2 * (radius + 1)) return; + + if (sw == 0) + { + tli_show_button(x, y, width, height, radius, off_color); + tli_draw_circle(x + radius, y + radius, WHITE, radius / 2, 1); + } + else + { + tli_show_button(x, y, width, height, radius, on_color); + tli_draw_circle(x + width - radius, y + radius, WHITE, radius / 2, 1); + } +} + + +#ifdef BSP_USING_LCD_EXAMPLE +//最大颜色数 目前只设置了14个颜色 +#define COLOR_MAX 14 + +//像素最大放大倍数 +#define PIXEL_SIZE_MAX 20 + +typedef struct button_struct +{ + uint16_t x; + uint16_t y; + uint16_t w; + uint16_t h; + uint16_t color; + uint16_t value; +} _widget_object_struct; + +uint16_t color_buf[COLOR_MAX] = {GRAYBLUE, BLACK, BLUE, BRED, GRED, GBLUE, RED, MAGENTA, GREEN, YELLOW, CYAN, BROWN, BRRED, GRAY}; +_widget_object_struct button_clear, button_color, button_pixel, button_eraser; + + +void widget_object_init(_widget_object_struct *obj, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t value); +void ui_init(void); + +int lcd_test(void) +{ + int touch_state = 0; + char color_num = 0; + char pixel_size = 0; + + // 屏幕初始化 + lcd_disp_config(); + // 触摸初始化 + FT5206_Init(); + //全屏清屏 + tli_draw_Rectangle(0, 0, 800, 480, WHITE, 1); + + + //初始化[清除]按钮的xywh + widget_object_init(&button_clear, 800 - 130, 480 - 80, 120, 70, BLUE, 0); + //初始化[颜色]按钮的xywh + widget_object_init(&button_color, 10, 480 - 80, 120, 70, BLUE, 0); + //初始化[像素]按钮的xywh + widget_object_init(&button_pixel, 400 - 60, 480 - 80, 120, 70, BLUE, pixel_size); + //初始化[橡皮擦]按钮的xywh + widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, 0); + + //UI显示 + ui_init(); + + while (1) + { + //触摸扫描 + touch_state = FT5206_Scan(0); + //如果屏幕被触摸 + if (touch_state == 1) + { + //[颜色]按钮被按下 + if (tp_dev.x[0] >= button_color.x && tp_dev.x[0] <= (button_color.x + button_color.w)) + { + if (tp_dev.y[0] >= button_color.y && tp_dev.y[0] <= (button_color.y + button_color.h)) + { + //判断是否松手 + letgo_scan(0, button_color.x, button_color.y, (button_color.x + button_color.w), (button_color.y + button_color.h)); + //改变颜色 + color_num = (color_num + 1) % COLOR_MAX; + //重新设置[颜色]按钮的背景色 + widget_object_init(&button_color, button_color.x, button_color.y, button_color.w, button_color.h, color_buf[color_num], 0); + //UI重新显示 + ui_init(); + } + } + //[清除]按钮被按下 + if (tp_dev.x[0] >= button_clear.x && tp_dev.x[0] <= (button_clear.x + button_clear.w)) + { + if (tp_dev.y[0] >= button_clear.y && tp_dev.y[0] <= (button_clear.y + button_clear.h)) + { + //判断是否松手 + letgo_scan(0, button_clear.x, button_clear.y, (button_clear.x + button_clear.w), (button_clear.y + button_clear.h)); + //清屏为背景色 + tli_draw_Rectangle(0, 0, 800, 480, WHITE, 1); + //UI重新显示 + ui_init(); + } + } + //[像素]按钮被按下 + if (tp_dev.x[0] >= button_pixel.x && tp_dev.x[0] <= (button_pixel.x + button_pixel.w)) + { + if (tp_dev.y[0] >= button_pixel.y && tp_dev.y[0] <= (button_pixel.y + button_pixel.h)) + { + //判断是否松手 + letgo_scan(0, button_pixel.x, button_pixel.y, (button_pixel.x + button_pixel.w), (button_pixel.y + button_pixel.h)); + //像素放大倍数自增 + pixel_size++; + //如果像素放大倍数大于最大倍数 + if (pixel_size > PIXEL_SIZE_MAX) pixel_size = 1; + //重新设置[颜色]按钮的背景色 + widget_object_init(&button_pixel, button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, button_pixel.color, pixel_size); + //UI重新显示 + ui_init(); + } + } + + //[擦除]按钮被按下 + if (tp_dev.x[0] >= button_eraser.x && tp_dev.x[0] <= (button_eraser.x + button_eraser.w)) + { + if (tp_dev.y[0] >= button_eraser.y && tp_dev.y[0] <= (button_eraser.y + button_eraser.h)) + { + //判断是否松手 + letgo_scan(0, button_eraser.x, button_eraser.y, (button_eraser.x + button_eraser.w), (button_eraser.y + button_eraser.h)); + //修改擦除按钮的状态 + button_eraser.value = !button_eraser.value; + //如果是擦除状态 + if (button_eraser.value) + { + //初始化[橡皮擦]按钮的xywh颜色修改为黑色 + widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLACK, button_eraser.value); + } + else + { + //初始化[橡皮擦]按钮的xywh颜色修改为蓝色 + widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, button_eraser.value); + } + //UI重新显示 + ui_init(); + } + } + + //如果不是擦除状态 + if (!button_eraser.value) + { + //绘制触摸点 + //根据[颜色]按钮的背景色设置触摸点的颜色 + point_enlargement(tp_dev.x[0], tp_dev.y[0], color_buf[color_num], button_pixel.value); + } + else + { + //擦除 + point_enlargement(tp_dev.x[0], tp_dev.y[0], WHITE, button_pixel.value); + } + } + } +} +INIT_COMPONENT_EXPORT(lcd_test); +/********************************************************** + * 函 数 名 称:widget_object_init + * 函 数 功 能:控件对象初始化 + * 传 入 参 数:obj:要初始化的控件 + * xywh:控件的(x,y)起点坐标 w宽h高 + * color:控件颜色 + * value:控件值 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void widget_object_init(_widget_object_struct *obj, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t value) +{ + obj->x = x; + obj->y = y; + obj->h = h; + obj->w = w; + obj->color = color; + obj->value = value; +} + + +/********************************************************** + * 函 数 名 称:ui_init + * 函 数 功 能:UI界面初始化 + * 传 入 参 数:无 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void ui_init(void) +{ + char temp_buf[20] = {0}; + + //绘制[清除]按钮 + //绘制一个圆角按钮 + tli_show_button(button_clear.x, button_clear.y, button_clear.w, button_clear.h, 12, button_clear.color); + //绘制圆角按钮的文本 + tli_show_string(button_clear.x + 20, button_clear.y + 20, WHITE, button_clear.color, 2, "clear", 0); + + //绘制[颜色]按钮 + //绘制一个圆角按钮 + tli_show_button(button_color.x, button_color.y, button_color.w, button_color.h, 12, button_color.color); + //绘制圆角按钮的文本 + tli_show_string(button_color.x + 20, button_color.y + 20, WHITE, button_color.color, 2, "color", 0); + + //绘制[像素]按钮 + //绘制一个圆角按钮 + tli_show_button(button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, 12, button_pixel.color); + if (button_pixel.value == 0) + { + //绘制圆角按钮的文本 + tli_show_string(button_pixel.x + 20, button_pixel.y + 20, WHITE, button_pixel.color, 2, "pixel", 0); + button_pixel.value = 1; + } + else + { + //绘制居中显示的字符串 + sprintf(temp_buf, "%d", button_pixel.value); + tli_show_string(button_pixel.x + (button_pixel.w / 2) - (strlen(temp_buf) / 2 * 16), button_pixel.y + 20, WHITE, button_pixel.color, 2, (uint8_t *)temp_buf, 0); + } + + //绘制[擦除]按钮 + //绘制一个圆角按钮 + tli_show_button(button_eraser.x, button_eraser.y, button_eraser.w, button_eraser.h, 12, button_eraser.color); + //绘制圆角按钮的文本 + tli_show_string(button_eraser.x + (button_eraser.w / 2) - (strlen("eraser") / 2 * 16), button_eraser.y + 20, WHITE, button_eraser.color, 2, "eraser", 0); +} + +#endif // RT_USING_LCD_EXAMPLE + diff --git a/bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.h b/bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.h new file mode 100644 index 0000000000..ed69826aec --- /dev/null +++ b/bsp/gd32/arm/libraries/gd32_drivers/drv_lcd.h @@ -0,0 +1,101 @@ +#ifndef GD32F450Z_LCD_H +#define GD32F450Z_LCD_H + +#include +#include +#include +#ifdef BSP_USING_SDRAM +#include +#endif /* BSP_USING_SDRAM */ + +/******************************************************************************* + * Definitions + ******************************************************************************/ + +#define LCD_WIDTH 800 +#define LCD_HEIGHT 480 +#define LCD_FB_BYTE_PER_PIXEL 1 + + +//#define HORIZONTAL_SYNCHRONOUS_PULSE 10 +//#define HORIZONTAL_BACK_PORCH 150 +//#define ACTIVE_WIDTH 800 +//#define HORIZONTAL_FRONT_PORCH 15 + +//#define VERTICAL_SYNCHRONOUS_PULSE 10 +//#define VERTICAL_BACK_PORCH 140 +//#define ACTIVE_HEIGHT 480 +//#define VERTICAL_FRONT_PORCH 40 + + +#define HORIZONTAL_SYNCHRONOUS_PULSE 10 +#define HORIZONTAL_BACK_PORCH 150 +#define ACTIVE_WIDTH 800 +#define HORIZONTAL_FRONT_PORCH 15 + +#define VERTICAL_SYNCHRONOUS_PULSE 10 +#define VERTICAL_BACK_PORCH 140 +#define ACTIVE_HEIGHT 480 +#define VERTICAL_FRONT_PORCH 40 + + +#define LCD_FRAME_BUF_ADDR 0XC0000000 + +//ɫ +#define WHITE 0xFFFF +#define BLACK 0x0000 +#define BLUE 0x001F +#define BRED 0XF81F +#define GRED 0XFFE0 +#define GBLUE 0X07FF +#define RED 0xF800 +#define MAGENTA 0xF81F +#define GREEN 0x07E0 +#define CYAN 0x7FFF +#define YELLOW 0xFFE0 +#define BROWN 0XBC40 //ɫ +#define BRRED 0XFC07 //غɫ +#define GRAY 0X8430 //ɫ +//GUIɫ + +#define DARKBLUE 0X01CF //ɫ +#define LIGHTBLUE 0X7D7C //dzɫ +#define GRAYBLUE 0X5458 //ɫ +//ɫΪPANELɫ + +#define LIGHTGREEN 0X841F //dzɫ +//#define LIGHTGRAY 0XEF5B //dzɫ(PANNEL) +#define LGRAY 0XC618 //dzɫ(PANNEL),屳ɫ + +#define LGRAYBLUE 0XA651 //dzɫ(мɫ) +#define LBBLUE 0X2B12 //dzɫ(ѡĿķɫ) + + +#if defined(__CC_ARM) || defined(__ARMCC_VERSION) +// Keil MDK +extern uint16_t ltdc_lcd_framebuf0[800][480] __attribute__((at(LCD_FRAME_BUF_ADDR))); +#elif defined(__GNUC__) +// GCC ( RT-Thread ʹõ GCC) +extern uint16_t ltdc_lcd_framebuf0[10][10]; +#endif + + +// extern uint16_t ltdc_lcd_framebuf0[10][10] ; + + +/******************************************************************************* + * API + ******************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + + +void lcd_disp_config(void); + +#if defined(__cplusplus) +} +#endif + +#endif /* GD32F450Z_LCD_H */ diff --git a/bsp/gd32/arm/libraries/gd32_drivers/drv_touch.c b/bsp/gd32/arm/libraries/gd32_drivers/drv_touch.c new file mode 100644 index 0000000000..6c90351ba7 --- /dev/null +++ b/bsp/gd32/arm/libraries/gd32_drivers/drv_touch.c @@ -0,0 +1,399 @@ +#include "drv_touch.h" +#include "stdio.h" +#include "string.h" +#include "drv_lcd.h" +#include +#include +#include +#include + + + +#define DRV_DEBUG +#define LOG_TAG "drv.touch" +#include + +_m_tp_dev tp_dev; + +const uint16_t FT5206_TPX_TBL[5] = {FT_TP1_REG, FT_TP2_REG, FT_TP3_REG, FT_TP4_REG, FT_TP5_REG}; +uint8_t g_gt_tnum = 5; // 默认支持的触摸屏点数(5点触摸) + +//#define ACTIVE_WIDTH 480 +//#define ACTIVE_HEIGHT 800 + + +void delay_us(uint32_t _nus) +{ + uint8_t fac_us = 0; + uint32_t ticks; + uint32_t t_old, t_now, t_cnt = 0; + uint32_t reload = SysTick->LOAD; //获取重装载值(只查询,不影响) + + fac_us = SystemCoreClock / 1000000; + ticks = _nus * fac_us - fac_us * 7 / 20; + t_old = SysTick->VAL; //获取当前值作为旧值(只查询,不影响) + + while (1) + { + /*systick为向下递减,未减到0导致重装载的情况下,新值小于旧值*/ + t_now = SysTick->VAL; //获取当前值作为新值(只查询,不影响) + + if (t_now < t_old) + { + t_cnt += t_old - t_now; //未发生重装载,cnt记录减少的值 + } + else + { + t_cnt += t_old + (reload - t_now); //重装载后,旧值已递减完毕,cnt需在再加上重装载值与新值的差值 + } + + if (t_cnt >= ticks) + { + break; //当计数cnt大于等于用户需要的ticks,即认为延时完毕,跳出循环 + } + + t_old = t_now; //获取当前值作为旧值,以供下一次循环做判断(只查询,不影响) + }; +} + + +void touch_delay_1us(uint16_t us) +{ + delay_us(us); +} + +// 控制I2C速度的延时 +void CT_Delay(void) +{ + touch_delay_1us(2); +} + +// 电容触摸芯片IIC接口初始化 +void CT_IIC_Init(void) +{ + /* enable the led clock */ + rcu_periph_clock_enable(SCL_RCU); + /* configure led GPIO port */ + gpio_mode_set(SCL_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SCL_PIN); + gpio_output_options_set(SCL_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, SCL_PIN); + + rcu_periph_clock_enable(SDA_RCU); + gpio_mode_set(SDA_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SDA_PIN); + gpio_output_options_set(SDA_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, SDA_PIN); +} +// 产生IIC起始信号 +void CT_IIC_Start(void) +{ + CT_SDA_OUT(); // sda线输出 + SDA_ON; + SCL_ON; // SCL=1时,SDA由1到0跳变 + touch_delay_1us(30); + SDA_OFF; // START:when CLK is high,DATA change form high to low + CT_Delay(); + SCL_OFF; // 钳住I2C总线,准备发送或接收数据 +} +// 产生IIC停止信号 +void CT_IIC_Stop(void) +{ + CT_SDA_OUT(); // sda线输出 + SCL_ON; // SCL=1时,SDA由0到1跳变 + touch_delay_1us(30); + SDA_OFF; // STOP:when CLK is high DATA change form low to high + CT_Delay(); + SDA_ON; // 发送I2C总线结束信号 +} +// 等待应答信号到来 +// 返回值:1,接收应答失败 +// 0,接收应答成功 +uint8_t CT_IIC_Wait_Ack(void) +{ + uint8_t ucErrTime = 0; + CT_SDA_IN(); // SDA设置为输入 + SDA_ON; + SCL_ON; + CT_Delay(); + while (CT_READ_SDA) + { + ucErrTime++; + if (ucErrTime > 250) + { + CT_IIC_Stop(); + return 1; + } + CT_Delay(); + } + SCL_OFF; // 时钟输出0 + return 0; +} +// 产生ACK应答 +void CT_IIC_Ack(void) +{ + SCL_OFF; + CT_SDA_OUT(); + CT_Delay(); + SDA_OFF; + CT_Delay(); + SCL_ON; + CT_Delay(); + SCL_OFF; +} +// 不产生ACK应答 +void CT_IIC_NAck(void) +{ + SCL_OFF; + CT_SDA_OUT(); + CT_Delay(); + SDA_ON; + CT_Delay(); + SCL_ON; + CT_Delay(); + SCL_OFF; +} +// IIC发送一个字节 +// 返回从机有无应答 +// 1,有应答 +// 0,无应答 +void CT_IIC_Send_Byte(uint8_t txd) +{ + uint8_t t; + CT_SDA_OUT(); + SCL_OFF; // 拉低时钟开始数据传输 + CT_Delay(); + for (t = 0; t < 8; t++) + { + // CT_IIC_SDA=(txd&0x80)>>7; + // CT_IIC_SDA((txd&0x80)>>7); + if ((txd & 0x80) >> 7) + { + gpio_bit_set(SDA_PORT, SDA_PIN); + } + else + { + gpio_bit_reset(SDA_PORT, SDA_PIN); + } + + txd <<= 1; + SCL_ON; + CT_Delay(); + SCL_OFF; + CT_Delay(); + } +} +// 读1个字节,ack=1时,发送ACK,ack=0,发送nACK +uint8_t CT_IIC_Read_Byte(unsigned char ack) +{ + volatile uint8_t i, receive = 0; + CT_SDA_IN(); // SDA设置为输入 + touch_delay_1us(30); + for (i = 0; i < 8; i++) + { + SCL_OFF; + CT_Delay(); + SCL_ON; + receive <<= 1; + + // printf("%d ",CT_READ_SDA); + if (CT_READ_SDA) + receive++; + } + // printf("\r\n receive:%0x \r\n",receive); + + if (!ack) + CT_IIC_NAck(); // 发送nACK + else + CT_IIC_Ack(); // 发送ACK + return receive; +} + +// 向FT5206写入一次数据 +uint8_t FT5206_WR_Reg(uint16_t reg, uint8_t *buf, uint8_t len) +{ + uint8_t i; + uint8_t ret = 0; + CT_IIC_Start(); + CT_IIC_Send_Byte(FT_CMD_WR); // 发送写命令 + CT_IIC_Wait_Ack(); + CT_IIC_Send_Byte(reg & 0XFF); // 发送低8位地址 + CT_IIC_Wait_Ack(); + for (i = 0; i < len; i++) + { + CT_IIC_Send_Byte(buf[i]); // 发数据 + ret = CT_IIC_Wait_Ack(); + if (ret) + break; + } + CT_IIC_Stop(); // 产生一个停止条件 + return ret; +} + +// 从FT5206读出一次数据 +void FT5206_RD_Reg(uint16_t reg, uint8_t *buf, uint8_t len) +{ + uint8_t i; + CT_IIC_Start(); + CT_IIC_Send_Byte(FT_CMD_WR); // 发送写命令 + CT_IIC_Wait_Ack(); + CT_IIC_Send_Byte(reg & 0XFF); // 发送低8位地址 + CT_IIC_Wait_Ack(); + CT_IIC_Start(); + CT_IIC_Send_Byte(FT_CMD_RD); // 发送读命令 + CT_IIC_Wait_Ack(); + for (i = 0; i < len; i++) + { + buf[i] = CT_IIC_Read_Byte(i == (len - 1) ? 0 : 1); // 发数据 + } + CT_IIC_Stop(); // 产生一个停止条件 +} + +// 初始化FT5206触摸屏 +uint8_t FT5206_Init(void) +{ + uint8_t temp[5]; + // PD11设置为上拉输入(INT) + /* enable the led clock */ + rcu_periph_clock_enable(INT_RCU); + /* configure led GPIO port */ + gpio_mode_set(INT_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, INT_PIN); + + // 初始化电容屏的I2C总线 + CT_IIC_Init(); + + FT5206_WR_Reg(FT_DEVIDE_MODE, temp, 1); // 进入正常操作模式 + FT5206_WR_Reg(FT_ID_G_MODE, temp, 1); // 查询模式 + temp[0] = 22; // 触摸有效值,22,越小越灵敏 + FT5206_WR_Reg(FT_ID_G_THGROUP, temp, 1); // 设置触摸有效值 + temp[0] = 12; // 激活周期,不能小于12,最大14 + FT5206_WR_Reg(FT_ID_G_PERIODACTIVE, temp, 1); + // 读取版本号,参考值:0x3003 + FT5206_RD_Reg(FT_ID_G_LIB_VERSION, &temp[0], 2); + printf("CTP ID:%x\r\n", ((uint16_t)temp[0] << 8) + temp[1]); + return 0; +} + +// 扫描触摸屏(采用查询方式) +// mode:0,正常扫描. +// 返回值:当前触屏状态. +// 0,触屏无触摸;1,触屏有触摸 +uint8_t FT5206_Scan(uint8_t mode) +{ + uint8_t buf[4]; + uint8_t i = 0; + uint8_t res = 0; + uint8_t temp; + uint16_t tempsta; + static uint8_t t = 0; // 控制查询间隔,从而降低CPU占用率 + t++; + if ((t % 10) == 0 || t < 10) // 空闲时,每进入10次CTP_Scan函数才检测1次,从而节省CPU使用率 + { + FT5206_RD_Reg(FT_REG_NUM_FINGER, &mode, 1); // 读取触摸点的状态 + if ((mode & 0XF) && ((mode & 0XF) <= g_gt_tnum)) + { + temp = 0XFF << (mode & 0XF); // 将点的个数转换为1的位数,匹配tp_dev.sta定义 + tempsta = tp_dev.sta; // 保存当前的tp_dev.sta值 + tp_dev.sta = (~temp) | TP_PRES_DOWN | TP_CATH_PRES; + tp_dev.x[g_gt_tnum - 1] = tp_dev.x[0]; // 保存触点0的数据,保存在最后一个上 + tp_dev.y[g_gt_tnum - 1] = tp_dev.y[0]; + // delay_1ms(4); //必要的延时,否则老是认为有按键按下 + for (i = 0; i < g_gt_tnum; i++) + { + if (tp_dev.sta & (1 << i)) // 触摸有效? + { + FT5206_RD_Reg(FT5206_TPX_TBL[i], buf, 4); // 读取XY坐标值 + if (tp_dev.touchtype & 0X01) // 横屏 + { + tp_dev.y[i] = ((uint16_t)(buf[0] & 0X0F) << 8) + buf[1]; + tp_dev.x[i] = ((uint16_t)(buf[2] & 0X0F) << 8) + buf[3]; + } + else + { + tp_dev.x[i] = (((uint16_t)(buf[0] & 0X0F) << 8) + buf[1]); + tp_dev.y[i] = ((uint16_t)(buf[2] & 0X0F) << 8) + buf[3]; + } + } + } + res = 1; + if (tp_dev.x[0] > ACTIVE_WIDTH || tp_dev.y[0] > ACTIVE_HEIGHT) // 非法数据(坐标超出了) + { + if ((mode & 0XF) > 1) // 有其他点有数据,则复第二个触点的数据到第一个触点. + { + tp_dev.x[0] = tp_dev.x[1]; + tp_dev.y[0] = tp_dev.y[1]; + t = 0; // 触发一次,则会最少连续监测10次,从而提高命中率 + } + else // 非法数据,则忽略此次数据(还原原来的) + { + tp_dev.x[0] = tp_dev.x[g_gt_tnum - 1]; + tp_dev.y[0] = tp_dev.y[g_gt_tnum - 1]; + mode = 0X80; + tp_dev.sta = tempsta; // 恢复tp_dev.sta + } + } + else + t = 0; // 触发一次,则会最少连续监测10次,从而提高命中率 + } + } + + if ((mode & 0X1F) == 0) // 无触摸点按下 + { + if (tp_dev.sta & TP_PRES_DOWN) // 之前是被按下的 + { + tp_dev.sta &= ~TP_PRES_DOWN; // 标记按键松开 + } + else // 之前就没有被按下 + { + tp_dev.x[0] = 0xffff; + tp_dev.y[0] = 0xffff; + tp_dev.sta &= 0XE0; // 清除点有效标记 + } + } + + if (t > 240) + t = 10; // 重新从10开始计数 + return res; +} + +/********************************************************** + * 函 数 名 称:letgo_scan + * 函 数 功 能:触摸松手判断 + * 传 入 参 数:contact:第几个触点(一共有5个触点) + * (sx,sy):判断触摸地的起始坐标 + * (ex,ey):判断触摸地的结束坐标 + * 函 数 返 回:无 + * 作 者:LCKFB + * 备 注:无 +**********************************************************/ +void letgo_scan(uint16_t contact, uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey) +{ + //等待松手 + while (FT5206_Scan(0)) + { + //如果离开了x轴触摸范围 + if (tp_dev.x[contact] <= sx || tp_dev.x[contact] >= ex) + { + return; + } + //如果离开了y轴触摸范围 + if (tp_dev.y[contact] <= sy && tp_dev.y[contact] >= ey) + { + return; + } + } +} + +int touch_test(void) +{ + int touch_state = 0; + FT5206_Init(); + + while (1) + { + touch_state = FT5206_Scan(0); + + if (touch_state == 1) + { + rt_kprintf("touch\r\n"); + } + rt_thread_mdelay(10); + } +} +MSH_CMD_EXPORT(touch_test, touch test) diff --git a/bsp/gd32/arm/libraries/gd32_drivers/drv_touch.h b/bsp/gd32/arm/libraries/gd32_drivers/drv_touch.h new file mode 100644 index 0000000000..6667271705 --- /dev/null +++ b/bsp/gd32/arm/libraries/gd32_drivers/drv_touch.h @@ -0,0 +1,96 @@ +#ifndef __TOUCH_H__ +#define __TOUCH_H__ +#include "gd32f4xx.h" + + +#define SCL_RCU RCU_GPIOB +#define SCL_PORT GPIOB +#define SCL_PIN GPIO_PIN_6 +#define SCL_ON gpio_bit_set(SCL_PORT, SCL_PIN) +#define SCL_OFF gpio_bit_reset(SCL_PORT, SCL_PIN) +#define SCL_TOGGLE gpio_bit_toggle(SCL_PORT, SCL_PIN) + +#define SDA_RCU RCU_GPIOB +#define SDA_PORT GPIOB +#define SDA_PIN GPIO_PIN_7 +#define SDA_ON gpio_bit_set(SDA_PORT, SDA_PIN) +#define SDA_OFF gpio_bit_reset(SDA_PORT, SDA_PIN) +#define SDA_TOGGLE gpio_bit_toggle(SDA_PORT, SDA_PIN) + +// IO方向设置 +#define CT_SDA_IN() gpio_mode_set(SCL_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, SDA_PIN); //{GPIOF->MODER&=~(3<<(2*11));GPIOF->MODER|=0<<2*11;} //PF11输入模式 +#define CT_SDA_OUT() gpio_mode_set(SCL_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SDA_PIN); //{GPIOF->MODER&=~(3<<(2*11));GPIOF->MODER|=1<<2*11;} //PF11输出模式 +// IO操作函数 +#define CT_IIC_SCL // PBout(0) //SCL +#define CT_IIC_SDA(val) ((val) == 1 ? SDA_ON : SDA_OFF) // PFout(11) //SDA +#define CT_READ_SDA gpio_input_bit_get(SDA_PORT, SDA_PIN) // PFin(11) //输入SDA + +#define RST_RCU RCU_GPIOD +#define RST_PORT GPIOD +#define RST_PIN GPIO_PIN_12 +#define RST_ON gpio_bit_set(RST_PORT, RST_PIN); +#define RST_OFF gpio_bit_reset(RST_PORT, RST_PIN); +#define RST_TOGGLE gpio_bit_toggle(RST_PORT, RST_PIN); + +#define INT_RCU RCU_GPIOD +#define INT_PORT GPIOD +#define INT_PIN GPIO_PIN_11 +#define INT_ON gpio_bit_set(INT_PORT, INT_PIN); +#define INT_OFF gpio_bit_reset(INT_PORT, INT_PIN); +#define INT_TOGGLE gpio_bit_toggle(INT_PORT, INT_PIN); + +// I2C读写命令 +#define FT_CMD_WR 0X70 // 写命令 +#define FT_CMD_RD 0X71 // 读命令 +// FT5206 部分寄存器定义 +#define FT_DEVIDE_MODE 0x00 // FT5206模式控制寄存器 +#define FT_REG_NUM_FINGER 0x02 // 触摸状态寄存器 +#define FT_TP1_REG 0X03 // 第一个触摸点数据地址 +#define FT_TP2_REG 0X09 // 第二个触摸点数据地址 +#define FT_TP3_REG 0X0F // 第三个触摸点数据地址 +#define FT_TP4_REG 0X15 // 第四个触摸点数据地址 +#define FT_TP5_REG 0X1B // 第五个触摸点数据地址 + +#define FT_ID_G_LIB_VERSION 0xA1 // 版本 +#define FT_ID_G_MODE 0xA4 // FT5206中断模式控制寄存器 +#define FT_ID_G_THGROUP 0x80 // 触摸有效值设置寄存器 +#define FT_ID_G_PERIODACTIVE 0x88 // 激活状态周期设置寄存器 + +#define TP_PRES_DOWN 0x80 // 触屏被按下 +#define TP_CATH_PRES 0x40 // 有按键按下了 +#define CT_MAX_TOUCH 5 // 电容屏支持的点数,固定为5点 +// 触摸屏控制器 +typedef struct +{ + // uint8_t (*init)(void); //初始化触摸屏控制器 + // uint8_t (*scan)(uint8_t); //扫描触摸屏.0,屏幕扫描;1,物理坐标; + // void (*adjust)(void); //触摸屏校准 + uint16_t x[CT_MAX_TOUCH]; // 当前坐标 + uint16_t y[CT_MAX_TOUCH]; // 电容屏有最多5组坐标,电阻屏则用x[0],y[0]代表:此次扫描时,触屏的坐标,用 + uint8_t sta; // 笔的状态 + float xfac; + float yfac; + short xoff; + short yoff; + uint8_t touchtype; +} _m_tp_dev; +extern _m_tp_dev tp_dev; // 触屏控制器在touch.c里面定义 + +// IIC所有操作函数 +void CT_IIC_Init(void); // 初始化IIC的IO口 +void CT_IIC_Start(void); // 发送IIC开始信号 +void CT_IIC_Stop(void); // 发送IIC停止信号 +void CT_IIC_Send_Byte(uint8_t txd); // IIC发送一个字节 +uint8_t CT_IIC_Read_Byte(unsigned char ack); // IIC读取一个字节 +uint8_t CT_IIC_Wait_Ack(void); // IIC等待ACK信号 +void CT_IIC_Ack(void); // IIC发送ACK信号 +void CT_IIC_NAck(void); // IIC不发送ACK信号 + +// 触摸屏操作函数 +uint8_t FT5206_WR_Reg(uint16_t reg, uint8_t *buf, uint8_t len); +void FT5206_RD_Reg(uint16_t reg, uint8_t *buf, uint8_t len); +uint8_t FT5206_Init(void); +uint8_t FT5206_Scan(uint8_t mode); +void letgo_scan(uint16_t contact, uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey); + +#endif diff --git a/bsp/gd32/arm/libraries/gd32_drivers/font.h b/bsp/gd32/arm/libraries/gd32_drivers/font.h new file mode 100644 index 0000000000..01e777bf78 --- /dev/null +++ b/bsp/gd32/arm/libraries/gd32_drivers/font.h @@ -0,0 +1,191 @@ +#ifndef __FONT_H +#define __FONT_H + +const unsigned char asc2_1608[95][16]={ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/ +{0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x18,0x18,0x00,0x00},/*"!",1*/ +{0x00,0x48,0x6C,0x24,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/ +{0x00,0x00,0x00,0x24,0x24,0x24,0x7F,0x12,0x12,0x12,0x7F,0x12,0x12,0x12,0x00,0x00},/*"#",3*/ +{0x00,0x00,0x08,0x1C,0x2A,0x2A,0x0A,0x0C,0x18,0x28,0x28,0x2A,0x2A,0x1C,0x08,0x08},/*"$",4*/ +{0x00,0x00,0x00,0x22,0x25,0x15,0x15,0x15,0x2A,0x58,0x54,0x54,0x54,0x22,0x00,0x00},/*"%",5*/ +{0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0A,0x76,0x25,0x29,0x11,0x91,0x6E,0x00,0x00},/*"&",6*/ +{0x00,0x06,0x06,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/ +{0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00},/*"(",8*/ +{0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00},/*")",9*/ +{0x00,0x00,0x00,0x00,0x08,0x08,0x6B,0x1C,0x1C,0x6B,0x08,0x08,0x00,0x00,0x00,0x00},/*"*",10*/ +{0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x08,0x00,0x00,0x00},/*"+",11*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x04,0x03},/*",",12*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00},/*".",14*/ +{0x00,0x00,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00},/*"/",15*/ +{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",16*/ +{0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",17*/ +{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00},/*"2",18*/ +{0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00},/*"3",19*/ +{0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00},/*"4",20*/ +{0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00},/*"5",21*/ +{0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"6",22*/ +{0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00},/*"7",23*/ +{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",24*/ +{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00},/*"9",25*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",26*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x04},/*";",27*/ +{0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00},/*"<",28*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},/*"=",29*/ +{0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/*">",30*/ +{0x00,0x00,0x00,0x3C,0x42,0x42,0x46,0x40,0x20,0x10,0x10,0x00,0x18,0x18,0x00,0x00},/*"?",31*/ +{0x00,0x00,0x00,0x1C,0x22,0x5A,0x55,0x55,0x55,0x55,0x2D,0x42,0x22,0x1C,0x00,0x00},/*"@",32*/ +{0x00,0x00,0x00,0x08,0x08,0x18,0x14,0x14,0x24,0x3C,0x22,0x42,0x42,0xE7,0x00,0x00},/*"A",33*/ +{0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x1E,0x22,0x42,0x42,0x42,0x22,0x1F,0x00,0x00},/*"B",34*/ +{0x00,0x00,0x00,0x7C,0x42,0x42,0x01,0x01,0x01,0x01,0x01,0x42,0x22,0x1C,0x00,0x00},/*"C",35*/ +{0x00,0x00,0x00,0x1F,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1F,0x00,0x00},/*"D",36*/ +{0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x42,0x42,0x3F,0x00,0x00},/*"E",37*/ +{0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x02,0x02,0x07,0x00,0x00},/*"F",38*/ +{0x00,0x00,0x00,0x3C,0x22,0x22,0x01,0x01,0x01,0x71,0x21,0x22,0x22,0x1C,0x00,0x00},/*"G",39*/ +{0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"H",40*/ +{0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"I",41*/ +{0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x0F},/*"J",42*/ +{0x00,0x00,0x00,0x77,0x22,0x12,0x0A,0x0E,0x0A,0x12,0x12,0x22,0x22,0x77,0x00,0x00},/*"K",43*/ +{0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x7F,0x00,0x00},/*"L",44*/ +{0x00,0x00,0x00,0x77,0x36,0x36,0x36,0x36,0x2A,0x2A,0x2A,0x2A,0x2A,0x6B,0x00,0x00},/*"M",45*/ +{0x00,0x00,0x00,0xE3,0x46,0x46,0x4A,0x4A,0x52,0x52,0x52,0x62,0x62,0x47,0x00,0x00},/*"N",46*/ +{0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x22,0x1C,0x00,0x00},/*"O",47*/ +{0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x3E,0x02,0x02,0x02,0x02,0x07,0x00,0x00},/*"P",48*/ +{0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x4D,0x53,0x32,0x1C,0x60,0x00},/*"Q",49*/ +{0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x3E,0x12,0x12,0x22,0x22,0x42,0xC7,0x00,0x00},/*"R",50*/ +{0x00,0x00,0x00,0x7C,0x42,0x42,0x02,0x04,0x18,0x20,0x40,0x42,0x42,0x3E,0x00,0x00},/*"S",51*/ +{0x00,0x00,0x00,0x7F,0x49,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00},/*"T",52*/ +{0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"U",53*/ +{0x00,0x00,0x00,0xE7,0x42,0x42,0x22,0x24,0x24,0x14,0x14,0x18,0x08,0x08,0x00,0x00},/*"V",54*/ +{0x00,0x00,0x00,0x6B,0x49,0x49,0x49,0x49,0x55,0x55,0x36,0x22,0x22,0x22,0x00,0x00},/*"W",55*/ +{0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00},/*"X",56*/ +{0x00,0x00,0x00,0x77,0x22,0x22,0x14,0x14,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00},/*"Y",57*/ +{0x00,0x00,0x00,0x7E,0x21,0x20,0x10,0x10,0x08,0x04,0x04,0x42,0x42,0x3F,0x00,0x00},/*"Z",58*/ +{0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00},/*"[",59*/ +{0x00,0x00,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x10,0x20,0x20,0x20,0x40,0x40},/*"\",60*/ +{0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00},/*"]",61*/ +{0x00,0x38,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},/*"_",63*/ +{0x00,0x06,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x78,0x44,0x42,0x42,0xFC,0x00,0x00},/*"a",65*/ +{0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x26,0x1A,0x00,0x00},/*"b",66*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x02,0x02,0x02,0x44,0x38,0x00,0x00},/*"c",67*/ +{0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x78,0x44,0x42,0x42,0x42,0x64,0xD8,0x00,0x00},/*"d",68*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x02,0x02,0x42,0x3C,0x00,0x00},/*"e",69*/ +{0x00,0x00,0x00,0xF0,0x88,0x08,0x08,0x7E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"f",70*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x22,0x22,0x1C,0x02,0x3C,0x42,0x42,0x3C},/*"g",71*/ +{0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"h",72*/ +{0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"i",73*/ +{0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x1E},/*"j",74*/ +{0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x72,0x12,0x0A,0x16,0x12,0x22,0x77,0x00,0x00},/*"k",75*/ +{0x00,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"l",76*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x92,0x92,0x92,0x92,0x92,0xB7,0x00,0x00},/*"m",77*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"n",78*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"o",79*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x26,0x42,0x42,0x42,0x22,0x1E,0x02,0x07},/*"p",80*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x44,0x42,0x42,0x42,0x44,0x78,0x40,0xE0},/*"q",81*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x4C,0x04,0x04,0x04,0x04,0x1F,0x00,0x00},/*"r",82*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x42,0x02,0x3C,0x40,0x42,0x3E,0x00,0x00},/*"s",83*/ +{0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x3E,0x08,0x08,0x08,0x08,0x08,0x30,0x00,0x00},/*"t",84*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x42,0x42,0x42,0x42,0x62,0xDC,0x00,0x00},/*"u",85*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x08,0x08,0x00,0x00},/*"v",86*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEB,0x49,0x49,0x55,0x55,0x22,0x22,0x00,0x00},/*"w",87*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00},/*"x",88*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x18,0x08,0x08,0x07},/*"y",89*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x22,0x10,0x08,0x08,0x44,0x7E,0x00,0x00},/*"z",90*/ +{0x00,0xC0,0x20,0x20,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x20,0x20,0xC0,0x00},/*"{",91*/ +{0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10},/*"|",92*/ +{0x00,0x06,0x08,0x08,0x08,0x08,0x08,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x06,0x00},/*"}",93*/ +{0x0C,0x32,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/ + + +}; +typedef struct +{ + unsigned char Index[2]; + char Msk[32]; +}typFNT_GB16; +//ȡģ峣С +const typFNT_GB16 tfont16[]= +{ +"",0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xFC,0x21,0x04,0x21,0x04,0x21,0x04, +0x21,0x04,0x21,0x04,0x21,0x04,0x3F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,/*0*/ +"",0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x80,0x3F,0x7C,0x08,0x10,0x08,0x10,0x04,0x10, +0x04,0x20,0x02,0x20,0x02,0x40,0x01,0x80,0x01,0x80,0x02,0x60,0x1C,0x18,0xE0,0x06,/*2*/ +"",0x00,0x00,0x00,0x00,0x67,0xC2,0x14,0x52,0x05,0x52,0x05,0x52,0xC5,0x52,0x25,0x52, +0x05,0x52,0x05,0x52,0x15,0x52,0x17,0x52,0x22,0x82,0x22,0x42,0x44,0x42,0x48,0x3E,/*2*/ +"",0x00,0x00,0x00,0x00,0x20,0x14,0x10,0x14,0x17,0xFE,0x00,0x12,0x00,0x10,0x60,0x10, +0x13,0xF0,0x10,0x90,0x10,0x90,0x10,0x90,0x14,0x92,0x14,0xEA,0x1F,0x0A,0x00,0x06,/*3*/ +}; +typedef struct +{ + unsigned char Index[2]; + char Msk[72]; +}typFNT_GB24; +//ȡģ峣С +const typFNT_GB24 tfont24[]= +{ +"",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00, +0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x3F,0xFF,0xFE,0x30,0x18,0x06,0x30,0x18, +0x06,0x30,0x18,0x06,0x30,0x18,0x06,0x30,0x18,0x06,0x3F,0xFF,0xFE,0x30,0x18,0x06, +0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*0*/ +"",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x1C,0x00,0x00, +0x06,0x00,0xFF,0xFF,0xFF,0x06,0x00,0x30,0x06,0x00,0x30,0x03,0x00,0x60,0x03,0x00, +0x60,0x01,0x80,0xC0,0x00,0xC1,0x80,0x00,0xE3,0x00,0x00,0x36,0x00,0x00,0x1C,0x00, +0x00,0x77,0x00,0x03,0xC1,0xE0,0x1E,0x00,0x3C,0x60,0x00,0x07,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*1*/ +"",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x03,0x21, +0xFF,0x33,0x39,0x83,0x33,0x11,0x83,0x33,0x01,0x9B,0x33,0xC1,0x9B,0x33,0x71,0x9B, +0x33,0x19,0x9B,0x33,0x01,0x9B,0x33,0x01,0x9B,0x33,0x11,0x9B,0x33,0x19,0xB3,0x33, +0x30,0x30,0x33,0x30,0x6C,0x03,0x30,0xC6,0x03,0x63,0x83,0x03,0x2E,0x01,0xBE,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*2*/ +"",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0xD8,0x30, +0x00,0xCE,0x18,0x00,0xC2,0x1C,0x00,0xC0,0x01,0xFF,0xFF,0x00,0x00,0xC0,0xF8,0x00, +0xC0,0x18,0x00,0xC0,0x19,0xFF,0xC0,0x18,0x18,0x40,0x18,0x18,0x60,0x19,0x18,0x60, +0x1B,0x18,0x61,0x1E,0x18,0x31,0x1C,0x1F,0xB1,0x39,0xF0,0x19,0x10,0x00,0x0F,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*3*/ +}; +typedef struct +{ + unsigned char Index[2]; + char Msk[128]; +}typFNT_GB32; +//ȡģ峣С +const typFNT_GB32 tfont32[]= +{ +"",0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0xC0,0x00, +0x00,0x01,0xC0,0xC0,0x00,0x01,0x07,0xC0,0x00,0x01,0xFF,0x00,0x02,0x1F,0xFE,0x00, +0x07,0xF0,0x1C,0x00,0x07,0xC0,0x70,0x00,0x0F,0x00,0xE0,0x00,0x0E,0x03,0xF0,0x00, +0x1C,0x0F,0xF0,0x00,0x3C,0x0F,0x70,0x00,0x3C,0x00,0xE0,0x00,0x18,0x00,0xC0,0x00, +0x00,0x00,0xC0,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x20,0x00, +0x00,0x00,0x37,0x00,0x00,0x01,0xFF,0x00,0x00,0x7F,0xF8,0x00,0x07,0xF8,0x30,0x00, +0x1F,0x80,0x30,0x00,0x00,0x80,0x30,0x00,0x00,0xC0,0x30,0x00,0x00,0x60,0x60,0x00, +0x00,0x18,0xE0,0x00,0x00,0x0F,0xC0,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,/*0*/ +"",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0xE0, +0x00,0x20,0x01,0xB8,0x00,0x70,0x3F,0xF8,0x00,0x61,0xFF,0xC0,0x00,0xC3,0x03,0x00, +0x01,0xC6,0x06,0x00,0x03,0x8C,0x06,0x00,0x03,0x08,0x0C,0x00,0x06,0x08,0x0C,0x00, +0x0E,0x18,0x18,0x3F,0x1E,0x10,0x1B,0xF3,0x1F,0x90,0x3F,0x07,0x00,0x80,0x3C,0x1C, +0x01,0x90,0x70,0x7C,0x01,0x90,0x60,0xFE,0x01,0xA0,0xC3,0xF8,0x01,0xA0,0x0F,0xD8, +0x03,0xA0,0x08,0x18,0x03,0x60,0x00,0x18,0x03,0x40,0x00,0x18,0x03,0xC0,0x00,0x18, +0x03,0x80,0x00,0x18,0x03,0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x10, +0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*1*/ +"",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x02,0x0C,0x10,0x08,0x07,0x1F,0xF8,0x04,0x03,0xBF,0xF0,0x02,0x01,0xBC,0x30,0x03, +0x03,0xEC,0x30,0x03,0x01,0x5C,0x60,0x03,0x00,0xD8,0x60,0x03,0x00,0xD8,0x60,0x03, +0x80,0x98,0x62,0x03,0x61,0xB8,0x43,0x07,0x71,0xB1,0x43,0x06,0x31,0x32,0x43,0x06, +0x33,0x76,0xC3,0x06,0x3A,0x64,0xC7,0x06,0x3E,0xEC,0xC0,0x06,0x3E,0x78,0xC0,0x06, +0x3C,0x30,0x40,0x06,0x7C,0x70,0x00,0x06,0x78,0xE0,0x60,0x06,0x7B,0xFF,0xF0,0x06, +0xF7,0xC0,0x00,0x06,0xE4,0x00,0x00,0x06,0x40,0x00,0x00,0x06,0x00,0x00,0x00,0x06, +0x00,0x00,0x00,0x7C,0x00,0x00,0x8F,0xF0,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,/*2*/ +"",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00, +0x00,0x00,0x7F,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0xC0, +0x00,0x00,0x00,0xCE,0x03,0x80,0x00,0xCF,0xFF,0xC0,0x00,0xDD,0x41,0x80,0x0F,0xFE, +0x00,0x07,0xFF,0xFC,0x00,0x0C,0x00,0xF0,0x00,0x18,0x0F,0xC0,0x3E,0x19,0xFF,0x40, +0xF3,0x11,0xBC,0x60,0x83,0x30,0x7F,0xE0,0x03,0xB1,0xFE,0x20,0x03,0x33,0x80,0x20, +0x03,0x70,0x00,0x30,0x03,0x60,0x00,0x10,0x03,0x60,0x00,0x18,0x07,0xC0,0x00,0x0C, +0x07,0xC0,0x00,0x04,0x07,0x80,0x00,0x02,0x01,0x00,0x00,0x03,0x00,0x00,0x00,0x01, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*3*/ +}; + +#endif diff --git a/components/libc/compilers/common/include/dirent.h b/components/libc/compilers/common/include/dirent.h index b650028e11..a44a40d80d 100644 --- a/components/libc/compilers/common/include/dirent.h +++ b/components/libc/compilers/common/include/dirent.h @@ -69,7 +69,7 @@ struct dirent typedef uint64_t ino_t; #endif struct libc_dirent { - ino_t d_ino; +// ino_t d_ino; off_t d_off; unsigned short d_reclen; unsigned char d_type; -- Gitee