From 8942c85ae886cac6316b7465f54f1fc86f750091 Mon Sep 17 00:00:00 2001 From: SEEKFREE_BUDING <2289331269@qq.com> Date: Sun, 8 Oct 2023 17:16:00 +0800 Subject: [PATCH] =?UTF-8?q?V3.2.3=20=20=20=20=20=20=20=20=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=89=80=E6=9C=89SPI=E9=80=9A=E4=BF=A1=E5=B1=8F?= =?UTF-8?q?=E5=B9=95(OLED=E9=99=A4=E5=A4=96)=E7=9A=84=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E6=98=BE=E7=A4=BA=E9=80=9F=E7=8E=87?= =?UTF-8?q?=E5=B0=86=E6=8F=90=E5=8D=87=E4=B8=80=E5=80=8D=E5=B7=A6=E5=8F=B3?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=E4=BF=AE=E6=94=B9=E4=B8=B2=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E9=BB=98=E8=AE=A4=E9=80=9A=E4=BF=A1=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../E01_gpio_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../E02_uart_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../E03_adc_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../E04_pwm_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../E05_pit_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../E06_exit_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../E08_eeprom_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../E09_timer_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../E15_fft_demo/libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../libraries/doc/version.txt | 3 + .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c | 2 +- .../iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h | 2 +- .../libraries/zf_common/zf_common_headfile.h | 3 + .../zf_device/zf_device_bluetooth_ch9141.c | 2 +- .../libraries/zf_device/zf_device_ips114.c | 345 ++++++++------ .../libraries/zf_device/zf_device_ips114.h | 7 +- .../libraries/zf_device/zf_device_ips200.c | 445 +++++++++++------- .../libraries/zf_device/zf_device_ips200.h | 7 +- .../libraries/zf_device/zf_device_oled.c | 2 +- .../libraries/zf_device/zf_device_oled.h | 8 +- .../libraries/zf_device/zf_device_tft180.c | 333 +++++++------ .../libraries/zf_device/zf_device_tft180.h | 7 +- .../libraries/zf_driver/zf_driver_uart.c | 95 ++-- .../libraries/zf_driver/zf_driver_uart.h | 15 +- .../user/cpu0_main.c | 2 - .../user/cpu1_main.c | 18 +- 242 files changed, 12214 insertions(+), 8222 deletions(-) diff --git a/Example/E01_gpio_demo/libraries/doc/version.txt b/Example/E01_gpio_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E01_gpio_demo/libraries/doc/version.txt +++ b/Example/E01_gpio_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E01_gpio_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E01_gpio_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E01_gpio_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E01_gpio_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E01_gpio_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E01_gpio_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E01_gpio_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E01_gpio_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E01_gpio_demo/libraries/zf_common/zf_common_headfile.h b/Example/E01_gpio_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E01_gpio_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E01_gpio_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E01_gpio_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips114.c b/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips114.h b/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips200.c b/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips200.h b/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_oled.c b/Example/E01_gpio_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_oled.h b/Example/E01_gpio_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_tft180.c b/Example/E01_gpio_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E01_gpio_demo/libraries/zf_device/zf_device_tft180.h b/Example/E01_gpio_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E01_gpio_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E01_gpio_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E01_gpio_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E01_gpio_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E01_gpio_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E01_gpio_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E01_gpio_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E01_gpio_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E01_gpio_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E01_gpio_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E02_uart_demo/libraries/doc/version.txt b/Example/E02_uart_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E02_uart_demo/libraries/doc/version.txt +++ b/Example/E02_uart_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E02_uart_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E02_uart_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E02_uart_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E02_uart_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E02_uart_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E02_uart_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E02_uart_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E02_uart_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E02_uart_demo/libraries/zf_common/zf_common_headfile.h b/Example/E02_uart_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E02_uart_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E02_uart_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E02_uart_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_ips114.c b/Example/E02_uart_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_ips114.h b/Example/E02_uart_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_ips200.c b/Example/E02_uart_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_ips200.h b/Example/E02_uart_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_oled.c b/Example/E02_uart_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_oled.h b/Example/E02_uart_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_tft180.c b/Example/E02_uart_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E02_uart_demo/libraries/zf_device/zf_device_tft180.h b/Example/E02_uart_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E02_uart_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E02_uart_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E02_uart_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E02_uart_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E02_uart_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E02_uart_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E02_uart_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E02_uart_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E02_uart_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E02_uart_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E03_adc_demo/libraries/doc/version.txt b/Example/E03_adc_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E03_adc_demo/libraries/doc/version.txt +++ b/Example/E03_adc_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E03_adc_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E03_adc_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E03_adc_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E03_adc_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E03_adc_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E03_adc_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E03_adc_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E03_adc_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E03_adc_demo/libraries/zf_common/zf_common_headfile.h b/Example/E03_adc_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E03_adc_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E03_adc_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E03_adc_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_ips114.c b/Example/E03_adc_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_ips114.h b/Example/E03_adc_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_ips200.c b/Example/E03_adc_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_ips200.h b/Example/E03_adc_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_oled.c b/Example/E03_adc_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_oled.h b/Example/E03_adc_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_tft180.c b/Example/E03_adc_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E03_adc_demo/libraries/zf_device/zf_device_tft180.h b/Example/E03_adc_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E03_adc_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E03_adc_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E03_adc_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E03_adc_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E03_adc_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E03_adc_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E03_adc_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E03_adc_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E03_adc_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E03_adc_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E04_pwm_demo/libraries/doc/version.txt b/Example/E04_pwm_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E04_pwm_demo/libraries/doc/version.txt +++ b/Example/E04_pwm_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E04_pwm_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E04_pwm_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E04_pwm_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E04_pwm_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E04_pwm_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E04_pwm_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E04_pwm_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E04_pwm_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E04_pwm_demo/libraries/zf_common/zf_common_headfile.h b/Example/E04_pwm_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E04_pwm_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E04_pwm_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E04_pwm_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips114.c b/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips114.h b/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips200.c b/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips200.h b/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_oled.c b/Example/E04_pwm_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_oled.h b/Example/E04_pwm_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_tft180.c b/Example/E04_pwm_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E04_pwm_demo/libraries/zf_device/zf_device_tft180.h b/Example/E04_pwm_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E04_pwm_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E04_pwm_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E04_pwm_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E04_pwm_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E04_pwm_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E04_pwm_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E04_pwm_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E04_pwm_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E04_pwm_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E04_pwm_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E05_pit_demo/libraries/doc/version.txt b/Example/E05_pit_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E05_pit_demo/libraries/doc/version.txt +++ b/Example/E05_pit_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E05_pit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E05_pit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E05_pit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E05_pit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E05_pit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E05_pit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E05_pit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E05_pit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E05_pit_demo/libraries/zf_common/zf_common_headfile.h b/Example/E05_pit_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E05_pit_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E05_pit_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E05_pit_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_ips114.c b/Example/E05_pit_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_ips114.h b/Example/E05_pit_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_ips200.c b/Example/E05_pit_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_ips200.h b/Example/E05_pit_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_oled.c b/Example/E05_pit_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_oled.h b/Example/E05_pit_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_tft180.c b/Example/E05_pit_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E05_pit_demo/libraries/zf_device/zf_device_tft180.h b/Example/E05_pit_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E05_pit_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E05_pit_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E05_pit_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E05_pit_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E05_pit_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E05_pit_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E05_pit_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E05_pit_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E05_pit_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E05_pit_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E06_exit_demo/libraries/doc/version.txt b/Example/E06_exit_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E06_exit_demo/libraries/doc/version.txt +++ b/Example/E06_exit_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E06_exit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E06_exit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E06_exit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E06_exit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E06_exit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E06_exit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E06_exit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E06_exit_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E06_exit_demo/libraries/zf_common/zf_common_headfile.h b/Example/E06_exit_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E06_exit_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E06_exit_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E06_exit_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_ips114.c b/Example/E06_exit_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_ips114.h b/Example/E06_exit_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_ips200.c b/Example/E06_exit_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_ips200.h b/Example/E06_exit_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_oled.c b/Example/E06_exit_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_oled.h b/Example/E06_exit_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_tft180.c b/Example/E06_exit_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E06_exit_demo/libraries/zf_device/zf_device_tft180.h b/Example/E06_exit_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E06_exit_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E06_exit_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E06_exit_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E06_exit_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E06_exit_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E06_exit_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E06_exit_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E06_exit_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E06_exit_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E06_exit_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E07_encoder_demo/libraries/doc/version.txt b/Example/E07_encoder_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E07_encoder_demo/libraries/doc/version.txt +++ b/Example/E07_encoder_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E07_encoder_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E07_encoder_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E07_encoder_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E07_encoder_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E07_encoder_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E07_encoder_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E07_encoder_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E07_encoder_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E07_encoder_demo/libraries/zf_common/zf_common_headfile.h b/Example/E07_encoder_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E07_encoder_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E07_encoder_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E07_encoder_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips114.c b/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips114.h b/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips200.c b/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips200.h b/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_oled.c b/Example/E07_encoder_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_oled.h b/Example/E07_encoder_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_tft180.c b/Example/E07_encoder_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E07_encoder_demo/libraries/zf_device/zf_device_tft180.h b/Example/E07_encoder_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E07_encoder_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E07_encoder_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E07_encoder_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E07_encoder_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E07_encoder_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E07_encoder_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E07_encoder_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E07_encoder_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E07_encoder_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E07_encoder_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E08_eeprom_demo/libraries/doc/version.txt b/Example/E08_eeprom_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E08_eeprom_demo/libraries/doc/version.txt +++ b/Example/E08_eeprom_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E08_eeprom_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E08_eeprom_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E08_eeprom_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E08_eeprom_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E08_eeprom_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E08_eeprom_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E08_eeprom_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E08_eeprom_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E08_eeprom_demo/libraries/zf_common/zf_common_headfile.h b/Example/E08_eeprom_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E08_eeprom_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E08_eeprom_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips114.c b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips114.h b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips200.c b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips200.h b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_oled.c b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_oled.h b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_tft180.c b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_tft180.h b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E08_eeprom_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E08_eeprom_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E08_eeprom_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E08_eeprom_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E08_eeprom_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E08_eeprom_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E08_eeprom_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E08_eeprom_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E08_eeprom_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E08_eeprom_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E09_timer_demo/libraries/doc/version.txt b/Example/E09_timer_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E09_timer_demo/libraries/doc/version.txt +++ b/Example/E09_timer_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E09_timer_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E09_timer_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E09_timer_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E09_timer_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E09_timer_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E09_timer_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E09_timer_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E09_timer_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E09_timer_demo/libraries/zf_common/zf_common_headfile.h b/Example/E09_timer_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E09_timer_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E09_timer_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E09_timer_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_ips114.c b/Example/E09_timer_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_ips114.h b/Example/E09_timer_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_ips200.c b/Example/E09_timer_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_ips200.h b/Example/E09_timer_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_oled.c b/Example/E09_timer_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_oled.h b/Example/E09_timer_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_tft180.c b/Example/E09_timer_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E09_timer_demo/libraries/zf_device/zf_device_tft180.h b/Example/E09_timer_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E09_timer_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E09_timer_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E09_timer_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E09_timer_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E09_timer_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E09_timer_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E09_timer_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E09_timer_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E09_timer_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E09_timer_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E10_printf_debug_log_demo/libraries/doc/version.txt b/Example/E10_printf_debug_log_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E10_printf_debug_log_demo/libraries/doc/version.txt +++ b/Example/E10_printf_debug_log_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E10_printf_debug_log_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E10_printf_debug_log_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E10_printf_debug_log_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E10_printf_debug_log_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E10_printf_debug_log_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E10_printf_debug_log_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E10_printf_debug_log_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E10_printf_debug_log_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_common/zf_common_headfile.h b/Example/E10_printf_debug_log_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E10_printf_debug_log_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips114.c b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips114.h b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips200.c b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips200.h b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_oled.c b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_oled.h b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_tft180.c b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_tft180.h b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E10_printf_debug_log_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E10_printf_debug_log_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E10_printf_debug_log_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E10_printf_debug_log_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E10_printf_debug_log_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E10_printf_debug_log_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E10_printf_debug_log_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E11_interrupt_priority_set_demo/libraries/doc/version.txt b/Example/E11_interrupt_priority_set_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/doc/version.txt +++ b/Example/E11_interrupt_priority_set_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E11_interrupt_priority_set_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E11_interrupt_priority_set_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E11_interrupt_priority_set_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E11_interrupt_priority_set_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E11_interrupt_priority_set_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E11_interrupt_priority_set_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_common/zf_common_headfile.h b/Example/E11_interrupt_priority_set_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips114.c b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips114.h b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips200.c b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips200.h b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_oled.c b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_oled.h b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_tft180.c b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_tft180.h b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E11_interrupt_priority_set_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E11_interrupt_priority_set_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E11_interrupt_priority_set_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E11_interrupt_priority_set_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E11_interrupt_priority_set_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/doc/version.txt b/Example/E12_cpu1_handles_interrupts_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/doc/version.txt +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E12_cpu1_handles_interrupts_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E12_cpu1_handles_interrupts_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_common/zf_common_headfile.h b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips114.c b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips114.h b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips200.c b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips200.h b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_oled.c b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_oled.h b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_tft180.c b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_tft180.h b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E12_cpu1_handles_interrupts_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E13_dual_core_demo/libraries/doc/version.txt b/Example/E13_dual_core_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E13_dual_core_demo/libraries/doc/version.txt +++ b/Example/E13_dual_core_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E13_dual_core_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E13_dual_core_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E13_dual_core_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E13_dual_core_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E13_dual_core_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E13_dual_core_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E13_dual_core_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E13_dual_core_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E13_dual_core_demo/libraries/zf_common/zf_common_headfile.h b/Example/E13_dual_core_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E13_dual_core_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E13_dual_core_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips114.c b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips114.h b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips200.c b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips200.h b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_oled.c b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_oled.h b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_tft180.c b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_tft180.h b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E13_dual_core_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E13_dual_core_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E13_dual_core_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E13_dual_core_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E13_dual_core_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E13_dual_core_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E13_dual_core_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E13_dual_core_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E13_dual_core_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E13_dual_core_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/doc/version.txt b/Example/E14_specifies_variable_or_code_location_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/doc/version.txt +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E14_specifies_variable_or_code_location_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E14_specifies_variable_or_code_location_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_common/zf_common_headfile.h b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips114.c b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips114.h b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips200.c b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips200.h b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_oled.c b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_oled.h b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_tft180.c b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_tft180.h b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E14_specifies_variable_or_code_location_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Example/E15_fft_demo/libraries/doc/version.txt b/Example/E15_fft_demo/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Example/E15_fft_demo/libraries/doc/version.txt +++ b/Example/E15_fft_demo/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Example/E15_fft_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Example/E15_fft_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Example/E15_fft_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Example/E15_fft_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Example/E15_fft_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Example/E15_fft_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Example/E15_fft_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Example/E15_fft_demo/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Example/E15_fft_demo/libraries/zf_common/zf_common_headfile.h b/Example/E15_fft_demo/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Example/E15_fft_demo/libraries/zf_common/zf_common_headfile.h +++ b/Example/E15_fft_demo/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Example/E15_fft_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_ips114.c b/Example/E15_fft_demo/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_ips114.c +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_ips114.h b/Example/E15_fft_demo/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_ips114.h +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_ips200.c b/Example/E15_fft_demo/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_ips200.c +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_ips200.h b/Example/E15_fft_demo/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_ips200.h +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_oled.c b/Example/E15_fft_demo/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_oled.c +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_oled.h b/Example/E15_fft_demo/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_oled.h +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_tft180.c b/Example/E15_fft_demo/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_tft180.c +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Example/E15_fft_demo/libraries/zf_device/zf_device_tft180.h b/Example/E15_fft_demo/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Example/E15_fft_demo/libraries/zf_device/zf_device_tft180.h +++ b/Example/E15_fft_demo/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Example/E15_fft_demo/libraries/zf_driver/zf_driver_uart.c b/Example/E15_fft_demo/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Example/E15_fft_demo/libraries/zf_driver/zf_driver_uart.c +++ b/Example/E15_fft_demo/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Example/E15_fft_demo/libraries/zf_driver/zf_driver_uart.h b/Example/E15_fft_demo/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Example/E15_fft_demo/libraries/zf_driver/zf_driver_uart.h +++ b/Example/E15_fft_demo/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt b/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt index 448f50f..b91dce5 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt +++ b/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.2.3 + 优化所有SPI通信屏幕(OLED除外)的通信方式,显示速率将提升一倍左右 + 修改串口的默认通信方式 V3.2.2 pit初始化新增调试状态检测,防止出现权限问题引起的总线报错 V3.2.1 diff --git a/Seekfree_TC264_Opensource_Library/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c b/Seekfree_TC264_Opensource_Library/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c index 9b07aa5..2f92e0d 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c +++ b/Seekfree_TC264_Opensource_Library/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.c @@ -402,7 +402,7 @@ uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 count) } -uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count) +uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin,const uint8 *data, uint32 count) { volatile Ifx_ASCLIN_TXDATA *txData = (volatile Ifx_ASCLIN_TXDATA *)&asclin->TXDATA.U; diff --git a/Seekfree_TC264_Opensource_Library/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h b/Seekfree_TC264_Opensource_Library/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h index 99cf4b6..f753a46 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h +++ b/Seekfree_TC264_Opensource_Library/libraries/infineon_libraries/iLLD/TC26B/Tricore/Asclin/Std/IfxAsclin.h @@ -1493,7 +1493,7 @@ IFX_EXTERN uint32 IfxAsclin_write32(Ifx_ASCLIN *asclin, uint32 *data, uint32 cou * \param count number of items to be send * \return the number of items that could not be send */ -IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, uint8 *data, uint32 count); +IFX_EXTERN uint32 IfxAsclin_write8(Ifx_ASCLIN *asclin, const uint8 *data, uint32 count); /** \} */ diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_common/zf_common_headfile.h b/Seekfree_TC264_Opensource_Library/libraries/zf_common/zf_common_headfile.h index 8ac338d..a048cbc 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_common/zf_common_headfile.h +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_common/zf_common_headfile.h @@ -107,6 +107,9 @@ #include "zf_device_wireless_uart.h" //===================================================外接设备驱动层=================================================== +//=====================================================用户层====================================================== + +//=====================================================用户层====================================================== #endif diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_bluetooth_ch9141.c b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_bluetooth_ch9141.c index af4562f..e61a3fd 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_bluetooth_ch9141.c +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_bluetooth_ch9141.c @@ -73,7 +73,7 @@ uint32 bluetooth_ch9141_send_byte (const uint8 data) { if(!gpio_get_level(BLUETOOTH_CH9141_RTS_PIN)) { - uart_write_byte_wait(BLUETOOTH_CH9141_INDEX, data); // 发送数据 + uart_write_byte(BLUETOOTH_CH9141_INDEX, data); // 发送数据 break; } time_count --; diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips114.c b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips114.c index 2182882..aa2f6bd 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips114.c +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips114.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -57,33 +58,53 @@ #include "zf_driver_spi.h" #include "zf_device_ips114.h" + uint16 ips114_width_max = 240; + uint16 ips114_height_max = 135; static uint16 ips114_pencolor = IPS114_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips114_bgcolor = IPS114_DEFAULT_BGCOLOR; // 背景颜色 static ips114_dir_enum ips114_display_dir = IPS114_DEFAULT_DISPLAY_DIR; // 显示方向 static ips114_font_size_enum ips114_display_font = IPS114_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint8 ips114_x_max = 240; // 屏幕X轴像素最大值 -static uint8 ips114_y_max = 135; // 屏幕Y轴像素最大值 #if IPS114_USE_SOFT_SPI static soft_spi_info_struct ips114_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 8bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) +#define ips114_write_8bit_data(data) (soft_spi_write_8bit(&ips114_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 IPS114 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (soft_spi_write_8bit(&ips114_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) +#define ips114_write_16bit_data(data) (soft_spi_write_16bit(&ips114_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&ips114_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 8bit 数据 @@ -92,7 +113,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) +#define ips114_write_8bit_data(data) (spi_write_8bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_8bit_data_array(data, len) (spi_write_8bit_array(IPS114_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 SPI 写 16bit 数据 @@ -101,7 +132,17 @@ static soft_spi_info_struct ips114_spi; // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) +#define ips114_write_16bit_data(data) (spi_write_16bit(IPS114_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS114 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips114_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips114_write_16bit_data_array(data, len) (spi_write_16bit_array(IPS114_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +166,7 @@ static void ips114_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); +// 使用示例 ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2, const uint16 y2) @@ -133,34 +174,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips114_x_max); - zf_assert(y1 < ips114_y_max); - zf_assert(x2 < ips114_x_max); - zf_assert(y2 < ips114_y_max); + zf_assert(x1 < ips114_width_max); + zf_assert(y1 < ips114_height_max); + zf_assert(x2 < ips114_width_max); + zf_assert(y2 < ips114_height_max); switch(ips114_display_dir) { case IPS114_PORTAIT: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 52); - ips114_write_16bit_data(x2 + 52); + ips114_write_16bit_data(x1 + 40); + ips114_write_16bit_data(x2 + 40); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); + ips114_write_16bit_data(y1 + 52); + ips114_write_16bit_data(y2 + 52); ips114_write_index(0x2c); // 储存器写 }break; case IPS114_PORTAIT_180: - { - ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 53); - ips114_write_16bit_data(x2 + 53); - ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 40); - ips114_write_16bit_data(y2 + 40); - ips114_write_index(0x2c); // 储存器写 - }break; - case IPS114_CROSSWISE: { ips114_write_index(0x2a); // 列地址设置 ips114_write_16bit_data(x1 + 40); @@ -170,14 +201,24 @@ static void ips114_set_region (const uint16 x1, const uint16 y1, const uint16 x2 ips114_write_16bit_data(y2 + 53); ips114_write_index(0x2c); // 储存器写 }break; + case IPS114_CROSSWISE: + { + ips114_write_index(0x2a); // 列地址设置 + ips114_write_16bit_data(x1 + 52); + ips114_write_16bit_data(x2 + 52); + ips114_write_index(0x2b); // 行地址设置 + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); + ips114_write_index(0x2c); // 储存器写 + }break; case IPS114_CROSSWISE_180: { ips114_write_index(0x2a); // 列地址设置 - ips114_write_16bit_data(x1 + 40); - ips114_write_16bit_data(x2 + 40); + ips114_write_16bit_data(x1 + 53); + ips114_write_16bit_data(x2 + 53); ips114_write_index(0x2b); // 行地址设置 - ips114_write_16bit_data(y1 + 52); - ips114_write_16bit_data(y2 + 52); + ips114_write_16bit_data(y1 + 40); + ips114_write_16bit_data(y2 + 40); ips114_write_index(0x2c); // 储存器写 }break; } @@ -196,8 +237,8 @@ static void ips114_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips114_x_max; - info.display_y_max = ips114_y_max; + info.display_x_max = ips114_width_max; + info.display_y_max = ips114_height_max; switch(ips114_display_font) { @@ -231,13 +272,18 @@ static void ips114_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips114_clear (void) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + color_buffer[i] = ips114_bgcolor; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -251,13 +297,18 @@ void ips114_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips114_full (const uint16 color) { - uint32 i = ips114_x_max * ips114_y_max; + uint16 color_buffer[ips114_width_max]; + uint32 i = 0, j = 0; IPS114_CS(0); - ips114_set_region(0, 0, ips114_x_max - 1, ips114_y_max - 1); - for( ; 0 < i; i --) + ips114_set_region(0, 0, ips114_width_max - 1, ips114_height_max - 1); + for(i = 0; i < ips114_width_max; i ++) { - ips114_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < ips114_height_max; j ++) + { + ips114_write_16bit_data_array(color_buffer, ips114_width_max); } IPS114_CS(1); } @@ -277,14 +328,14 @@ void ips114_set_dir (ips114_dir_enum dir) case IPS114_PORTAIT: case IPS114_PORTAIT_180: { - ips114_x_max = 135; - ips114_y_max = 240; + ips114_width_max = 240; + ips114_height_max = 135; }break; case IPS114_CROSSWISE: case IPS114_CROSSWISE_180: { - ips114_x_max = 240; - ips114_y_max = 135; + ips114_width_max = 135; + ips114_height_max = 240; }break; } } @@ -317,8 +368,8 @@ void ips114_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips114_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -328,8 +379,8 @@ void ips114_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); IPS114_CS(0); ips114_set_region(x, y, x, y); @@ -352,10 +403,10 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips114_x_max); - zf_assert(y_start < ips114_y_max); - zf_assert(x_end < ips114_x_max); - zf_assert(y_end < ips114_y_max); + zf_assert(x_start < ips114_width_max); + zf_assert(y_start < ips114_height_max); + zf_assert(x_end < ips114_width_max); + zf_assert(y_end < ips114_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -376,6 +427,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips114_draw_point(x_start, y_start, color); y_start += y_dir; } + ips114_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -386,6 +438,7 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips114_draw_point(x_start, y_start, color); } else { @@ -395,14 +448,15 @@ void ips114_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips114_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips114_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -412,8 +466,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint8 i = 0, j = 0; @@ -422,42 +476,44 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { case IPS114_6X8_FONT: { + uint16 display_buffer[6*8]; + ips114_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 6] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 6] = (ips114_bgcolor); } temp_top >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 6*8); }break; case IPS114_8X16_FONT: { + uint16 display_buffer[8*16]; + ips114_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips114_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8] = (ips114_bgcolor); } temp_top >>= 1; } @@ -465,15 +521,16 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips114_write_16bit_data(ips114_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_pencolor); } else { - ips114_write_16bit_data(ips114_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips114_bgcolor); } temp_bottom >>= 1; } } + ips114_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS114_16X16_FONT: { @@ -485,8 +542,8 @@ void ips114_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips114_show_string(0, 0, "seekfree"); @@ -496,8 +553,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); uint16 j = 0; while('\0' != dat[j]) @@ -514,8 +571,8 @@ void ips114_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -526,8 +583,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -553,8 +610,8 @@ void ips114_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -565,8 +622,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -591,8 +648,8 @@ void ips114_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示浮点数 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -607,8 +664,8 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -632,13 +689,13 @@ void ips114_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -650,46 +707,49 @@ void ips114_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips114_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -702,53 +762,54 @@ void ips114_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips114_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips114_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips114_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips114_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips114_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -761,29 +822,31 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; IPS114_CS(0); - ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 + ips114_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips114_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips114_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips114_write_16bit_data_array(data_buffer, dis_width); } } IPS114_CS(1); @@ -791,13 +854,13 @@ void ips114_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS114 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips114_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips114_height_max] // 返回参数 void // 使用示例 ips114_show_wave(56,35,data,128,64,128,64); // 备注信息 @@ -806,21 +869,23 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; IPS114_CS(0); ips114_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips114_write_16bit_data(ips114_bgcolor); + data_buffer[i] = (ips114_bgcolor); } + ips114_write_16bit_data_array(data_buffer, dis_width); } IPS114_CS(1); @@ -834,8 +899,8 @@ void ips114_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips114_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips114_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -848,8 +913,8 @@ void ips114_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips114_x_max); - zf_assert(y < ips114_y_max); + zf_assert(x < ips114_width_max); + zf_assert(y < ips114_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -923,10 +988,10 @@ void ips114_init (void) system_delay_ms(100); switch(ips114_display_dir) { - case IPS114_PORTAIT: ips114_write_8bit_data(0x00); break; - case IPS114_PORTAIT_180: ips114_write_8bit_data(0xC0); break; - case IPS114_CROSSWISE: ips114_write_8bit_data(0x70); break; - case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT: ips114_write_8bit_data(0xA0); break; + case IPS114_PORTAIT_180: ips114_write_8bit_data(0x70); break; + case IPS114_CROSSWISE: ips114_write_8bit_data(0x00); break; + case IPS114_CROSSWISE_180: ips114_write_8bit_data(0xC0); break; } ips114_write_index(0x3A); diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips114.h b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips114.h index 178dbc3..81dfc3c 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips114.h +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips114.h @@ -77,7 +77,7 @@ #define IPS114_CS_PIN (P15_2) // CS 片选引脚 #define IPS114_BLK_PIN (P15_4) // 液晶背光引脚定义 -#define IPS114_DEFAULT_DISPLAY_DIR (IPS114_CROSSWISE_180) // 默认的显示方向 +#define IPS114_DEFAULT_DISPLAY_DIR ( IPS114_PORTAIT ) // 默认的显示方向 #define IPS114_DEFAULT_PENCOLOR (RGB565_RED) // 默认的画笔颜色 #define IPS114_DEFAULT_BGCOLOR (RGB565_WHITE) // 默认的背景颜色 #define IPS114_DEFAULT_DISPLAY_FONT (IPS114_8X16_FONT) // 默认的字体模式 @@ -104,8 +104,11 @@ typedef enum IPS114_8X16_FONT = 1, // 8x16 字体 IPS114_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips114_font_size_enum; -//=================================================定义 IPS114 参数结构体=============================================== +extern uint16 ips114_width_max ; +extern uint16 ips114_height_max; + +//=================================================定义 IPS114 参数结构体=============================================== //=================================================声明 IPS114 基础函数================================================ void ips114_clear (void); // IPS114 清屏函数 diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips200.c b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips200.c index 722d665..cd8681f 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips200.c +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips200.c @@ -32,6 +32,7 @@ * 日期 作者 备注 * 2022-09-15 pudding first version * 2023-04-28 pudding 增加中文注释说明 +* 2023-10-07 pudding SPI串口屏 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /******************************************************************************************************************** * 接线定义: @@ -70,16 +71,13 @@ #include "zf_driver_spi.h" #include "zf_device_ips200.h" - - -static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; // 定义通信类型,默认SPI单排针 - + uint16 ips200_width_max = 240; + uint16 ips200_height_max = 320; static uint16 ips200_pencolor = IPS200_DEFAULT_PENCOLOR; // 画笔颜色(字体色) static uint16 ips200_bgcolor = IPS200_DEFAULT_BGCOLOR; // 背景颜色 +static ips200_type_enum ips200_display_type = IPS200_TYPE_SPI; static ips200_dir_enum ips200_display_dir = IPS200_DEFAULT_DISPLAY_DIR; // 显示方向 static ips200_font_size_enum ips200_display_font = IPS200_DEFAULT_DISPLAY_FONT; // 显示字体类型 -static uint16 ips200_x_max = 240; // 屏幕X轴像素最大值 -static uint16 ips200_y_max = 320; // 屏幕Y轴像素最大值 static gpio_pin_enum ips_rst_pin = IPS200_RST_PIN_SPI; // 定义复位所用引脚 static gpio_pin_enum ips_bl_pin = IPS200_BLk_PIN_SPI; // 定义背光所用引脚 @@ -88,22 +86,42 @@ static gpio_pin_enum ips_cs_pin = IPS200_CS_PIN_SPI; #if IPS200_USE_SOFT_SPI static soft_spi_info_struct ips200_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 8bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) +#define ips200_write_8bit_data_spi(data) (soft_spi_write_8bit(&ips200_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 SPI 写 16bit 数据 +// 函数简介 IPS200 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (soft_spi_write_8bit_array(&ips200_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) +#define ips200_write_16bit_data_spi(data) (soft_spi_write_16bit(&ips200_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (soft_spi_write_16bit_array(&ips200_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 8bit 数据 @@ -112,7 +130,17 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_8bit_data_spi(command); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) +#define ips200_write_8bit_data_spi(data) (spi_write_8bit(IPS200_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_8bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_8bit_data_spi_array(data, len) (spi_write_8bit_array(IPS200_SPI, (data), (len))) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 SPI 写 16bit 数据 @@ -121,15 +149,24 @@ static soft_spi_info_struct ips200_spi; // 使用示例 ips200_write_16bit_data_spi(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +#define ips200_write_16bit_data_spi(data) (spi_write_16bit(IPS200_SPI, (data))) +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 ips200_write_16bit_data_spi_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define ips200_write_16bit_data_spi_array(data, len) (spi_write_16bit_array(IPS200_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- -// 函数简介 内部调用,用户无需关心 -// 参数说明 dat 数据 -// @return -// @since v1.0 -// Sample usage: +// 函数简介 IPS200 并行写数据 +// 参数说明 data 数据 +// 返回参数 void +// 使用示例 ips200_write_data(data); +// 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_data(uint8 dat) { @@ -139,10 +176,11 @@ static void ips200_write_data(uint8 dat) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 写命令 内部调用 -// 参数说明 command 命令 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 写命令 +// 参数说明 command 命令 +// 返回参数 void +// 使用示例 ips200_write_command(0x2a); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_command (const uint8 command) { @@ -161,14 +199,16 @@ static void ips200_write_command (const uint8 command) ips200_write_data(command); IPS200_WR(1); IPS200_CS(1); + IPS200_RS(1); } } //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 8bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_write_8bit_data (const uint8 dat) { @@ -179,7 +219,6 @@ static void ips200_write_8bit_data (const uint8 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data(dat); @@ -187,12 +226,41 @@ static void ips200_write_8bit_data (const uint8 dat) IPS200_CS(1); } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 8bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_8bit_data(0x0C); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_8bit_data_array (const uint8 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_8bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)*dat); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} + //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS200 向液晶屏写 16bit 数据 内部调用 -// 参数说明 dat 数据 -// @return void -// 备注信息 内部调用 用户无需关心 +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- void ips200_write_16bit_data (const uint16 dat) { @@ -203,7 +271,6 @@ void ips200_write_16bit_data (const uint16 dat) else { IPS200_CS(0); - IPS200_RS(1); IPS200_RD(1); IPS200_WR(0); ips200_write_data((uint8)(dat >> 8)); @@ -215,6 +282,36 @@ void ips200_write_16bit_data (const uint16 dat) } } +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 IPS200 向液晶屏写 16bit 数据 +// 参数说明 dat 数据 +// 返回参数 void +// 使用示例 ips200_write_16bit_data(x1); +// 备注信息 内部调用 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +static void ips200_write_16bit_data_array (const uint16 *dat, uint32 len) +{ + if(IPS200_TYPE_SPI == ips200_display_type) + { + ips200_write_16bit_data_spi_array(dat, len); + } + else + { + IPS200_CS(0); + IPS200_RD(1); + while(len --) + { + IPS200_WR(0); + ips200_write_data((uint8)(*dat >> 8)); + IPS200_WR(1); + IPS200_WR(0); + ips200_write_data((uint8)(*dat & 0xFF)); + IPS200_WR(1); + dat ++; + } + IPS200_CS(1); + } +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 设置显示区域 // 参数说明 x1 起始x轴坐标 @@ -222,7 +319,7 @@ void ips200_write_16bit_data (const uint16 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); +// 使用示例 ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); // 备注信息 内部调用 用户无需关心 //------------------------------------------------------------------------------------------------------------------- static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -230,19 +327,19 @@ static void ips200_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < ips200_x_max); - zf_assert(y1 < ips200_y_max); - zf_assert(x2 < ips200_x_max); - zf_assert(y2 < ips200_y_max); + zf_assert(x1 < ips200_width_max); + zf_assert(y1 < ips200_height_max); + zf_assert(x2 < ips200_width_max); + zf_assert(y2 < ips200_height_max); ips200_write_command(0x2a); ips200_write_16bit_data(x1); ips200_write_16bit_data(x2); - + ips200_write_command(0x2b); ips200_write_16bit_data(y1); ips200_write_16bit_data(y2); - + ips200_write_command(0x2c); } @@ -259,26 +356,29 @@ static void ips200_debug_init (void) debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = ips200_x_max; - info.display_y_max = ips200_y_max; + info.display_x_max = ips200_width_max; + info.display_y_max = ips200_height_max; switch(ips200_display_font) { case IPS200_6X8_FONT: + { info.font_x_size = 6; info.font_y_size = 8; - break; + }break; case IPS200_8X16_FONT: + { info.font_x_size = 8; info.font_y_size = 16; - break; + }break; case IPS200_16X16_FONT: + { // 暂不支持 - break; + }break; } info.output_screen = ips200_show_string; info.output_screen_clear = ips200_clear; - + debug_output_init(&info); } @@ -291,18 +391,21 @@ static void ips200_debug_init (void) //------------------------------------------------------------------------------------------------------------------- void ips200_clear (void) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(ips200_bgcolor); - } + color_buffer[i] = ips200_bgcolor; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -319,18 +422,21 @@ void ips200_clear (void) //------------------------------------------------------------------------------------------------------------------- void ips200_full (const uint16 color) { + uint16 color_buffer[ips200_width_max]; uint16 i = 0, j = 0; + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } - ips200_set_region(0, 0, ips200_x_max - 1, ips200_y_max - 1); - for(i = 0; i < ips200_x_max; i ++) + ips200_set_region(0, 0, ips200_width_max - 1, ips200_height_max - 1); + for(i = 0; i < ips200_width_max; i ++) { - for (j = 0; j < ips200_y_max; j ++) - { - ips200_write_16bit_data(color); - } + color_buffer[i] = color; + } + for (j = 0; j < ips200_height_max; j ++) + { + ips200_write_16bit_data_array(color_buffer, ips200_width_max); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -353,14 +459,14 @@ void ips200_set_dir (ips200_dir_enum dir) case IPS200_PORTAIT: case IPS200_PORTAIT_180: { - ips200_x_max = 240; - ips200_y_max = 320; + ips200_width_max = 240; + ips200_height_max = 320; }break; case IPS200_CROSSWISE: case IPS200_CROSSWISE_180: { - ips200_x_max = 320; - ips200_y_max = 240; + ips200_width_max = 320; + ips200_height_max = 240; }break; } } @@ -393,19 +499,19 @@ void ips200_set_color (const uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画点 -// 参数说明 x 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_point(0, 0, RGB565_RED); //坐标0,0画一个红色的点 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); if(IPS200_TYPE_SPI == ips200_display_type) { @@ -421,23 +527,23 @@ void ips200_draw_point (uint16 x, uint16 y, const uint16 color) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 画线 -// 参数说明 x_start 坐标x方向的起点 [0, ips200_x_max-1] -// 参数说明 y_start 坐标y方向的起点 [0, ips200_y_max-1] -// 参数说明 x_end 坐标x方向的终点 [0, ips200_x_max-1] -// 参数说明 y_end 坐标y方向的终点 [0, ips200_y_max-1] +// 参数说明 x_start 坐标x方向的起点 [0, ips200_width_max-1] +// 参数说明 y_start 坐标y方向的起点 [0, ips200_height_max-1] +// 参数说明 x_end 坐标x方向的终点 [0, ips200_width_max-1] +// 参数说明 y_end 坐标y方向的终点 [0, ips200_height_max-1] // 参数说明 color 颜色格式 RGB565 或者可以使用 zf_common_font.h 内 rgb565_color_enum 枚举值或者自行写入 // 返回参数 void // 使用示例 ips200_draw_line(0, 0, 10, 10, RGB565_RED); // 坐标 0,0 到 10,10 画一条红色的线 -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_end, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < ips200_x_max); - zf_assert(y_start < ips200_y_max); - zf_assert(x_end < ips200_x_max); - zf_assert(y_end < ips200_y_max); + zf_assert(x_start < ips200_width_max); + zf_assert(y_start < ips200_height_max); + zf_assert(x_end < ips200_width_max); + zf_assert(y_end < ips200_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); @@ -458,6 +564,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en ips200_draw_point(x_start, y_start, color); y_start += y_dir; } + ips200_draw_point(x_start, y_start, color); break; } if(func_abs(y_start - y_end) > func_abs(x_start - x_end)) @@ -468,6 +575,7 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + ips200_draw_point(x_start, y_start, color); } else { @@ -477,25 +585,26 @@ void ips200_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + ips200_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 ips200_show_char(0, 0, 'x'); // 坐标0,0写一个字符x -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); uint8 i = 0, j = 0; @@ -507,42 +616,44 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { case IPS200_6X8_FONT: { + uint16 display_buffer[6*8]; + ips200_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 6] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 6] = (ips200_bgcolor); } temp_top >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 6*8); }break; case IPS200_8X16_FONT: { + uint16 display_buffer[8*16]; + ips200_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - ips200_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8] = (ips200_bgcolor); } temp_top >>= 1; } @@ -550,15 +661,16 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - ips200_write_16bit_data(ips200_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_pencolor); } else { - ips200_write_16bit_data(ips200_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (ips200_bgcolor); } temp_bottom >>= 1; } } + ips200_write_16bit_data_array(display_buffer, 8 * 16); }break; case IPS200_16X16_FONT: { @@ -573,20 +685,20 @@ void ips200_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 ips200_show_string(0, 0, "seekfree"); -// 备注信息 +// 备注信息 //------------------------------------------------------------------------------------------------------------------- void ips200_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); - + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -602,8 +714,8 @@ void ips200_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -614,8 +726,8 @@ void ips200_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -653,8 +765,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -679,8 +791,8 @@ void ips200_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 double // 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 @@ -695,8 +807,8 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -720,13 +832,13 @@ void ips200_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W, OV7725_H); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -738,13 +850,15 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -754,20 +868,21 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -777,13 +892,13 @@ void ips200_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 ips200_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); @@ -796,13 +911,14 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -812,27 +928,27 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - ips200_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - ips200_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - ips200_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -842,13 +958,13 @@ void ips200_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, ips200_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 ips200_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W, SCC8660_H, 1); @@ -861,13 +977,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; if(IPS200_TYPE_SPI == ips200_display_type) { @@ -877,16 +993,18 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - ips200_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + ips200_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + ips200_write_16bit_data_array(data_buffer, dis_width); } } if(IPS200_TYPE_SPI == ips200_display_type) @@ -897,13 +1015,13 @@ void ips200_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 IPS200 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, ips200_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, ips200_height_max] // 返回参数 void // 使用示例 ips200_show_wave(0, 0, data, 128, 64, 64, 32); // 备注信息 @@ -912,24 +1030,26 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); } ips200_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - ips200_write_16bit_data(ips200_bgcolor); + data_buffer[i] = (ips200_bgcolor); } + ips200_write_16bit_data_array(data_buffer, dis_width); } if(IPS200_TYPE_SPI == ips200_display_type) { @@ -946,8 +1066,8 @@ void ips200_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, ips200_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, ips200_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -960,8 +1080,8 @@ void ips200_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < ips200_x_max); - zf_assert(y < ips200_y_max); + zf_assert(x < ips200_width_max); + zf_assert(y < ips200_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; @@ -1068,6 +1188,7 @@ void ips200_init (ips200_type_enum type_select) system_delay_ms(5); IPS200_RST(1); system_delay_ms(120); + if(IPS200_TYPE_SPI == ips200_display_type) { IPS200_CS(0); @@ -1086,7 +1207,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0x3A); ips200_write_8bit_data(0x05); - + ips200_write_command(0xB2); ips200_write_8bit_data(0x0C); ips200_write_8bit_data(0x0C); @@ -1104,7 +1225,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x01); ips200_write_command(0xC3); - ips200_write_8bit_data(0x19); // GVDD=4.8V + ips200_write_8bit_data(0x19); // GVDD=4.8V ips200_write_command(0xC4); ips200_write_8bit_data(0x20); // VDV, 0x20:0v @@ -1118,7 +1239,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_command(0xD0); ips200_write_8bit_data(0xA4); ips200_write_8bit_data(0xA1); - + ips200_write_command(0xE0); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); @@ -1135,7 +1256,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x31); ips200_write_8bit_data(0x34); - ips200_write_command(0xE1); + ips200_write_command(0xE1); ips200_write_8bit_data(0xD0); ips200_write_8bit_data(0x08); ips200_write_8bit_data(0x0E); @@ -1152,7 +1273,7 @@ void ips200_init (ips200_type_enum type_select) ips200_write_8bit_data(0x34); ips200_write_command(0x21); - + ips200_write_command(0x29); if(IPS200_TYPE_SPI == ips200_display_type) { diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips200.h b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips200.h index cc4cdf8..ce59927 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips200.h +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_ips200.h @@ -157,8 +157,11 @@ typedef enum IPS200_8X16_FONT = 1, // 8x16 字体 IPS200_16X16_FONT = 2, // 16x16 字体 目前不支持 }ips200_font_size_enum; -//==================================================定义 IPS200 参数结构体=============================================== +extern uint16 ips200_width_max; +extern uint16 ips200_height_max; + +//==================================================定义 IPS200 参数结构体=============================================== //==================================================声明 IPS200 基础函数================================================ void ips200_clear (void); // IPS200 清屏函数 @@ -213,7 +216,7 @@ void ips200_init (ips200_type_enum type_select); // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 // 返回参数 void -// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_W); +// 使用示例 ips200_displayimage8660(scc8660_image[0], SCC8660_W, SCC8660_H); // 备注信息 拓展的一键显示函数,默认无缩放,从屏幕坐标起始点开始显示 //------------------------------------------------------------------------------------------------------------------- #define ips200_displayimage8660(p, width, height) (ips200_show_rgb565_image(0, 0, (p), SCC8660_W, SCC8660_H, (width), (height), 1)) diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_oled.c b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_oled.c index d4a9e35..5314209 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_oled.c +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_oled.c @@ -725,7 +725,7 @@ void oled_init (void) oled_write_command(0x81); // 设置对比度控制寄存器 oled_write_command(OLED_BRIGHTNESS); // 设置SEG输出电流亮度 - if(OLED_CROSSWISE == oled_display_dir) + if(OLED_PORTAIT == oled_display_dir) { oled_write_command(0xa1); // 设置 SEG/列 映射 0xa0左右反置 0xa1正常 oled_write_command(0xc8); // 设置 COM/行扫描方向 0xc0上下反置 0xc8正常 diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_oled.h b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_oled.h index e641410..d52d2fd 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_oled.h +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_oled.h @@ -50,7 +50,7 @@ #ifndef _zf_device_oled_h_ #define _zf_device_oled_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //===================================================定义 OLED 基本配置================================================= #define OLED_USE_SOFT_SPI (0 ) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -75,7 +75,7 @@ #define OLED_DC_PIN (P15_0 ) // 液晶命令位引脚定义 #define OLED_CS_PIN (P15_2 ) // CS 片选引脚 #define OLED_BRIGHTNESS (0x7f) // 设置OLED亮度 越大越亮 范围0-0XFF -#define OLED_DEFAULT_DISPLAY_DIR (OLED_CROSSWISE) // 默认的显示方向 +#define OLED_DEFAULT_DISPLAY_DIR ( OLED_PORTAIT ) // 默认的显示方向 #define OLED_DEFAULT_DISPLAY_FONT (OLED_6X8_FONT ) // 默认的字体模式 #define OLED_X_MAX (128) // 屏幕X轴像素最大值 #define OLED_Y_MAX (64 ) // 屏幕Y轴像素最大值 @@ -89,8 +89,8 @@ //===================================================定义 OLED 参数结构体================================================= typedef enum { - OLED_CROSSWISE = 0, // 横屏模式 - OLED_CROSSWISE_180 = 1, // 横屏模式 旋转180 + OLED_PORTAIT = 0, // 竖屏模式 + OLED_PORTAIT_180 = 1, // 竖屏模式 旋转180 }oled_dir_enum; typedef enum diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_tft180.c b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_tft180.c index a0d7378..db50824 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_tft180.c +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_tft180.c @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 修改数据传输方式,性能提升一倍左右 ********************************************************************************************************************/ /********************************************************************************************************************* * 接线定义: @@ -56,34 +57,53 @@ #include "zf_driver_spi.h" #include "zf_device_tft180.h" -static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) -static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 + uint16 tft180_width_max = 160; + uint16 tft180_height_max = 128; +static uint16 tft180_pencolor = TFT180_DEFAULT_PENCOLOR; // 画笔颜色(字体色) +static uint16 tft180_bgcolor = TFT180_DEFAULT_BGCOLOR; // 背景颜色 -static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 -static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 - -static uint8 tft180_x_max = 160; // 屏幕X轴像素最大值 -static uint8 tft180_y_max = 128; // 屏幕Y轴像素最大值 +static tft180_dir_enum tft180_display_dir = TFT180_DEFAULT_DISPLAY_DIR; // 显示方向 +static tft180_font_size_enum tft180_display_font = TFT180_DEFAULT_DISPLAY_FONT; // 显示字体类型 #if TFT180_USE_SOFT_SPI static soft_spi_info_struct tft180_spi; //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 8bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) +#define tft180_write_8bit_data(data) (soft_spi_write_8bit(&tft180_spi, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 TFT180 SPI 写 16bit 数据 +// 函数简介 TFT180 软件 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (soft_spi_write_8bit_array(&tft180_spi, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 tft180_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) +#define tft180_write_16bit_data(data) (soft_spi_write_16bit(&tft180_spi, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 软件 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (soft_spi_write_16bit_array(&tft180_spi, (data), (len))) #else //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 SPI 写 8bit 数据 @@ -92,16 +112,36 @@ static soft_spi_info_struct tft180_spi; // 使用示例 tft180_write_8bit_data(dat); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) +#define tft180_write_8bit_data(data) (spi_write_8bit(TFT180_SPI, (data))) //------------------------------------------------------------------------------------------------------------------- -// 函数简介 IPS114 SPI 写 16bit 数据 +// 函数简介 TFT180 SPI 写 8bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_8bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_8bit_data_array(data, len) (spi_write_8bit_array(TFT180_SPI, (data), (len))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据 // 参数说明 data 数据 // 返回参数 void // 使用示例 ips114_write_16bit_data(x1 + 52); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- -#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) +#define tft180_write_16bit_data(data) (spi_write_16bit(TFT180_SPI, (data))) + +//------------------------------------------------------------------------------------------------------------------- +// 函数简介 TFT180 SPI 写 16bit 数据数组 +// 参数说明 *data 数据 +// 参数说明 len 数据长度 +// 返回参数 void +// 使用示例 tft180_write_16bit_data_array(data, len); +// 备注信息 内部调用 +//------------------------------------------------------------------------------------------------------------------- +#define tft180_write_16bit_data_array(data, len) (spi_write_16bit_array(TFT180_SPI, (data), (len))) #endif //------------------------------------------------------------------------------------------------------------------- @@ -125,7 +165,7 @@ static void tft180_write_index (const uint8 dat) // 参数说明 x2 结束x轴坐标 // 参数说明 y2 结束y轴坐标 // 返回参数 void -// 使用示例 tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); +// 使用示例 tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); // 备注信息 内部调用 //------------------------------------------------------------------------------------------------------------------- static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) @@ -133,10 +173,10 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 // 检查一下你的显示调用的函数 自己计算一下哪里超过了屏幕显示范围 - zf_assert(x1 < tft180_x_max); - zf_assert(y1 < tft180_y_max); - zf_assert(x2 < tft180_x_max); - zf_assert(y2 < tft180_y_max); + zf_assert(x1 < tft180_width_max); + zf_assert(y1 < tft180_height_max); + zf_assert(x2 < tft180_width_max); + zf_assert(y2 < tft180_height_max); switch(tft180_display_dir) { @@ -181,14 +221,14 @@ static void tft180_set_region (uint16 x1, uint16 y1, uint16 x2, uint16 y2) // 使用示例 tft180_debug_init(); // 备注信息 内部使用 //------------------------------------------------------------------------------------------------------------------- -static void tft180_debug_init(void) +static void tft180_debug_init (void) { debug_output_struct info; debug_output_struct_init(&info); info.type_index = 1; - info.display_x_max = tft180_x_max; - info.display_y_max = tft180_y_max; + info.display_x_max = tft180_width_max; + info.display_y_max = tft180_height_max; switch(tft180_display_font) { @@ -222,13 +262,18 @@ static void tft180_debug_init(void) //------------------------------------------------------------------------------------------------------------------- void tft180_clear (void) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + color_buffer[i] = tft180_bgcolor; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -242,13 +287,18 @@ void tft180_clear (void) //------------------------------------------------------------------------------------------------------------------- void tft180_full (const uint16 color) { - uint32 i = tft180_x_max * tft180_y_max; + uint16 color_buffer[tft180_width_max]; + uint16 i = 0, j = 0; TFT180_CS(0); - tft180_set_region(0, 0, tft180_x_max - 1, tft180_y_max - 1); - for( ; 0 < i; i --) + tft180_set_region(0, 0, tft180_width_max - 1, tft180_height_max - 1); + for(i = 0; i < tft180_width_max; i ++) { - tft180_write_16bit_data(color); + color_buffer[i] = color; + } + for (j = 0; j < tft180_height_max; j ++) + { + tft180_write_16bit_data_array(color_buffer, tft180_width_max); } TFT180_CS(1); } @@ -268,14 +318,14 @@ void tft180_set_dir (tft180_dir_enum dir) case TFT180_PORTAIT: case TFT180_PORTAIT_180: { - tft180_x_max = 128; - tft180_y_max = 160; + tft180_width_max = 128; + tft180_height_max = 160; }break; case TFT180_CROSSWISE: case TFT180_CROSSWISE_180: { - tft180_x_max = 160; - tft180_y_max = 128; + tft180_width_max = 160; + tft180_height_max = 128; }break; } } @@ -308,8 +358,8 @@ void tft180_set_color (uint16 pen, const uint16 bgcolor) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 画点 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的颜色 // 返回参数 void // 使用示例 tft180_draw_point(0, 0, RGB565_RED); // 坐标 0,0 画一个红色的点 @@ -319,8 +369,8 @@ void tft180_draw_point (uint16 x, uint16 y, const uint16 color) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); TFT180_CS(0); tft180_set_region(x, y, x, y); @@ -343,15 +393,16 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x_start < tft180_x_max); - zf_assert(y_start < tft180_y_max); - zf_assert(x_end < tft180_x_max); - zf_assert(y_end < tft180_y_max); + zf_assert(x_start < tft180_width_max); + zf_assert(y_start < tft180_height_max); + zf_assert(x_end < tft180_width_max); + zf_assert(y_end < tft180_height_max); int16 x_dir = (x_start < x_end ? 1 : -1); int16 y_dir = (y_start < y_end ? 1 : -1); float temp_rate = 0; float temp_b = 0; + do { if(x_start != x_end) @@ -366,6 +417,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en tft180_draw_point(x_start, y_start, color); y_start += y_dir; } + tft180_draw_point(x_start, y_start, color); break; } @@ -377,6 +429,7 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en y_start += y_dir; x_start = (int16)(((float)y_start - temp_b) / temp_rate); } + tft180_draw_point(x_start, y_start, color); } else { @@ -386,14 +439,15 @@ void tft180_draw_line (uint16 x_start, uint16 y_start, uint16 x_end, uint16 y_en x_start += x_dir; y_start = (int16)((float)x_start * temp_rate + temp_b); } + tft180_draw_point(x_start, y_start, color); } }while(0); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符 // 返回参数 void // 使用示例 tft180_show_char(0, 0, 'x'); // 坐标 0,0 写一个字符 x @@ -403,8 +457,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); uint8 i = 0, j = 0; @@ -413,42 +467,44 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { case TFT180_6X8_FONT: { + uint16 display_buffer[6*8]; + tft180_set_region(x, y, x + 5, y + 7); for(i = 0; 6 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 8); // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_6x8[dat - 32][i]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 6] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 6] = (tft180_bgcolor); } temp_top >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 6*8); }break; case TFT180_8X16_FONT: { + uint16 display_buffer[8*16]; + tft180_set_region(x, y, x + 7, y + 15); for(i = 0; 8 > i; i ++) { - tft180_set_region(x + i, y, x + i, y + 15); - // 减 32 因为是取模是从空格开始取得 空格在 ascii 中序号是 32 uint8 temp_top = ascii_font_8x16[dat - 32][i]; uint8 temp_bottom = ascii_font_8x16[dat - 32][i + 8]; for(j = 0; 8 > j; j ++) { if(temp_top & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8] = (tft180_bgcolor); } temp_top >>= 1; } @@ -456,15 +512,16 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) { if(temp_bottom & 0x01) { - tft180_write_16bit_data(tft180_pencolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_pencolor); } else { - tft180_write_16bit_data(tft180_bgcolor); + display_buffer[i + j * 8 + 4 * 16] = (tft180_bgcolor); } temp_bottom >>= 1; } } + tft180_write_16bit_data_array(display_buffer, 8 * 16); }break; case TFT180_16X16_FONT: { @@ -476,8 +533,8 @@ void tft180_show_char (uint16 x, uint16 y, const char dat) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示字符串 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的字符串 // 返回参数 void // 使用示例 tft180_show_string(0, 0, "seekfree"); @@ -487,9 +544,9 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); - + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); + uint16 j = 0; while('\0' != dat[j]) { @@ -505,20 +562,20 @@ void tft180_show_string (uint16 x, uint16 y, const char dat[]) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位有符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 int32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void // 使用示例 tft180_show_int(0, 0, x, 3); // x 可以为 int32 int16 int8 类型 -// 备注信息 负数会显示一个 ‘-’号 正数显示一个空格 +// 备注信息 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -529,6 +586,7 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num + 1); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -543,8 +601,8 @@ void tft180_show_int (uint16 x, uint16 y, const int32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示32位无符号 (去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 dat 需要显示的变量 数据类型 uint32 // 参数说明 num 需要显示的位数 最高10位 不包含正负号 // 返回参数 void @@ -555,8 +613,8 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(10 >= num); @@ -566,6 +624,7 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) memset(data_buffer, 0, 12); memset(data_buffer, ' ', num); + // 用来计算余数显示 123 显示 2 位则应该显示 23 if(10 > num) { for(; 0 < num; num --) @@ -580,24 +639,24 @@ void tft180_show_uint (uint16 x, uint16 y, const uint32 dat, uint8 num) //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示浮点数(去除整数部分无效的0) -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] -// 参数说明 dat 需要显示的变量,数据类型float或double -// 参数说明 num 整数位显示长度 最高8位 +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] +// 参数说明 dat 需要显示的变量 数据类型 double +// 参数说明 num 整数位显示长度 最高8位 // 参数说明 pointnum 小数位显示长度 最高6位 // 返回参数 void // 使用示例 tft180_show_float(0, 0, x, 2, 3); // 显示浮点数 整数显示2位 小数显示三位 // 备注信息 特别注意当发现小数部分显示的值与你写入的值不一样的时候, // 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题, // 有关问题的详情,请自行百度学习 浮点数精度丢失问题。 -// 负数会显示一个 ‘-’号 正数显示一个空格 +// 负数会显示一个 ‘-’号 //------------------------------------------------------------------------------------------------------------------- void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 pointnum) { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(0 < num); zf_assert(8 >= num); zf_assert(0 < pointnum); @@ -621,13 +680,13 @@ void tft180_show_float (uint16 x, uint16 y, const double dat, uint8 num, uint8 p //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示二值图像 数据每八个点组成一个字节数据 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_binary_image(0, 0, ov7725_image_binary[0], OV7725_W, OV7725_H, OV7725_W / 2, OV7725_H / 2); // 备注信息 用于显示小钻风的未解压的压缩二值化图像 @@ -639,46 +698,49 @@ void tft180_show_binary_image (uint16 x, uint16 y, const uint8 *image, uint16 wi { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint8 temp = 0; - uint32 width_index = 0, height_index = 0; + uint32 width_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width / 8; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { width_index = i * width / dis_width; - temp = *(image + height_index * width / 8 + width_index / 8); // 读取像素点 + temp = *(image_temp + width_index / 8); // 读取像素点 if(0x80 & (temp << (width_index % 8))) { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } else { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 8bit 灰度图像 带二值化阈值 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 threshold 二值化显示阈值 0-不开启二值化 // 返回参数 void // 使用示例 tft180_show_gray_image(0, 0, mt9v03x_image[0], MT9V03X_W, MT9V03X_H, MT9V03X_W / 2, MT9V03X_H / 2, 0); @@ -691,53 +753,54 @@ void tft180_show_gray_image (uint16 x, uint16 y, const uint8 *image, uint16 widt { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; uint16 color = 0,temp = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint8 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - temp = *(image + height_index * width + width_index); // 读取像素点 + temp = *(image_temp + i * width / dis_width); // 读取像素点 if(threshold == 0) { color = (0x001f & ((temp) >> 3)) << 11; color = color | (((0x003f) & ((temp) >> 2)) << 5); color = color | (0x001f & ((temp) >> 3)); - tft180_write_16bit_data(color); + data_buffer[i] = (color); } else if(temp < threshold) { - tft180_write_16bit_data(RGB565_BLACK); + data_buffer[i] = (RGB565_BLACK); } else { - tft180_write_16bit_data(RGB565_WHITE); + data_buffer[i] = (RGB565_WHITE); } } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); } //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示 RGB565 彩色图像 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *image 图像数组指针 // 参数说明 width 图像实际宽度 // 参数说明 height 图像实际高度 -// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 图像显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_height 图像显示高度 参数范围 [0, tft180_height_max] // 参数说明 color_mode 色彩模式 0-低位在前 1-高位在前 // 返回参数 void // 使用示例 tft180_show_rgb565_image(0, 0, scc8660_image[0], SCC8660_W, SCC8660_H, SCC8660_W / 2, SCC8660_H / 2, 1); @@ -750,29 +813,31 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != image); uint32 i = 0, j = 0; - uint16 color = 0; - uint32 width_index = 0, height_index = 0; + uint16 data_buffer[dis_width]; + const uint16 *image_temp; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_height - 1); // 设置显示区域 for(j = 0; j < dis_height; j ++) { - height_index = j * height / dis_height; + image_temp = image + j * height / dis_height * width; // 直接对 image 操作会 Hardfault 暂时不知道为什么 for(i = 0; i < dis_width; i ++) { - width_index = i * width / dis_width; - color = *(image + height_index * width + width_index); // 读取像素点 - if(color_mode) - { - color = ((color & 0xff) << 8) | (color >> 8); - } - tft180_write_16bit_data(color); + data_buffer[i] = *(image_temp + i * width / dis_width); // 读取像素点 + } + if(color_mode) + { + tft180_write_8bit_data_array((uint8 *)data_buffer, dis_width * 2); + } + else + { + tft180_write_16bit_data_array(data_buffer, dis_width); } } TFT180_CS(1); @@ -780,13 +845,13 @@ void tft180_show_rgb565_image (uint16 x, uint16 y, const uint16 *image, uint16 w //------------------------------------------------------------------------------------------------------------------- // 函数简介 TFT180 显示波形 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 *wave 波形数组指针 // 参数说明 width 波形实际宽度 // 参数说明 value_max 波形实际最大值 -// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_x_max] -// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_y_max] +// 参数说明 dis_width 波形显示宽度 参数范围 [0, tft180_width_max] +// 参数说明 dis_value_max 波形显示最大值 参数范围 [0, tft180_height_max] // 返回参数 void // 使用示例 tft180_show_wave(32, 64, data, 128, 64, 64, 32); // 备注信息 @@ -795,21 +860,23 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != wave); uint32 i = 0, j = 0; uint32 width_index = 0, value_max_index = 0; + uint16 data_buffer[dis_width]; TFT180_CS(0); tft180_set_region(x, y, x + dis_width - 1, y + dis_value_max - 1); // 设置显示区域 - for(i = 0; i < dis_value_max; i ++) + for(j = 0; j < dis_value_max; j ++) { - for(j = 0; j < dis_width; j ++) + for(i = 0; i < dis_width; i ++) { - tft180_write_16bit_data(tft180_bgcolor); + data_buffer[i] = (tft180_bgcolor); } + tft180_write_16bit_data_array(data_buffer, dis_width); } TFT180_CS(1); @@ -823,8 +890,8 @@ void tft180_show_wave (uint16 x, uint16 y, const uint16 *wave, uint16 width, uin //------------------------------------------------------------------------------------------------------------------- // 函数简介 汉字显示 -// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_x_max-1] -// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_y_max-1] +// 参数说明 x 坐标x方向的起点 参数范围 [0, tft180_width_max-1] +// 参数说明 y 坐标y方向的起点 参数范围 [0, tft180_height_max-1] // 参数说明 size 取模的时候设置的汉字字体大小 也就是一个汉字占用的点阵长宽为多少个点 取模的时候需要长宽是一样的 // 参数说明 *chinese_buffer 需要显示的汉字数组 // 参数说明 number 需要显示多少位 @@ -837,19 +904,19 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b { // 如果程序在输出了断言信息 并且提示出错位置在这里 // 那么一般是屏幕显示的时候超过屏幕分辨率范围了 - zf_assert(x < tft180_x_max); - zf_assert(y < tft180_y_max); + zf_assert(x < tft180_width_max); + zf_assert(y < tft180_height_max); zf_assert(NULL != chinese_buffer); int i = 0, j = 0, k = 0; uint8 temp = 0, temp1 = 0, temp2 = 0; const uint8 *p_data = chinese_buffer; - + temp2 = size / 8; - + TFT180_CS(0); tft180_set_region(x, y, number * size - 1 + x, y + size - 1); - + for(i = 0; i < size; i ++) { temp1 = number; @@ -873,7 +940,7 @@ void tft180_show_chinese (uint16 x, uint16 y, uint8 size, const uint8 *chinese_b p_data ++; } p_data = p_data - temp2 + temp2 * size; - } + } } TFT180_CS(1); } diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_tft180.h b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_tft180.h index 927ccac..47491ee 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_tft180.h +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_tft180.h @@ -52,7 +52,7 @@ #ifndef _zf_device_tft180_h_ #define _zf_device_tft180_h_ -#include "zf_device_type.h" +#include "zf_common_typedef.h" //=================================================定义 TFT180 基本配置================================================ #define TFT180_USE_SOFT_SPI (0) // 默认使用硬件 SPI 方式驱动 建议使用硬件 SPI 方式驱动 @@ -104,8 +104,11 @@ typedef enum TFT180_8X16_FONT = 1, // 8x16 字体 TFT180_16X16_FONT = 2, // 16x16 字体 目前不支持 }tft180_font_size_enum; -//=================================================定义 TFT180 参数结构体=============================================== +extern uint16 tft180_width_max ; +extern uint16 tft180_height_max; + +//=================================================定义 TFT180 参数结构体=============================================== //=================================================声明 TFT180 基础函数================================================ void tft180_clear (void); // TFT180 清屏函数 diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_driver/zf_driver_uart.c b/Seekfree_TC264_Opensource_Library/libraries/zf_driver/zf_driver_uart.c index 2173b99..b7c5430 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_driver/zf_driver_uart.c +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_driver/zf_driver_uart.c @@ -31,6 +31,8 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-09-27 pudding 修改串口发送和接收的通信逻辑,将直接从底层读取或者写入数据,不再通过中断处理 +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #include "IFXPORT.h" @@ -40,6 +42,7 @@ #include "SysSe/Bsp/Bsp.h" #include "isr_config.h" #include "zf_common_debug.h" +#include "zf_common_function.h" #include "zf_driver_uart.h" @@ -54,18 +57,14 @@ static IfxAsclin_Asc_Config uart_config; // 创建串口缓存数组 -static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - -static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; -static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8]; - +static uint8 uart0_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart0_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart1_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart2_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_tx_buffer[1 + sizeof(Ifx_Fifo) + 8]; +static uint8 uart3_rx_buffer[1 + sizeof(Ifx_Fifo) + 8]; //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口中断优先级设置 @@ -125,29 +124,29 @@ void uart_set_buffer (uart_index_enum uartn) { uart_config.txBuffer = &uart0_tx_buffer; uart_config.rxBuffer = &uart0_rx_buffer; - uart_config.txBufferSize = UART0_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_1: { uart_config.txBuffer = &uart1_tx_buffer; uart_config.rxBuffer = &uart1_rx_buffer; - uart_config.txBufferSize = UART1_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_2: { uart_config.txBuffer = &uart2_tx_buffer; uart_config.rxBuffer = &uart2_rx_buffer; - uart_config.txBufferSize = UART2_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; case UART_3: { uart_config.txBuffer = &uart3_tx_buffer; uart_config.rxBuffer = &uart3_rx_buffer; - uart_config.txBufferSize = UART3_TX_BUFFER_SIZE; - uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE; + uart_config.txBufferSize = 1; + uart_config.rxBufferSize = 1; }break; default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); } @@ -251,23 +250,10 @@ void uart_mux (uart_index_enum uartn, uart_tx_pin_enum tx_pin, uart_rx_pin_enum else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE); }break; + default:break; } } -//------------------------------------------------------------------------------------------------------------------- -// 函数简介 串口等待发送 -// 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 -// 参数说明 dat 需要发送的字节 -// 返回参数 void -// 使用示例 uart_write_byte_wait(UART_1, 0xA5); // 往串口1的发送缓冲区写入0xA5,并等待数据发送完成 -// 备注信息 -//------------------------------------------------------------------------------------------------------------------- -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) -{ - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); - while(TRUE == uart_get_handle(uart_n)->txInProgress); -} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送写入 // 参数说明 uart_n 串口模块号 参照 zf_driver_uart.h 内 uart_index_enum 枚举体定义 @@ -278,10 +264,12 @@ void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat) //------------------------------------------------------------------------------------------------------------------- void uart_write_byte (uart_index_enum uart_n, const uint8 dat) { - Ifx_SizeT count = 1; - (void)IfxAsclin_Asc_write(uart_get_handle(uart_n), &dat, &count, TIME_INFINITE); -} + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getTxFifoFillLevel(uart_handle->asclin) != 0); + IfxAsclin_write8(uart_handle->asclin, &dat, 1); +} //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口发送数组 @@ -329,8 +317,14 @@ void uart_write_string (uart_index_enum uart_n, const char *str) //------------------------------------------------------------------------------------------------------------------- uint8 uart_read_byte (uart_index_enum uart_n) { - while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n))); - return (uint8)IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + + uint8 return_num = 0; + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + while(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) == 0); + IfxAsclin_read8(uart_handle->asclin, &return_num, 1); + + return return_num; } @@ -345,9 +339,11 @@ uint8 uart_read_byte (uart_index_enum uart_n) uint8 uart_query_byte (uart_index_enum uart_n, uint8 *dat) { uint8 return_num = 0; - if(IfxAsclin_Asc_getReadCount(uart_get_handle(uart_n)) >0) + IfxAsclin_Asc* uart_handle; + uart_handle = uart_get_handle(uart_n); + if(IfxAsclin_getRxFifoFillLevel(uart_handle->asclin) > 0) { - *dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uart_n)); + IfxAsclin_read8(uart_handle->asclin, dat, 1); return_num = 1; } return return_num; @@ -378,7 +374,6 @@ void uart_tx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableTxFifoOutlet(asclinSFR, (boolean)status); } @@ -407,9 +402,9 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) { IfxSrc_disable(src); } - IfxAsclin_enableRxFifoInlet(asclinSFR, (boolean)status); } + //------------------------------------------------------------------------------------------------------------------- // 函数简介 串口初始化 // 参数说明 uartn 串口模块号(UART_0,UART_1,UART_2,UART_3) @@ -422,23 +417,22 @@ void uart_rx_interrupt (uart_index_enum uart_n, uint32 status) //------------------------------------------------------------------------------------------------------------------- void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, uart_rx_pin_enum rx_pin) { - - boolean interrupt_state = disableInterrupts(); volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uart_n); - IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 + IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); // 初始化化配置结构体 - uart_set_buffer(uart_n); // 设置缓冲区 + uart_set_buffer(uart_n); // 设置缓冲区 - uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_set_interrupt_priority(uart_n); // 设置中断优先级 + uart_config.clockSource = IfxAsclin_ClockSource_ascFastClock; // 使用高速时钟 最大波特率6.25M uart_config.baudrate.prescaler = 4; uart_config.baudrate.baudrate = (float32)baud; uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8; - IfxAsclin_Asc_Pins pins; // 设置引脚 + IfxAsclin_Asc_Pins pins; // 设置引脚 pins.cts = NULL; pins.rts = NULL; uart_mux(uart_n, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx); @@ -448,6 +442,7 @@ void uart_init (uart_index_enum uart_n, uint32 baud, uart_tx_pin_enum tx_pin, ua uart_config.pins = &pins; IfxAsclin_Asc_initModule(uart_get_handle(uart_n), &uart_config); - + uart_rx_interrupt(uart_n, 0); + uart_tx_interrupt(uart_n, 0); restoreInterrupts(interrupt_state); } diff --git a/Seekfree_TC264_Opensource_Library/libraries/zf_driver/zf_driver_uart.h b/Seekfree_TC264_Opensource_Library/libraries/zf_driver/zf_driver_uart.h index fd17caa..8d1d111 100644 --- a/Seekfree_TC264_Opensource_Library/libraries/zf_driver/zf_driver_uart.h +++ b/Seekfree_TC264_Opensource_Library/libraries/zf_driver/zf_driver_uart.h @@ -31,6 +31,7 @@ * 修改记录 * 日期 作者 备注 * 2022-09-15 pudding first version +* 2023-10-07 pudding 新增统一回调函数指针 ********************************************************************************************************************/ #ifndef _zf_driver_uart_h_ @@ -39,19 +40,6 @@ #include "ifxAsclin_Asc.h" #include "zf_common_typedef.h" -#define UART0_TX_BUFFER_SIZE 256 // 定义串口0发送缓冲区大小 -#define UART0_RX_BUFFER_SIZE 16 // 定义串口0接收缓冲区大小 - -#define UART1_TX_BUFFER_SIZE 256 -#define UART1_RX_BUFFER_SIZE 16 - -#define UART2_TX_BUFFER_SIZE 256 -#define UART2_RX_BUFFER_SIZE 16 - -#define UART3_TX_BUFFER_SIZE 256 -#define UART3_RX_BUFFER_SIZE 16 - - typedef enum // 枚举串口引脚 此枚举定义不允许用户修改 { UART0_TX_P14_0, // 串口0 发送引脚可选范围 @@ -127,7 +115,6 @@ extern IfxAsclin_Asc uart2_handle; extern IfxAsclin_Asc uart3_handle; //====================================================串口 基础函数==================================================== -void uart_write_byte_wait (uart_index_enum uart_n, const uint8 dat); void uart_write_byte (uart_index_enum uartn, const uint8 dat); void uart_write_buffer (uart_index_enum uartn, const uint8 *buff, uint32 len); void uart_write_string (uart_index_enum uartn, const char *str); diff --git a/Seekfree_TC264_Opensource_Library/user/cpu0_main.c b/Seekfree_TC264_Opensource_Library/user/cpu0_main.c index 238d5c5..f0f5277 100644 --- a/Seekfree_TC264_Opensource_Library/user/cpu0_main.c +++ b/Seekfree_TC264_Opensource_Library/user/cpu0_main.c @@ -41,7 +41,6 @@ // 本例程是开源库空工程 可用作移植或者测试各类内外设 // **************************** 代码区域 **************************** - int core0_main(void) { clock_init(); // 获取时钟频率<务必保留> @@ -58,7 +57,6 @@ int core0_main(void) - // 此处编写需要循环执行的代码 } } diff --git a/Seekfree_TC264_Opensource_Library/user/cpu1_main.c b/Seekfree_TC264_Opensource_Library/user/cpu1_main.c index f256a93..ef5e75b 100644 --- a/Seekfree_TC264_Opensource_Library/user/cpu1_main.c +++ b/Seekfree_TC264_Opensource_Library/user/cpu1_main.c @@ -37,17 +37,12 @@ #pragma section all "cpu1_dsram" // 将本语句与#pragma section all restore语句之间的全局变量都放在CPU1的RAM中 - -// 工程导入到软件之后,应该选中工程然后点击refresh刷新一下之后再编译 -// 工程默认设置为关闭优化,可以自己右击工程选择properties->C/C++ Build->Setting -// 然后在右侧的窗口中找到C/C++ Compiler->Optimization->Optimization level处设置优化等级 -// 一般默认新建立的工程都会默认开2级优化,因此大家也可以设置为2级优化 - -// 对于TC系列默认是不支持中断嵌套的,希望支持中断嵌套需要在中断内使用 enableInterrupts(); 来开启中断嵌套 -// 简单点说实际上进入中断后TC系列的硬件自动调用了 disableInterrupts(); 来拒绝响应任何的中断,因此需要我们自己手动调用 enableInterrupts(); 来开启中断的响应。 - - // **************************** 代码区域 **************************** + +// 本例程是开源库空工程 可用作移植或者测试各类内外设 +// 本例程是开源库空工程 可用作移植或者测试各类内外设 +// 本例程是开源库空工程 可用作移植或者测试各类内外设 + void core1_main(void) { disable_Watchdog(); // 关闭看门狗 @@ -56,7 +51,6 @@ void core1_main(void) - // 此处编写用户代码 例如外设初始化代码等 cpu_wait_event_ready(); // 等待所有核心初始化完毕 while (TRUE) @@ -65,8 +59,8 @@ void core1_main(void) - // 此处编写需要循环执行的代码 } } #pragma section all restore +// **************************** 代码区域 ****************************