From 00c4d601f48824b5854bf82ebc51350b864a74d0 Mon Sep 17 00:00:00 2001 From: wlyu Date: Mon, 26 Sep 2022 14:24:19 +0800 Subject: [PATCH 01/30] added socket test command on nuttx --- .../socket_demo/lwip_tcp_socket_demo.c | 1 + .../app_match_nuttx/apps/nshlib/nsh.h | 7 +++ .../apps/nshlib/nsh_Applicationscmd.c | 47 +++++++++++++++++++ .../app_match_nuttx/apps/nshlib/nsh_command.c | 7 +++ 4 files changed, 62 insertions(+) diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c index d9eb4788a..37f54ed34 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c @@ -29,6 +29,7 @@ #ifdef ADD_NUTTX_FETURES #include #include +#include #include "stdio.h" #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index c899bfd6b..08e7c5521 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1462,6 +1462,13 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, int cmd_Extsram(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif +#if defined(CONFIG_SOCKET_DEMO) && !defined(CONFIG_NSH_DISABLE_SOCKET_DEMO) + int cmd_Udpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + int cmd_Udprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + int cmd_Tcpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + int cmd_Tcprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + #if defined(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS) && !defined(CONFIG_NSH_DISABLE_HCHO_TB600B_WQ_HCHO1OS) int cmd_Hcho1os(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index de46c9f9e..f5aab84a6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -77,6 +77,53 @@ int cmd_Extsram(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +/**************************************************************************** + * Name: socket test + ****************************************************************************/ +#if defined(CONFIG_SOCKET_DEMO) && !defined(CONFIG_NSH_DISABLE_SOCKET_DEMO) +extern void udp_set_ip(char *ip_str); +extern int udp_recv_demo(void); +int cmd_Udprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, UDP receive!\n"); + if(argc == 2) + udp_set_ip(argv[1]); + udp_recv_demo(); + return OK; +} + +extern int udp_send_demo(void); +int cmd_Udpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, UDP send!\n"); + if(argc == 2) + udp_set_ip(argv[1]); + udp_send_demo(); + return OK; +} + +extern void tcp_set_ip(char *ip_str); +extern int tcp_recv_demo(void); +int cmd_Tcprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, TCP receive!\n"); + if(argc == 2) + tcp_set_ip(argv[1]); + tcp_recv_demo(); + return OK; +} + +extern int tcp_send_demo(void); +int cmd_Tcpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, TCP send!\n"); + if(argc == 2) + tcp_set_ip(argv[1]); + tcp_send_demo(); + return OK; +} +#endif + /**************************************************************************** * Name: cmd_Hcho1os ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index f513ecf23..e80aceda0 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -608,6 +608,13 @@ static const struct cmdmap_s g_cmdmap[] = { "sram", cmd_Extsram, 1, 1, "[Extra sdram demo cmd.]" }, #endif +#if defined(CONFIG_SOCKET_DEMO) && !defined(CONFIG_NSH_DISABLE_SOCKET_DEMO) + { "udpsend", cmd_Udpsend, 1, 2, "[Udp send demo cmd.]" }, + { "udprecv", cmd_Udprecv, 1, 2, "[Udp recv demo cmd.]" }, + { "tcpsend", cmd_Tcpsend, 1, 2, "[Tcp send demo cmd.]" }, + { "tcprecv", cmd_Tcprecv, 1, 2, "[Tcp recv demo cmd.]" }, +#endif + #if defined(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS) && !defined(CONFIG_NSH_DISABLE_HCHO_TB600B_WQ_HCHO1OS) { "hcho1os", cmd_Hcho1os, 1, 1, "[get the concentration of formaldehyde with sensor tb600b_wq_hcho1os.]" }, #endif From dcc91fd4a97db9bcff47378e6c3f63aadd75527e Mon Sep 17 00:00:00 2001 From: wlyu Date: Mon, 26 Sep 2022 14:24:19 +0800 Subject: [PATCH 02/30] added socket test command on nuttx --- .../socket_demo/lwip_tcp_socket_demo.c | 12 +++++ .../socket_demo/lwip_udp_socket_demo.c | 10 ++++ .../app_match_nuttx/apps/nshlib/nsh.h | 7 +++ .../apps/nshlib/nsh_Applicationscmd.c | 47 +++++++++++++++++++ .../app_match_nuttx/apps/nshlib/nsh_command.c | 7 +++ 5 files changed, 83 insertions(+) diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c index d9eb4788a..ec31187a9 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c @@ -29,6 +29,7 @@ #ifdef ADD_NUTTX_FETURES #include #include +#include #include "stdio.h" #endif @@ -218,6 +219,17 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | #ifdef ADD_NUTTX_FETURES + +void tcp_set_ip(char *ip_str) +{ + char ip[4] = {0}; + if(sscanf(ip_str, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])) + { + printf("config ip %s\n", ip_str); + memcpy(tcp_socket_ip, ip, 4); + } +} + void tcp_recv_demo(void) { TCPSocketRecvTask(NULL); diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c index 2637dd830..0b0211cab 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c @@ -196,6 +196,16 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | #endif #ifdef ADD_NUTTX_FETURES +void udp_set_ip(char *ip_str) +{ + char ip[4] = {0}; + if(sscanf(ip_str, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])) + { + printf("config ip %s\n", ip_str); + memcpy(udp_socket_ip, ip, 4); + } +} + void udp_recv_demo(void) { UdpSocketRecvTask(NULL); diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index c899bfd6b..08e7c5521 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1462,6 +1462,13 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, int cmd_Extsram(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif +#if defined(CONFIG_SOCKET_DEMO) && !defined(CONFIG_NSH_DISABLE_SOCKET_DEMO) + int cmd_Udpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + int cmd_Udprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + int cmd_Tcpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + int cmd_Tcprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + #if defined(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS) && !defined(CONFIG_NSH_DISABLE_HCHO_TB600B_WQ_HCHO1OS) int cmd_Hcho1os(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index de46c9f9e..f5aab84a6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -77,6 +77,53 @@ int cmd_Extsram(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +/**************************************************************************** + * Name: socket test + ****************************************************************************/ +#if defined(CONFIG_SOCKET_DEMO) && !defined(CONFIG_NSH_DISABLE_SOCKET_DEMO) +extern void udp_set_ip(char *ip_str); +extern int udp_recv_demo(void); +int cmd_Udprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, UDP receive!\n"); + if(argc == 2) + udp_set_ip(argv[1]); + udp_recv_demo(); + return OK; +} + +extern int udp_send_demo(void); +int cmd_Udpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, UDP send!\n"); + if(argc == 2) + udp_set_ip(argv[1]); + udp_send_demo(); + return OK; +} + +extern void tcp_set_ip(char *ip_str); +extern int tcp_recv_demo(void); +int cmd_Tcprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, TCP receive!\n"); + if(argc == 2) + tcp_set_ip(argv[1]); + tcp_recv_demo(); + return OK; +} + +extern int tcp_send_demo(void); +int cmd_Tcpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, TCP send!\n"); + if(argc == 2) + tcp_set_ip(argv[1]); + tcp_send_demo(); + return OK; +} +#endif + /**************************************************************************** * Name: cmd_Hcho1os ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index f513ecf23..e80aceda0 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -608,6 +608,13 @@ static const struct cmdmap_s g_cmdmap[] = { "sram", cmd_Extsram, 1, 1, "[Extra sdram demo cmd.]" }, #endif +#if defined(CONFIG_SOCKET_DEMO) && !defined(CONFIG_NSH_DISABLE_SOCKET_DEMO) + { "udpsend", cmd_Udpsend, 1, 2, "[Udp send demo cmd.]" }, + { "udprecv", cmd_Udprecv, 1, 2, "[Udp recv demo cmd.]" }, + { "tcpsend", cmd_Tcpsend, 1, 2, "[Tcp send demo cmd.]" }, + { "tcprecv", cmd_Tcprecv, 1, 2, "[Tcp recv demo cmd.]" }, +#endif + #if defined(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS) && !defined(CONFIG_NSH_DISABLE_HCHO_TB600B_WQ_HCHO1OS) { "hcho1os", cmd_Hcho1os, 1, 1, "[get the concentration of formaldehyde with sensor tb600b_wq_hcho1os.]" }, #endif From 485911f15f5ee05a7a73fd9109abea05ce485490 Mon Sep 17 00:00:00 2001 From: wlyu Date: Tue, 27 Sep 2022 14:26:14 +0800 Subject: [PATCH 03/30] support lcd demo on application framework --- APP_Framework/Applications/app_test/Kconfig | 4 + APP_Framework/Applications/app_test/Makefile | 6 +- .../Applications/app_test/test_lcd.c | 510 ++++++++++++++++++ .../xidatong-arm32/configs/lcdnsh/defconfig | 3 + .../app_match_nuttx/apps/nshlib/nsh.h | 2 +- .../apps/nshlib/nsh_Applicationscmd.c | 2 +- .../app_match_nuttx/apps/nshlib/nsh_command.c | 4 +- 7 files changed, 526 insertions(+), 5 deletions(-) create mode 100755 APP_Framework/Applications/app_test/test_lcd.c diff --git a/APP_Framework/Applications/app_test/Kconfig b/APP_Framework/Applications/app_test/Kconfig index b2e94cf6e..a1d8f6be2 100644 --- a/APP_Framework/Applications/app_test/Kconfig +++ b/APP_Framework/Applications/app_test/Kconfig @@ -33,5 +33,9 @@ menu "test app" config USER_TEST_SEMC bool "Config test semc sdram" default n + + config USER_TEST_LCD + bool "Config test lcd device" + default n endif endmenu diff --git a/APP_Framework/Applications/app_test/Makefile b/APP_Framework/Applications/app_test/Makefile index c6f0f3a9d..f84755909 100644 --- a/APP_Framework/Applications/app_test/Makefile +++ b/APP_Framework/Applications/app_test/Makefile @@ -16,6 +16,10 @@ ifeq ($(CONFIG_USER_TEST_SEMC),y) SRC_FILES += test_extsram.c endif +ifeq ($(CONFIG_USER_TEST_LCD),y) + SRC_FILES += +endif + ifeq ($(CONFIG_ADD_XIZI_FETURES),y) include $(KERNEL_ROOT)/compiler.mk endif @@ -23,7 +27,7 @@ endif include $(KERNEL_ROOT)/.config ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) include $(APPDIR)/Make.defs - CSRCS += test_extsram.c + CSRCS += test_extsram.c test_lcd.c include $(APPDIR)/Application.mk endif diff --git a/APP_Framework/Applications/app_test/test_lcd.c b/APP_Framework/Applications/app_test/test_lcd.c new file mode 100755 index 000000000..557f7f78c --- /dev/null +++ b/APP_Framework/Applications/app_test/test_lcd.c @@ -0,0 +1,510 @@ +/**************************************************************************** + * apps/examples/fb/fb_main.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef ADD_NUTTX_FETURES + +#ifdef CONFIG_K210_LCD + +#include "nuttx/arch.h" +#include "nuttx/lcd/lt768.h" +#include "nuttx/lcd/lt768_lib.h" +#include "nuttx/lcd/k210_lcd.h" + +void LcdDemo(void) +{ + int x1 = 100, y1 = 100, x2 = 200, y2 = 200; + + Main_Image_Start_Address(LCD_START_ADDR); + Main_Image_Width(LCD_XSIZE_TFT); + Main_Window_Start_XY(0, 0); + Canvas_Image_Start_address(LCD_START_ADDR); + Canvas_image_width(LCD_XSIZE_TFT); + Active_Window_XY(0, 0); + Active_Window_WH(LCD_XSIZE_TFT, LCD_YSIZE_TFT); + up_mdelay(10); + Canvas_Image_Start_address(LCD_START_ADDR); + + for(int i = 0; i < 3; i++) + { + syslog(LOG_NOTICE, "Disp_demo %d\n", i); + LT768_DrawSquare_Fill(x1, y1, x2, y2, Red); + up_mdelay(2000); + LT768_DrawSquare_Fill(x1, y1, x2, y2, Green); + up_mdelay(2000); + LT768_DrawSquare_Fill(x1, y1, x2, y2, Blue); + up_mdelay(2000); + } +} + +#else + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/**************************************************************************** + * Preprocessor Definitions + ****************************************************************************/ + +#define NCOLORS 6 +#define TEST_FB_DEV "/dev/fb0" + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct fb_state_s +{ + int fd; + struct fb_videoinfo_s vinfo; + struct fb_planeinfo_s pinfo; +#ifdef CONFIG_FB_OVERLAY + struct fb_overlayinfo_s oinfo; +#endif + FAR void *fbmem; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const char g_default_fbdev[] = TEST_FB_DEV; + +/* Violet-Blue-Green-Yellow-Orange-Red */ + +static const uint32_t g_rgb24[NCOLORS] = +{ + RGB24_VIOLET, RGB24_BLUE, RGB24_GREEN, + RGB24_YELLOW, RGB24_ORANGE, RGB24_RED +}; + +static const uint16_t g_rgb16[NCOLORS] = +{ + RGB16_VIOLET, RGB16_BLUE, RGB16_GREEN, + RGB16_YELLOW, RGB16_ORANGE, RGB16_RED +}; + +static const uint8_t g_rgb8[NCOLORS] = +{ + RGB8_VIOLET, RGB8_BLUE, RGB8_GREEN, + RGB8_YELLOW, RGB8_ORANGE, RGB8_RED +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * draw_rect + ****************************************************************************/ + +static void draw_rect32(FAR struct fb_state_s *state, + FAR struct fb_area_s *area, int color) +{ + FAR uint32_t *dest; + FAR uint8_t *row; + int x; + int y; + + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; + for (y = 0; y < area->h; y++) + { + dest = ((FAR uint32_t *)row) + area->x; + for (x = 0; x < area->w; x++) + { + *dest++ = g_rgb24[color]; + } + + row += state->pinfo.stride; + } +} + +static void draw_rect16(FAR struct fb_state_s *state, + FAR struct fb_area_s *area, int color) +{ + FAR uint16_t *dest; + FAR uint8_t *row; + int x; + int y; + + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; + for (y = 0; y < area->h; y++) + { + dest = ((FAR uint16_t *)row) + area->x; + for (x = 0; x < area->w; x++) + { + *dest++ = g_rgb16[color]; + } + + row += state->pinfo.stride; + } +} + +static void draw_rect8(FAR struct fb_state_s *state, + FAR struct fb_area_s *area, int color) +{ + FAR uint8_t *dest; + FAR uint8_t *row; + int x; + int y; + + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; + for (y = 0; y < area->h; y++) + { + dest = row + area->x; + for (x = 0; x < area->w; x++) + { + *dest++ = g_rgb8[color]; + } + + row += state->pinfo.stride; + } +} + +static void draw_rect1(FAR struct fb_state_s *state, + FAR struct fb_area_s *area, int color) +{ + FAR uint8_t *pixel; + FAR uint8_t *row; + uint8_t color8 = (color & 1) == 0 ? 0 : 0xff; + uint8_t lmask; + uint8_t rmask; + int startx; + int endx; + int x; + int y; + + /* Calculate the framebuffer address of the first row to draw on */ + + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; + + /* Calculate the start byte position rounding down so that we get the + * first byte containing any part of the pixel sequence. Then calculate + * the last byte position with a ceil() operation so it includes any final + * final pixels of the sequence. + */ + + startx = (area->x >> 3); + endx = ((area->x + area->w + 6) >> 3); + + /* Calculate a mask on the first and last bytes of the sequence that may + * not be completely filled with pixel. + */ + + lmask = 0xff << (8 - (area->x & 7)); + rmask = 0xff >> ((area->x + area->w - 1) & 7); + + /* Now draw each row, one-at-a-time */ + + for (y = 0; y < area->h; y++) + { + /* 'pixel' points to the 1st pixel the next row */ + + pixel = row + startx; + + /* Special case: The row is less no more than one byte wide */ + + if (startx == endx) + { + uint8_t mask = lmask | rmask; + + *pixel = (*pixel & mask) | (color8 & ~mask); + } + else + { + /* Special case the first byte of the row */ + + *pixel = (*pixel & lmask) | (color8 & ~lmask); + pixel++; + + /* Handle all middle bytes in the row */ + + for (x = startx + 1; x < endx; x++) + { + *pixel++ = color8; + } + + /* Handle the final byte of the row */ + + *pixel = (*pixel & rmask) | (color8 & ~rmask); + } + + row += state->pinfo.stride; + } +} + +static void draw_rect(FAR struct fb_state_s *state, + FAR struct fb_area_s *area, int color) +{ +#ifdef CONFIG_FB_UPDATE + int ret; +#endif + + switch (state->pinfo.bpp) + { + case 32: + draw_rect32(state, area, color); + break; + + case 16: + draw_rect16(state, area, color); + break; + + case 8: + default: + draw_rect8(state, area, color); + break; + + case 1: + draw_rect1(state, area, color); + break; + } + +#ifdef CONFIG_FB_UPDATE + ret = ioctl(state->fd, FBIO_UPDATE, + (unsigned long)((uintptr_t)area)); + if (ret < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIO_UPDATE) failed: %d\n", + errcode); + } +#endif +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * fb_main + ****************************************************************************/ + +int test_lcd(int argc, FAR char *argv[]) +{ + FAR const char *fbdev = g_default_fbdev; + struct fb_state_s state; + struct fb_area_s area; + int nsteps; + int xstep; + int ystep; + int width; + int height; + int color; + int x; + int y; + int ret; + + /* There is a single required argument: The path to the framebuffer + * driver. + */ + + if (argc == 2) + { + fbdev = argv[1]; + } + else if (argc != 1) + { + fprintf(stderr, "ERROR: Single argument required\n"); + fprintf(stderr, "USAGE: %s []\n", argv[0]); + return EXIT_FAILURE; + } + + /* Open the framebuffer driver */ + + state.fd = open(fbdev, O_RDWR); + if (state.fd < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: Failed to open %s: %d\n", fbdev, errcode); + return EXIT_FAILURE; + } + + /* Get the characteristics of the framebuffer */ + + ret = ioctl(state.fd, FBIOGET_VIDEOINFO, + (unsigned long)((uintptr_t)&state.vinfo)); + if (ret < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIOGET_VIDEOINFO) failed: %d\n", + errcode); + close(state.fd); + return EXIT_FAILURE; + } + + printf("VideoInfo:\n"); + printf(" fmt: %u\n", state.vinfo.fmt); + printf(" xres: %u\n", state.vinfo.xres); + printf(" yres: %u\n", state.vinfo.yres); + printf(" nplanes: %u\n", state.vinfo.nplanes); + +#ifdef CONFIG_FB_OVERLAY + printf("noverlays: %u\n", state.vinfo.noverlays); + + /* Select the first overlay, which should be the composed framebuffer */ + + ret = ioctl(state.fd, FBIO_SELECT_OVERLAY, 0); + if (ret < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIO_SELECT_OVERLAY) failed: %d\n", + errcode); + close(state.fd); + return EXIT_FAILURE; + } + + /* Get the first overlay information */ + + state.oinfo.overlay = 0; + ret = ioctl(state.fd, FBIOGET_OVERLAYINFO, + (unsigned long)((uintptr_t)&state.oinfo)); + if (ret < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIOGET_OVERLAYINFO) failed: %d\n", + errcode); + close(state.fd); + return EXIT_FAILURE; + } + + printf("OverlayInfo (overlay 0):\n"); + printf(" fbmem: %p\n", state.oinfo.fbmem); + printf(" fblen: %lu\n", (unsigned long)state.oinfo.fblen); + printf(" stride: %u\n", state.oinfo.stride); + printf(" overlay: %u\n", state.oinfo.overlay); + printf(" bpp: %u\n", state.oinfo.bpp); + printf(" blank: %u\n", state.oinfo.blank); + printf("chromakey: 0x%08" PRIx32 "\n", state.oinfo.chromakey); + printf(" color: 0x%08" PRIx32 "\n", state.oinfo.color); + printf(" transp: 0x%02x\n", state.oinfo.transp.transp); + printf(" mode: %u\n", state.oinfo.transp.transp_mode); + printf(" area: (%u,%u) => (%u,%u)\n", + state.oinfo.sarea.x, state.oinfo.sarea.y, + state.oinfo.sarea.w, state.oinfo.sarea.h); + printf(" accl: %" PRIu32 "\n", state.oinfo.accl); + +#endif + + ret = ioctl(state.fd, FBIOGET_PLANEINFO, + (unsigned long)((uintptr_t)&state.pinfo)); + if (ret < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", + errcode); + close(state.fd); + return EXIT_FAILURE; + } + + printf("PlaneInfo (plane 0):\n"); + printf(" fbmem: %p\n", state.pinfo.fbmem); + printf(" fblen: %lu\n", (unsigned long)state.pinfo.fblen); + printf(" stride: %u\n", state.pinfo.stride); + printf(" display: %u\n", state.pinfo.display); + printf(" bpp: %u\n", state.pinfo.bpp); + + /* Only these pixel depths are supported. viinfo.fmt is ignored, only + * certain color formats are supported. + */ + + if (state.pinfo.bpp != 32 && state.pinfo.bpp != 16 && + state.pinfo.bpp != 8 && state.pinfo.bpp != 1) + { + fprintf(stderr, "ERROR: bpp=%u not supported\n", state.pinfo.bpp); + close(state.fd); + return EXIT_FAILURE; + } + + /* mmap() the framebuffer. + * + * NOTE: In the FLAT build the frame buffer address returned by the + * FBIOGET_PLANEINFO IOCTL command will be the same as the framebuffer + * address. mmap(), however, is the preferred way to get the framebuffer + * address because in the KERNEL build, it will perform the necessary + * address mapping to make the memory accessible to the application. + */ + + state.fbmem = mmap(NULL, state.pinfo.fblen, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_FILE, state.fd, 0); + if (state.fbmem == MAP_FAILED) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", + errcode); + close(state.fd); + return EXIT_FAILURE; + } + + printf("Mapped FB: %p\n", state.fbmem); + + /* Draw some rectangles */ + + nsteps = 2 * (NCOLORS - 1) + 1; + xstep = state.vinfo.xres / nsteps; + ystep = state.vinfo.yres / nsteps; + width = state.vinfo.xres; + height = state.vinfo.yres; + + for (x = 0, y = 0, color = 0; + color < NCOLORS; + x += xstep, y += ystep, color++) + { + area.x = x; + area.y = y; + area.w = width; + area.h = height; + + printf("%2d: (%3d,%3d) (%3d,%3d)\n", + color, area.x, area.y, area.w, area.h); + + draw_rect(&state, &area, color); + usleep(500 * 1000); + + width -= (2 * xstep); + height -= (2 * ystep); + } + + printf("Test finished\n"); + munmap(state.fbmem, state.pinfo.fblen); + close(state.fd); + return EXIT_SUCCESS; +} + +void LcdDemo(void) +{ + test_lcd(1, NULL); +} + +#endif +#endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/lcdnsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/lcdnsh/defconfig index df2f82504..3219e42d0 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/lcdnsh/defconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/lcdnsh/defconfig @@ -107,3 +107,6 @@ CONFIG_EXAMPLES_TOUCHSCREEN_MINOR=0 CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH="/dev/input0" CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES=0 +CONFIG_USER_TEST=y +CONFIG_USER_TEST_LCD=y + diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index 08e7c5521..1aba1a1ff 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1454,7 +1454,7 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif -#if defined(CONFIG_K210_LCD) && !defined(CONFIG_NSH_DISABLE_LCD) +#if defined(CONFIG_USER_TEST_LCD) && !defined(CONFIG_NSH_DISABLE_USER_TEST_LCD) int cmd_Lcd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index f5aab84a6..c6096f2e6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -54,7 +54,7 @@ int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) /**************************************************************************** * Name: cmd_lcd ****************************************************************************/ -#if defined(CONFIG_K210_LCD) && !defined(CONFIG_NSH_DISABLE_LCD) +#if defined(CONFIG_USER_TEST_LCD) && !defined(CONFIG_NSH_DISABLE_USER_TEST_LCD) extern void LcdDemo(void); int cmd_Lcd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index e80aceda0..e040899fa 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -600,8 +600,8 @@ static const struct cmdmap_s g_cmdmap[] = { "ch438", cmd_Ch438, 1, 1, "[ch438 demo cmd.]" }, #endif -#if defined(CONFIG_K210_LCD) && !defined(CONFIG_NSH_DISABLE_LCD) - { "lcd", cmd_Lcd, 1, 1, "[LCD demo cmd.]" }, +#if defined(CONFIG_USER_TEST_LCD) && !defined(CONFIG_NSH_DISABLE_USER_TEST_LCD) + { "lcd", cmd_Lcd, 1, 1, "[LCD demo cmd.]" }, #endif #if defined(CONFIG_USER_TEST_SEMC) && !defined(CONFIG_NSH_DISABLE_USER_TEST_SEMC) From 6603f121c6e17b347e970f9dd252eb59f0e87cfa Mon Sep 17 00:00:00 2001 From: wlyu Date: Tue, 27 Sep 2022 18:19:50 +0800 Subject: [PATCH 04/30] support lcd demo on nuttx and optimize lt768 drivers --- .../Applications/app_test/test_lcd.c | 16 +- .../xidatong-riscv64/configs/lcdnsh/defconfig | 5 +- .../app_match_nuttx/nuttx/drivers/lcd/lt768.c | 12751 ++++++++-------- .../nuttx/drivers/lcd/lt768_lib.c | 7507 +++++---- .../nuttx/include/nuttx/lcd/lt768.h | 1389 +- .../nuttx/include/nuttx/lcd/lt768_lib.h | 1219 +- 6 files changed, 11755 insertions(+), 11132 deletions(-) diff --git a/APP_Framework/Applications/app_test/test_lcd.c b/APP_Framework/Applications/app_test/test_lcd.c index 557f7f78c..14a6146f1 100755 --- a/APP_Framework/Applications/app_test/test_lcd.c +++ b/APP_Framework/Applications/app_test/test_lcd.c @@ -35,7 +35,7 @@ void LcdDemo(void) { - int x1 = 100, y1 = 100, x2 = 200, y2 = 200; + int x1 = 50, y1 = 50, x2 = LCD_XSIZE_TFT - 50, y2 = LCD_YSIZE_TFT - 50; Main_Image_Start_Address(LCD_START_ADDR); Main_Image_Width(LCD_XSIZE_TFT); @@ -49,11 +49,23 @@ void LcdDemo(void) for(int i = 0; i < 3; i++) { - syslog(LOG_NOTICE, "Disp_demo %d\n", i); + x1 = 50; + y1 = 50; + x2 = LCD_XSIZE_TFT - 50; + y2 = LCD_YSIZE_TFT - 50; + syslog(LOG_NOTICE, "Disp_demo %d (%d,%d - %d,%d)\n", i, x1, y1, x2, y2); LT768_DrawSquare_Fill(x1, y1, x2, y2, Red); up_mdelay(2000); + x1 += 20; + y1 += 20; + x2 -= 20; + y2 -= 20; LT768_DrawSquare_Fill(x1, y1, x2, y2, Green); up_mdelay(2000); + x1 += 20; + y1 += 20; + x2 -= 20; + y2 -= 20; LT768_DrawSquare_Fill(x1, y1, x2, y2, Blue); up_mdelay(2000); } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/lcdnsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/lcdnsh/defconfig index 062a4e8e7..a5e7abb94 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/lcdnsh/defconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/lcdnsh/defconfig @@ -62,4 +62,7 @@ CONFIG_K210_HAVE_LCD=y CONFIG_K210_LCD=y CONFIG_K210_LCD_BACKLIGHT=y CONFIG_LCD=y -CONFIG_LCD_LT768=y \ No newline at end of file +CONFIG_LCD_LT768=y + +CONFIG_USER_TEST=y +CONFIG_USER_TEST_LCD=y diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/drivers/lcd/lt768.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/drivers/lcd/lt768.c index 2d5d1bfdc..2cfffc1ba 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/drivers/lcd/lt768.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/drivers/lcd/lt768.c @@ -1,6371 +1,6380 @@ -/********************* COPYRIGHT *********************** -* File Name : LT768.c -* Author : Levetop Electronics -* Version : V1.0 -* Date : 2017-8-25 -* Description : 操作LT768的寄存器函数 - 具体操作哪个寄存器请看LT768.h文件 -*********************************************************/ - -#include -#include "nuttx/arch.h" -#include "nuttx/lcd/lt768.h" -#include "nuttx/lcd/k210_lcd.h" - -//============================================================================== -void LCD_RegisterWrite(unsigned char Cmd,unsigned char Data) -{ - LCD_CmdWrite(Cmd); - LCD_DataWrite(Data); -} - -unsigned char LCD_RegisterRead(unsigned char Cmd) -{ - unsigned char temp; - LCD_CmdWrite(Cmd); - temp=LCD_DataRead(); - return temp; -} - -/******************************************************************************/ -/*Sub program area */ -/******************************************************************************/ -void Check_Mem_WR_FIFO_not_Full(void) -{ - /* 0: Memory Write FIFO is not full. - 1: Memory Write FIFO is full. */ - do - { - } - while(LCD_StatusRead()&0x80); -} -void Check_Mem_WR_FIFO_Empty(void) -{ - /* 0: Memory Write FIFO is not empty. - 1: Memory Write FIFO is empty. */ - do - { - } - while((LCD_StatusRead()&0x40) == 0x00); -} -void Check_Mem_RD_FIFO_not_Full(void) -{ - /* 0: Memory Read FIFO is not full. - 1: Memory Read FIFO is full. */ - do - { - } - while(LCD_StatusRead()&0x20); -} -void Check_Mem_RD_FIFO_not_Empty(void) -{ - /* 0: Memory Read FIFO is not empty. - 1: Memory Read FIFO is empty. - */ - do - { - } - while(LCD_StatusRead()&0x10); -} -void Check_2D_Busy(void) -{ - do - { - } - while(LCD_StatusRead()&0x08); -} -void Check_SDRAM_Ready(void) -{ - /* 0: SDRAM is not ready for access - 1: SDRAM is ready for access */ - unsigned char temp; - - do - { - temp=LCD_StatusRead(); - } - while((temp&0x04) == 0x00); -} - -unsigned char Power_Saving_Status(void) -{ - unsigned char temp; - - if((LCD_StatusRead()&0x02)==0x02) - { - temp = 1; - } - else - { - temp = 0; - } - - return temp; -} - -void Check_Power_is_Normal(void) -{ - /* 0: Normal operation state - 1: Power saving state */ - do - { - } - while(LCD_StatusRead()&0x02); -} -void Check_Power_is_Saving(void) -{ - /* 0: Normal operation state - 1: Power saving state */ - do - { - } - while((LCD_StatusRead()&0x02) == 0x00); -} -void Check_NO_Interrupt(void) -{ - /* 0: without interrupt event - 1: interrupt event occur - */ - do - { - } - while(LCD_StatusRead()&0x01); -} -void Check_Interrupt_Occur(void) -{ - /* 0: without interrupt event - 1: interrupt event occur - */ - do - { - } - while((LCD_StatusRead()&0x01) == 0x00); -} - -void Check_Busy_Draw(void) -{ - unsigned char temp; - - do - { - temp=LCD_StatusRead(); - } - while(temp&0x08); -} - -//[00h]========================================================================= - -void LT768_SW_Reset(void)//IC Reset -{ - unsigned char temp; - LCD_CmdWrite(0x00); - temp = LCD_DataRead(); - temp |= 0x01; - LCD_DataWrite(temp); - - do - { - temp = LCD_DataRead(); - } - while(temp&0x01); -} - -//[01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h] -void Enable_PLL(void) -{ - /* 0: PLL disable; allow change PLL parameter. - 1: PLL enable; cannot change PLL parameter.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); - up_udelay(1);//PLL -} -void LT768_Sleep(void) -{ - /* 0: Normal mode. - 1: Sleep mode.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void LT768_WakeUp(void) -{ - /* 0: Normal mode. - 1: Sleep mode.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Key_Scan_Enable(void) -{ - /* 0: Disable. - 1: Enable.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void Key_Scan_Disable(void) -{ - /* 0: Disable. - 1: Enable.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void TFT_24bit(void) -{ - /* 00b: 24-bits output. - 01b: 18-bits output, unused pins are set as GPIO. - 10b: 16-bits output, unused pins are set as GPIO. - 11b: LVDS, all 24-bits unused output pins are set as GPIO.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp &= cClrb4; - temp &= cClrb3; - LCD_DataWrite(temp); -} -void TFT_18bit(void) -{ - /* 00b: 24-bits output. - 01b: 18-bits output, unused pins are set as GPIO. - 10b: 16-bits output, unused pins are set as GPIO. - 11b: LVDS, all 24-bits unused output pins are set as GPIO.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp &= cClrb4; - temp |= cSetb3; - LCD_DataWrite(temp); -} -void TFT_16bit(void) -{ - /* 00b: 24-bits output. - 01b: 18-bits output, unused pins are set as GPIO. - 10b: 16-bits output, unused pins are set as GPIO. - 11b: LVDS, all 24-bits unused output pins are set as GPIO.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp |= cSetb4; - temp &= cClrb3; - LCD_DataWrite(temp); -} -void TFT_LVDS(void) -{ - /* 00b: 24-bits output. - 01b: 18-bits output, unused pins are set as GPIO. - 10b: 16-bits output, unused pins are set as GPIO. - 11b: LVDS, all 24-bits unused output pins are set as GPIO.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp |= cSetb4; - temp |= cSetb3; - LCD_DataWrite(temp); -} - -void LT768_I2CM_Enable(void) -{ - /* I2C master Interface Enable/Disable - 0: Disable - 1: Enable*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} - -void LT768_I2CM_Disable(void) -{ - /* I2C master Interface Enable/Disable - 0: Disable - 1: Enable*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} - -void Enable_SFlash_SPI(void) -{ - /* Serial Flash SPI Interface Enable/Disable - 0: Disable - 1: Enable*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} - -void Disable_SFlash_SPI(void) -{ - /* Serial Flash SPI Interface Enable/Disable - 0: Disable - 1: Enable*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -void Host_Bus_8bit(void) -{ - /* Parallel Host Data Bus Width Selection - 0: 8-bit Parallel Host Data Bus. - 1: 16-bit Parallel Host Data Bus.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Host_Bus_16bit(void) -{ - /* Parallel Host Data Bus Width Selection - 0: 8-bit Parallel Host Data Bus. - 1: 16-bit Parallel Host Data Bus.*/ - unsigned char temp; - LCD_CmdWrite(0x01); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} - -//[02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h] - -void RGB_8b_8bpp(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb7; - temp &= cClrb6; - LCD_DataWrite(temp); -} -void RGB_8b_16bpp(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb7; - temp |= cSetb6; - LCD_DataWrite(temp); -} -void RGB_8b_24bpp(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb7; - temp &= cClrb6; - LCD_DataWrite(temp); -} - -void RGB_16b_8bpp(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp |= cSetb7; - temp &= cClrb6; - LCD_DataWrite(temp); -} -void RGB_16b_16bpp(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb7; - temp |= cSetb6; - LCD_DataWrite(temp); -} -void RGB_16b_24bpp_mode1(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb7; - temp &= cClrb6; - LCD_DataWrite(temp); -} -void RGB_16b_24bpp_mode2(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp |= cSetb7; - temp |= cSetb6; - LCD_DataWrite(temp); -} - -void MemRead_Left_Right_Top_Down(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb5; - temp &= cClrb4; - LCD_DataWrite(temp); -} -void MemRead_Right_Left_Top_Down(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb5; - temp |= cSetb4; - LCD_DataWrite(temp); -} -void MemRead_Top_Down_Left_Right(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp |= cSetb5; - temp &= cClrb4; - LCD_DataWrite(temp); -} -void MemRead_Down_Top_Left_Right(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp |= cSetb5; - temp |= cSetb4; - LCD_DataWrite(temp); -} -void MemWrite_Left_Right_Top_Down(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb2; - temp &= cClrb1; - LCD_DataWrite(temp); -} -void MemWrite_Right_Left_Top_Down(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp &= cClrb2; - temp |= cSetb1; - LCD_DataWrite(temp); -} -void MemWrite_Top_Down_Left_Right(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp |= cSetb2; - temp &= cClrb1; - LCD_DataWrite(temp); -} -void MemWrite_Down_Top_Left_Right(void) -{ - unsigned char temp; - LCD_CmdWrite(0x02); - temp = LCD_DataRead(); - temp |= cSetb2; - temp |= cSetb1; - LCD_DataWrite(temp); -} -//[03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h] -void Interrupt_Active_Low(void) -{ - /* MPU Interrupt active level - 0 : active low. - 1 : active high.*/ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void Interrupt_Active_High(void) -{ - /* MPU Interrupt active level - 0 : active low. - 1 : active high.*/ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void ExtInterrupt_Debounce(void) -{ - /* External interrupt de-bounce - 0 : without de-bounce - 1 : enable de-bounce (1024 OSC clock)*/ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void ExtInterrupt_Nodebounce(void) -{ - /* External interrupt de-bounce - 0 : without de-bounce - 1 : enable de-bounce (1024 OSC clock)*/ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void ExtInterrupt_Input_Low_Level_Trigger(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp &= cClrb5; - temp &= cClrb4; - LCD_DataWrite(temp); -} -void ExtInterrupt_Input_High_Level_Trigger(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp |= cSetb5; - temp &= cClrb4; - LCD_DataWrite(temp); -} -void ExtInterrupt_Input_Falling_Edge_Trigger(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp &= cClrb5; - temp |= cSetb4; - LCD_DataWrite(temp); -} -void ExtInterrupt_Input_Rising_Edge_Trigger(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp |= cSetb5; - temp |= cSetb4; - LCD_DataWrite(temp); -} -void LVDS_Format1(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void LVDS_Format2(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Graphic_Mode(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Text_Mode(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Memory_Select_SDRAM(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp &= cClrb1; - temp &= cClrb0; // B - LCD_DataWrite(temp); -} -void Memory_Select_Graphic_Cursor_RAM(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp |= cSetb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Memory_Select_Color_Palette_RAM(void) -{ - unsigned char temp; - LCD_CmdWrite(0x03); - temp = LCD_DataRead(); - temp |= cSetb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} - -//[05h]========================================================================= -//[06h]========================================================================= -//[07h]========================================================================= -//[08h]========================================================================= -//[09h]========================================================================= -//[0Ah]========================================================================= -//[0Bh]========================================================================= - -void Enable_Resume_Interrupt(void) -{ - /* - Resume Interrupt Enable - 0: Disable. - 1: Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void Disable_Resume_Interrupt(void) -{ - /* - Resume Interrupt Enable - 0: Disable. - 1: Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void Enable_ExtInterrupt_Input(void) -{ - /* - External Interrupt (PS[0] pin) Enable - 0: Disable. - 1: Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Disable_ExtInterrupt_Input(void) -{ - /* - External Interrupt (PS[0] pin) Enable - 0: Disable. - 1: Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Enable_I2CM_Interrupt(void) -{ - /* - I2C Master Interrupt Enable - 0: Disable. - 1: Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void Disable_I2CM_Interrupt(void) -{ - /* - I2C Master Interrupt Enable - 0: Disable. - 1: Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void Enable_Vsync_Interrupt(void) -{ - /* - Vsync time base interrupt Enable Bit - 0: Disable Interrupt. - 1: Enable Interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Disable_Vsync_Interrupt(void) -{ - /* - Vsync time base interrupt Enable Bit - 0: Disable Interrupt. - 1: Enable Interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Enable_KeyScan_Interrupt(void) -{ - /* - Key Scan Interrupt Enable Bit - 0: Disable Key scan interrupt. - 1: Enable Key scan interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Disable_KeyScan_Interrupt(void) -{ - /* - Key Scan Interrupt Enable Bit - 0: Disable Key scan interrupt. - 1: Enable Key scan interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void Enable_DMA_Draw_BTE_Interrupt(void) -{ - /* - Serial flash DMA Complete | Draw task finished | BTE Process - Complete etc. Interrupt Enable - 0: Disable Interrupt. - 1: Enable Interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Disable_DMA_Draw_BTE_Interrupt(void) -{ - /* - Serial flash DMA Complete | Draw task finished | BTE Process - Complete etc. Interrupt Enable - 0: Disable Interrupt. - 1: Enable Interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Enable_PWM1_Interrupt(void) -{ - /* - PWM timer 1 Interrupt Enable Bit - 0: Disable Interrupt. - 1: Enable Interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} -void Disable_PWM1_Interrupt(void) -{ - /* - PWM timer 1 Interrupt Enable Bit - 0: Disable Interrupt. - 1: Enable Interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -void Enable_PWM0_Interrupt(void) -{ - /* - PWM timer 0 Interrupt Enable Bit - 0: Disable Interrupt. - 1: Enable Interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} -void Disable_PWM0_Interrupt(void) -{ - /* - PWM timer 0 Interrupt Enable Bit - 0: Disable Interrupt. - 1: Enable Interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0B); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} - -//[0Ch]========================================================================= -unsigned char Read_Interrupt_status(void) -{ - /* - [Bit7]Read Function ..Resume Interrupt Status - 0: No Resume interrupt happens. - 1: Resume interrupt happens. - [Bit6]Read Function .. PS[0] pin Interrupt Status - 0: No PS[0] pin interrupt happens. - 1: PS[0] pin interrupt happens. - [Bit5]Read Function .. I2C master Interrupt Status - 0: No I2C master interrupt happens. - 1: I2C master interrupt happens. - [Bit4]Read Function .. Vsync Interrupt Status - 0: No interrupt happens. - 1: interrupt happens. - [Bit3]Read Function ..Key Scan Interrupt Status - 0: No Key Scan interrupt happens. - 1: Key Scan interrupt happens. - [Bit2]Read Function..Interrupt Status - 0: No interrupt happens. - 1: interrupt happens. - [Bit1]Read Function..Interrupt Status - 0: No interrupt happens. - 1: interrupt happens. - [Bit0]Read Function..Interrupt Status - 0: No interrupt happens. - 1: interrupt happens. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - return temp; -} -void Clear_Resume_Interrupt_Flag(void) -{ - /* - Resume Interrupt flag - Write Function .. Resume Interrupt Clear Bit - 0: No operation. - 1: Clear Resume interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void Clear_ExtInterrupt_Input_Flag(void) -{ - /* - External Interrupt (PS[0] pin) flag - Write Function .. PS[0] pin edge Interrupt Clear Bit - 0: No operation. - 1: Clear the PS[0] pin edge interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Clear_I2CM_Interrupt_Flag(void) -{ - /* - I2C master Interrupt flag - Write Function.. I2C master Interrupt Clear Bit - 0: No operation. - 1: Clear the I2C master interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void Clear_Vsync_Interrupt_Flag(void) -{ - /* - Vsync Time base interrupt flag - Write Function ..Vsync Interrupt Clear Bit - 0: No operation. - 1: Clear the interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Clear_KeyScan_Interrupt_Flag(void) -{ - /* - Key Scan Interrupt flag - Write Function..Key Scan Interrupt Clear Bit - 0: No operation. - 1: Clear the Key Scan interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Clear_DMA_Draw_BTE_Interrupt_Flag(void) -{ - /* - Serial flash DMA Complete | Draw task finished | BTE - Process Complete etc. Interrupt flag - Write Function.. Interrupt Clear Bit - 0: No operation. - 1: Clear interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Clear_PWM1_Interrupt_Flag(void) -{ - /* - PWM 1 timer Interrupt flag - Write Function..Interrupt Clear Bit - 0: No operation. - 1: Clear interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} -void Clear_PWM0_Interrupt_Flag(void) -{ - /* - PWM 0 timer Interrupt flag - Write Function..Interrupt Clear Bit - 0: No operation. - 1: Clear interrupt. - */ - unsigned char temp; - LCD_CmdWrite(0x0C); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} -//[0Dh]========================================================================= -void Mask_Resume_Interrupt_Flag(void) -{ - /* - Mask Resume Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void Mask_ExtInterrupt_Input_Flag(void) -{ - /* - Mask External Interrupt (PS[0] pin) Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Mask_I2CM_Interrupt_Flag(void) -{ - /* - Mask I2C Master Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void Mask_Vsync_Interrupt_Flag(void) -{ - /* - Mask Vsync time base interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Mask_KeyScan_Interrupt_Flag(void) -{ - /* - Mask Key Scan Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Mask_DMA_Draw_BTE_Interrupt_Flag(void) -{ - /* - Mask Serial flash DMA Complete | Draw task finished | BTE - Process Complete etc. Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Mask_PWM1_Interrupt_Flag(void) -{ - /* - Mask PWM timer 1 Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} -void Mask_PWM0_Interrupt_Flag(void) -{ - /* - Mask PWM timer 0 Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} - -void Enable_Resume_Interrupt_Flag(void) -{ - /* - Mask Resume Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void Enable_ExtInterrupt_Inpur_Flag(void) -{ - /* - Mask External Interrupt (PS[0] pin) Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Enable_I2CM_Interrupt_Flag(void) -{ - /* - Mask I2C Master Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void Enable_Vsync_Interrupt_Flag(void) -{ - /* - Mask Vsync time base interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Enable_KeyScan_Interrupt_Flag(void) -{ - /* - Mask Key Scan Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void Enable_DMA_Draw_BTE_Interrupt_Flag(void) -{ - /* - Mask Serial flash DMA Complete | Draw task finished | BTE - Process Complete etc. Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Enable_PWM1_Interrupt_Flag(void) -{ - /* - Mask PWM timer 1 Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -void Enable_PWM0_Interrupt_Flag(void) -{ - /* - Mask PWM timer 0 Interrupt Flag - 0: Enable. - 1: Mask. - */ - unsigned char temp; - LCD_CmdWrite(0x0D); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} - -//[0Eh]========================================================================= -void Enable_GPIOF_PullUp(void) -{ - /* - GPIO_F[7:0] Pull-Up Enable (XPDAT[23:19, 15:13]) - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void Enable_GPIOE_PullUp(void) -{ - /* - GPIO_E[7:0] Pull-Up Enable (XPDAT[12:10, 7:3]) - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Enable_GPIOD_PullUp(void) -{ - /* - GPIO_D[7:0] Pull-Up Enable (XPDAT[18, 2, 17, 16, 9, 8, 1,0]) - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Enable_GPIOC_PullUp(void) -{ - /* - GPIO_C[6:0] Pull-Up Enable (XSDA, XSCL, XnSFCS1, - XnSFCS0, XMISO, XMOSI , XSCK) - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Enable_XDB15_8_PullUp(void) -{ - /* - XDB[15:8] Pull-Up Enable - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} -void Enable_XDB7_0_PullUp(void) -{ - /* - XDB[7:0] Pull-Up Enable - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} -void Disable_GPIOF_PullUp(void) -{ - /* - GPIO_F[7:0] Pull-Up Enable (XPDAT[23:19, 15:13]) - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void Disable_GPIOE_PullUp(void) -{ - /* - GPIO_E[7:0] Pull-Up Enable (XPDAT[12:10, 7:3]) - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Disable_GPIOD_PullUp(void) -{ - /* - GPIO_D[7:0] Pull-Up Enable (XPDAT[18, 2, 17, 16, 9, 8, 1,0]) - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void Disable_GPIOC_PullUp(void) -{ - /* - GPIO_C[6:0] Pull-Up Enable (XSDA, XSCL, XnSFCS1, - XnSFCS0, XMISO, XMOSI , XSCK) - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Disable_XDB15_8_PullUp(void) -{ - /* - XDB[15:8] Pull-Up Enable - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -void Disable_XDB7_0_PullUp(void) -{ - /* - XDB[7:0] Pull-Up Enable - 0: Pull-Up Disable - 1: Pull-Up Enable - */ - unsigned char temp; - LCD_CmdWrite(0x0E); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} -//[0Fh]========================================================================= -void XPDAT18_Set_GPIO_D7(void) -{ - /* - XPDAT[18]  not scan function select - 0: GPIO-D7 - 1: KOUT[4] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void XPDAT18_Set_KOUT4(void) -{ - /* - XPDAT[18]  not scan function select - 0: GPIO-D7 - 1: KOUT[4] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void XPDAT17_Set_GPIO_D5(void) -{ - /* - XPDAT[17]  not scan function select - 0: GPIO-D5 - 1: KOUT[2] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void XPDAT17_Set_KOUT2(void) -{ - /* - XPDAT[17]  not scan function select - 0: GPIO-D5 - 1: KOUT[2] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void XPDAT16_Set_GPIO_D4(void) -{ - /* - XPDAT[16]  not scan function select - 0: GPIO-D4 - 1: KOUT[1] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void XPDAT16_Set_KOUT1(void) -{ - /* - XPDAT[16]  not scan function select - 0: GPIO-D4 - 1: KOUT[1] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void XPDAT9_Set_GPIO_D3(void) -{ - /* - XPDAT[9]  not scan function select - 0: GPIO-D3 - 1: KOUT[3] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void XPDAT9_Set_KOUT3(void) -{ - /* - XPDAT[9]  not scan function select - 0: GPIO-D3 - 1: KOUT[3] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void XPDAT8_Set_GPIO_D2(void) -{ - /* - XPDAT[8]  not scan function select - 0: GPIO-D2 - 1: KIN[3] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void XPDAT8_Set_KIN3(void) -{ - /* - XPDAT[8]  not scan function select - 0: GPIO-D2 - 1: KIN[3] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void XPDAT2_Set_GPIO_D6(void) -{ - /* - XPDAT[2]  not scan function select - 0: GPIO-D6 - 1: KIN[4] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} -void XPDAT2_Set_KIN4(void) -{ - /* - XPDAT[2]  not scan function select - 0: GPIO-D6 - 1: KIN[4] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void XPDAT1_Set_GPIO_D1(void) -{ - /* - XPDAT[1]  not scan function select - 0: GPIO-D1 - 1: KIN[2] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -void XPDAT1_Set_KIN2(void) -{ - /* - XPDAT[1]  not scan function select - 0: GPIO-D1 - 1: KIN[2] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} -void XPDAT0_Set_GPIO_D0(void) -{ - /* - XPDAT[0]  not scan function select - 0: GPIO-D0 - 1: KIN[1] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} -void XPDAT0_Set_KIN1(void) -{ - /* - XPDAT[0]  not scan function select - 0: GPIO-D0 - 1: KIN[1] - */ - unsigned char temp; - LCD_CmdWrite(0x0F); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} - -//[10h]========================================================================= -void Enable_PIP1(void) -{ - /* - PIP 1 window Enable/Disable - 0 : PIP 1 window disable. - 1 : PIP 1 window enable - PIP 1 window always on top of PIP 2 window. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void Disable_PIP1(void) -{ - /* - PIP 1 window Enable/Disable - 0 : PIP 1 window disable. - 1 : PIP 1 window enable - PIP 1 window always on top of PIP 2 window. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void Enable_PIP2(void) -{ - /* - PIP 2 window Enable/Disable - 0 : PIP 2 window disable. - 1 : PIP 2 window enable - PIP 1 window always on top of PIP 2 window. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Disable_PIP2(void) -{ - /* - PIP 2 window Enable/Disable - 0 : PIP 2 window disable. - 1 : PIP 2 window enable - PIP 1 window always on top of PIP 2 window. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Select_PIP1_Parameter(void) -{ - /* - 0: To configure PIP 1ˇs parameters. - 1: To configure PIP 2ˇs parameters.. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Select_PIP2_Parameter(void) -{ - /* - 0: To configure PIP 1ˇs parameters. - 1: To configure PIP 2ˇs parameters.. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Select_Main_Window_8bpp(void) -{ - /* - Main Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp &= cClrb3; - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Select_Main_Window_16bpp(void) -{ - /* - Main Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp &= cClrb3; - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Select_Main_Window_24bpp(void) -{ - /* - Main Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x10); - temp = LCD_DataRead(); - temp |= cSetb3; - //temp |= cSetb2; - LCD_DataWrite(temp); -} -//[11h]========================================================================= -void Select_PIP2_Window_8bpp(void) -{ - /* - PIP 1 Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x11); - temp = LCD_DataRead(); - temp &= cClrb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Select_PIP2_Window_16bpp(void) -{ - /* - PIP 1 Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x11); - temp = LCD_DataRead(); - temp &= cClrb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} -void Select_PIP2_Window_24bpp(void) -{ - /* - PIP 1 Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x11); - temp = LCD_DataRead(); - temp |= cSetb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Select_PIP1_Window_8bpp(void) -{ - /* - PIP 2 Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x11); - temp = LCD_DataRead(); - temp &= cClrb3; - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Select_PIP1_Window_16bpp(void) -{ - /* - PIP 2 Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x11); - temp = LCD_DataRead(); - temp &= cClrb3; - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Select_PIP1_Window_24bpp(void) -{ - /* - PIP 2 Window Color Depth Setting - 00b: 8-bpp generic TFT, i.e. 256 colors. - 01b: 16-bpp generic TFT, i.e. 65K colors. - 1xb: 24-bpp generic TFT, i.e. 1.67M colors. - */ - unsigned char temp; - LCD_CmdWrite(0x11); - temp = LCD_DataRead(); - temp |= cSetb3; - temp &= cClrb2; - LCD_DataWrite(temp); -} - -//[12h]========================================================================= -void PCLK_Rising(void) -{ - /* - PCLK Inversion - 0: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK falling edge. - 1: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK rising edge. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void PCLK_Falling(void) -{ - /* - PCLK Inversion - 0: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK falling edge. - 1: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK rising edge. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void Display_ON(void) -{ - /* - Display ON/OFF - 0b: Display Off. - 1b: Display On. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - syslog(LOG_NOTICE, "Display_ON.pre_read=%02x\n", temp); - temp |= cSetb6; - LCD_DataWrite(temp); - temp = LCD_DataRead(); - syslog(LOG_NOTICE, "Display_ON.write_read=%02x\n", temp); -} - -void Display_OFF(void) -{ - /* - Display ON/OFF - 0b: Display Off. - 1b: Display On. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Color_Bar_ON(void) -{ - /* - Display Test Color Bar - 0b: Disable. - 1b: Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void Color_Bar_OFF(void) -{ - /* - Display Test Color Bar - 0b: Disable. - 1b: Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void HSCAN_L_to_R(void) -{ - /* - Horizontal Scan Direction - 0 : From Left to Right - 1 : From Right to Left - PIP window will be disabled when HDIR set as 1. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void HSCAN_R_to_L(void) -{ - /* - Horizontal Scan Direction - 0 : From Left to Right - 1 : From Right to Left - PIP window will be disabled when HDIR set as 1. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void VSCAN_T_to_B(void) -{ - /* - Vertical Scan direction - 0 : From Top to Bottom - 1 : From bottom to Top - PIP window will be disabled when VDIR set as 1. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void VSCAN_B_to_T(void) -{ - /* - Vertical Scan direction - 0 : From Top to Bottom - 1 : From bottom to Top - PIP window will be disabled when VDIR set as 1. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void PDATA_Set_RGB(void) -{ - /* - parallel PDATA[23:0] Output Sequence - 000b : RGB. - 001b : RBG. - 010b : GRB. - 011b : GBR. - 100b : BRG. - 101b : BGR. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &=0xf8; - LCD_DataWrite(temp); -} -void PDATA_Set_RBG(void) -{ - /* - parallel PDATA[23:0] Output Sequence - 000b : RGB. - 001b : RBG. - 010b : GRB. - 011b : GBR. - 100b : BRG. - 101b : BGR. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &=0xf8; - temp |= cSetb0; - LCD_DataWrite(temp); -} -void PDATA_Set_GRB(void) -{ - /* - parallel PDATA[23:0] Output Sequence - 000b : RGB. - 001b : RBG. - 010b : GRB. - 011b : GBR. - 100b : BRG. - 101b : BGR. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &=0xf8; - temp |= cSetb1; - LCD_DataWrite(temp); -} -void PDATA_Set_GBR(void) -{ - /* - parallel PDATA[23:0] Output Sequence - 000b : RGB. - 001b : RBG. - 010b : GRB. - 011b : GBR. - 100b : BRG. - 101b : BGR. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &=0xf8; - temp |= cSetb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} -void PDATA_Set_BRG(void) -{ - /* - parallel PDATA[23:0] Output Sequence - 000b : RGB. - 001b : RBG. - 010b : GRB. - 011b : GBR. - 100b : BRG. - 101b : BGR. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &=0xf8; - temp |= cSetb2; - LCD_DataWrite(temp); -} -void PDATA_Set_BGR(void) -{ - /* - parallel PDATA[23:0] Output Sequence - 000b : RGB. - 001b : RBG. - 010b : GRB. - 011b : GBR. - 100b : BRG. - 101b : BGR. - */ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp &=0xf8; - temp |= cSetb2; - temp |= cSetb0; - LCD_DataWrite(temp); -} - -void PDATA_IDLE_STATE(void) -{ - unsigned char temp; - LCD_CmdWrite(0x12); - temp = LCD_DataRead(); - temp |=0x07; - LCD_DataWrite(temp); -} - - -//[13h]========================================================================= -void HSYNC_Low_Active(void) -{ - /* - HSYNC Polarity - 0 : Low active. - 1 : High active. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void HSYNC_High_Active(void) -{ - /* - HSYNC Polarity - 0 : Low active. - 1 : High active. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void VSYNC_Low_Active(void) -{ - /* - VSYNC Polarity - 0 : Low active. - 1 : High active. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void VSYNC_High_Active(void) -{ - /* - VSYNC Polarity - 0 : Low active. - 1 : High active. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void DE_Low_Active(void) -{ - /* - DE Polarity - 0 : High active. - 1 : Low active. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void DE_High_Active(void) -{ - /* - DE Polarity - 0 : High active. - 1 : Low active. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void Idle_DE_Low(void) -{ - /* - DE IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pin ¨DE〃 output is low. - 1 : Pin ¨DE〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Idle_DE_High(void) -{ - /* - DE IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pin ¨DE〃 output is low. - 1 : Pin ¨DE〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Idle_PCLK_Low(void) -{ - /* - PCLK IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pin ¨PCLK〃 output is low. - 1 : Pin ¨PCLK〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void Idle_PCLK_High(void) -{ - /* - PCLK IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pin ¨PCLK〃 output is low. - 1 : Pin ¨PCLK〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Idle_PDAT_Low(void) -{ - /* - PDAT IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pins ¨PDAT[23:0]〃 output is low. - 1 : Pins ¨PCLK[23:0]〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Idle_PDAT_High(void) -{ - /* - PDAT IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pins ¨PDAT[23:0]〃 output is low. - 1 : Pins ¨PCLK[23:0]〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Idle_HSYNC_Low(void) -{ - /* - HSYNC IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pin ¨HSYNC〃 output is low. - 1 : Pin ¨HSYNC〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -void Idle_HSYNC_High(void) -{ - /* - HSYNC IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pin ¨HSYNC〃 output is low. - 1 : Pin ¨HSYNC〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} -void Idle_VSYNC_Low(void) -{ - /* - VSYNC IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pin ¨VSYNC〃 output is low. - 1 : Pin ¨VSYNC〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Idle_VSYNC_High(void) -{ - /* - VSYNC IDLE STATE(When STANDBY or DISPLAY OFF ) - 0 : Pin ¨VSYNC〃 output is low. - 1 : Pin ¨VSYNC〃 output is high. - */ - unsigned char temp; - LCD_CmdWrite(0x13); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} - -//[14h][15h][1Ah][1Bh]========================================================================= - -void LCD_HorizontalWidth_VerticalHeight(unsigned short WX,unsigned short HY) -{ - /* - [14h] Horizontal Display Width Setting Bit[7:0] - [15h] Horizontal Display Width Fine Tuning (HDWFT) [3:0] - The register specifies the LCD panel horizontal display width in - the unit of 8 pixels resolution. - Horizontal display width(pixels) = (HDWR + 1) * 8 + HDWFTR - - [1Ah] Vertical Display Height Bit[7:0] - Vertical Display Height(Line) = VDHR + 1 - [1Bh] Vertical Display Height Bit[10:8] - Vertical Display Height(Line) = VDHR + 1 - */ - unsigned char temp; - - if(WX<8) - { - LCD_CmdWrite(0x14); - LCD_DataWrite(0x00); - LCD_CmdWrite(0x15); - LCD_DataWrite(WX); - temp=HY-1; - LCD_CmdWrite(0x1A); - LCD_DataWrite(temp); - temp=(HY-1)>>8; - LCD_CmdWrite(0x1B); - LCD_DataWrite(temp); - } - else - { - temp=(WX/8)-1; - LCD_CmdWrite(0x14); - LCD_DataWrite(temp); - temp=WX%8; - LCD_CmdWrite(0x15); - LCD_DataWrite(temp); - temp=HY-1; - LCD_CmdWrite(0x1A); - LCD_DataWrite(temp); - temp=(HY-1)>>8; - LCD_CmdWrite(0x1B); - LCD_DataWrite(temp); - } -} -//[16h][17h]========================================================================= -void LCD_Horizontal_Non_Display(unsigned short WX) -{ - /* - [16h] Horizontal Non-Display Period(HNDR) Bit[4:0] - This register specifies the horizontal non-display period. Also - called back porch. - Horizontal non-display period(pixels) = (HNDR + 1) * 8 + HNDFTR - - [17h] Horizontal Non-Display Period Fine Tuning(HNDFT) [3:0] - This register specifies the fine tuning for horizontal non-display - period; it is used to support the SYNC mode panel. Each level of - this modulation is 1-pixel. - Horizontal non-display period(pixels) = (HNDR + 1) * 8 + HNDFTR - */ - unsigned char temp; - - if(WX<8) - { - LCD_CmdWrite(0x16); - LCD_DataWrite(0x00); - LCD_CmdWrite(0x17); - LCD_DataWrite(WX); - } - else - { - temp=(WX/8)-1; - LCD_CmdWrite(0x16); - LCD_DataWrite(temp); - temp=WX%8; - LCD_CmdWrite(0x17); - LCD_DataWrite(temp); - } -} -//[18h]========================================================================= -void LCD_HSYNC_Start_Position(unsigned short WX) -{ - /* - [18h] HSYNC Start Position[4:0] - The starting position from the end of display area to the - beginning of HSYNC. Each level of this modulation is 8-pixel. - Also called front porch. - HSYNC Start Position(pixels) = (HSTR + 1)x8 - */ - unsigned char temp; - - if(WX<8) - { - LCD_CmdWrite(0x18); - LCD_DataWrite(0x00); - } - else - { - temp=(WX/8)-1; - LCD_CmdWrite(0x18); - LCD_DataWrite(temp); - } -} -//[19h]========================================================================= -void LCD_HSYNC_Pulse_Width(unsigned short WX) -{ - /* - [19h] HSYNC Pulse Width(HPW) [4:0] - The period width of HSYNC. - HSYNC Pulse Width(pixels) = (HPW + 1)x8 - */ - unsigned char temp; - - if(WX<8) - { - LCD_CmdWrite(0x19); - LCD_DataWrite(0x00); - } - else - { - temp=(WX/8)-1; - LCD_CmdWrite(0x19); - LCD_DataWrite(temp); - } -} -//[1Ch][1Dh]========================================================================= -void LCD_Vertical_Non_Display(unsigned short HY) -{ - /* - [1Ch] Vertical Non-Display Period Bit[7:0] - Vertical Non-Display Period(Line) = (VNDR + 1) - - [1Dh] Vertical Non-Display Period Bit[9:8] - Vertical Non-Display Period(Line) = (VNDR + 1) - */ - unsigned char temp; - temp=HY-1; - LCD_CmdWrite(0x1C); - LCD_DataWrite(temp); - LCD_CmdWrite(0x1D); - LCD_DataWrite(temp>>8); -} -//[1Eh]========================================================================= -void LCD_VSYNC_Start_Position(unsigned short HY) -{ - /* - [1Eh] VSYNC Start Position[7:0] - The starting position from the end of display area to the beginning of VSYNC. - VSYNC Start Position(Line) = (VSTR + 1) - */ - unsigned char temp; - temp=HY-1; - LCD_CmdWrite(0x1E); - LCD_DataWrite(temp); -} -//[1Fh]========================================================================= -void LCD_VSYNC_Pulse_Width(unsigned short HY) -{ - /* - [1Fh] VSYNC Pulse Width[5:0] - The pulse width of VSYNC in lines. - VSYNC Pulse Width(Line) = (VPWR + 1) - */ - unsigned char temp; - temp=HY-1; - LCD_CmdWrite(0x1F); - LCD_DataWrite(temp); -} -//[20h][21h][22h][23h]========================================================================= -void Main_Image_Start_Address(unsigned long Addr) -{ - /* - [20h] Main Image Start Address[7:2] - [21h] Main Image Start Address[15:8] - [22h] Main Image Start Address [23:16] - [23h] Main Image Start Address [31:24] - */ - LCD_RegisterWrite(0x20,Addr); - LCD_RegisterWrite(0x21,Addr>>8); - LCD_RegisterWrite(0x22,Addr>>16); - LCD_RegisterWrite(0x23,Addr>>24); -} -//[24h][25h]========================================================================= -void Main_Image_Width(unsigned short WX) -{ - /* - [24h] Main Image Width [7:0] - [25h] Main Image Width [12:8] - Unit: Pixel. - It must be divisible by 4. MIW Bit [1:0] tie to ¨0〃 internally. - The value is physical pixel number. Maximum value is 8188 pixels - */ - LCD_RegisterWrite(0x24,WX); - LCD_RegisterWrite(0x25,WX>>8); -} -//[26h][27h][28h][29h]========================================================================= -void Main_Window_Start_XY(unsigned short WX,unsigned short HY) -{ - /* - [26h] Main Window Upper-Left corner X-coordination [7:0] - [27h] Main Window Upper-Left corner X-coordination [12:8] - Reference Main Image coordination. - Unit: Pixel - It must be divisible by 4. MWULX Bit [1:0] tie to ¨0〃 internally. - X-axis coordination plus Horizontal display width cannot large than 8188. - - [28h] Main Window Upper-Left corner Y-coordination [7:0] - [29h] Main Window Upper-Left corner Y-coordination [12:8] - Reference Main Image coordination. - Unit: Pixel - Range is between 0 and 8191. - */ - LCD_RegisterWrite(0x26,WX); - LCD_RegisterWrite(0x27,WX>>8); - LCD_RegisterWrite(0x28,HY); - LCD_RegisterWrite(0x29,HY>>8); -} -//[2Ah][2Bh][2Ch][2Dh]========================================================================= -void PIP_Display_Start_XY(unsigned short WX,unsigned short HY) -{ - /* - [2Ah] PIP Window Display Upper-Left corner X-coordination [7:0] - [2Bh] PIP Window Display Upper-Left corner X-coordination [12:8] - Reference Main Window coordination. - Unit: Pixel - It must be divisible by 4. PWDULX Bit [1:0] tie to ¨0〃 internally. - X-axis coordination should less than horizontal display width. - According to bit of Select Configure PIP 1 or 2 Windowˇs parameters. - Function bit will be configured for relative PIP window. - - [2Ch] PIP Window Display Upper-Left corner Y-coordination [7:0] - [2Dh] PIP Window Display Upper-Left corner Y-coordination [12:8] - Reference Main Window coordination. - Unit: Pixel - Y-axis coordination should less than vertical display height. - According to bit of Select Configure PIP 1 or 2 Windowˇs parameters. - Function bit will be configured for relative PIP window. - */ - LCD_RegisterWrite(0x2A,WX); - LCD_RegisterWrite(0x2B,WX>>8); - LCD_RegisterWrite(0x2C,HY); - LCD_RegisterWrite(0x2D,HY>>8); -} -//[2Eh][2Fh][30h][31h]========================================================================= -void PIP_Image_Start_Address(unsigned long Addr) -{ - /* - [2Eh] PIP Image Start Address[7:2] - [2Fh] PIP Image Start Address[15:8] - [30h] PIP Image Start Address [23:16] - [31h] PIP Image Start Address [31:24] - */ - LCD_RegisterWrite(0x2E,Addr); - LCD_RegisterWrite(0x2F,Addr>>8); - LCD_RegisterWrite(0x30,Addr>>16); - LCD_RegisterWrite(0x31,Addr>>24); -} -//[32h][33h]========================================================================= -void PIP_Image_Width(unsigned short WX) -{ - /* - [32h] PIP Image Width [7:0] - [33h] PIP Image Width [12:8] - Unit: Pixel. - It must be divisible by 4. PIW Bit [1:0] tie to ¨0〃 internally. - The value is physical pixel number. - This width should less than horizontal display width. - According to bit of Select Configure PIP 1 or 2 Windowˇs parameters. - Function bit will be configured for relative PIP window. - */ - LCD_RegisterWrite(0x32,WX); - LCD_RegisterWrite(0x33,WX>>8); -} -//[34h][35h][36h][37h]========================================================================= -void PIP_Window_Image_Start_XY(unsigned short WX,unsigned short HY) -{ - /* - [34h] PIP 1 or 2 Window Image Upper-Left corner X-coordination [7:0] - [35h] PIP Window Image Upper-Left corner X-coordination [12:8] - Reference PIP Image coordination. - Unit: Pixel - It must be divisible by 4. PWIULX Bit [1:0] tie to ¨0〃 internally. - X-axis coordination plus PIP image width cannot large than 8188. - According to bit of Select Configure PIP 1 or 2 Windowˇs parameters. - Function bit will be configured for relative PIP window. - - [36h] PIP Windows Display Upper-Left corner Y-coordination [7:0] - [37h] PIP Windows Image Upper-Left corner Y-coordination [12:8] - Reference PIP Image coordination. - Unit: Pixel - Y-axis coordination plus PIP window height should less than 8191. - According to bit of Select Configure PIP 1 or 2 Windowˇs parameters. - Function bit will be configured for relative PIP window. - */ - LCD_RegisterWrite(0x34,WX); - LCD_RegisterWrite(0x35,WX>>8); - LCD_RegisterWrite(0x36,HY); - LCD_RegisterWrite(0x37,HY>>8); -} -//[38h][39h][3Ah][3Bh]========================================================================= -void PIP_Window_Width_Height(unsigned short WX,unsigned short HY) -{ - /* - [38h] PIP Window Width [7:0] - [39h] PIP Window Width [10:8] - Unit: Pixel. - It must be divisible by 4. The value is physical pixel number. - Maximum value is 8188 pixels. - According to bit of Select Configure PIP 1 or 2 Windowˇs parameters. - Function bit will be configured for relative PIP window. - - [3Ah] PIP Window Height [7:0] - [3Bh] PIP Window Height [10:8] - Unit: Pixel - The value is physical pixel number. Maximum value is 8191 pixels. - According to bit of Select Configure PIP 1 or 2 Windowˇs parameters. - Function bit will be configured for relative PIP window. - */ - LCD_RegisterWrite(0x38,WX); - LCD_RegisterWrite(0x39,WX>>8); - LCD_RegisterWrite(0x3A,HY); - LCD_RegisterWrite(0x3B,HY>>8); -} - -//[3Ch]========================================================================= -void Enable_Graphic_Cursor(void) -{ - /* - Graphic Cursor Enable - 0 : Graphic Cursor disable. - 1 : Graphic Cursor enable. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Disable_Graphic_Cursor(void) -{ - /* - Graphic Cursor Enable - 0 : Graphic Cursor disable. - 1 : Graphic Cursor enable. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -// -void Select_Graphic_Cursor_1(void) -{ - /* - Graphic Cursor Selection Bit - Select one from four graphic cursor types. (00b to 11b) - 00b : Graphic Cursor Set 1. - 01b : Graphic Cursor Set 2. - 10b : Graphic Cursor Set 3. - 11b : Graphic Cursor Set 4. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp &= cClrb3; - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Select_Graphic_Cursor_2(void) -{ - /* - Graphic Cursor Selection Bit - Select one from four graphic cursor types. (00b to 11b) - 00b : Graphic Cursor Set 1. - 01b : Graphic Cursor Set 2. - 10b : Graphic Cursor Set 3. - 11b : Graphic Cursor Set 4. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp &= cClrb3; - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Select_Graphic_Cursor_3(void) -{ - /* - Graphic Cursor Selection Bit - Select one from four graphic cursor types. (00b to 11b) - 00b : Graphic Cursor Set 1. - 01b : Graphic Cursor Set 2. - 10b : Graphic Cursor Set 3. - 11b : Graphic Cursor Set 4. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp |= cSetb3; - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Select_Graphic_Cursor_4(void) -{ - /* - Graphic Cursor Selection Bit - Select one from four graphic cursor types. (00b to 11b) - 00b : Graphic Cursor Set 1. - 01b : Graphic Cursor Set 2. - 10b : Graphic Cursor Set 3. - 11b : Graphic Cursor Set 4. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp |= cSetb3; - temp |= cSetb2; - LCD_DataWrite(temp); -} -// -void Enable_Text_Cursor(void) -{ - /* - Text Cursor Enable - 0 : Disable. - 1 : Enable. - Text cursor & Graphic cursor cannot enable simultaneously. - Graphic cursor has higher priority then Text cursor if enabled simultaneously. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} -void Disable_Text_Cursor(void) -{ - /* - Text Cursor Enable - 0 : Disable. - 1 : Enable. - Text cursor & Graphic cursor cannot enable simultaneously. - Graphic cursor has higher priority then Text cursor if enabled simultaneously. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -// -void Enable_Text_Cursor_Blinking(void) -{ - /* - Text Cursor Blinking Enable - 0 : Disable. - 1 : Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} -void Disable_Text_Cursor_Blinking(void) -{ - /* - Text Cursor Blinking Enable - 0 : Disable. - 1 : Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x3C); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} -//[3Dh]========================================================================= -void Blinking_Time_Frames(unsigned char temp) -{ - /* - Text Cursor Blink Time Setting (Unit: Frame) - 00h : 1 frame time. - 01h : 2 frames time. - 02h : 3 frames time. - : - FFh : 256 frames time. - */ - LCD_CmdWrite(0x3D); - LCD_DataWrite(temp); -} -//[3Eh]========================================================================= -void Text_Cursor_H_V(unsigned short WX,unsigned short HY) -{ - /* - [3Eh] - Text Cursor Horizontal Size Setting[4:0] - Unit : Pixel - Zero-based number. Value ¨0〃 means 1 pixel. - Note : When font is enlarged, the cursor setting will multiply the - same times as the font enlargement. - [3Fh] - Text Cursor Vertical Size Setting[4:0] - Unit : Pixel - Zero-based number. Value ¨0〃 means 1 pixel. - Note : When font is enlarged, the cursor setting will multiply the - same times as the font enlargement. - */ - LCD_CmdWrite(0x3E); - LCD_DataWrite(WX); - LCD_CmdWrite(0x3F); - LCD_DataWrite(HY); -} -//[40h][41h][42h][43h]========================================================================= -void Graphic_Cursor_XY(unsigned short WX,unsigned short HY) -{ - /* - [40h] Graphic Cursor Horizontal Location[7:0] - [41h] Graphic Cursor Horizontal Location[12:8] - [42h] Graphic Cursor Vertical Location[7:0] - [43h] Graphic Cursor Vertical Location[12:8] - Reference main Window coordination. - */ - LCD_RegisterWrite(0x40,WX); - LCD_RegisterWrite(0x41,WX>>8); - LCD_RegisterWrite(0x42,HY); - LCD_RegisterWrite(0x43,HY>>8); -} -//[44h]========================================================================= -void Set_Graphic_Cursor_Color_1(unsigned char temp) -{ - /* - [44h] Graphic Cursor Color 0 with 256 Colors - RGB Format [7:0] = RRRGGGBB. - */ - LCD_RegisterWrite(0x44,temp); -} -//[45h]========================================================================= -void Set_Graphic_Cursor_Color_2(unsigned char temp) -{ - /* - [45h] Graphic Cursor Color 1 with 256 Colors - RGB Format [7:0] = RRRGGGBB. - */ - LCD_RegisterWrite(0x45,temp); -} -//[50h][51h][52h][53h]========================================================================= -void Canvas_Image_Start_address(unsigned long Addr) -{ - /* - [50h] Start address of Canvas [7:0] - [51h] Start address of Canvas [15:8] - [52h] Start address of Canvas [23:16] - [53h] Start address of Canvas [31:24] - */ - LCD_RegisterWrite(0x50,Addr); - LCD_RegisterWrite(0x51,Addr>>8); - LCD_RegisterWrite(0x52,Addr>>16); - LCD_RegisterWrite(0x53,Addr>>24); -} -//[54h][55h]========================================================================= -void Canvas_image_width(unsigned short WX) -{ - /* - [54h] Canvas image width [7:2] - [55h] Canvas image width [12:8] - */ - LCD_RegisterWrite(0x54,WX); - LCD_RegisterWrite(0x55,WX>>8); -} -//[56h][57h][58h][59h]========================================================================= -void Active_Window_XY(unsigned short WX,unsigned short HY) -{ - /* - [56h] Active Window Upper-Left corner X-coordination [7:0] - [57h] Active Window Upper-Left corner X-coordination [12:8] - [58h] Active Window Upper-Left corner Y-coordination [7:0] - [59h] Active Window Upper-Left corner Y-coordination [12:8] - */ - LCD_RegisterWrite(0x56,WX); - LCD_RegisterWrite(0x57,WX>>8); - LCD_RegisterWrite(0x58,HY); - LCD_RegisterWrite(0x59,HY>>8); -} -//[5Ah][5Bh][5Ch][5Dh]========================================================================= -void Active_Window_WH(unsigned short WX,unsigned short HY) -{ - /* - [5Ah] Width of Active Window [7:0] - [5Bh] Width of Active Window [12:8] - [5Ch] Height of Active Window [7:0] - [5Dh] Height of Active Window [12:8] - */ - LCD_RegisterWrite(0x5A,WX); - LCD_RegisterWrite(0x5B,WX>>8); - LCD_RegisterWrite(0x5C,HY); - LCD_RegisterWrite(0x5D,HY>>8); -} -//[5Eh]========================================================================= -void Select_Write_Data_Position(void) -{ - /* - Select to read back Graphic Read/Write position - 0: read back Graphic Write position - 1: read back Graphic Read position - */ - unsigned char temp; - LCD_CmdWrite(0x5E); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void Select_Read_Data_Position(void) -{ - /* - Select to read back Graphic Read/Write position - 0: read back Graphic Write position - 1: read back Graphic Read position - */ - unsigned char temp; - LCD_CmdWrite(0x5E); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Memory_XY_Mode(void) -{ - /* - Canvas addressing mode - 0: Block mode (X-Y coordination addressing) - 1: linear mode - */ - unsigned char temp; - LCD_CmdWrite(0x5E); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Memory_Linear_Mode(void) -{ - /* - Canvas addressing mode - 0: Block mode (X-Y coordination addressing) - 1: linear mode - */ - unsigned char temp; - LCD_CmdWrite(0x5E); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Memory_8bpp_Mode(void) -{ - /* - Canvas imageˇs color depth & memory R/W data width - In Block Mode: - 00: 8bpp - 01: 16bpp - 1x: 24bpp - In Linear Mode: - X0: 8-bits memory data read/write. - X1: 16-bits memory data read/write - */ - unsigned char temp; - LCD_CmdWrite(0x5E); - temp = LCD_DataRead(); - temp &= cClrb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Memory_16bpp_Mode(void) -{ - /* - Canvas imageˇs color depth & memory R/W data width - In Block Mode: - 00: 8bpp - 01: 16bpp - 1x: 24bpp - In Linear Mode: - X0: 8-bits memory data read/write. - X1: 16-bits memory data read/write - */ - unsigned char temp; - LCD_CmdWrite(0x5E); - temp = LCD_DataRead(); - temp &= cClrb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} -void Memory_24bpp_Mode(void) -{ - /* - Canvas imageˇs color depth & memory R/W data width - In Block Mode: - 00: 8bpp - 01: 16bpp - 1x: 24bpp - In Linear Mode: - X0: 8-bits memory data read/write. - X1: 16-bits memory data read/write - */ - unsigned char temp; - LCD_CmdWrite(0x5E); - temp = LCD_DataRead(); - temp |= cSetb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} - -//[5Fh][60h][61h][62h]========================================================================= -void Goto_Pixel_XY(unsigned short WX,unsigned short HY) -{ - /* - [Write]: Set Graphic Read/Write position - [Read]: Current Graphic Read/Write position - Read back is Read position or Write position depends on - REG[5Eh] bit3, Select to read back Graphic Read/Write position. - When DPRAM Linear mode:Graphic Read/Write Position [31:24][23:16][15:8][7:0] - When DPRAM Active window mode:Graphic Read/Write - Horizontal Position [12:8][7:0], - Vertical Position [12:8][7:0]. - Reference Canvas image coordination. Unit: Pixel - */ - LCD_RegisterWrite(0x5F,WX); - LCD_RegisterWrite(0x60,WX>>8); - LCD_RegisterWrite(0x61,HY); - LCD_RegisterWrite(0x62,HY>>8); -} -void Goto_Linear_Addr(unsigned long Addr) -{ - LCD_RegisterWrite(0x5F,Addr); - LCD_RegisterWrite(0x60,Addr>>8); - LCD_RegisterWrite(0x61,Addr>>16); - LCD_RegisterWrite(0x62,Addr>>24); -} - - -//[63h][64h][65h][66h]========================================================================= -void Goto_Text_XY(unsigned short WX,unsigned short HY) -{ - /* - Write: Set Text Write position - Read: Current Text Write position - Text Write X-coordination [12:8][7:0] - Text Write Y-coordination [12:8][7:0] - Reference Canvas image coordination. - Unit: Pixel - */ - LCD_RegisterWrite(0x63,WX); - LCD_RegisterWrite(0x64,WX>>8); - LCD_RegisterWrite(0x65,HY); - LCD_RegisterWrite(0x66,HY>>8); -} -//[67h]========================================================================= -/* -[bit7]Draw Line / Triangle Start Signal -Write Function -0 : Stop the drawing function. -1 : Start the drawing function. -Read Function -0 : Drawing function complete. -1 : Drawing function is processing. -[bit5]Fill function for Triangle Signal -0 : Non fill. -1 : Fill. -[bit1]Draw Triangle or Line Select Signal -0 : Draw Line -1 : Draw Triangle -*/ -void Start_Line(void) -{ - LCD_CmdWrite(0x67); - LCD_DataWrite(0x80); - Check_Busy_Draw(); -} -void Start_Triangle(void) -{ - LCD_CmdWrite(0x67); - LCD_DataWrite(0x82);//B1000_0010 - Check_Busy_Draw(); -} -void Start_Triangle_Fill(void) -{ - LCD_CmdWrite(0x67); - LCD_DataWrite(0xA2);//B1010_0010 - Check_Busy_Draw(); -} -//[68h][69h][6Ah][6Bh]========================================================================= -//线起点 -void Line_Start_XY(unsigned short WX,unsigned short HY) -{ - /* - [68h] Draw Line/Square/Triangle Start X-coordination [7:0] - [69h] Draw Line/Square/Triangle Start X-coordination [12:8] - [6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0] - [6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8] - */ - LCD_CmdWrite(0x68); - LCD_DataWrite(WX); - LCD_CmdWrite(0x69); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x6A); - LCD_DataWrite(HY); - LCD_CmdWrite(0x6B); - LCD_DataWrite(HY>>8); -} -//[6Ch][6Dh][6Eh][6Fh]========================================================================= -//线终点 -void Line_End_XY(unsigned short WX,unsigned short HY) -{ - /* - [6Ch] Draw Line/Square/Triangle End X-coordination [7:0] - [6Dh] Draw Line/Square/Triangle End X-coordination [12:8] - [6Eh] Draw Line/Square/Triangle End Y-coordination [7:0] - [6Fh] Draw Line/Square/Triangle End Y-coordination [12:8] - */ - LCD_CmdWrite(0x6C); - LCD_DataWrite(WX); - LCD_CmdWrite(0x6D); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x6E); - LCD_DataWrite(HY); - LCD_CmdWrite(0x6F); - LCD_DataWrite(HY>>8); -} -//[68h]~[73h]========================================================================= -//à-翴1 -void Triangle_Point1_XY(unsigned short WX,unsigned short HY) -{ - /* - [68h] Draw Line/Square/Triangle Start X-coordination [7:0] - [69h] Draw Line/Square/Triangle Start X-coordination [12:8] - [6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0] - [6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8] - */ - LCD_CmdWrite(0x68); - LCD_DataWrite(WX); - LCD_CmdWrite(0x69); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x6A); - LCD_DataWrite(HY); - LCD_CmdWrite(0x6B); - LCD_DataWrite(HY>>8); -} -//à-翴2 -void Triangle_Point2_XY(unsigned short WX,unsigned short HY) -{ - /* - [6Ch] Draw Line/Square/Triangle End X-coordination [7:0] - [6Dh] Draw Line/Square/Triangle End X-coordination [12:8] - [6Eh] Draw Line/Square/Triangle End Y-coordination [7:0] - [6Fh] Draw Line/Square/Triangle End Y-coordination [12:8] - */ - LCD_CmdWrite(0x6C); - LCD_DataWrite(WX); - LCD_CmdWrite(0x6D); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x6E); - LCD_DataWrite(HY); - LCD_CmdWrite(0x6F); - LCD_DataWrite(HY>>8); -} -//à-翴3 -void Triangle_Point3_XY(unsigned short WX,unsigned short HY) -{ - /* - [70h] Draw Triangle Point 3 X-coordination [7:0] - [71h] Draw Triangle Point 3 X-coordination [12:8] - [72h] Draw Triangle Point 3 Y-coordination [7:0] - [73h] Draw Triangle Point 3 Y-coordination [12:8] - */ - LCD_CmdWrite(0x70); - LCD_DataWrite(WX); - LCD_CmdWrite(0x71); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x72); - LCD_DataWrite(HY); - LCD_CmdWrite(0x73); - LCD_DataWrite(HY>>8); -} -//よ癬翴 -void Square_Start_XY(unsigned short WX,unsigned short HY) -{ - /* - [68h] Draw Line/Square/Triangle Start X-coordination [7:0] - [69h] Draw Line/Square/Triangle Start X-coordination [12:8] - [6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0] - [6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8] - */ - LCD_CmdWrite(0x68); - LCD_DataWrite(WX); - LCD_CmdWrite(0x69); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x6A); - LCD_DataWrite(HY); - LCD_CmdWrite(0x6B); - LCD_DataWrite(HY>>8); -} -//よ沧翴 -void Square_End_XY(unsigned short WX,unsigned short HY) -{ - /* - [6Ch] Draw Line/Square/Triangle End X-coordination [7:0] - [6Dh] Draw Line/Square/Triangle End X-coordination [12:8] - [6Eh] Draw Line/Square/Triangle End Y-coordination [7:0] - [6Fh] Draw Line/Square/Triangle End Y-coordination [12:8] - */ - LCD_CmdWrite(0x6C); - LCD_DataWrite(WX); - LCD_CmdWrite(0x6D); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x6E); - LCD_DataWrite(HY); - LCD_CmdWrite(0x6F); - LCD_DataWrite(HY>>8); -} -//[76h]========================================================================= -/* -[bit7] -Draw Circle / Ellipse / Square /Circle Square Start Signal -Write Function -0 : Stop the drawing function. -1 : Start the drawing function. -Read Function -0 : Drawing function complete. -1 : Drawing function is processing. -[bit6] -Fill the Circle / Ellipse / Square / Circle Square Signal -0 : Non fill. -1 : fill. -[bit5 bit4] -Draw Circle / Ellipse / Square / Ellipse Curve / Circle Square Select -00 : Draw Circle / Ellipse -01 : Draw Circle / Ellipse Curve -10 : Draw Square. -11 : Draw Circle Square. -[bit1 bit0] -Draw Circle / Ellipse Curve Part Select -00 : -01 : -10 : -11 : -*/ -void Start_Circle_or_Ellipse(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0x80);//B1000_XXXX - Check_Busy_Draw(); -} -void Start_Circle_or_Ellipse_Fill(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xC0);//B1100_XXXX - Check_Busy_Draw(); -} -// -void Start_Left_Down_Curve(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0x90);//B1001_XX00 - Check_Busy_Draw(); -} -void Start_Left_Up_Curve(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0x91);//B1001_XX01 - Check_Busy_Draw(); -} -void Start_Right_Up_Curve(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0x92);//B1001_XX10 - Check_Busy_Draw(); -} -void Start_Right_Down_Curve(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0x93);//B1001_XX11 - Check_Busy_Draw(); -} -// -void Start_Left_Down_Curve_Fill(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xD0);//B1101_XX00 - Check_Busy_Draw(); -} -void Start_Left_Up_Curve_Fill(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xD1);//B1101_XX01 - Check_Busy_Draw(); -} -void Start_Right_Up_Curve_Fill(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xD2);//B1101_XX10 - Check_Busy_Draw(); -} -void Start_Right_Down_Curve_Fill(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xD3);//B1101_XX11 - Check_Busy_Draw(); -} -// -void Start_Square(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xA0);//B1010_XXXX - Check_Busy_Draw(); -} -void Start_Square_Fill(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xE0);//B1110_XXXX - Check_Busy_Draw(); -} -void Start_Circle_Square(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xB0);//B1011_XXXX - Check_Busy_Draw(); -} -void Start_Circle_Square_Fill(void) -{ - LCD_CmdWrite(0x76); - LCD_DataWrite(0xF0);//B1111_XXXX - Check_Busy_Draw(); -} -//[77h]~[7Eh]========================================================================= -//蛾いみ -void Circle_Center_XY(unsigned short WX,unsigned short HY) -{ - /* - [7Bh] Draw Circle/Ellipse/Circle Square Center X-coordination [7:0] - [7Ch] Draw Circle/Ellipse/Circle Square Center X-coordination [12:8] - [7Dh] Draw Circle/Ellipse/Circle Square Center Y-coordination [7:0] - [7Eh] Draw Circle/Ellipse/Circle Square Center Y-coordination [12:8] - */ - LCD_CmdWrite(0x7B); - LCD_DataWrite(WX); - LCD_CmdWrite(0x7C); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x7D); - LCD_DataWrite(HY); - LCD_CmdWrite(0x7E); - LCD_DataWrite(HY>>8); -} -//掘蛾いみ -void Ellipse_Center_XY(unsigned short WX,unsigned short HY) -{ - /* - [7Bh] Draw Circle/Ellipse/Circle Square Center X-coordination [7:0] - [7Ch] Draw Circle/Ellipse/Circle Square Center X-coordination [12:8] - [7Dh] Draw Circle/Ellipse/Circle Square Center Y-coordination [7:0] - [7Eh] Draw Circle/Ellipse/Circle Square Center Y-coordination [12:8] - */ - LCD_CmdWrite(0x7B); - LCD_DataWrite(WX); - LCD_CmdWrite(0x7C); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x7D); - LCD_DataWrite(HY); - LCD_CmdWrite(0x7E); - LCD_DataWrite(HY>>8); -} -//蛾畖 -void Circle_Radius_R(unsigned short WX) -{ - /* - [77h] Draw Circle/Ellipse/Circle Square Major radius [7:0] - [78h] Draw Circle/Ellipse/Circle Square Major radius [12:8] - [79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0] - [7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8] - */ - LCD_CmdWrite(0x77); - LCD_DataWrite(WX); - LCD_CmdWrite(0x78); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x79); - LCD_DataWrite(WX); - LCD_CmdWrite(0x7A); - LCD_DataWrite(WX>>8); -} - -//掘蛾畖 -void Ellipse_Radius_RxRy(unsigned short WX,unsigned short HY) -{ - /* - [77h] Draw Circle/Ellipse/Circle Square Major radius [7:0] - [78h] Draw Circle/Ellipse/Circle Square Major radius [12:8] - [79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0] - [7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8] - */ - LCD_CmdWrite(0x77); - LCD_DataWrite(WX); - LCD_CmdWrite(0x78); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x79); - LCD_DataWrite(HY); - LCD_CmdWrite(0x7A); - LCD_DataWrite(HY>>8); -} - -//よ锣à畖 -void Circle_Square_Radius_RxRy(unsigned short WX,unsigned short HY) -{ - /* - [77h] Draw Circle/Ellipse/Circle Square Major radius [7:0] - [78h] Draw Circle/Ellipse/Circle Square Major radius [12:8] - [79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0] - [7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8] - */ - LCD_CmdWrite(0x77); - LCD_DataWrite(WX); - LCD_CmdWrite(0x78); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0x79); - LCD_DataWrite(HY); - LCD_CmdWrite(0x7A); - LCD_DataWrite(HY>>8); -} - -//[84h]========================================================================= -void Set_PWM_Prescaler_1_to_256(unsigned short WX) -{ - /* - PWM Prescaler Register - These 8 bits determine prescaler value for Timer 0 and 1. - Time base is ¨Core_Freq / (Prescaler + 1)〃 - */ - WX=WX-1; - LCD_CmdWrite(0x84); - LCD_DataWrite(WX); -} -//[85h]========================================================================= -void Select_PWM1_Clock_Divided_By_1(void) -{ - /* - Select MUX input for PWM Timer 1. - 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; - */ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp &= cClrb7; - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Select_PWM1_Clock_Divided_By_2(void) -{ - /* - Select MUX input for PWM Timer 1. - 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; - */ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp &= cClrb7; - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Select_PWM1_Clock_Divided_By_4(void) -{ - /* - Select MUX input for PWM Timer 1. - 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; - */ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp |= cSetb7; - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Select_PWM1_Clock_Divided_By_8(void) -{ - /* - Select MUX input for PWM Timer 1. - 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; - */ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp |= cSetb7; - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Select_PWM0_Clock_Divided_By_1(void) -{ - /* - Select MUX input for PWM Timer 0. - 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; - */ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp &= cClrb5; - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Select_PWM0_Clock_Divided_By_2(void) -{ - /* - Select MUX input for PWM Timer 0. - 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; - */ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp &= cClrb5; - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Select_PWM0_Clock_Divided_By_4(void) -{ - /* - Select MUX input for PWM Timer 0. - 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; - */ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp |= cSetb5; - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Select_PWM0_Clock_Divided_By_8(void) -{ - /* - Select MUX input for PWM Timer 0. - 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; - */ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp |= cSetb5; - temp |= cSetb4; - LCD_DataWrite(temp); -} -//[85h].[bit3][bit2]========================================================================= -/* -XPWM[1] pin function control -0X: XPWM[1] output system error flag (REG[00h] bit[1:0], Scan bandwidth insufficient + Memory access out of range) -10: XPWM[1] enabled and controlled by PWM timer 1 -11: XPWM[1] output oscillator clock -//If XTEST[0] set high, then XPWM[1] will become panel scan clock input. -*/ -void Select_PWM1_is_ErrorFlag(void) -{ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void Select_PWM1(void) -{ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp |= cSetb3; - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Select_PWM1_is_Osc_Clock(void) -{ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp |= cSetb3; - temp |= cSetb2; - LCD_DataWrite(temp); -} -//[85h].[bit1][bit0]========================================================================= -/* -XPWM[0] pin function control -0X: XPWM[0] becomes GPIO-C[7] -10: XPWM[0] enabled and controlled by PWM timer 0 -11: XPWM[0] output core clock -*/ -void Select_PWM0_is_GPIO_C7(void) -{ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -void Select_PWM0(void) -{ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp |= cSetb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Select_PWM0_is_Core_Clock(void) -{ - unsigned char temp; - LCD_CmdWrite(0x85); - temp = LCD_DataRead(); - temp |= cSetb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} -//[86h]========================================================================= -//[86h]PWM1 -void Enable_PWM1_Inverter(void) -{ - /* - PWM Timer 1 output inverter on/off. - Determine the output inverter on/off for Timer 1. - 0 = Inverter off - 1 = Inverter on for PWM1 - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Disable_PWM1_Inverter(void) -{ - /* - PWM Timer 1 output inverter on/off. - Determine the output inverter on/off for Timer 1. - 0 = Inverter off - 1 = Inverter on for PWM1 - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Auto_Reload_PWM1(void) -{ - /* - PWM Timer 1 auto reload on/off - Determine auto reload on/off for Timer 1. - 0 = One-shot - 1 = Interval mode(auto reload) - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void One_Shot_PWM1(void) -{ - /* - PWM Timer 1 auto reload on/off - Determine auto reload on/off for Timer 1. - 0 = One-shot - 1 = Interval mode(auto reload) - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void Start_PWM1(void) -{ - /* - PWM Timer 1 start/stop - Determine start/stop for Timer 1. - 0 = Stop - 1 = Start for Timer 1 - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Stop_PWM1(void) -{ - /* - PWM Timer 1 start/stop - Determine start/stop for Timer 1. - 0 = Stop - 1 = Start for Timer 1 - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -//[86h]PWM0 -void Enable_PWM0_Dead_Zone(void) -{ - /* - PWM Timer 0 Dead zone enable - Determine the dead zone operation. 0 = Disable. 1 = Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Disable_PWM0_Dead_Zone(void) -{ - /* - PWM Timer 0 Dead zone enable - Determine the dead zone operation. 0 = Disable. 1 = Enable. - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp &= cClrb3; - LCD_DataWrite(temp); -} -void Enable_PWM0_Inverter(void) -{ - /* - PWM Timer 0 output inverter on/off - Determine the output inverter on/off for Timer 0. - 0 = Inverter off - 1 = Inverter on for PWM0 - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Disable_PWM0_Inverter(void) -{ - /* - PWM Timer 0 output inverter on/off - Determine the output inverter on/off for Timer 0. - 0 = Inverter off - 1 = Inverter on for PWM0 - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Auto_Reload_PWM0(void) -{ - /* - PWM Timer 0 auto reload on/off - Determine auto reload on/off for Timer 0. - 0 = One-shot - 1 = Interval mode(auto reload) - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} -void One_Shot_PWM0(void) -{ - /* - PWM Timer 1 auto reload on/off - Determine auto reload on/off for Timer 1. - 0 = One-shot - 1 = Interval mode(auto reload) - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} -void Start_PWM0(void) -{ - /* - PWM Timer 0 start/stop - Determine start/stop for Timer 0. - 0 = Stop - 1 = Start for Timer 0 - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} -void Stop_PWM0(void) -{ - /* - PWM Timer 0 start/stop - Determine start/stop for Timer 0. - 0 = Stop - 1 = Start for Timer 0 - */ - unsigned char temp; - LCD_CmdWrite(0x86); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} -//[87h]========================================================================= -void Set_Timer0_Dead_Zone_Length(unsigned char temp) -{ - /* - Timer 0 Dead zone length register - These 8 bits determine the dead zone length. The 1 unit time of - the dead zone length is equal to that of timer 0. - */ - LCD_CmdWrite(0x87); - LCD_DataWrite(temp); -} -//[88h][89h]========================================================================= -void Set_Timer0_Compare_Buffer(unsigned short WX) -{ - /* - Timer 0 compare buffer register - Compare buffer register total has 16 bits. - When timer counter equal or less than compare buffer register will cause PWM out - high level if inv_on bit is off. - */ - LCD_CmdWrite(0x88); - LCD_DataWrite(WX); - LCD_CmdWrite(0x89); - LCD_DataWrite(WX>>8); -} -//[8Ah][8Bh]========================================================================= -void Set_Timer0_Count_Buffer(unsigned short WX) -{ - /* - Timer 0 count buffer register - Count buffer register total has 16 bits. - When timer counter equal to 0 will cause PWM timer reload Count buffer register if reload_en bit set as enable. - It may read back timer counterˇs real time value when PWM timer start. - */ - LCD_CmdWrite(0x8A); - LCD_DataWrite(WX); - LCD_CmdWrite(0x8B); - LCD_DataWrite(WX>>8); -} -//[8Ch][8Dh]========================================================================= -void Set_Timer1_Compare_Buffer(unsigned short WX) -{ - /* - Timer 0 compare buffer register - Compare buffer register total has 16 bits. - When timer counter equal or less than compare buffer register will cause PWM out - high level if inv_on bit is off. - */ - LCD_CmdWrite(0x8C); - LCD_DataWrite(WX); - LCD_CmdWrite(0x8D); - LCD_DataWrite(WX>>8); -} -//[8Eh][8Fh]========================================================================= -void Set_Timer1_Count_Buffer(unsigned short WX) -{ - /* - Timer 0 count buffer register - Count buffer register total has 16 bits. - When timer counter equal to 0 will cause PWM timer reload Count buffer register if reload_en bit set as enable. - It may read back timer counterˇs real time value when PWM timer start. - */ - LCD_CmdWrite(0x8E); - LCD_DataWrite(WX); - LCD_CmdWrite(0x8F); - LCD_DataWrite(WX>>8); -} - - -//[90h]~[B5h]========================================================================= - -//[90h]========================================================================= -void BTE_Enable(void) -{ - /* - BTE Function Enable - 0 : BTE Function disable. - 1 : BTE Function enable. - */ - unsigned char temp; - LCD_CmdWrite(0x90); - temp = LCD_DataRead(); - temp |= cSetb4 ; - LCD_DataWrite(temp); -} - -//[90h]========================================================================= -void BTE_Disable(void) -{ - /* - BTE Function Enable - 0 : BTE Function disable. - 1 : BTE Function enable. - */ - unsigned char temp; - LCD_CmdWrite(0x90); - temp = LCD_DataRead(); - temp &= cClrb4 ; - LCD_DataWrite(temp); -} - -//[90h]========================================================================= -void Check_BTE_Busy(void) -{ - /* - BTE Function Status - 0 : BTE Function is idle. - 1 : BTE Function is busy. - */ - unsigned char temp; - - do - { - temp=LCD_StatusRead(); - } - while(temp&0x08); -} -//[90h]========================================================================= -void Pattern_Format_8X8(void) -{ - /* - Pattern Format - 0 : 8X8 - 1 : 16X16 - */ - unsigned char temp; - LCD_CmdWrite(0x90); - temp = LCD_DataRead(); - temp &= cClrb0 ; - LCD_DataWrite(temp); -} -//[90h]========================================================================= -void Pattern_Format_16X16(void) -{ - /* - Pattern Format - 0 : 8X8 - 1 : 16X16 - */ - unsigned char temp; - LCD_CmdWrite(0x90); - temp = LCD_DataRead(); - temp |= cSetb0 ; - LCD_DataWrite(temp); -} - -//[91h]========================================================================= -void BTE_ROP_Code(unsigned char setx) -{ - /* - BTE ROP Code[Bit7:4] - - 0000 : 0(Blackness) - 0001 : ~S0.~S1 or ~ ( S0+S1 ) - 0010 : ~S0.S1 - 0011 : ~S0 - 0100 : S0.~S1 - 0101 : ~S1 - 0110 : S0^S1 - 0111 : ~S0+~S1 or ~ ( S0.S1 ) - 1000 : S0.S1 - 1001 : ~ ( S0^S1 ) - 1010 : S1 - 1011 : ~S0+S1 - 1100 : S0 - 1101 : S0+~S1 - 1110 : S0+S1 - 1111 : 1 ( Whiteness ) - */ - unsigned char temp; - LCD_CmdWrite(0x91); - temp = LCD_DataRead(); - temp &= 0x0f ; - temp |= (setx<<4); - LCD_DataWrite(temp); -} - -//[91h]========================================================================= -void BTE_Operation_Code(unsigned char setx) -{ - /* - BTE Operation Code[Bit3:0] - - 0000 : MPU Write BTE with ROP. - 0001 : MPU Read BTE w/o ROP. - 0010 : Memory copy (move) BTE in positive direction with ROP. - 0011 : Memory copy (move) BTE in negative direction with ROP. - 0100 : MPU Transparent Write BTE. (w/o ROP.) - 0101 : Transparent Memory copy (move) BTE in positive direction (w/o ROP.) - 0110 : Pattern Fill with ROP. - 0111 : Pattern Fill with key-chroma - 1000 : Color Expansion - 1001 : Color Expansion with transparency - 1010 : Move BTE in positive direction with Alpha blending - 1011 : MPU Write BTE with Alpha blending - 1100 : Solid Fill - 1101 : Reserved - 1110 : Reserved - 1111 : Reserved - */ - unsigned char temp; - LCD_CmdWrite(0x91); - temp = LCD_DataRead(); - temp &= 0xf0 ; - temp |= setx ; - LCD_DataWrite(temp); -} -//[92h]========================================================================= -void BTE_S0_Color_8bpp(void) -{ - /* - S0 Color Depth - 00 : 256 Color - 01 : 64k Color - 1x : 16M Color - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp &= cClrb6 ; - temp &= cClrb5 ; - LCD_DataWrite(temp); -} -//[92h]========================================================================= -void BTE_S0_Color_16bpp(void) -{ - /* - S0 Color Depth - 00 : 256 Color - 01 : 64k Color - 1x : 16M Color - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp &= cClrb6 ; - temp |= cSetb5 ; - LCD_DataWrite(temp); -} -//[92h]========================================================================= -void BTE_S0_Color_24bpp(void) -{ - /* - S0 Color Depth - 00 : 256 Color - 01 : 64k Color - 1x : 16M Color - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp |= cSetb6 ; - //temp |= cSetb5 ; - LCD_DataWrite(temp); -} -//[92h]========================================================================= -void BTE_S1_Color_8bpp(void) -{ - /* - S1 Color Depth - 000 : 256 Color - 001 : 64k Color - 010 : 16M Color - 011 : Constant Color - 100 : 8 bit pixel alpha blending - 101 : 16 bit pixel alpha blending - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp &= cClrb4 ; - temp &= cClrb3 ; - temp &= cClrb2 ; - LCD_DataWrite(temp); -} -//[92h]========================================================================= -void BTE_S1_Color_16bpp(void) -{ - /* - S1 Color Depth - 000 : 256 Color - 001 : 64k Color - 010 : 16M Color - 011 : Constant Color - 100 : 8 bit pixel alpha blending - 101 : 16 bit pixel alpha blending - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp &= cClrb4 ; - temp &= cClrb3 ; - temp |= cSetb2 ; - LCD_DataWrite(temp); -} -//[92h]========================================================================= -void BTE_S1_Color_24bpp(void) -{ - /* - S1 Color Depth - 000 : 256 Color - 001 : 64k Color - 010 : 16M Color - 011 : Constant Color - 100 : 8 bit pixel alpha blending - 101 : 16 bit pixel alpha blending - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp &= cClrb4 ; - temp |= cSetb3 ; - temp &= cClrb2 ; - LCD_DataWrite(temp); -} - -//[92h]========================================================================= -void BTE_S1_Color_Constant(void) -{ - /* - S1 Color Depth - 000 : 256 Color - 001 : 64k Color - 010 : 16M Color - 011 : Constant Color - 100 : 8 bit pixel alpha blending - 101 : 16 bit pixel alpha blending - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp &= cClrb4 ; - temp |= cSetb3 ; - temp |= cSetb2 ; - LCD_DataWrite(temp); -} - - - -//[92h]========================================================================= -void BTE_S1_Color_8bit_Alpha(void) -{ - /* - S1 Color Depth - 000 : 256 Color - 001 : 64k Color - 010 : 16M Color - 011 : Constant Color - 100 : 8 bit pixel alpha blending - 101 : 16 bit pixel alpha blending - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp |= cSetb4 ; - temp &= cClrb3 ; - temp &= cClrb2 ; - LCD_DataWrite(temp); -} - -//[92h]========================================================================= -void BTE_S1_Color_16bit_Alpha(void) -{ - /* - S1 Color Depth - 000 : 256 Color - 001 : 64k Color - 010 : 16M Color - 011 : Constant Color - 100 : 8 bit pixel alpha blending - 101 : 16 bit pixel alpha blending - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp |= cSetb4 ; - temp &= cClrb3 ; - temp |= cSetb2 ; - LCD_DataWrite(temp); -} - -//[92h]========================================================================= -void BTE_Destination_Color_8bpp(void) -{ - /* - Destination Color Depth - 00 : 256 Color - 01 : 64k Color - 1x : 16M Color - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp &= cClrb1 ; - temp &= cClrb0 ; - LCD_DataWrite(temp); -} -//[92h]========================================================================= -void BTE_Destination_Color_16bpp(void) -{ - /* - Destination Color Depth - 00 : 256 Color - 01 : 64k Color - 1x : 16M Color - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp &= cClrb1 ; - temp |= cSetb0 ; - LCD_DataWrite(temp); -} -//[92h]========================================================================= -void BTE_Destination_Color_24bpp(void) -{ - /* - Destination Color Depth - 00 : 256 Color - 10 : 64k Color - 1x : 16M Color - */ - unsigned char temp; - LCD_CmdWrite(0x92); - temp = LCD_DataRead(); - temp |= cSetb1 ; - //temp |= cSetb0 ; - LCD_DataWrite(temp); -} - - -//[93h][94h][95h][96h]========================================================================= -void BTE_S0_Memory_Start_Address(unsigned long Addr) -{ - /* - [93h] BTE S0 Memory Start Address [7:0] - [94h] BTE S0 Memory Start Address [15:8] - [95h] BTE S0 Memory Start Address [23:16] - [96h] BTE S0 Memory Start Address [31:24] - Bit [1:0] tie to ¨0〃 internally. - */ - LCD_RegisterWrite(0x93,Addr); - LCD_RegisterWrite(0x94,Addr>>8); - LCD_RegisterWrite(0x95,Addr>>16); - LCD_RegisterWrite(0x96,Addr>>24); -} - - -//[97h][98h]========================================================================= -void BTE_S0_Image_Width(unsigned short WX) -{ - /* - [97h] BTE S0 Image Width [7:0] - [98h] BTE S0 Image Width [12:8] - Unit: Pixel. - Bit [1:0] tie to ¨0〃 internally. - */ - LCD_RegisterWrite(0x97,WX); - LCD_RegisterWrite(0x98,WX>>8); -} - - -//[99h][9Ah][9Bh][9Ch]========================================================================= -void BTE_S0_Window_Start_XY(unsigned short WX,unsigned short HY) -{ - /* - [99h] BTE S0 Window Upper-Left corner X-coordination [7:0] - [9Ah] BTE S0 Window Upper-Left corner X-coordination [12:8] - [9Bh] BTE S0 Window Upper-Left corner Y-coordination [7:0] - [9Ch] BTE S0 Window Upper-Left corner Y-coordination [12:8] - */ - LCD_RegisterWrite(0x99,WX); - LCD_RegisterWrite(0x9A,WX>>8); - LCD_RegisterWrite(0x9B,HY); - LCD_RegisterWrite(0x9C,HY>>8); -} - - - - -//[9Dh][9Eh][9Fh][A0h]========================================================================= -void BTE_S1_Memory_Start_Address(unsigned long Addr) -{ - /* - [9Dh] BTE S1 Memory Start Address [7:0] - [9Eh] BTE S1 Memory Start Address [15:8] - [9Fh] BTE S1 Memory Start Address [23:16] - [A0h] BTE S1 Memory Start Address [31:24] - Bit [1:0] tie to ¨0〃 internally. - */ - LCD_RegisterWrite(0x9D,Addr); - LCD_RegisterWrite(0x9E,Addr>>8); - LCD_RegisterWrite(0x9F,Addr>>16); - LCD_RegisterWrite(0xA0,Addr>>24); -} - - -//Input data format:R3G3B2 -void S1_Constant_color_256(unsigned char temp) -{ - LCD_CmdWrite(0x9D); - LCD_DataWrite(temp); - LCD_CmdWrite(0x9E); - LCD_DataWrite(temp<<3); - LCD_CmdWrite(0x9F); - LCD_DataWrite(temp<<6); -} - -//Input data format:R5G6B6 -void S1_Constant_color_65k(unsigned short temp) -{ - LCD_CmdWrite(0x9D); - LCD_DataWrite(temp>>8); - LCD_CmdWrite(0x9E); - LCD_DataWrite(temp>>3); - LCD_CmdWrite(0x9F); - LCD_DataWrite(temp<<3); -} - -//Input data format:R8G8B8 -void S1_Constant_color_16M(unsigned long temp) -{ - LCD_CmdWrite(0x9D); - LCD_DataWrite(temp>>16); - LCD_CmdWrite(0x9E); - LCD_DataWrite(temp>>8); - LCD_CmdWrite(0x9F); - LCD_DataWrite(temp); -} - - - - -//[A1h][A2h]========================================================================= -void BTE_S1_Image_Width(unsigned short WX) -{ - /* - [A1h] BTE S1 Image Width [7:0] - [A2h] BTE S1 Image Width [12:8] - Unit: Pixel. - Bit [1:0] tie to ¨0〃 internally. - */ - LCD_RegisterWrite(0xA1,WX); - LCD_RegisterWrite(0xA2,WX>>8); -} - - -//[A3h][A4h][A5h][A6h]========================================================================= -void BTE_S1_Window_Start_XY(unsigned short WX,unsigned short HY) -{ - /* - [A3h] BTE S1 Window Upper-Left corner X-coordination [7:0] - [A4h] BTE S1 Window Upper-Left corner X-coordination [12:8] - [A5h] BTE S1 Window Upper-Left corner Y-coordination [7:0] - [A6h] BTE S1 Window Upper-Left corner Y-coordination [12:8] - */ - LCD_RegisterWrite(0xA3,WX); - LCD_RegisterWrite(0xA4,WX>>8); - LCD_RegisterWrite(0xA5,HY); - LCD_RegisterWrite(0xA6,HY>>8); -} - - - - -//[A7h][A8h][A9h][AAh]========================================================================= -void BTE_Destination_Memory_Start_Address(unsigned long Addr) -{ - /* - [A7h] BTE Destination Memory Start Address [7:0] - [A8h] BTE Destination Memory Start Address [15:8] - [A9h] BTE Destination Memory Start Address [23:16] - [AAh] BTE Destination Memory Start Address [31:24] - Bit [1:0] tie to ¨0〃 internally. - */ - LCD_RegisterWrite(0xA7,Addr); - LCD_RegisterWrite(0xA8,Addr>>8); - LCD_RegisterWrite(0xA9,Addr>>16); - LCD_RegisterWrite(0xAA,Addr>>24); -} - - -//[ABh][ACh]========================================================================= -void BTE_Destination_Image_Width(unsigned short WX) -{ - /* - [ABh] BTE Destination Image Width [7:0] - [ACh] BTE Destination Image Width [12:8] - Unit: Pixel. - Bit [1:0] tie to ¨0〃 internally. - */ - LCD_RegisterWrite(0xAB,WX); - LCD_RegisterWrite(0xAC,WX>>8); -} - - -//[ADh][AEh][AFh][B0h]========================================================================= -void BTE_Destination_Window_Start_XY(unsigned short WX,unsigned short HY) -{ - /* - [ADh] BTE Destination Window Upper-Left corner X-coordination [7:0] - [AEh] BTE Destination Window Upper-Left corner X-coordination [12:8] - [AFh] BTE Destination Window Upper-Left corner Y-coordination [7:0] - [B0h] BTE Destination Window Upper-Left corner Y-coordination [12:8] - */ - LCD_RegisterWrite(0xAD,WX); - LCD_RegisterWrite(0xAE,WX>>8); - LCD_RegisterWrite(0xAF,HY); - LCD_RegisterWrite(0xB0,HY>>8); -} - - -//[B1h][B2h][B3h][B4h]=============================================================== - -void BTE_Window_Size(unsigned short WX, unsigned short WY) - -{ - /* - [B1h] BTE Window Width [7:0] - [B2h] BTE Window Width [12:8] - - [B3h] BTE Window Height [7:0] - [B4h] BTE Window Height [12:8] - */ - LCD_RegisterWrite(0xB1,WX); - LCD_RegisterWrite(0xB2,WX>>8); - LCD_RegisterWrite(0xB3,WY); - LCD_RegisterWrite(0xB4,WY>>8); -} - -//[B5h]========================================================================= -void BTE_Alpha_Blending_Effect(unsigned char temp) -{ - /* - Window Alpha Blending effect for S0 & S1 - The value of alpha in the color code ranges from 0.0 to 1.0, - where 0.0 represents a fully transparent color, and 1.0 - represents a fully opaque color. - 00h: 0 - 01h: 1/32 - 02h: 2/32 - : - 1Eh: 30/32 - 1Fh: 31/32 - 2Xh: 1 - Output Effect = (S0 image x (1 - alpha setting value)) + (S1 image x alpha setting value) - */ - LCD_CmdWrite(0xB5); - LCD_DataWrite(temp); -} - - -//[B6h]========================================================================= -void Start_SFI_DMA(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB6); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} - -void Check_Busy_SFI_DMA(void) -{ - LCD_CmdWrite(0xB6); - - do - { - } - while((LCD_DataRead()&0x01)==0x01); -} - - -//[B7h]========================================================================= -void Select_SFI_0(void) -{ - /*[bit7] - Serial Flash/ROM I/F # Select - 0: Serial Flash/ROM 0 I/F is selected. - 1: Serial Flash/ROM 1 I/F is selected. - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void Select_SFI_1(void) -{ - /*[bit7] - Serial Flash/ROM I/F # Select - 0: Serial Flash/ROM 0 I/F is selected. - 1: Serial Flash/ROM 1 I/F is selected. - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void Select_SFI_Font_Mode(void) -{ - /*[bit6] - Serial Flash /ROM Access Mode - 0: Font mode  for external cgrom - 1: DMA mode  for cgram , pattern , bootstart image or osd - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Select_SFI_DMA_Mode(void) -{ - /*[bit6] - Serial Flash /ROM Access Mode - 0: Font mode  for external cgrom - 1: DMA mode  for cgram , pattern , bootstart image or osd - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Select_SFI_24bit_Address(void) -{ - /*[bit5] - Serial Flash/ROM Address Mode - 0: 24 bits address mode - 1: 32 bits address mode - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} -void Select_SFI_32bit_Address(void) -{ - /*[bit5] - Serial Flash/ROM Address Mode - 0: 24 bits address mode - 1: 32 bits address mode - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} -void Select_SFI_Waveform_Mode_0(void) -{ - /*[bit4] - Serial Flash/ROM Waveform Mode - Mode 0. - Mode 3. - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Select_SFI_Waveform_Mode_3(void) -{ - /*[bit4] - Serial Flash/ROM Waveform Mode - Mode 0. - Mode 3. - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Select_SFI_0_DummyRead(void) -{ - /*[bit3][bit2] - Serial Flash /ROM Read Cycle 0 RW - 00b: no dummy cycle mode - 01b: 1 dummy cycle mode - 10b: 2 dummy cycle mode - 11b: 4 dummy cycle mode - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= 0xF3; - LCD_DataWrite(temp); -} -void Select_SFI_8_DummyRead(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= 0xF3; - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Select_SFI_16_DummyRead(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= 0xF3; - temp |= cSetb3; - LCD_DataWrite(temp); -} -void Select_SFI_24_DummyRead(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp |= 0x0c; - LCD_DataWrite(temp); -} -void Select_SFI_Single_Mode(void) -{ - /*[bit1][bit0] - Serial Flash /ROM I/F Data Latch Mode Select - 0Xb: Single Mode - 10b: Dual Mode 0. - 11b: Dual Mode 1. - */ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= 0xFC; - LCD_DataWrite(temp); -} -void Select_SFI_Dual_Mode0(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp &= 0xFC; - temp |= cSetb1; - LCD_DataWrite(temp); -} -void Select_SFI_Dual_Mode1(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB7); - temp = LCD_DataRead(); - temp |= 0x03; - LCD_DataWrite(temp); -} - -//REG[B8h] SPI master Tx /Rx FIFO Data Register (SPIDR) -unsigned char SPI_Master_FIFO_Data_Put(unsigned char Data) -{ - unsigned char temp; - LCD_CmdWrite(0xB8); - LCD_DataWrite(Data); - - while(Tx_FIFO_Empty_Flag()==0); - - temp = SPI_Master_FIFO_Data_Get(); - return temp; -} - -unsigned char SPI_Master_FIFO_Data_Get(void) -{ - unsigned char temp; - - while(Rx_FIFO_Empty_Flag()==1); - - LCD_CmdWrite(0xB8); - temp=LCD_DataRead(); - //while(Rx_FIFO_full_flag()); - return temp; -} - -//REG[B9h] SPI master Control Register (SPIMCR2) -void Mask_SPI_Master_Interrupt_Flag(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} - -void Select_nSS_drive_on_xnsfcs0(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp &= cClrb5; - LCD_DataWrite(temp); -} - -void Select_nSS_drive_on_xnsfcs1(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp |= cSetb5; - LCD_DataWrite(temp); -} - -//0: inactive (nSS port will goes high) -void nSS_Inactive(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -//1: active (nSS port will goes low) -void nSS_Active(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} - -//Interrupt enable for FIFO overflow error [OVFIRQEN] -void OVFIRQEN_Enable(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} -//Interrupt enable for while Tx FIFO empty & SPI engine/FSM idle -void EMTIRQEN_Enable(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} - - -//At CPOL=0 the base value of the clock is zero -//o For CPHA=0, data are read on the clock's rising edge (low->high transition) and -//data are changed on a falling edge (high->low clock transition). -//o For CPHA=1, data are read on the clock's falling edge and data are changed on a -//rising edge. - -//At CPOL=1 the base value of the clock is one (inversion of CPOL=0) -//o For CPHA=0, data are read on clock's falling edge and data are changed on a -//rising edge. -//o For CPHA=1, data are read on clock's rising edge and data are changed on a -//falling edge. - -void Reset_CPOL(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp &= cClrb1; - LCD_DataWrite(temp); -} - -void Set_CPOL(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp |= cSetb1; - LCD_DataWrite(temp); -} - - -void Reset_CPHA(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp &= cClrb0; - LCD_DataWrite(temp); -} - -void Set_CPHA(void) -{ - unsigned char temp; - LCD_CmdWrite(0xB9); - temp = LCD_DataRead(); - temp |= cSetb0; - LCD_DataWrite(temp); -} - - -//REG[BAh] SPI master Status Register (SPIMSR) -unsigned char Tx_FIFO_Empty_Flag(void) -{ - LCD_CmdWrite(0xBA); - - if((LCD_DataRead()&0x80)==0x80) - { - return 1; - } - else - { - return 0; - } -} - -unsigned char Tx_FIFO_Full_Flag(void) -{ - LCD_CmdWrite(0xBA); - - if((LCD_DataRead()&0x40)==0x40) - { - return 1; - } - else - { - return 0; - } -} - -unsigned char Rx_FIFO_Empty_Flag(void) -{ - LCD_CmdWrite(0xBA); - - if((LCD_DataRead()&0x20)==0x20) - { - return 1; - } - else - { - return 0; - } -} - -unsigned char Rx_FIFO_full_flag(void) -{ - LCD_CmdWrite(0xBA); - - if((LCD_DataRead()&0x10)==0x10) - { - return 1; - } - else - { - return 0; - } -} - -unsigned char OVFI_Flag(void) -{ - LCD_CmdWrite(0xBA); - - if((LCD_DataRead()&0x08)==0x08) - { - return 1; - } - else - { - return 0; - } -} - -void Clear_OVFI_Flag(void) -{ - unsigned char temp; - LCD_CmdWrite(0xBA); - temp = LCD_DataRead(); - temp |= cSetb3; - LCD_DataWrite(temp); -} - -unsigned char EMTI_Flag(void) -{ - LCD_CmdWrite(0xBA); - - if((LCD_DataRead()&0x04)==0x04) - { - return 1; - } - else - { - return 0; - } -} - -void Clear_EMTI_Flag(void) -{ - unsigned char temp; - LCD_CmdWrite(0xBA); - temp = LCD_DataRead(); - temp |= cSetb2; - LCD_DataWrite(temp); -} - - -//REG[BB] SPI Clock period (SPIDIV) -void SPI_Clock_Period(unsigned char temp) -{ - LCD_CmdWrite(0xBB); - LCD_DataWrite(temp); -} - -//[BCh][BDh][BEh][BFh]========================================================================= -void SFI_DMA_Source_Start_Address(unsigned long Addr) -{ - /* - DMA Source START ADDRESS - This bits index serial flash address [7:0][15:8][23:16][31:24] - */ - LCD_CmdWrite(0xBC); - LCD_DataWrite(Addr); - LCD_CmdWrite(0xBD); - LCD_DataWrite(Addr>>8); - LCD_CmdWrite(0xBE); - LCD_DataWrite(Addr>>16); - LCD_CmdWrite(0xBF); - LCD_DataWrite(Addr>>24); -} -//[C0h][C1h][C2h][C3h]========================================================================= -void SFI_DMA_Destination_Start_Address(unsigned long Addr) -{ - /* - DMA Destination START ADDRESS - [1:0]Fix at 0 - This bits index SDRAM address [7:0][15:8][23:16][31:24] - */ - LCD_CmdWrite(0xC0); - LCD_DataWrite(Addr); - LCD_CmdWrite(0xC1); - LCD_DataWrite(Addr>>8); - LCD_CmdWrite(0xC2); - LCD_DataWrite(Addr>>16); - LCD_CmdWrite(0xC3); - LCD_DataWrite(Addr>>24); -} -//[C0h][C1h][C2h][C3h]========================================================================= -void SFI_DMA_Destination_Upper_Left_Corner(unsigned short WX,unsigned short HY) -{ - /* - C0h - This register defines DMA Destination Window Upper-Left corner - X-coordination [7:0] on Canvas area. - When REG DMACR bit 1 = 1 (Block Mode) - This register defines Destination address [7:2] in SDRAM. - C1h - When REG DMACR bit 1 = 0 (Linear Mode) - This register defines DMA Destination Window Upper-Left corner - X-coordination [12:8] on Canvas area. - When REG DMACR bit 1 = 1 (Block Mode) - This register defines Destination address [15:8] in SDRAM. - C2h - When REG DMACR bit 1 = 0 (Linear Mode) - This register defines DMA Destination Window Upper-Left corner - Y-coordination [7:0] on Canvas area. - When REG DMACR bit 1 = 1 (Block Mode) - This register defines Destination address [23:16] in SDRAM. - C3h - When REG DMACR bit 1 = 0 (Linear Mode) - This register defines DMA Destination Window Upper-Left corner - Y-coordination [12:8] on Canvas area. - When REG DMACR bit 1 = 1 (Block Mode) - This register defines Destination address [31:24] in SDRAM. - */ - LCD_CmdWrite(0xC0); - LCD_DataWrite(WX); - LCD_CmdWrite(0xC1); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0xC2); - LCD_DataWrite(HY); - LCD_CmdWrite(0xC3); - LCD_DataWrite(HY>>8); -} - - - -//[C6h][C7h][C8h][C9h]========================================================================= -void SFI_DMA_Transfer_Number(unsigned long Addr) -{ - /* - Unit : Pixel - When REG DMACR bit 1 = 0 (Linear Mode) - DMA Transfer Number [7:0][15:8][23:16][31:24] - - When REG DMACR bit 1 = 1 (Block Mode) - DMA Block Width [7:0][15:8] - DMA Block HIGH[7:0][15:8] - */ - LCD_CmdWrite(0xC6); - LCD_DataWrite(Addr); - LCD_CmdWrite(0xC7); - LCD_DataWrite(Addr>>8); - LCD_CmdWrite(0xC8); - LCD_DataWrite(Addr>>16); - LCD_CmdWrite(0xC9); - LCD_DataWrite(Addr>>24); -} -void SFI_DMA_Transfer_Width_Height(unsigned short WX,unsigned short HY) -{ - /* - When REG DMACR bit 1 = 0 (Linear Mode) - DMA Transfer Number [7:0][15:8][23:16][31:24] - - When REG DMACR bit 1 = 1 (Block Mode) - DMA Block Width [7:0][15:8] - DMA Block HIGH[7:0][15:8] - */ - LCD_CmdWrite(0xC6); - LCD_DataWrite(WX); - LCD_CmdWrite(0xC7); - LCD_DataWrite(WX>>8); - LCD_CmdWrite(0xC8); - LCD_DataWrite(HY); - LCD_CmdWrite(0xC9); - LCD_DataWrite(HY>>8); -} -//[CAh][CBh]========================================================================= -void SFI_DMA_Source_Width(unsigned short WX) -{ - /* - DMA Source Picture Width [7:0][12:8] - Unit: pixel - */ - LCD_CmdWrite(0xCA); - LCD_DataWrite(WX); - LCD_CmdWrite(0xCB); - LCD_DataWrite(WX>>8); -} - -//[CCh]========================================================================= - -void Font_Select_UserDefine_Mode(void) -{ - /*[bit7-6] - User-defined Font /CGROM Font Selection Bit in Text Mode - 00 : Internal CGROM - 01 : Genitop serial flash - 10 : User-defined Font - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp |= cSetb7; - temp &= cClrb6; - LCD_DataWrite(temp); -} -void CGROM_Select_Internal_CGROM(void) -{ - /*[bit7-6] - User-defined Font /CGROM Font Selection Bit in Text Mode - 00 : Internal CGROM - 01 : Genitop serial flash - 10 : User-defined Font - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp &= cClrb7; - temp &= cClrb6; - LCD_DataWrite(temp); -} -void CGROM_Select_Genitop_FontROM(void) -{ - /*[bit7-6] - User-defined Font /CGROM Font Selection Bit in Text Mode - 00 : Internal CGROM - 01 : Genitop serial flash - 10 : User-defined Font - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp &= cClrb7; - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Font_Select_8x16_16x16(void) -{ - /*[bit5-4] - Font Height Setting - 00b : 8x16 / 16x16. - 01b : 12x24 / 24x24. - 10b : 16x32 / 32x32. - *** User-defined Font width is decided by font code. Genitop - serial flashˇs font width is decided by font code or GT Font ROM - control register. - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp &= cClrb5; - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Font_Select_12x24_24x24(void) -{ - /*[bit5-4] - Font Height Setting - 00b : 8x16 / 16x16. - 01b : 12x24 / 24x24. - 10b : 16x32 / 32x32. - *** User-defined Font width is decided by font code. Genitop - serial flashˇs font width is decided by font code or GT Font ROM - control register. - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp &= cClrb5; - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Font_Select_16x32_32x32(void) -{ - /*[bit5-4] - Font Height Setting - 00b : 8x16 / 16x16. - 01b : 12x24 / 24x24. - 10b : 16x32 / 32x32. - *** User-defined Font width is decided by font code. Genitop - serial flashˇs font width is decided by font code or GT Font ROM - control register. - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp |= cSetb5; - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Internal_CGROM_Select_ISOIEC8859_1(void) -{ - /* - Font Selection for internal CGROM - When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the - 8x16 character sets with the standard coding of ISO/IEC 8859-1~4, - which supports English and most of European country languages. - 00b : ISO/IEC 8859-1. - 01b : ISO/IEC 8859-2. - 10b : ISO/IEC 8859-3. - 11b : ISO/IEC 8859-4. - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp &= cClrb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Internal_CGROM_Select_ISOIEC8859_2(void) -{ - /* - Font Selection for internal CGROM - When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the - 8x16 character sets with the standard coding of ISO/IEC 8859-1~4, - which supports English and most of European country languages. - 00b : ISO/IEC 8859-1. - 01b : ISO/IEC 8859-2. - 10b : ISO/IEC 8859-3. - 11b : ISO/IEC 8859-4. - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp &= cClrb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} -void Internal_CGROM_Select_ISOIEC8859_3(void) -{ - /* - Font Selection for internal CGROM - When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the - 8x16 character sets with the standard coding of ISO/IEC 8859-1~4, - which supports English and most of European country languages. - 00b : ISO/IEC 8859-1. - 01b : ISO/IEC 8859-2. - 10b : ISO/IEC 8859-3. - 11b : ISO/IEC 8859-4. - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp |= cSetb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Internal_CGROM_Select_ISOIEC8859_4(void) -{ - /* - Font Selection for internal CGROM - When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the - 8x16 character sets with the standard coding of ISO/IEC 8859-1~4, - which supports English and most of European country languages. - 00b : ISO/IEC 8859-1. - 01b : ISO/IEC 8859-2. - 10b : ISO/IEC 8859-3. - 11b : ISO/IEC 8859-4. - */ - unsigned char temp; - LCD_CmdWrite(0xCC); - temp = LCD_DataRead(); - temp |= cSetb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} -//[CDh]========================================================================= -void Enable_Font_Alignment(void) -{ - /* - Full Alignment Selection Bit - 0 : Full alignment disable. - 1 : Full alignment enable. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} -void Disable_Font_Alignment(void) -{ - /* - Full Alignment Selection Bit - 0 : Full alignment disable. - 1 : Full alignment enable. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp &= cClrb7; - LCD_DataWrite(temp); -} -void Font_Background_select_Transparency(void) -{ - /* - Font Transparency - 0 : Font with background color. - 1 : Font with background transparency. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} -void Font_Background_select_Color(void) -{ - /* - Font Transparency - 0 : Font with background color. - 1 : Font with background transparency. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp &= cClrb6; - LCD_DataWrite(temp); -} -void Font_0_degree(void) -{ - /* - Font Rotation - 0 : Normal - Text direction from left to right then from top to bottom - 1 : Counterclockwise 90 degree & horizontal flip - Text direction from top to bottom then from left to right - (it should accommodate with set VDIR as 1) - This attribute can be changed only when previous font write - finished (core_busy = 0) - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp &= cClrb4; - LCD_DataWrite(temp); -} -void Font_90_degree(void) -{ - /* - Font Rotation - 0 : Normal - Text direction from left to right then from top to bottom - 1 : Counterclockwise 90 degree & horizontal flip - Text direction from top to bottom then from left to right - (it should accommodate with set VDIR as 1) - This attribute can be changed only when previous font write - finished (core_busy = 0) - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp |= cSetb4; - LCD_DataWrite(temp); -} -void Font_Width_X1(void) -{ - /* - Horizontal Font Enlargement - 00b : X1. - 01b : X2. - 10b : X3. - 11b : X4. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp &= cClrb3; - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Font_Width_X2(void) -{ - /* - Horizontal Font Enlargement - 00b : X1. - 01b : X2. - 10b : X3. - 11b : X4. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp &= cClrb3; - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Font_Width_X3(void) -{ - /* - Horizontal Font Enlargement - 00b : X1. - 01b : X2. - 10b : X3. - 11b : X4. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp |= cSetb3; - temp &= cClrb2; - LCD_DataWrite(temp); -} -void Font_Width_X4(void) -{ - /* - Horizontal Font Enlargement - 00b : X1. - 01b : X2. - 10b : X3. - 11b : X4. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp |= cSetb3; - temp |= cSetb2; - LCD_DataWrite(temp); -} -void Font_Height_X1(void) -{ - /* - Vertical Font Enlargement - 00b : X1. - 01b : X2. - 10b : X3. - 11b : X4. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp &= cClrb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Font_Height_X2(void) -{ - /* - Vertical Font Enlargement - 00b : X1. - 01b : X2. - 10b : X3. - 11b : X4. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp &= cClrb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} -void Font_Height_X3(void) -{ - /* - Vertical Font Enlargement - 00b : X1. - 01b : X2. - 10b : X3. - 11b : X4. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp |= cSetb1; - temp &= cClrb0; - LCD_DataWrite(temp); -} -void Font_Height_X4(void) -{ - /* - Vertical Font Enlargement - 00b : X1. - 01b : X2. - 10b : X3. - 11b : X4. - */ - unsigned char temp; - LCD_CmdWrite(0xCD); - temp = LCD_DataRead(); - temp |= cSetb1; - temp |= cSetb0; - LCD_DataWrite(temp); -} - -//[CEh]========================================================================= -void GTFont_Select_GT21L16TW_GT21H16T1W(void) -{ - /* - GT Serial Font ROM Select - 000b: GT21L16TW / GT21H16T1W - 001b: GT23L16U2W - 010b: GT23L24T3Y / GT23H24T3Y - 011b: GT23L24M1Z - 100b: GT23L32S4W / GT23H32S4W - 101b: GT20L24F6Y - 110b: GT21L24S1W - 111b: GT22L16A1Y - */ - unsigned char temp; - LCD_CmdWrite(0xCE); - temp = LCD_DataRead(); - temp &= cClrb7; - temp &= cClrb6; - temp &= cClrb5; - LCD_DataWrite(temp); -} -void GTFont_Select_GT23L16U2W(void) -{ - /* - GT Serial Font ROM Select - 000b: GT21L16TW / GT21H16T1W - 001b: GT23L16U2W - 010b: GT23L24T3Y / GT23H24T3Y - 011b: GT23L24M1Z - 100b: GT23L32S4W / GT23H32S4W - 101b: GT20L24F6Y - 110b: GT21L24S1W - 111b: GT22L16A1Y - */ - unsigned char temp; - LCD_CmdWrite(0xCE); - temp = LCD_DataRead(); - temp &= cClrb7; - temp &= cClrb6; - temp |= cSetb5; - LCD_DataWrite(temp); -} -void GTFont_Select_GT23L24T3Y_GT23H24T3Y(void) -{ - /* - GT Serial Font ROM Select - 000b: GT21L16TW / GT21H16T1W - 001b: GT23L16U2W - 010b: GT23L24T3Y / GT23H24T3Y - 011b: GT23L24M1Z - 100b: GT23L32S4W / GT23H32S4W - 101b: GT20L24F6Y - 110b: GT21L24S1W - 111b: GT22L16A1Y - */ - unsigned char temp; - LCD_CmdWrite(0xCE); - temp = LCD_DataRead(); - temp &= cClrb7; - temp |= cSetb6; - temp &= cClrb5; - LCD_DataWrite(temp); -} -void GTFont_Select_GT23L24M1Z(void) -{ - /* - GT Serial Font ROM Select - 000b: GT21L16TW / GT21H16T1W - 001b: GT23L16U2W - 010b: GT23L24T3Y / GT23H24T3Y - 011b: GT23L24M1Z - 100b: GT23L32S4W / GT23H32S4W - 101b: GT20L24F6Y - 110b: GT21L24S1W - 111b: GT22L16A1Y - */ - unsigned char temp; - LCD_CmdWrite(0xCE); - temp = LCD_DataRead(); - temp &= cClrb7; - temp |= cSetb6; - temp |= cSetb5; - LCD_DataWrite(temp); -} -void GTFont_Select_GT23L32S4W_GT23H32S4W(void) -{ - /* - GT Serial Font ROM Select - 000b: GT21L16TW / GT21H16T1W - 001b: GT23L16U2W - 010b: GT23L24T3Y / GT23H24T3Y - 011b: GT23L24M1Z - 100b: GT23L32S4W / GT23H32S4W - 101b: GT20L24F6Y - 110b: GT21L24S1W - 111b: GT22L16A1Y - */ - unsigned char temp; - LCD_CmdWrite(0xCE); - temp = LCD_DataRead(); - temp |= cSetb7; - temp &= cClrb6; - temp &= cClrb5; - LCD_DataWrite(temp); -} -void GTFont_Select_GT20L24F6Y(void) -{ - /* - GT Serial Font ROM Select - 000b: GT21L16TW / GT21H16T1W - 001b: GT23L16U2W - 010b: GT23L24T3Y / GT23H24T3Y - 011b: GT23L24M1Z - 100b: GT23L32S4W / GT23H32S4W - 101b: GT20L24F6Y - 110b: GT21L24S1W - 111b: GT22L16A1Y - */ - unsigned char temp; - LCD_CmdWrite(0xCE); - temp = LCD_DataRead(); - temp |= cSetb7; - temp &= cClrb6; - temp |= cSetb5; - LCD_DataWrite(temp); -} -void GTFont_Select_GT21L24S1W(void) -{ - /* - GT Serial Font ROM Select - 000b: GT21L16TW / GT21H16T1W - 001b: GT23L16U2W - 010b: GT23L24T3Y / GT23H24T3Y - 011b: GT23L24M1Z - 100b: GT23L32S4W / GT23H32S4W - 101b: GT20L24F6Y - 110b: GT21L24S1W - 111b: GT22L16A1Y - */ - unsigned char temp; - LCD_CmdWrite(0xCE); - temp = LCD_DataRead(); - temp |= cSetb7; - temp |= cSetb6; - temp &= cClrb5; - LCD_DataWrite(temp); -} -void GTFont_Select_GT22L16A1Y(void) -{ - /* - GT Serial Font ROM Select - 000b: GT21L16TW / GT21H16T1W - 001b: GT23L16U2W - 010b: GT23L24T3Y / GT23H24T3Y - 011b: GT23L24M1Z - 100b: GT23L32S4W / GT23H32S4W - 101b: GT20L24F6Y - 110b: GT21L24S1W - 111b: GT22L16A1Y - */ - unsigned char temp; - LCD_CmdWrite(0xCE); - temp = LCD_DataRead(); - temp |= cSetb7; - temp |= cSetb6; - temp |= cSetb5; - LCD_DataWrite(temp); -} - -//[CFh]========================================================================= -void Set_GTFont_Decoder(unsigned char temp) -{ - /* - [bit7-3] - FONT ROM Coding Setting - For specific GT serial Font ROM, the coding method must be set for decoding. - 00000b: GB2312 - 00001b: GB12345/GB18030 - 00010b: BIG5 - 00011b: UNICODE - 00100b: ASCII - 00101b: UNI-Japanese - 00110b: JIS0208 - 00111b: Latin/Greek/ Cyrillic / Arabic/Thai/Hebrew - 01000b: Korea - 10001b: ISO-8859-1 - 10010b: ISO-8859-2 - 10011b: ISO-8859-3 - 10100b: ISO-8859-4 - 10101b: ISO-8859-5 - 10110b: ISO-8859-6 - 10111b: ISO-8859-7 - 11000b: ISO-8859-8 - 11001b: ISO-8859-9 - 11010b: ISO-8859-10 - 11011b: ISO-8859-11 - 11100b: ISO-8859-12 - 11101b: ISO-8859-13 - 11110b: ISO-8859-14 - 11111b: ISO-8859-15 - - [bit1-0] - ASCII / Latin/Greek/ Cyrillic / Arabic - (ASCII) (Latin/Greek/Cyrillic) (Arabic) - 00b Normal Normal NA - 01b Arial Variable Width Presentation Forms-A - 10b Roman NA Presentation Forms-B - 11b Bold NA NA - */ - LCD_CmdWrite(0xCF); - LCD_DataWrite(temp); -} -//[D0h]========================================================================= -void Font_Line_Distance(unsigned char temp) -{ - /*[bit4-0] - Font Line Distance Setting - Setting the font character line distance when setting memory font - write cursor auto move. (Unit: pixel) - */ - LCD_CmdWrite(0xD0); - LCD_DataWrite(temp); -} -//[D1h]========================================================================= -void Set_Font_to_Font_Width(unsigned char temp) -{ - /*[bit5-0] - Font to Font Width Setting (Unit: pixel) - */ - LCD_CmdWrite(0xD1); - LCD_DataWrite(temp); -} -//[D2h]~[D4h]========================================================================= -void Foreground_RGB(unsigned char RED,unsigned char GREEN,unsigned char BLUE) -{ - /* - [D2h] Foreground Color - Red, for draw, text or color expansion - [D3h] Foreground Color - Green, for draw, text or color expansion - [D4h] Foreground Color - Blue, for draw, text or color expansion - */ - LCD_CmdWrite(0xD2); - LCD_DataWrite(RED); - LCD_CmdWrite(0xD3); - LCD_DataWrite(GREEN); - LCD_CmdWrite(0xD4); - LCD_DataWrite(BLUE); -} - -//Input data format:R3G3B2 -void Foreground_color_256(unsigned char temp) -{ - LCD_CmdWrite(0xD2); - LCD_DataWrite(temp); - LCD_CmdWrite(0xD3); - LCD_DataWrite(temp<<3); - LCD_CmdWrite(0xD4); - LCD_DataWrite(temp<<6); -} - -//Input data format:R5G6B5 -void Foreground_color_65k(unsigned short temp) -{ - LCD_CmdWrite(0xD2); - LCD_DataWrite(temp>>8); - LCD_CmdWrite(0xD3); - LCD_DataWrite(temp>>3); - LCD_CmdWrite(0xD4); - LCD_DataWrite(temp<<3); -} - -//Input data format:R8G8B8 -void Foreground_color_16M(unsigned long temp) -{ - LCD_CmdWrite(0xD2); - LCD_DataWrite(temp>>16); - LCD_CmdWrite(0xD3); - LCD_DataWrite(temp>>8); - LCD_CmdWrite(0xD4); - LCD_DataWrite(temp); -} - - - -//[D5h]~[D7h]========================================================================= -/* -[D5h] Background Color - Red, for Text or color expansion -[D6h] Background Color - Green, for Text or color expansion -[D7h] Background Color - Blue, for Text or color expansion -*/ -void Background_RGB(unsigned char RED,unsigned char GREEN,unsigned char BLUE) -{ - LCD_CmdWrite(0xD5); - LCD_DataWrite(RED); - LCD_CmdWrite(0xD6); - LCD_DataWrite(GREEN); - LCD_CmdWrite(0xD7); - LCD_DataWrite(BLUE); -} - -//Input data format:R3G3B2 -void Background_color_256(unsigned char temp) -{ - LCD_CmdWrite(0xD5); - LCD_DataWrite(temp); - LCD_CmdWrite(0xD6); - LCD_DataWrite(temp<<3); - LCD_CmdWrite(0xD7); - LCD_DataWrite(temp<<6); -} - -//Input data format:R5G6B6 -void Background_color_65k(unsigned short temp) -{ - LCD_CmdWrite(0xD5); - LCD_DataWrite(temp>>8); - LCD_CmdWrite(0xD6); - LCD_DataWrite(temp>>3); - LCD_CmdWrite(0xD7); - LCD_DataWrite(temp<<3); -} - -//Input data format:R8G8B8 -void Background_color_16M(unsigned long temp) -{ - LCD_CmdWrite(0xD5); - LCD_DataWrite(temp>>16); - LCD_CmdWrite(0xD6); - LCD_DataWrite(temp>>8); - LCD_CmdWrite(0xD7); - LCD_DataWrite(temp); -} - -//[DBh]~[DEh]========================================================================= -void CGRAM_Start_address(unsigned long Addr) -{ - /* - CGRAM START ADDRESS [31:0] - */ - LCD_CmdWrite(0xDB); - LCD_DataWrite(Addr); - LCD_CmdWrite(0xDC); - LCD_DataWrite(Addr>>8); - LCD_CmdWrite(0xDD); - LCD_DataWrite(Addr>>16); - LCD_CmdWrite(0xDE); - LCD_DataWrite(Addr>>24); -} - -//[DFh]========================================================================= -/* -[bit7] Enter Power saving state -0: Normal state. -1: Enter power saving state. -[bit1][bit0] Power saving Mode definition -00: NA -01: Standby Mode -10: Suspend Mode -11: Sleep Mode -*/ -void Power_Normal_Mode(void) -{ - LCD_CmdWrite(0xDF); - LCD_DataWrite(0x00); -} -void Power_Saving_Standby_Mode(void) -{ - LCD_CmdWrite(0xDF); - LCD_DataWrite(0x01); - LCD_CmdWrite(0xDF); - LCD_DataWrite(0x81); -} -void Power_Saving_Suspend_Mode(void) -{ - LCD_CmdWrite(0xDF); -// LCD_DataWrite(0x02); -// LCD_CmdWrite(0xDF); - LCD_DataWrite(0x82); -} -void Power_Saving_Sleep_Mode(void) -{ - LCD_CmdWrite(0xDF); -// LCD_DataWrite(0x03); -// LCD_CmdWrite(0xDF); - LCD_DataWrite(0x83); -} - - -//[E5h]~[E6h]========================================================================= -void LT768_I2CM_Clock_Prescale(unsigned short WX) -{ - /* - I2C Master Clock Pre-scale [7:0] - I2C Master Clock Pre-scale [15:8] - */ - LCD_CmdWrite(0xE5); - LCD_DataWrite(WX); - LCD_CmdWrite(0xE6); - LCD_DataWrite(WX>>8); -} -//[E7h]========================================================================= -void LT768_I2CM_Transmit_Data(unsigned char temp) -{ - /* - I2C Master Transmit[7:0] - */ - LCD_CmdWrite(0xE7); - LCD_DataWrite(temp); -} -//[E8h]========================================================================= -unsigned char LT768_I2CM_Receiver_Data(void) -{ - /* - I2C Master Receiver [7:0] - */ - unsigned char temp; - LCD_CmdWrite(0xE8); - temp=LCD_DataRead(); - return temp; -} -//[E9h]========================================================================= -/* -[bit7] START -Generate (repeated) start condition and be cleared by hardware automatically -Note : This bit is always read as 0. -[bit6] STOP -Generate stop condition and be cleared by hardware automatically -Note : This bit is always read as 0. -[bit5] -READ(READ and WRITE canˇt be used simultaneously) -Read form slave and be cleared by hardware automatically -Note : This bit is always read as 0. -[bit4] -WRITE(READ and WRITE canˇt be used simultaneously) -Write to slave and be cleared by hardware automatically -Note : This bit is always read as 0. -[bit3] ACKNOWLEDGE -When as a I2C master receiver -0 : Sent ACK. -1 : Sent NACK. -Note : This bit is always read as 0. -[bit0] Noise Filter -0 : Enable. -1 : Disable. -*/ - -#define Disable_I2CM_Noise_Filter - -void LT768_I2CM_Stop(void) -{ - LCD_CmdWrite(0xE9); -#ifdef Disable_I2CM_Noise_Filter - LCD_DataWrite(0x40); -#endif -#ifdef Enable_I2CM_Noise_Filter - LCD_DataWrite(0x41); -#endif -} -void LT768_I2CM_Read_With_Ack(void) -{ - LCD_CmdWrite(0xE9); -#ifdef Disable_I2CM_Noise_Filter - LCD_DataWrite(0x20); -#endif -#ifdef Enable_I2CM_Noise_Filter - LCD_DataWrite(0x21); -#endif -} - -void LT768_I2CM_Read_With_Nack(void) -{ - LCD_CmdWrite(0xE9); -#ifdef Disable_I2CM_Noise_Filter - LCD_DataWrite(0x68); -#endif -#ifdef Enable_I2CM_Noise_Filter - LCD_DataWrite(0x69); -#endif -} - -void LT768_I2CM_Write_With_Start(void) -{ - LCD_CmdWrite(0xE9); -#ifdef Disable_I2CM_Noise_Filter - LCD_DataWrite(0x90); -#endif -#ifdef Enable_I2CM_Noise_Filter - LCD_DataWrite(0x91); -#endif -} - -void LT768_I2CM_Write(void) -{ - LCD_CmdWrite(0xE9); -#ifdef Disable_I2CM_Noise_Filter - LCD_DataWrite(0x10); -#endif -#ifdef Enable_I2CM_Noise_Filter - LCD_DataWrite(0x11); -#endif -} - - - -//[EAh]========================================================================= -/* - 0=Ack - 1=Nack -*/ -unsigned char LT768_I2CM_Check_Slave_ACK(void) -{ - unsigned char temp; - /*[bit7] - Received acknowledge from slave - 0 : Acknowledge received. - 1 : No Acknowledge received. - */ - LCD_CmdWrite(0xEA); - temp=LCD_DataRead(); - - if((temp&0x80)==0x80) - { - return 1; - } - else - { - return 0; - } -} - - -/* - 0=Idle - 1=Busy -*/ -unsigned char LT768_I2CM_Bus_Busy(void) -{ - unsigned char temp; - /*[bit6] - I2C Bus is Busy - 0 : Idle. - 1 : Busy. - */ - LCD_CmdWrite(0xEA); - temp=LCD_DataRead(); - - if((temp&0x40)==0x40) - { - return 1; - } - else - { - return 0; - } -} - -/* - 0=Complete - 1=Transferring -*/ -unsigned char LT768_I2CM_transmit_Progress(void) -{ - unsigned char temp; - /*[bit6] - 0=Complete - 1=Transferring - */ - LCD_CmdWrite(0xEA); - temp=LCD_DataRead(); - - if((temp&0x02)==0x02) - { - return 1; - } - else - { - return 0; - } -} - -/* -0= Arbitration win -1= Arbitration lost -*/ -unsigned char LT768_I2CM_Arbitration(void) -{ - unsigned char temp; - /*[bit6] - I2C Bus is Busy - 0 : Idle. - 1 : Busy. - */ - LCD_CmdWrite(0xEA); - temp=LCD_DataRead(); - temp&=0x01; - return temp; -} - - -//[F0h]========================================================================= -void Set_GPIO_A_In_Out(unsigned char temp) -{ - /* - GPO-A_dir[7:0] : General Purpose I/O direction control. - 0: Output - 1: Input - */ - LCD_CmdWrite(0xF0); - LCD_DataWrite(temp); -} -//[F1h]========================================================================= -void Write_GPIO_A_7_0(unsigned char temp) -{ - /* - GPI-A[7:0] : General Purpose Input, share with DB[15:8] - GPO-A[7:0] : General Purpose Output, share with DB[15:8] - */ - LCD_CmdWrite(0xF1); - LCD_DataWrite(temp); -} -unsigned char Read_GPIO_A_7_0(void) -{ - /* - GPI-A[7:0] : General Purpose Input, share with DB[15:8] - GPO-A[7:0] : General Purpose Output, share with DB[15:8] - */ - unsigned char temp; - LCD_CmdWrite(0xF1); - temp=LCD_DataRead(); - return temp; -} -//[F2h]========================================================================= -void Write_GPIO_B_7_4(unsigned char temp) -{ - /* - GPI-B[7:0] : General Purpose Input ; share with {XKIN[3:0], XA0, XnWR, XnRD, XnCS} - GPO-B[7:4] : General Purpose Output ; share with XKOUT[3:0] ; - */ - LCD_CmdWrite(0xF2); - LCD_DataWrite(temp); -} -unsigned char Read_GPIO_B_7_0(void) -{ - /* - GPI-B[7:0] : General Purpose Input ; share with {XKIN[3:0], XA0, XnWR, XnRD, XnCS} - GPO-B[7:4] : General Purpose Output ; share with XKOUT[3:0] ; - */ - unsigned char temp; - LCD_CmdWrite(0xF2); - temp=LCD_DataRead(); - return temp; -} - -//[F3h]========================================================================= -void Set_GPIO_C_In_Out(unsigned char temp) -{ - /* - GPIO-C_dir[7:0] : General Purpose I/O direction control. - 0: Output - 1: Input - */ - LCD_CmdWrite(0xF3); - LCD_DataWrite(temp); -} -//[F4h]========================================================================= -void Write_GPIO_C_7_0(unsigned char temp) -{ - /* - GPIO-C[7:0] : General Purpose Input / Output - share with {XPWM0, XI2CSDA, XI2CSCL, XnSFCS1, XnSFCS0,XMISO, XMOSI, XSCLK} - */ - LCD_CmdWrite(0xF4); - LCD_DataWrite(temp); -} -unsigned char Read_GPIO_C_7_0(void) -{ - /* - GPIO-C[7:0] : General Purpose Input / Output - share with {XPWM0, XI2CSDA, XI2CSCL, XnSFCS1, XnSFCS0,XMISO, XMOSI, XSCLK} - */ - unsigned char temp; - LCD_CmdWrite(0xF4); - temp=LCD_DataRead(); - return temp; -} -//[F5h]========================================================================= -void Set_GPIO_D_In_Out(unsigned char temp) -{ - /* - GPIO-D_dir[7:0] : General Purpose I/O direction control. - 0: Output - 1: Input - */ - LCD_CmdWrite(0xF5); - LCD_DataWrite(temp); -} -//[F6h]========================================================================= -void Write_GPIO_D_7_0(unsigned char temp) -{ - /* - GPIO-D[7:0] : General Purpose Input/Output - */ - LCD_CmdWrite(0xF6); - LCD_DataWrite(temp); -} -unsigned char Read_GPIO_D_7_0(void) -{ - /* - GPIO-D[7:0] : General Purpose Input/Output - */ - unsigned char temp; - LCD_CmdWrite(0xF6); - temp=LCD_DataRead(); - return temp; -} -//[F7h]========================================================================= -void Set_GPIO_E_In_Out(unsigned char temp) -{ - /* - GPIO-E_dir[7:0] : General Purpose I/O direction control. - 0: Output - 1: Input - */ - LCD_CmdWrite(0xF7); - LCD_DataWrite(temp); -} -//[F8h]========================================================================= -void Write_GPIO_E_7_0(unsigned char temp) -{ - /* - GPIO-E[7:0] : General Purpose Input/Output. - share with {PDAT[23:19], PDAT[15:13]} - */ - LCD_CmdWrite(0xF8); - LCD_DataWrite(temp); -} -unsigned char Read_GPIO_E_7_0(void) -{ - /* - GPIO-E[7:0] : General Purpose Input/Output. - share with {PDAT[23:19], PDAT[15:13]} - */ - unsigned char temp; - LCD_CmdWrite(0xF8); - temp=LCD_DataRead(); - return temp; -} -//[F9h]========================================================================= -void Set_GPIO_F_In_Out(unsigned char temp) -{ - /* - GPIO-F_dir[7:0] : General Purpose I/O direction control. - 0: Output - 1: Input - */ - LCD_CmdWrite(0xF9); - LCD_DataWrite(temp); -} -//[FAh]========================================================================= -void Write_GPIO_F_7_0(unsigned char temp) -{ - /* - GPIO-F[7:0] : General Purpose Input/Output. - share with {XPDAT[12:10], XPDAT[7:3]} - */ - LCD_CmdWrite(0xFA); - LCD_DataWrite(temp); -} -unsigned char Read_GPIO_F_7_0(void) -{ - /* - GPIO-F[7:0] : General Purpose Input/Output. - share with {XPDAT[12:10], XPDAT[7:3]} - */ - unsigned char temp; - LCD_CmdWrite(0xFA); - temp=LCD_DataRead(); - return temp; -} - -//[FBh]========================================================================= - - -void Long_Key_enable(void) -{ - /* - Key-Scan Control Register 1 - [bit6] LongKey Enable Bit - 1 : Enable. Long key period is set by KSCR2 bit4-2. - 0 : Disable. - */ - unsigned char temp; - LCD_CmdWrite(0xFB); - temp=LCD_DataRead(); - temp |= cSetb6; - LCD_DataWrite(temp); -} - - -void Key_Scan_Freg(unsigned char setx) -{ - /*KF2-0: Key-Scan Frequency */ - unsigned char temp; - LCD_CmdWrite(0xFB); - temp = LCD_DataRead(); - temp &= 0xf0; - temp|= (setx&0x07); - LCD_DataWrite(temp); -} - - -//[FCh]========================================================================= - -void Key_Scan_Wakeup_Function_Enable(void) -{ - /* - Key-Scan Controller Register 2 - [bit7] - Key-Scan Wakeup Function Enable Bit - 0: Key-Scan Wakeup function is disabled. - 1: Key-Scan Wakeup function is enabled. - */ - unsigned char temp; - LCD_CmdWrite(0xFC); - temp=LCD_DataRead(); - temp |= cSetb7; - LCD_DataWrite(temp); -} - - -void Long_Key_Timing_Adjustment(unsigned char setx) -{ - /*Long Key Timing Adjustment*/ - unsigned char temp,temp1; - temp = setx & 0x1c; - LCD_CmdWrite(0xFC); - temp1 = LCD_DataRead(); - temp1|=temp; - LCD_DataWrite(temp1); -} - -unsigned char Numbers_of_Key_Hit(void) -{ - unsigned char temp; - LCD_CmdWrite(0xFC); - temp = LCD_DataRead(); //read key touch number - temp = temp & 0x03; // - return temp; -} - -//[FDh][FEh][FFh]========================================================================= -unsigned char Read_Key_Strobe_Data_0(void) -{ - /* - Key Strobe Data 0 - The corresponding key code 0 that is pressed. - */ - unsigned char temp; - LCD_CmdWrite(0xFD); - temp=LCD_DataRead(); - return temp; -} -unsigned char Read_Key_Strobe_Data_1(void) -{ - /* - Key Strobe Data 1 - The corresponding key code 1 that is pressed. - */ - unsigned char temp; - LCD_CmdWrite(0xFE); - temp=LCD_DataRead(); - return temp; -} -unsigned char Read_Key_Strobe_Data_2(void) -{ - /* - Key Strobe Data 2 - The corresponding key code 2 that is pressed. - */ - unsigned char temp; - LCD_CmdWrite(0xFF); - temp=LCD_DataRead(); - return temp; -} - -void Show_String(char *str) -{ - Text_Mode(); //文本模式 - LCD_CmdWrite(0x04); - - while(*str != '\0') - { - LCD_DataWrite(*str); - Check_Mem_WR_FIFO_not_Full(); - ++str; - } - - Check_2D_Busy(); - Graphic_Mode(); //back to graphic mode;图形模式 -} - - -void Show_picture(unsigned long numbers,const unsigned short *datap) -{ - unsigned long i; - LCD_CmdWrite(0x04); - - for(i=0; i +#include "nuttx/arch.h" +#include "nuttx/lcd/lt768.h" + +//============================================================================== + +void LCD_RegisterWrite(uint8_t Cmd, uint8_t Data) +{ + LCD_CmdWrite(Cmd); + LCD_DataWrite(Data); +} + +uint8_t LCD_RegisterRead(uint8_t Cmd) +{ + uint8_t temp; + LCD_CmdWrite(Cmd); + temp = LCD_DataRead(); + return temp; +} + +/******************************************************************************/ +/*Sub program area */ +/******************************************************************************/ +void Check_Mem_WR_FIFO_not_Full(void) +{ + /* 0: Memory Write FIFO is not full. + 1: Memory Write FIFO is full. */ + do + { + } + while(LCD_StatusRead()&0x80); +} +void Check_Mem_WR_FIFO_Empty(void) +{ + /* 0: Memory Write FIFO is not empty. + 1: Memory Write FIFO is empty. */ + do + { + } + while((LCD_StatusRead()&0x40) == 0x00); +} +void Check_Mem_RD_FIFO_not_Full(void) +{ + /* 0: Memory Read FIFO is not full. + 1: Memory Read FIFO is full. */ + do + { + } + while(LCD_StatusRead()&0x20); +} +void Check_Mem_RD_FIFO_not_Empty(void) +{ + /* 0: Memory Read FIFO is not empty. + 1: Memory Read FIFO is empty. + */ + do + { + } + while(LCD_StatusRead()&0x10); +} +void Check_2D_Busy(void) +{ + do + { + } + while(LCD_StatusRead()&0x08); +} +void Check_SDRAM_Ready(void) +{ + /* 0: SDRAM is not ready for access + 1: SDRAM is ready for access */ + uint8_t temp; + + do + { + temp = LCD_StatusRead(); + } + while((temp&0x04) == 0x00); +} + +uint8_t Power_Saving_Status(void) +{ + uint8_t temp; + + if((LCD_StatusRead()&0x02)==0x02) + { + temp = 1; + } + else + { + temp = 0; + } + + return temp; +} + +void Check_Power_is_Normal(void) +{ + /* 0: Normal operation state + 1: Power saving state */ + do + { + } + while(LCD_StatusRead()&0x02); +} +void Check_Power_is_Saving(void) +{ + /* 0: Normal operation state + 1: Power saving state */ + do + { + } + while((LCD_StatusRead()&0x02) == 0x00); +} +void Check_NO_Interrupt(void) +{ + /* 0: without interrupt event + 1: interrupt event occur + */ + do + { + } + while(LCD_StatusRead()&0x01); +} +void Check_Interrupt_Occur(void) +{ + /* 0: without interrupt event + 1: interrupt event occur + */ + do + { + } + while((LCD_StatusRead()&0x01) == 0x00); +} + +void Check_Busy_Draw(void) +{ + uint8_t temp; + + do + { + temp = LCD_StatusRead(); + } + while(temp&0x08); +} + +//[00h]========================================================================= + +void LT768_SW_Reset(void)//IC Reset?? +{ + uint8_t temp; + LCD_CmdWrite(0x00); + temp = LCD_DataRead(); + temp |= 0x01; + LCD_DataWrite(temp); + + do + { + temp = LCD_DataRead(); + } + while(temp&0x01); +} + +//[01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h][01h] +void Enable_PLL(void) +{ + /* 0: PLL disable; allow change PLL parameter. + 1: PLL enable; cannot change PLL parameter.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); + up_udelay(1);//PLL +} +void LT768_Sleep(void) +{ + /* 0: Normal mode. + 1: Sleep mode.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void LT768_WakeUp(void) +{ + /* 0: Normal mode. + 1: Sleep mode.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Key_Scan_Enable(void) +{ + /* 0: Disable. + 1: Enable.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void Key_Scan_Disable(void) +{ + /* 0: Disable. + 1: Enable.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void TFT_24bit(void) +{ + /* 00b: 24-bits output. + 01b: 18-bits output, unused pins are set as GPIO. + 10b: 16-bits output, unused pins are set as GPIO. + 11b: LVDS, all 24-bits unused output pins are set as GPIO.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp &= cClrb4; + temp &= cClrb3; + LCD_DataWrite(temp); +} +void TFT_18bit(void) +{ + /* 00b: 24-bits output. + 01b: 18-bits output, unused pins are set as GPIO. + 10b: 16-bits output, unused pins are set as GPIO. + 11b: LVDS, all 24-bits unused output pins are set as GPIO.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp &= cClrb4; + temp |= cSetb3; + LCD_DataWrite(temp); +} +void TFT_16bit(void) +{ + /* 00b: 24-bits output. + 01b: 18-bits output, unused pins are set as GPIO. + 10b: 16-bits output, unused pins are set as GPIO. + 11b: LVDS, all 24-bits unused output pins are set as GPIO.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp |= cSetb4; + temp &= cClrb3; + LCD_DataWrite(temp); +} +void TFT_LVDS(void) +{ + /* 00b: 24-bits output. + 01b: 18-bits output, unused pins are set as GPIO. + 10b: 16-bits output, unused pins are set as GPIO. + 11b: LVDS, all 24-bits unused output pins are set as GPIO.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp |= cSetb4; + temp |= cSetb3; + LCD_DataWrite(temp); +} + +void LT768_I2CM_Enable(void) +{ + /* I2C master Interface Enable/Disable + 0: Disable + 1: Enable*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} + +void LT768_I2CM_Disable(void) +{ + /* I2C master Interface Enable/Disable + 0: Disable + 1: Enable*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} + +void Enable_SFlash_SPI(void) +{ + /* Serial Flash SPI Interface Enable/Disable + 0: Disable + 1: Enable*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} + +void Disable_SFlash_SPI(void) +{ + /* Serial Flash SPI Interface Enable/Disable + 0: Disable + 1: Enable*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +void Host_Bus_8bit(void) +{ + /* Parallel Host Data Bus Width Selection + 0: 8-bit Parallel Host Data Bus. + 1: 16-bit Parallel Host Data Bus.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Host_Bus_16bit(void) +{ + /* Parallel Host Data Bus Width Selection + 0: 8-bit Parallel Host Data Bus. + 1: 16-bit Parallel Host Data Bus.*/ + uint8_t temp; + LCD_CmdWrite(0x01); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} + +//[02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h][02h] + +void RGB_8b_8bpp(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb7; + temp &= cClrb6; + LCD_DataWrite(temp); +} +void RGB_8b_16bpp(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb7; + temp |= cSetb6; + LCD_DataWrite(temp); +} +void RGB_8b_24bpp(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb7; + temp &= cClrb6; + LCD_DataWrite(temp); +} + +void RGB_16b_8bpp(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp |= cSetb7; + temp &= cClrb6; + LCD_DataWrite(temp); +} +void RGB_16b_16bpp(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb7; + temp |= cSetb6; + LCD_DataWrite(temp); +} +void RGB_16b_24bpp_mode1(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb7; + temp &= cClrb6; + LCD_DataWrite(temp); +} +void RGB_16b_24bpp_mode2(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp |= cSetb7; + temp |= cSetb6; + LCD_DataWrite(temp); +} + +void MemRead_Left_Right_Top_Down(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb5; + temp &= cClrb4; + LCD_DataWrite(temp); +} +void MemRead_Right_Left_Top_Down(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb5; + temp |= cSetb4; + LCD_DataWrite(temp); +} +void MemRead_Top_Down_Left_Right(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp |= cSetb5; + temp &= cClrb4; + LCD_DataWrite(temp); +} +void MemRead_Down_Top_Left_Right(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp |= cSetb5; + temp |= cSetb4; + LCD_DataWrite(temp); +} +void MemWrite_Left_Right_Top_Down(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb2; + temp &= cClrb1; + LCD_DataWrite(temp); +} +void MemWrite_Right_Left_Top_Down(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp &= cClrb2; + temp |= cSetb1; + LCD_DataWrite(temp); +} +void MemWrite_Top_Down_Left_Right(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp |= cSetb2; + temp &= cClrb1; + LCD_DataWrite(temp); +} +void MemWrite_Down_Top_Left_Right(void) +{ + uint8_t temp; + LCD_CmdWrite(0x02); + temp = LCD_DataRead(); + temp |= cSetb2; + temp |= cSetb1; + LCD_DataWrite(temp); +} +//[03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h][03h] +void Interrupt_Active_Low(void) +{ + /* MPU Interrupt active level + 0 : active low. + 1 : active high.*/ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void Interrupt_Active_High(void) +{ + /* MPU Interrupt active level + 0 : active low. + 1 : active high.*/ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void ExtInterrupt_Debounce(void) +{ + /* External interrupt de-bounce + 0 : without de-bounce + 1 : enable de-bounce (1024 OSC clock)*/ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void ExtInterrupt_Nodebounce(void) +{ + /* External interrupt de-bounce + 0 : without de-bounce + 1 : enable de-bounce (1024 OSC clock)*/ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void ExtInterrupt_Input_Low_Level_Trigger(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp &= cClrb5; + temp &= cClrb4; + LCD_DataWrite(temp); +} +void ExtInterrupt_Input_High_Level_Trigger(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp |= cSetb5; + temp &= cClrb4; + LCD_DataWrite(temp); +} +void ExtInterrupt_Input_Falling_Edge_Trigger(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp &= cClrb5; + temp |= cSetb4; + LCD_DataWrite(temp); +} +void ExtInterrupt_Input_Rising_Edge_Trigger(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp |= cSetb5; + temp |= cSetb4; + LCD_DataWrite(temp); +} +void LVDS_Format1(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void LVDS_Format2(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Graphic_Mode(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Text_Mode(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Memory_Select_SDRAM(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp &= cClrb1; + temp &= cClrb0; // B + LCD_DataWrite(temp); +} +void Memory_Select_Graphic_Cursor_RAM(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp |= cSetb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Memory_Select_Color_Palette_RAM(void) +{ + uint8_t temp; + LCD_CmdWrite(0x03); + temp = LCD_DataRead(); + temp |= cSetb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} + +//[05h]========================================================================= +//[06h]========================================================================= +//[07h]========================================================================= +//[08h]========================================================================= +//[09h]========================================================================= +//[0Ah]========================================================================= +//[0Bh]========================================================================= + +void Enable_Resume_Interrupt(void) +{ + /* + Resume Interrupt Enable + 0: Disable. + 1: Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void Disable_Resume_Interrupt(void) +{ + /* + Resume Interrupt Enable + 0: Disable. + 1: Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void Enable_ExtInterrupt_Input(void) +{ + /* + External Interrupt (PS[0] pin) Enable + 0: Disable. + 1: Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Disable_ExtInterrupt_Input(void) +{ + /* + External Interrupt (PS[0] pin) Enable + 0: Disable. + 1: Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Enable_I2CM_Interrupt(void) +{ + /* + I2C Master Interrupt Enable + 0: Disable. + 1: Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void Disable_I2CM_Interrupt(void) +{ + /* + I2C Master Interrupt Enable + 0: Disable. + 1: Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void Enable_Vsync_Interrupt(void) +{ + /* + Vsync time base interrupt Enable Bit + 0: Disable Interrupt. + 1: Enable Interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Disable_Vsync_Interrupt(void) +{ + /* + Vsync time base interrupt Enable Bit + 0: Disable Interrupt. + 1: Enable Interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Enable_KeyScan_Interrupt(void) +{ + /* + Key Scan Interrupt Enable Bit + 0: Disable Key scan interrupt. + 1: Enable Key scan interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Disable_KeyScan_Interrupt(void) +{ + /* + Key Scan Interrupt Enable Bit + 0: Disable Key scan interrupt. + 1: Enable Key scan interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void Enable_DMA_Draw_BTE_Interrupt(void) +{ + /* + Serial flash DMA Complete | Draw task finished | BTE Process + Complete etc. Interrupt Enable + 0: Disable Interrupt. + 1: Enable Interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Disable_DMA_Draw_BTE_Interrupt(void) +{ + /* + Serial flash DMA Complete | Draw task finished | BTE Process + Complete etc. Interrupt Enable + 0: Disable Interrupt. + 1: Enable Interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Enable_PWM1_Interrupt(void) +{ + /* + PWM timer 1 Interrupt Enable Bit + 0: Disable Interrupt. + 1: Enable Interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} +void Disable_PWM1_Interrupt(void) +{ + /* + PWM timer 1 Interrupt Enable Bit + 0: Disable Interrupt. + 1: Enable Interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +void Enable_PWM0_Interrupt(void) +{ + /* + PWM timer 0 Interrupt Enable Bit + 0: Disable Interrupt. + 1: Enable Interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} +void Disable_PWM0_Interrupt(void) +{ + /* + PWM timer 0 Interrupt Enable Bit + 0: Disable Interrupt. + 1: Enable Interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0B); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} + +//[0Ch]========================================================================= +uint8_t Read_Interrupt_status(void) +{ + /* + [Bit7]Read Function ..Resume Interrupt Status + 0: No Resume interrupt happens. + 1: Resume interrupt happens. + [Bit6]Read Function .. PS[0] pin Interrupt Status + 0: No PS[0] pin interrupt happens. + 1: PS[0] pin interrupt happens. + [Bit5]Read Function .. I2C master Interrupt Status + 0: No I2C master interrupt happens. + 1: I2C master interrupt happens. + [Bit4]Read Function .. Vsync Interrupt Status + 0: No interrupt happens. + 1: interrupt happens. + [Bit3]Read Function ..Key Scan Interrupt Status + 0: No Key Scan interrupt happens. + 1: Key Scan interrupt happens. + [Bit2]Read Function..Interrupt Status + 0: No interrupt happens. + 1: interrupt happens. + [Bit1]Read Function..Interrupt Status + 0: No interrupt happens. + 1: interrupt happens. + [Bit0]Read Function..Interrupt Status + 0: No interrupt happens. + 1: interrupt happens. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + return temp; +} +void Clear_Resume_Interrupt_Flag(void) +{ + /* + Resume Interrupt flag + Write Function .. Resume Interrupt Clear Bit + 0: No operation. + 1: Clear Resume interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void Clear_ExtInterrupt_Input_Flag(void) +{ + /* + External Interrupt (PS[0] pin) flag + Write Function .. PS[0] pin edge Interrupt Clear Bit + 0: No operation. + 1: Clear the PS[0] pin edge interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Clear_I2CM_Interrupt_Flag(void) +{ + /* + I2C master Interrupt flag + Write Function.. I2C master Interrupt Clear Bit + 0: No operation. + 1: Clear the I2C master interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void Clear_Vsync_Interrupt_Flag(void) +{ + /* + Vsync Time base interrupt flag + Write Function ..Vsync Interrupt Clear Bit + 0: No operation. + 1: Clear the interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Clear_KeyScan_Interrupt_Flag(void) +{ + /* + Key Scan Interrupt flag + Write Function..Key Scan Interrupt Clear Bit + 0: No operation. + 1: Clear the Key Scan interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Clear_DMA_Draw_BTE_Interrupt_Flag(void) +{ + /* + Serial flash DMA Complete | Draw task finished | BTE + Process Complete etc. Interrupt flag + Write Function.. Interrupt Clear Bit + 0: No operation. + 1: Clear interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Clear_PWM1_Interrupt_Flag(void) +{ + /* + PWM 1 timer Interrupt flag + Write Function..Interrupt Clear Bit + 0: No operation. + 1: Clear interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} +void Clear_PWM0_Interrupt_Flag(void) +{ + /* + PWM 0 timer Interrupt flag + Write Function..Interrupt Clear Bit + 0: No operation. + 1: Clear interrupt. + */ + uint8_t temp; + LCD_CmdWrite(0x0C); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} +//[0Dh]========================================================================= +void Mask_Resume_Interrupt_Flag(void) +{ + /* + Mask Resume Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void Mask_ExtInterrupt_Input_Flag(void) +{ + /* + Mask External Interrupt (PS[0] pin) Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Mask_I2CM_Interrupt_Flag(void) +{ + /* + Mask I2C Master Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void Mask_Vsync_Interrupt_Flag(void) +{ + /* + Mask Vsync time base interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Mask_KeyScan_Interrupt_Flag(void) +{ + /* + Mask Key Scan Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Mask_DMA_Draw_BTE_Interrupt_Flag(void) +{ + /* + Mask Serial flash DMA Complete | Draw task finished | BTE + Process Complete etc. Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Mask_PWM1_Interrupt_Flag(void) +{ + /* + Mask PWM timer 1 Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} +void Mask_PWM0_Interrupt_Flag(void) +{ + /* + Mask PWM timer 0 Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} + +void Enable_Resume_Interrupt_Flag(void) +{ + /* + Mask Resume Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void Enable_ExtInterrupt_Inpur_Flag(void) +{ + /* + Mask External Interrupt (PS[0] pin) Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Enable_I2CM_Interrupt_Flag(void) +{ + /* + Mask I2C Master Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void Enable_Vsync_Interrupt_Flag(void) +{ + /* + Mask Vsync time base interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Enable_KeyScan_Interrupt_Flag(void) +{ + /* + Mask Key Scan Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void Enable_DMA_Draw_BTE_Interrupt_Flag(void) +{ + /* + Mask Serial flash DMA Complete | Draw task finished | BTE + Process Complete etc. Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Enable_PWM1_Interrupt_Flag(void) +{ + /* + Mask PWM timer 1 Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +void Enable_PWM0_Interrupt_Flag(void) +{ + /* + Mask PWM timer 0 Interrupt Flag + 0: Enable. + 1: Mask. + */ + uint8_t temp; + LCD_CmdWrite(0x0D); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} + +//[0Eh]========================================================================= +void Enable_GPIOF_PullUp(void) +{ + /* + GPIO_F[7:0] Pull-Up Enable (XPDAT[23:19, 15:13]) + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void Enable_GPIOE_PullUp(void) +{ + /* + GPIO_E[7:0] Pull-Up Enable (XPDAT[12:10, 7:3]) + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Enable_GPIOD_PullUp(void) +{ + /* + GPIO_D[7:0] Pull-Up Enable (XPDAT[18, 2, 17, 16, 9, 8, 1,0]) + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Enable_GPIOC_PullUp(void) +{ + /* + GPIO_C[6:0] Pull-Up Enable (XSDA, XSCL, XnSFCS1, + XnSFCS0, XMISO, XMOSI , XSCK) + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Enable_XDB15_8_PullUp(void) +{ + /* + XDB[15:8] Pull-Up Enable + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} +void Enable_XDB7_0_PullUp(void) +{ + /* + XDB[7:0] Pull-Up Enable + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} +void Disable_GPIOF_PullUp(void) +{ + /* + GPIO_F[7:0] Pull-Up Enable (XPDAT[23:19, 15:13]) + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void Disable_GPIOE_PullUp(void) +{ + /* + GPIO_E[7:0] Pull-Up Enable (XPDAT[12:10, 7:3]) + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Disable_GPIOD_PullUp(void) +{ + /* + GPIO_D[7:0] Pull-Up Enable (XPDAT[18, 2, 17, 16, 9, 8, 1,0]) + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void Disable_GPIOC_PullUp(void) +{ + /* + GPIO_C[6:0] Pull-Up Enable (XSDA, XSCL, XnSFCS1, + XnSFCS0, XMISO, XMOSI , XSCK) + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Disable_XDB15_8_PullUp(void) +{ + /* + XDB[15:8] Pull-Up Enable + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +void Disable_XDB7_0_PullUp(void) +{ + /* + XDB[7:0] Pull-Up Enable + 0: Pull-Up Disable + 1: Pull-Up Enable + */ + uint8_t temp; + LCD_CmdWrite(0x0E); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} +//[0Fh]========================================================================= +void XPDAT18_Set_GPIO_D7(void) +{ + /* + XPDAT[18] ? not scan function select + 0: GPIO-D7 + 1: KOUT[4] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void XPDAT18_Set_KOUT4(void) +{ + /* + XPDAT[18] ? not scan function select + 0: GPIO-D7 + 1: KOUT[4] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void XPDAT17_Set_GPIO_D5(void) +{ + /* + XPDAT[17] ? not scan function select + 0: GPIO-D5 + 1: KOUT[2] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void XPDAT17_Set_KOUT2(void) +{ + /* + XPDAT[17] ? not scan function select + 0: GPIO-D5 + 1: KOUT[2] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void XPDAT16_Set_GPIO_D4(void) +{ + /* + XPDAT[16] ? not scan function select + 0: GPIO-D4 + 1: KOUT[1] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void XPDAT16_Set_KOUT1(void) +{ + /* + XPDAT[16] ? not scan function select + 0: GPIO-D4 + 1: KOUT[1] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void XPDAT9_Set_GPIO_D3(void) +{ + /* + XPDAT[9] ? not scan function select + 0: GPIO-D3 + 1: KOUT[3] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void XPDAT9_Set_KOUT3(void) +{ + /* + XPDAT[9] ? not scan function select + 0: GPIO-D3 + 1: KOUT[3] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void XPDAT8_Set_GPIO_D2(void) +{ + /* + XPDAT[8] ? not scan function select + 0: GPIO-D2 + 1: KIN[3] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void XPDAT8_Set_KIN3(void) +{ + /* + XPDAT[8] ? not scan function select + 0: GPIO-D2 + 1: KIN[3] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void XPDAT2_Set_GPIO_D6(void) +{ + /* + XPDAT[2] ? not scan function select + 0: GPIO-D6 + 1: KIN[4] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} +void XPDAT2_Set_KIN4(void) +{ + /* + XPDAT[2] ? not scan function select + 0: GPIO-D6 + 1: KIN[4] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void XPDAT1_Set_GPIO_D1(void) +{ + /* + XPDAT[1] ? not scan function select + 0: GPIO-D1 + 1: KIN[2] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +void XPDAT1_Set_KIN2(void) +{ + /* + XPDAT[1] ? not scan function select + 0: GPIO-D1 + 1: KIN[2] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} +void XPDAT0_Set_GPIO_D0(void) +{ + /* + XPDAT[0] ? not scan function select + 0: GPIO-D0 + 1: KIN[1] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} +void XPDAT0_Set_KIN1(void) +{ + /* + XPDAT[0] ? not scan function select + 0: GPIO-D0 + 1: KIN[1] + */ + uint8_t temp; + LCD_CmdWrite(0x0F); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} + +//[10h]========================================================================= +void Enable_PIP1(void) +{ + /* + PIP 1 window Enable/Disable + 0 : PIP 1 window disable. + 1 : PIP 1 window enable + PIP 1 window always on top of PIP 2 window. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void Disable_PIP1(void) +{ + /* + PIP 1 window Enable/Disable + 0 : PIP 1 window disable. + 1 : PIP 1 window enable + PIP 1 window always on top of PIP 2 window. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void Enable_PIP2(void) +{ + /* + PIP 2 window Enable/Disable + 0 : PIP 2 window disable. + 1 : PIP 2 window enable + PIP 1 window always on top of PIP 2 window. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Disable_PIP2(void) +{ + /* + PIP 2 window Enable/Disable + 0 : PIP 2 window disable. + 1 : PIP 2 window enable + PIP 1 window always on top of PIP 2 window. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Select_PIP1_Parameter(void) +{ + /* + 0: To configure PIP 1's parameters. + 1: To configure PIP 2's parameters.. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Select_PIP2_Parameter(void) +{ + /* + 0: To configure PIP 1's parameters. + 1: To configure PIP 2's parameters.. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Select_Main_Window_8bpp(void) +{ + /* + Main Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp &= cClrb3; + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Select_Main_Window_16bpp(void) +{ + /* + Main Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp &= cClrb3; + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Select_Main_Window_24bpp(void) +{ + /* + Main Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x10); + temp = LCD_DataRead(); + temp |= cSetb3; + //temp |= cSetb2; + LCD_DataWrite(temp); +} +//[11h]========================================================================= +void Select_PIP2_Window_8bpp(void) +{ + /* + PIP 1 Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x11); + temp = LCD_DataRead(); + temp &= cClrb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Select_PIP2_Window_16bpp(void) +{ + /* + PIP 1 Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x11); + temp = LCD_DataRead(); + temp &= cClrb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} +void Select_PIP2_Window_24bpp(void) +{ + /* + PIP 1 Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x11); + temp = LCD_DataRead(); + temp |= cSetb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Select_PIP1_Window_8bpp(void) +{ + /* + PIP 2 Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x11); + temp = LCD_DataRead(); + temp &= cClrb3; + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Select_PIP1_Window_16bpp(void) +{ + /* + PIP 2 Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x11); + temp = LCD_DataRead(); + temp &= cClrb3; + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Select_PIP1_Window_24bpp(void) +{ + /* + PIP 2 Window Color Depth Setting + 00b: 8-bpp generic TFT, i.e. 256 colors. + 01b: 16-bpp generic TFT, i.e. 65K colors. + 1xb: 24-bpp generic TFT, i.e. 1.67M colors. + */ + uint8_t temp; + LCD_CmdWrite(0x11); + temp = LCD_DataRead(); + temp |= cSetb3; + temp &= cClrb2; + LCD_DataWrite(temp); +} + +//[12h]========================================================================= +void PCLK_Rising(void) +{ + /* + PCLK Inversion + 0: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK falling edge. + 1: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK rising edge. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void PCLK_Falling(void) +{ + /* + PCLK Inversion + 0: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK falling edge. + 1: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK rising edge. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void Display_ON(void) +{ + /* + Display ON/OFF + 0b: Display Off. + 1b: Display On. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + syslog(LOG_NOTICE, "Display_ON.pre_read=%02x\n", temp); + temp |= cSetb6; + LCD_DataWrite(temp); + temp = LCD_DataRead(); + syslog(LOG_NOTICE, "Display_ON.write_read=%02x\n", temp); +} + +void Display_OFF(void) +{ + /* + Display ON/OFF + 0b: Display Off. + 1b: Display On. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Color_Bar_ON(void) +{ + /* + Display Test Color Bar + 0b: Disable. + 1b: Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void Color_Bar_OFF(void) +{ + /* + Display Test Color Bar + 0b: Disable. + 1b: Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void HSCAN_L_to_R(void) +{ + /* + Horizontal Scan Direction + 0 : From Left to Right + 1 : From Right to Left + PIP window will be disabled when HDIR set as 1. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void HSCAN_R_to_L(void) +{ + /* + Horizontal Scan Direction + 0 : From Left to Right + 1 : From Right to Left + PIP window will be disabled when HDIR set as 1. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void VSCAN_T_to_B(void) +{ + /* + Vertical Scan direction + 0 : From Top to Bottom + 1 : From bottom to Top + PIP window will be disabled when VDIR set as 1. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void VSCAN_B_to_T(void) +{ + /* + Vertical Scan direction + 0 : From Top to Bottom + 1 : From bottom to Top + PIP window will be disabled when VDIR set as 1. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void PDATA_Set_RGB(void) +{ + /* + parallel PDATA[23:0] Output Sequence + 000b : RGB. + 001b : RBG. + 010b : GRB. + 011b : GBR. + 100b : BRG. + 101b : BGR. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &=0xf8; + LCD_DataWrite(temp); +} +void PDATA_Set_RBG(void) +{ + /* + parallel PDATA[23:0] Output Sequence + 000b : RGB. + 001b : RBG. + 010b : GRB. + 011b : GBR. + 100b : BRG. + 101b : BGR. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &=0xf8; + temp |= cSetb0; + LCD_DataWrite(temp); +} +void PDATA_Set_GRB(void) +{ + /* + parallel PDATA[23:0] Output Sequence + 000b : RGB. + 001b : RBG. + 010b : GRB. + 011b : GBR. + 100b : BRG. + 101b : BGR. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &=0xf8; + temp |= cSetb1; + LCD_DataWrite(temp); +} +void PDATA_Set_GBR(void) +{ + /* + parallel PDATA[23:0] Output Sequence + 000b : RGB. + 001b : RBG. + 010b : GRB. + 011b : GBR. + 100b : BRG. + 101b : BGR. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &=0xf8; + temp |= cSetb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} +void PDATA_Set_BRG(void) +{ + /* + parallel PDATA[23:0] Output Sequence + 000b : RGB. + 001b : RBG. + 010b : GRB. + 011b : GBR. + 100b : BRG. + 101b : BGR. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &=0xf8; + temp |= cSetb2; + LCD_DataWrite(temp); +} +void PDATA_Set_BGR(void) +{ + /* + parallel PDATA[23:0] Output Sequence + 000b : RGB. + 001b : RBG. + 010b : GRB. + 011b : GBR. + 100b : BRG. + 101b : BGR. + */ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp &=0xf8; + temp |= cSetb2; + temp |= cSetb0; + LCD_DataWrite(temp); +} + +void PDATA_IDLE_STATE(void) +{ + uint8_t temp; + LCD_CmdWrite(0x12); + temp = LCD_DataRead(); + temp |=0x07; + LCD_DataWrite(temp); +} + + +//[13h]========================================================================= +void HSYNC_Low_Active(void) +{ + /* + HSYNC Polarity + 0 : Low active. + 1 : High active. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void HSYNC_High_Active(void) +{ + /* + HSYNC Polarity + 0 : Low active. + 1 : High active. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void VSYNC_Low_Active(void) +{ + /* + VSYNC Polarity + 0 : Low active. + 1 : High active. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void VSYNC_High_Active(void) +{ + /* + VSYNC Polarity + 0 : Low active. + 1 : High active. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void DE_Low_Active(void) +{ + /* + DE Polarity + 0 : High active. + 1 : Low active. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void DE_High_Active(void) +{ + /* + DE Polarity + 0 : High active. + 1 : Low active. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void Idle_DE_Low(void) +{ + /* + DE IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pin 'DE' output is low. + 1 : Pin 'DE' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Idle_DE_High(void) +{ + /* + DE IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pin DE output is low. + 1 : Pin DE output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Idle_PCLK_Low(void) +{ + /* + PCLK IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pin 'PCLK' output is low. + 1 : Pin 'PCLK' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void Idle_PCLK_High(void) +{ + /* + PCLK IDLE STATE(When STANDBY or DISPLAY OFF) + 0 : Pin 'PCLK' output is low. + 1 : Pin 'PCLK' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Idle_PDAT_Low(void) +{ + /* + PDAT IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pins 'PDAT[23:0]' output is low. + 1 : Pins 'PCLK[23:0]' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Idle_PDAT_High(void) +{ + /* + PDAT IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pins 'PDAT[23:0]' output is low. + 1 : Pins 'PCLK[23:0]' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Idle_HSYNC_Low(void) +{ + /* + HSYNC IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pin 'HSYNC' output is low. + 1 : Pin 'HSYNC' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +void Idle_HSYNC_High(void) +{ + /* + HSYNC IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pin 'HSYNC' output is low. + 1 : Pin 'HSYNC' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} +void Idle_VSYNC_Low(void) +{ + /* + VSYNC IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pin 'VSYNC' output is low. + 1 : Pin 'VSYNC' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Idle_VSYNC_High(void) +{ + /* + VSYNC IDLE STATE(When STANDBY or DISPLAY OFF ) + 0 : Pin 'VSYNC' output is low. + 1 : Pin 'VSYNC' output is high. + */ + uint8_t temp; + LCD_CmdWrite(0x13); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} + +//[14h][15h][1Ah][1Bh]========================================================================= + +void LCD_HorizontalWidth_VerticalHeight(unsigned short WX,unsigned short HY) +{ + /* + [14h] Horizontal Display Width Setting Bit[7:0] + [15h] Horizontal Display Width Fine Tuning (HDWFT) [3:0] + The register specifies the LCD panel horizontal display width in + the unit of 8 pixels resolution. + Horizontal display width(pixels) = (HDWR + 1) * 8 + HDWFTR + + [1Ah] Vertical Display Height Bit[7:0] + Vertical Display Height(Line) = VDHR + 1 + [1Bh] Vertical Display Height Bit[10:8] + Vertical Display Height(Line) = VDHR + 1 + */ + uint8_t temp; + + if(WX<8) + { + LCD_CmdWrite(0x14); + LCD_DataWrite(0x00); + LCD_CmdWrite(0x15); + LCD_DataWrite(WX); + temp=HY-1; + LCD_CmdWrite(0x1A); + LCD_DataWrite(temp); + temp=(HY-1) >> 8; + LCD_CmdWrite(0x1B); + LCD_DataWrite(temp); + } + else + { + temp=(WX/8)-1; + LCD_CmdWrite(0x14); + LCD_DataWrite(temp); + temp=WX%8; + LCD_CmdWrite(0x15); + LCD_DataWrite(temp); + temp=HY-1; + LCD_CmdWrite(0x1A); + LCD_DataWrite(temp); + temp=(HY-1) >> 8; + LCD_CmdWrite(0x1B); + LCD_DataWrite(temp); + } +} +//[16h][17h]========================================================================= +void LCD_Horizontal_Non_Display(unsigned short WX) +{ + /* + [16h] Horizontal Non-Display Period(HNDR) Bit[4:0] + This register specifies the horizontal non-display period. Also + called back porch. + Horizontal non-display period(pixels) = (HNDR + 1) * 8 + HNDFTR + + [17h] Horizontal Non-Display Period Fine Tuning(HNDFT) [3:0] + This register specifies the fine tuning for horizontal non-display + period; it is used to support the SYNC mode panel. Each level of + this modulation is 1-pixel. + Horizontal non-display period(pixels) = (HNDR + 1) * 8 + HNDFTR + */ + uint8_t temp; + + if(WX<8) + { + LCD_CmdWrite(0x16); + LCD_DataWrite(0x00); + LCD_CmdWrite(0x17); + LCD_DataWrite(WX); + } + else + { + temp=(WX/8)-1; + LCD_CmdWrite(0x16); + LCD_DataWrite(temp); + temp=WX%8; + LCD_CmdWrite(0x17); + LCD_DataWrite(temp); + } +} +//[18h]========================================================================= +void LCD_HSYNC_Start_Position(unsigned short WX) +{ + /* + [18h] HSYNC Start Position[4:0] + The starting position from the end of display area to the + beginning of HSYNC. Each level of this modulation is 8-pixel. + Also called front porch. + HSYNC Start Position(pixels) = (HSTR + 1)x8 + */ + uint8_t temp; + + if(WX<8) + { + LCD_CmdWrite(0x18); + LCD_DataWrite(0x00); + } + else + { + temp=(WX/8)-1; + LCD_CmdWrite(0x18); + LCD_DataWrite(temp); + } +} +//[19h]========================================================================= +void LCD_HSYNC_Pulse_Width(unsigned short WX) +{ + /* + [19h] HSYNC Pulse Width(HPW) [4:0] + The period width of HSYNC. + HSYNC Pulse Width(pixels) = (HPW + 1)x8 + */ + uint8_t temp; + + if(WX<8) + { + LCD_CmdWrite(0x19); + LCD_DataWrite(0x00); + } + else + { + temp=(WX/8)-1; + LCD_CmdWrite(0x19); + LCD_DataWrite(temp); + } +} +//[1Ch][1Dh]========================================================================= +void LCD_Vertical_Non_Display(unsigned short HY) +{ + /* + [1Ch] Vertical Non-Display Period Bit[7:0] + Vertical Non-Display Period(Line) = (VNDR + 1) + + [1Dh] Vertical Non-Display Period Bit[9:8] + Vertical Non-Display Period(Line) = (VNDR + 1) + */ + uint8_t temp; + temp=HY-1; + LCD_CmdWrite(0x1C); + LCD_DataWrite(temp); + LCD_CmdWrite(0x1D); + LCD_DataWrite(temp >> 8); +} +//[1Eh]========================================================================= +void LCD_VSYNC_Start_Position(unsigned short HY) +{ + /* + [1Eh] VSYNC Start Position[7:0] + The starting position from the end of display area to the beginning of VSYNC. + VSYNC Start Position(Line) = (VSTR + 1) + */ + uint8_t temp; + temp=HY-1; + LCD_CmdWrite(0x1E); + LCD_DataWrite(temp); +} +//[1Fh]========================================================================= +void LCD_VSYNC_Pulse_Width(unsigned short HY) +{ + /* + [1Fh] VSYNC Pulse Width[5:0] + The pulse width of VSYNC in lines. + VSYNC Pulse Width(Line) = (VPWR + 1) + */ + uint8_t temp; + temp=HY-1; + LCD_CmdWrite(0x1F); + LCD_DataWrite(temp); +} +//[20h][21h][22h][23h]========================================================================= +void Main_Image_Start_Address(uint32_t Addr) +{ + /* + [20h] Main Image Start Address[7:2] + [21h] Main Image Start Address[15:8] + [22h] Main Image Start Address [23:16] + [23h] Main Image Start Address [31:24] + */ + LCD_RegisterWrite(0x20,Addr); + LCD_RegisterWrite(0x21,Addr >> 8); + LCD_RegisterWrite(0x22,Addr >> 16); + LCD_RegisterWrite(0x23,Addr >> 24); +} +//[24h][25h]========================================================================= +void Main_Image_Width(unsigned short WX) +{ + /* + [24h] Main Image Width [7:0] + [25h] Main Image Width [12:8] + Unit: Pixel. + It must be divisible by 4. MIW Bit [1:0] tie to '0' internally. + The value is physical pixel number. Maximum value is 8188 pixels + */ + LCD_RegisterWrite(0x24,WX); + LCD_RegisterWrite(0x25,WX >> 8); +} +//[26h][27h][28h][29h]========================================================================= +void Main_Window_Start_XY(unsigned short WX,unsigned short HY) +{ + /* + [26h] Main Window Upper-Left corner X-coordination [7:0] + [27h] Main Window Upper-Left corner X-coordination [12:8] + Reference Main Image coordination. + Unit: Pixel + It must be divisible by 4. MWULX Bit [1:0] tie to '0' internally. + X-axis coordination plus Horizontal display width cannot large than 8188. + + [28h] Main Window Upper-Left corner Y-coordination [7:0] + [29h] Main Window Upper-Left corner Y-coordination [12:8] + Reference Main Image coordination. + Unit: Pixel + Range is between 0 and 8191. + */ + LCD_RegisterWrite(0x26,WX); + LCD_RegisterWrite(0x27,WX >> 8); + LCD_RegisterWrite(0x28,HY); + LCD_RegisterWrite(0x29,HY >> 8); +} +//[2Ah][2Bh][2Ch][2Dh]========================================================================= +void PIP_Display_Start_XY(unsigned short WX,unsigned short HY) +{ + /* + [2Ah] PIP Window Display Upper-Left corner X-coordination [7:0] + [2Bh] PIP Window Display Upper-Left corner X-coordination [12:8] + Reference Main Window coordination. + Unit: Pixel + It must be divisible by 4. PWDULX Bit [1:0] tie to '0' internally. + X-axis coordination should less than horizontal display width. + According to bit of Select Configure PIP 1 or 2 Window's parameters. + Function bit will be configured for relative PIP window. + + [2Ch] PIP Window Display Upper-Left corner Y-coordination [7:0] + [2Dh] PIP Window Display Upper-Left corner Y-coordination [12:8] + Reference Main Window coordination. + Unit: Pixel + Y-axis coordination should less than vertical display height. + According to bit of Select Configure PIP 1 or 2 Window's parameters. + Function bit will be configured for relative PIP window. + */ + LCD_RegisterWrite(0x2A,WX); + LCD_RegisterWrite(0x2B,WX >> 8); + LCD_RegisterWrite(0x2C,HY); + LCD_RegisterWrite(0x2D,HY >> 8); +} +//[2Eh][2Fh][30h][31h]========================================================================= +void PIP_Image_Start_Address(uint32_t Addr) +{ + /* + [2Eh] PIP Image Start Address[7:2] + [2Fh] PIP Image Start Address[15:8] + [30h] PIP Image Start Address [23:16] + [31h] PIP Image Start Address [31:24] + */ + LCD_RegisterWrite(0x2E,Addr); + LCD_RegisterWrite(0x2F,Addr >> 8); + LCD_RegisterWrite(0x30,Addr >> 16); + LCD_RegisterWrite(0x31,Addr >> 24); +} +//[32h][33h]========================================================================= +void PIP_Image_Width(unsigned short WX) +{ + /* + [32h] PIP Image Width [7:0] + [33h] PIP Image Width [12:8] + Unit: Pixel. + It must be divisible by 4. PIW Bit [1:0] tie to '0' internally. + The value is physical pixel number. + This width should less than horizontal display width. + According to bit of Select Configure PIP 1 or 2 Window's parameters. + Function bit will be configured for relative PIP window. + */ + LCD_RegisterWrite(0x32,WX); + LCD_RegisterWrite(0x33,WX >> 8); +} +//[34h][35h][36h][37h]========================================================================= +void PIP_Window_Image_Start_XY(unsigned short WX,unsigned short HY) +{ + /* + [34h] PIP 1 or 2 Window Image Upper-Left corner X-coordination [7:0] + [35h] PIP Window Image Upper-Left corner X-coordination [12:8] + Reference PIP Image coordination. + Unit: Pixel + It must be divisible by 4. PWIULX Bit [1:0] tie to '0' internally. + X-axis coordination plus PIP image width cannot large than 8188. + According to bit of Select Configure PIP 1 or 2 Window's parameters. + Function bit will be configured for relative PIP window. + + [36h] PIP Windows Display Upper-Left corner Y-coordination [7:0] + [37h] PIP Windows Image Upper-Left corner Y-coordination [12:8] + Reference PIP Image coordination. + Unit: Pixel + Y-axis coordination plus PIP window height should less than 8191. + According to bit of Select Configure PIP 1 or 2 Window's parameters. + Function bit will be configured for relative PIP window. + */ + LCD_RegisterWrite(0x34,WX); + LCD_RegisterWrite(0x35,WX >> 8); + LCD_RegisterWrite(0x36,HY); + LCD_RegisterWrite(0x37,HY >> 8); +} +//[38h][39h][3Ah][3Bh]========================================================================= +void PIP_Window_Width_Height(unsigned short WX,unsigned short HY) +{ + /* + [38h] PIP Window Width [7:0] + [39h] PIP Window Width [10:8] + Unit: Pixel. + It must be divisible by 4. The value is physical pixel number. + Maximum value is 8188 pixels. + According to bit of Select Configure PIP 1 or 2 Window's parameters. + Function bit will be configured for relative PIP window. + + [3Ah] PIP Window Height [7:0] + [3Bh] PIP Window Height [10:8] + Unit: Pixel + The value is physical pixel number. Maximum value is 8191 pixels. + According to bit of Select Configure PIP 1 or 2 Window's parameters. + Function bit will be configured for relative PIP window. + */ + LCD_RegisterWrite(0x38,WX); + LCD_RegisterWrite(0x39,WX >> 8); + LCD_RegisterWrite(0x3A,HY); + LCD_RegisterWrite(0x3B,HY >> 8); +} + +//[3Ch]========================================================================= +void Enable_Graphic_Cursor(void) +{ + /* + Graphic Cursor Enable + 0 : Graphic Cursor disable. + 1 : Graphic Cursor enable. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Disable_Graphic_Cursor(void) +{ + /* + Graphic Cursor Enable + 0 : Graphic Cursor disable. + 1 : Graphic Cursor enable. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +// +void Select_Graphic_Cursor_1(void) +{ + /* + Graphic Cursor Selection Bit + Select one from four graphic cursor types. (00b to 11b) + 00b : Graphic Cursor Set 1. + 01b : Graphic Cursor Set 2. + 10b : Graphic Cursor Set 3. + 11b : Graphic Cursor Set 4. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp &= cClrb3; + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Select_Graphic_Cursor_2(void) +{ + /* + Graphic Cursor Selection Bit + Select one from four graphic cursor types. (00b to 11b) + 00b : Graphic Cursor Set 1. + 01b : Graphic Cursor Set 2. + 10b : Graphic Cursor Set 3. + 11b : Graphic Cursor Set 4. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp &= cClrb3; + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Select_Graphic_Cursor_3(void) +{ + /* + Graphic Cursor Selection Bit + Select one from four graphic cursor types. (00b to 11b) + 00b : Graphic Cursor Set 1. + 01b : Graphic Cursor Set 2. + 10b : Graphic Cursor Set 3. + 11b : Graphic Cursor Set 4. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp |= cSetb3; + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Select_Graphic_Cursor_4(void) +{ + /* + Graphic Cursor Selection Bit + Select one from four graphic cursor types. (00b to 11b) + 00b : Graphic Cursor Set 1. + 01b : Graphic Cursor Set 2. + 10b : Graphic Cursor Set 3. + 11b : Graphic Cursor Set 4. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp |= cSetb3; + temp |= cSetb2; + LCD_DataWrite(temp); +} +// +void Enable_Text_Cursor(void) +{ + /* + Text Cursor Enable + 0 : Disable. + 1 : Enable. + Text cursor & Graphic cursor cannot enable simultaneously. + Graphic cursor has higher priority then Text cursor if enabled simultaneously. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} +void Disable_Text_Cursor(void) +{ + /* + Text Cursor Enable + 0 : Disable. + 1 : Enable. + Text cursor & Graphic cursor cannot enable simultaneously. + Graphic cursor has higher priority then Text cursor if enabled simultaneously. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +// +void Enable_Text_Cursor_Blinking(void) +{ + /* + Text Cursor Blinking Enable + 0 : Disable. + 1 : Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} +void Disable_Text_Cursor_Blinking(void) +{ + /* + Text Cursor Blinking Enable + 0 : Disable. + 1 : Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x3C); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} +//[3Dh]========================================================================= +void Blinking_Time_Frames(uint8_t temp) +{ + /* + Text Cursor Blink Time Setting (Unit: Frame) + 00h : 1 frame time. + 01h : 2 frames time. + 02h : 3 frames time. + : + FFh : 256 frames time. + */ + LCD_CmdWrite(0x3D); + LCD_DataWrite(temp); +} +//[3Eh]========================================================================= +void Text_Cursor_H_V(unsigned short WX,unsigned short HY) +{ + /* + [3Eh] + Text Cursor Horizontal Size Setting[4:0] + Unit : Pixel + Zero-based number. Value '0' means 1 pixel. + Note : When font is enlarged, the cursor setting will multiply the + same times as the font enlargement. + [3Fh] + Text Cursor Vertical Size Setting[4:0] + Unit : Pixel + Zero-based number. Value '0' means 1 pixel. + Note : When font is enlarged, the cursor setting will multiply the + same times as the font enlargement. + */ + LCD_CmdWrite(0x3E); + LCD_DataWrite(WX); + LCD_CmdWrite(0x3F); + LCD_DataWrite(HY); +} +//[40h][41h][42h][43h]========================================================================= +void Graphic_Cursor_XY(unsigned short WX,unsigned short HY) +{ + /* + [40h] Graphic Cursor Horizontal Location[7:0] + [41h] Graphic Cursor Horizontal Location[12:8] + [42h] Graphic Cursor Vertical Location[7:0] + [43h] Graphic Cursor Vertical Location[12:8] + Reference main Window coordination. + */ + LCD_RegisterWrite(0x40,WX); + LCD_RegisterWrite(0x41,WX >> 8); + LCD_RegisterWrite(0x42,HY); + LCD_RegisterWrite(0x43,HY >> 8); +} +//[44h]========================================================================= +void Set_Graphic_Cursor_Color_1(uint8_t temp) +{ + /* + [44h] Graphic Cursor Color 0 with 256 Colors + RGB Format [7:0] = RRRGGGBB. + */ + LCD_RegisterWrite(0x44,temp); +} +//[45h]========================================================================= +void Set_Graphic_Cursor_Color_2(uint8_t temp) +{ + /* + [45h] Graphic Cursor Color 1 with 256 Colors + RGB Format [7:0] = RRRGGGBB. + */ + LCD_RegisterWrite(0x45,temp); +} +//[50h][51h][52h][53h]========================================================================= +void Canvas_Image_Start_address(uint32_t Addr) +{ + /* + [50h] Start address of Canvas [7:0] + [51h] Start address of Canvas [15:8] + [52h] Start address of Canvas [23:16] + [53h] Start address of Canvas [31:24] + */ + LCD_RegisterWrite(0x50,Addr); + LCD_RegisterWrite(0x51,Addr >> 8); + LCD_RegisterWrite(0x52,Addr >> 16); + LCD_RegisterWrite(0x53,Addr >> 24); +} +//[54h][55h]========================================================================= +void Canvas_image_width(unsigned short WX) +{ + /* + [54h] Canvas image width [7:2] + [55h] Canvas image width [12:8] + */ + LCD_RegisterWrite(0x54,WX); + LCD_RegisterWrite(0x55,WX >> 8); +} +//[56h][57h][58h][59h]========================================================================= +void Active_Window_XY(unsigned short WX,unsigned short HY) +{ + /* + [56h] Active Window Upper-Left corner X-coordination [7:0] + [57h] Active Window Upper-Left corner X-coordination [12:8] + [58h] Active Window Upper-Left corner Y-coordination [7:0] + [59h] Active Window Upper-Left corner Y-coordination [12:8] + */ + LCD_RegisterWrite(0x56,WX); + LCD_RegisterWrite(0x57,WX >> 8); + LCD_RegisterWrite(0x58,HY); + LCD_RegisterWrite(0x59,HY >> 8); +} +//[5Ah][5Bh][5Ch][5Dh]========================================================================= +void Active_Window_WH(unsigned short WX,unsigned short HY) +{ + /* + [5Ah] Width of Active Window [7:0] + [5Bh] Width of Active Window [12:8] + [5Ch] Height of Active Window [7:0] + [5Dh] Height of Active Window [12:8] + */ + LCD_RegisterWrite(0x5A,WX); + LCD_RegisterWrite(0x5B,WX >> 8); + LCD_RegisterWrite(0x5C,HY); + LCD_RegisterWrite(0x5D,HY >> 8); +} +//[5Eh]========================================================================= +void Select_Write_Data_Position(void) +{ + /* + Select to read back Graphic Read/Write position + 0: read back Graphic Write position + 1: read back Graphic Read position + */ + uint8_t temp; + LCD_CmdWrite(0x5E); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void Select_Read_Data_Position(void) +{ + /* + Select to read back Graphic Read/Write position + 0: read back Graphic Write position + 1: read back Graphic Read position + */ + uint8_t temp; + LCD_CmdWrite(0x5E); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Memory_XY_Mode(void) +{ + /* + Canvas addressing mode + 0: Block mode (X-Y coordination addressing) + 1: linear mode + */ + uint8_t temp; + LCD_CmdWrite(0x5E); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Memory_Linear_Mode(void) +{ + /* + Canvas addressing mode + 0: Block mode (X-Y coordination addressing) + 1: linear mode + */ + uint8_t temp; + LCD_CmdWrite(0x5E); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Memory_8bpp_Mode(void) +{ + /* + Canvas image's color depth & memory R/W data width + In Block Mode: + 00: 8bpp + 01: 16bpp + 1x: 24bpp + In Linear Mode: + X0: 8-bits memory data read/write. + X1: 16-bits memory data read/write + */ + uint8_t temp; + LCD_CmdWrite(0x5E); + temp = LCD_DataRead(); + temp &= cClrb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Memory_16bpp_Mode(void) +{ + /* + Canvas image's color depth & memory R/W data width + In Block Mode: + 00: 8bpp + 01: 16bpp + 1x: 24bpp + In Linear Mode: + X0: 8-bits memory data read/write. + X1: 16-bits memory data read/write + */ + uint8_t temp; + LCD_CmdWrite(0x5E); + temp = LCD_DataRead(); + temp &= cClrb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} +void Memory_24bpp_Mode(void) +{ + /* + Canvas image's color depth & memory R/W data width + In Block Mode: + 00: 8bpp + 01: 16bpp + 1x: 24bpp + In Linear Mode: + X0: 8-bits memory data read/write. + X1: 16-bits memory data read/write + */ + uint8_t temp; + LCD_CmdWrite(0x5E); + temp = LCD_DataRead(); + temp |= cSetb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} + +//[5Fh][60h][61h][62h]========================================================================= +void Goto_Pixel_XY(unsigned short WX,unsigned short HY) +{ + /* + [Write]: Set Graphic Read/Write position + [Read]: Current Graphic Read/Write position + Read back is Read position or Write position depends on + REG[5Eh] bit3, Select to read back Graphic Read/Write position. + When DPRAM Linear mode:Graphic Read/Write Position [31:24][23:16][15:8][7:0] + When DPRAM Active window mode:Graphic Read/Write + Horizontal Position [12:8][7:0], + Vertical Position [12:8][7:0]. + Reference Canvas image coordination. Unit: Pixel + */ + LCD_RegisterWrite(0x5F,WX); + LCD_RegisterWrite(0x60,WX >> 8); + LCD_RegisterWrite(0x61,HY); + LCD_RegisterWrite(0x62,HY >> 8); +} +void Goto_Linear_Addr(uint32_t Addr) +{ + LCD_RegisterWrite(0x5F,Addr); + LCD_RegisterWrite(0x60,Addr >> 8); + LCD_RegisterWrite(0x61,Addr >> 16); + LCD_RegisterWrite(0x62,Addr >> 24); +} + + +//[63h][64h][65h][66h]========================================================================= +void Goto_Text_XY(unsigned short WX,unsigned short HY) +{ + /* + Write: Set Text Write position + Read: Current Text Write position + Text Write X-coordination [12:8][7:0] + Text Write Y-coordination [12:8][7:0] + Reference Canvas image coordination. + Unit: Pixel + */ + LCD_RegisterWrite(0x63,WX); + LCD_RegisterWrite(0x64,WX >> 8); + LCD_RegisterWrite(0x65,HY); + LCD_RegisterWrite(0x66,HY >> 8); +} +//[67h]========================================================================= +/* +[bit7]Draw Line / Triangle Start Signal +Write Function +0 : Stop the drawing function. +1 : Start the drawing function. +Read Function +0 : Drawing function complete. +1 : Drawing function is processing. +[bit5]Fill function for Triangle Signal +0 : Non fill. +1 : Fill. +[bit1]Draw Triangle or Line Select Signal +0 : Draw Line +1 : Draw Triangle +*/ +void Start_Line(void) +{ + LCD_CmdWrite(0x67); + LCD_DataWrite(0x80); + Check_Busy_Draw(); +} +void Start_Triangle(void) +{ + LCD_CmdWrite(0x67); + LCD_DataWrite(0x82);//B1000_0010 + Check_Busy_Draw(); +} +void Start_Triangle_Fill(void) +{ + LCD_CmdWrite(0x67); + LCD_DataWrite(0xA2);//B1010_0010 + Check_Busy_Draw(); +} +//[68h][69h][6Ah][6Bh]========================================================================= +//line start x, y +void Line_Start_XY(unsigned short WX,unsigned short HY) +{ + /* + [68h] Draw Line/Square/Triangle Start X-coordination [7:0] + [69h] Draw Line/Square/Triangle Start X-coordination [12:8] + [6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0] + [6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8] + */ + LCD_CmdWrite(0x68); + LCD_DataWrite(WX); + LCD_CmdWrite(0x69); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x6A); + LCD_DataWrite(HY); + LCD_CmdWrite(0x6B); + LCD_DataWrite(HY >> 8); +} +//[6Ch][6Dh][6Eh][6Fh]========================================================================= +//line end x, y +void Line_End_XY(unsigned short WX,unsigned short HY) +{ + /* + [6Ch] Draw Line/Square/Triangle End X-coordination [7:0] + [6Dh] Draw Line/Square/Triangle End X-coordination [12:8] + [6Eh] Draw Line/Square/Triangle End Y-coordination [7:0] + [6Fh] Draw Line/Square/Triangle End Y-coordination [12:8] + */ + LCD_CmdWrite(0x6C); + LCD_DataWrite(WX); + LCD_CmdWrite(0x6D); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x6E); + LCD_DataWrite(HY); + LCD_CmdWrite(0x6F); + LCD_DataWrite(HY >> 8); +} +//[68h]~[73h]========================================================================= + +void Triangle_Point1_XY(unsigned short WX,unsigned short HY) +{ + /* + [68h] Draw Line/Square/Triangle Start X-coordination [7:0] + [69h] Draw Line/Square/Triangle Start X-coordination [12:8] + [6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0] + [6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8] + */ + LCD_CmdWrite(0x68); + LCD_DataWrite(WX); + LCD_CmdWrite(0x69); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x6A); + LCD_DataWrite(HY); + LCD_CmdWrite(0x6B); + LCD_DataWrite(HY >> 8); +} + +void Triangle_Point2_XY(unsigned short WX,unsigned short HY) +{ + /* + [6Ch] Draw Line/Square/Triangle End X-coordination [7:0] + [6Dh] Draw Line/Square/Triangle End X-coordination [12:8] + [6Eh] Draw Line/Square/Triangle End Y-coordination [7:0] + [6Fh] Draw Line/Square/Triangle End Y-coordination [12:8] + */ + LCD_CmdWrite(0x6C); + LCD_DataWrite(WX); + LCD_CmdWrite(0x6D); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x6E); + LCD_DataWrite(HY); + LCD_CmdWrite(0x6F); + LCD_DataWrite(HY >> 8); +} + +void Triangle_Point3_XY(unsigned short WX,unsigned short HY) +{ + /* + [70h] Draw Triangle Point 3 X-coordination [7:0] + [71h] Draw Triangle Point 3 X-coordination [12:8] + [72h] Draw Triangle Point 3 Y-coordination [7:0] + [73h] Draw Triangle Point 3 Y-coordination [12:8] + */ + LCD_CmdWrite(0x70); + LCD_DataWrite(WX); + LCD_CmdWrite(0x71); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x72); + LCD_DataWrite(HY); + LCD_CmdWrite(0x73); + LCD_DataWrite(HY >> 8); +} + +void Square_Start_XY(unsigned short WX,unsigned short HY) +{ + /* + [68h] Draw Line/Square/Triangle Start X-coordination [7:0] + [69h] Draw Line/Square/Triangle Start X-coordination [12:8] + [6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0] + [6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8] + */ + LCD_CmdWrite(0x68); + LCD_DataWrite(WX); + LCD_CmdWrite(0x69); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x6A); + LCD_DataWrite(HY); + LCD_CmdWrite(0x6B); + LCD_DataWrite(HY >> 8); +} + +void Square_End_XY(unsigned short WX,unsigned short HY) +{ + /* + [6Ch] Draw Line/Square/Triangle End X-coordination [7:0] + [6Dh] Draw Line/Square/Triangle End X-coordination [12:8] + [6Eh] Draw Line/Square/Triangle End Y-coordination [7:0] + [6Fh] Draw Line/Square/Triangle End Y-coordination [12:8] + */ + LCD_CmdWrite(0x6C); + LCD_DataWrite(WX); + LCD_CmdWrite(0x6D); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x6E); + LCD_DataWrite(HY); + LCD_CmdWrite(0x6F); + LCD_DataWrite(HY >> 8); +} +//[76h]========================================================================= +/* +[bit7] +Draw Circle / Ellipse / Square /Circle Square Start Signal +Write Function +0 : Stop the drawing function. +1 : Start the drawing function. +Read Function +0 : Drawing function complete. +1 : Drawing function is processing. +[bit6] +Fill the Circle / Ellipse / Square / Circle Square Signal +0 : Non fill. +1 : fill. +[bit5 bit4] +Draw Circle / Ellipse / Square / Ellipse Curve / Circle Square Select +00 : Draw Circle / Ellipse +01 : Draw Circle / Ellipse Curve +10 : Draw Square. +11 : Draw Circle Square. +[bit1 bit0] +Draw Circle / Ellipse Curve Part Select +00 : +01 : +10 : +11 : +*/ +void Start_Circle_or_Ellipse(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0x80);//B1000_XXXX + Check_Busy_Draw(); +} +void Start_Circle_or_Ellipse_Fill(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xC0);//B1100_XXXX + Check_Busy_Draw(); +} +// +void Start_Left_Down_Curve(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0x90);//B1001_XX00 + Check_Busy_Draw(); +} +void Start_Left_Up_Curve(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0x91);//B1001_XX01 + Check_Busy_Draw(); +} +void Start_Right_Up_Curve(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0x92);//B1001_XX10 + Check_Busy_Draw(); +} +void Start_Right_Down_Curve(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0x93);//B1001_XX11 + Check_Busy_Draw(); +} +// +void Start_Left_Down_Curve_Fill(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xD0);//B1101_XX00 + Check_Busy_Draw(); +} +void Start_Left_Up_Curve_Fill(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xD1);//B1101_XX01 + Check_Busy_Draw(); +} +void Start_Right_Up_Curve_Fill(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xD2);//B1101_XX10 + Check_Busy_Draw(); +} +void Start_Right_Down_Curve_Fill(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xD3);//B1101_XX11 + Check_Busy_Draw(); +} +// +void Start_Square(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xA0);//B1010_XXXX + Check_Busy_Draw(); +} +void Start_Square_Fill(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xE0);//B1110_XXXX + Check_Busy_Draw(); +} +void Start_Circle_Square(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xB0);//B1011_XXXX + Check_Busy_Draw(); +} +void Start_Circle_Square_Fill(void) +{ + LCD_CmdWrite(0x76); + LCD_DataWrite(0xF0);//B1111_XXXX + Check_Busy_Draw(); +} +//[77h]~[7Eh]========================================================================= +void Circle_Center_XY(unsigned short WX,unsigned short HY) +{ + /* + [7Bh] Draw Circle/Ellipse/Circle Square Center X-coordination [7:0] + [7Ch] Draw Circle/Ellipse/Circle Square Center X-coordination [12:8] + [7Dh] Draw Circle/Ellipse/Circle Square Center Y-coordination [7:0] + [7Eh] Draw Circle/Ellipse/Circle Square Center Y-coordination [12:8] + */ + LCD_CmdWrite(0x7B); + LCD_DataWrite(WX); + LCD_CmdWrite(0x7C); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x7D); + LCD_DataWrite(HY); + LCD_CmdWrite(0x7E); + LCD_DataWrite(HY >> 8); +} + +void Ellipse_Center_XY(unsigned short WX,unsigned short HY) +{ + /* + [7Bh] Draw Circle/Ellipse/Circle Square Center X-coordination [7:0] + [7Ch] Draw Circle/Ellipse/Circle Square Center X-coordination [12:8] + [7Dh] Draw Circle/Ellipse/Circle Square Center Y-coordination [7:0] + [7Eh] Draw Circle/Ellipse/Circle Square Center Y-coordination [12:8] + */ + LCD_CmdWrite(0x7B); + LCD_DataWrite(WX); + LCD_CmdWrite(0x7C); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x7D); + LCD_DataWrite(HY); + LCD_CmdWrite(0x7E); + LCD_DataWrite(HY >> 8); +} + +void Circle_Radius_R(unsigned short WX) +{ + /* + [77h] Draw Circle/Ellipse/Circle Square Major radius [7:0] + [78h] Draw Circle/Ellipse/Circle Square Major radius [12:8] + [79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0] + [7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8] + */ + LCD_CmdWrite(0x77); + LCD_DataWrite(WX); + LCD_CmdWrite(0x78); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x79); + LCD_DataWrite(WX); + LCD_CmdWrite(0x7A); + LCD_DataWrite(WX >> 8); +} + +void Ellipse_Radius_RxRy(unsigned short WX,unsigned short HY) +{ + /* + [77h] Draw Circle/Ellipse/Circle Square Major radius [7:0] + [78h] Draw Circle/Ellipse/Circle Square Major radius [12:8] + [79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0] + [7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8] + */ + LCD_CmdWrite(0x77); + LCD_DataWrite(WX); + LCD_CmdWrite(0x78); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x79); + LCD_DataWrite(HY); + LCD_CmdWrite(0x7A); + LCD_DataWrite(HY >> 8); +} + +void Circle_Square_Radius_RxRy(unsigned short WX,unsigned short HY) +{ + /* + [77h] Draw Circle/Ellipse/Circle Square Major radius [7:0] + [78h] Draw Circle/Ellipse/Circle Square Major radius [12:8] + [79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0] + [7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8] + */ + LCD_CmdWrite(0x77); + LCD_DataWrite(WX); + LCD_CmdWrite(0x78); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0x79); + LCD_DataWrite(HY); + LCD_CmdWrite(0x7A); + LCD_DataWrite(HY >> 8); +} + +//[84h]========================================================================= +void Set_PWM_Prescaler_1_to_256(unsigned short WX) +{ + /* + PWM Prescaler Register + These 8 bits determine prescaler value for Timer 0 and 1. + Time base is 'Core_Freq / (Prescaler + 1)' + */ + WX=WX-1; + LCD_CmdWrite(0x84); + LCD_DataWrite(WX); +} +//[85h]========================================================================= +void Select_PWM1_Clock_Divided_By_1(void) +{ + /* + Select MUX input for PWM Timer 1. + 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; + */ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp &= cClrb7; + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Select_PWM1_Clock_Divided_By_2(void) +{ + /* + Select MUX input for PWM Timer 1. + 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; + */ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp &= cClrb7; + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Select_PWM1_Clock_Divided_By_4(void) +{ + /* + Select MUX input for PWM Timer 1. + 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; + */ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp |= cSetb7; + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Select_PWM1_Clock_Divided_By_8(void) +{ + /* + Select MUX input for PWM Timer 1. + 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; + */ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp |= cSetb7; + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Select_PWM0_Clock_Divided_By_1(void) +{ + /* + Select MUX input for PWM Timer 0. + 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; + */ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp &= cClrb5; + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Select_PWM0_Clock_Divided_By_2(void) +{ + /* + Select MUX input for PWM Timer 0. + 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; + */ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp &= cClrb5; + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Select_PWM0_Clock_Divided_By_4(void) +{ + /* + Select MUX input for PWM Timer 0. + 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; + */ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp |= cSetb5; + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Select_PWM0_Clock_Divided_By_8(void) +{ + /* + Select MUX input for PWM Timer 0. + 00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8; + */ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp |= cSetb5; + temp |= cSetb4; + LCD_DataWrite(temp); +} +//[85h].[bit3][bit2]========================================================================= +/* +XPWM[1] pin function control +0X: XPWM[1] output system error flag (REG[00h] bit[1:0], Scan bandwidth insufficient + Memory access out of range) +10: XPWM[1] enabled and controlled by PWM timer 1 +11: XPWM[1] output oscillator clock +//If XTEST[0] set high, then XPWM[1] will become panel scan clock input. +*/ +void Select_PWM1_is_ErrorFlag(void) +{ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void Select_PWM1(void) +{ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp |= cSetb3; + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Select_PWM1_is_Osc_Clock(void) +{ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp |= cSetb3; + temp |= cSetb2; + LCD_DataWrite(temp); +} +//[85h].[bit1][bit0]========================================================================= +/* +XPWM[0] pin function control +0X: XPWM[0] becomes GPIO-C[7] +10: XPWM[0] enabled and controlled by PWM timer 0 +11: XPWM[0] output core clock +*/ +void Select_PWM0_is_GPIO_C7(void) +{ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +void Select_PWM0(void) +{ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp |= cSetb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Select_PWM0_is_Core_Clock(void) +{ + uint8_t temp; + LCD_CmdWrite(0x85); + temp = LCD_DataRead(); + temp |= cSetb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} +//[86h]========================================================================= +//[86h]PWM1 +void Enable_PWM1_Inverter(void) +{ + /* + PWM Timer 1 output inverter on/off. + Determine the output inverter on/off for Timer 1. + 0 = Inverter off + 1 = Inverter on for PWM1 + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Disable_PWM1_Inverter(void) +{ + /* + PWM Timer 1 output inverter on/off. + Determine the output inverter on/off for Timer 1. + 0 = Inverter off + 1 = Inverter on for PWM1 + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Auto_Reload_PWM1(void) +{ + /* + PWM Timer 1 auto reload on/off + Determine auto reload on/off for Timer 1. + 0 = One-shot + 1 = Interval mode(auto reload) + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void One_Shot_PWM1(void) +{ + /* + PWM Timer 1 auto reload on/off + Determine auto reload on/off for Timer 1. + 0 = One-shot + 1 = Interval mode(auto reload) + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void Start_PWM1(void) +{ + /* + PWM Timer 1 start/stop + Determine start/stop for Timer 1. + 0 = Stop + 1 = Start for Timer 1 + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Stop_PWM1(void) +{ + /* + PWM Timer 1 start/stop + Determine start/stop for Timer 1. + 0 = Stop + 1 = Start for Timer 1 + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +//[86h]PWM0 +void Enable_PWM0_Dead_Zone(void) +{ + /* + PWM Timer 0 Dead zone enable + Determine the dead zone operation. 0 = Disable. 1 = Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Disable_PWM0_Dead_Zone(void) +{ + /* + PWM Timer 0 Dead zone enable + Determine the dead zone operation. 0 = Disable. 1 = Enable. + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp &= cClrb3; + LCD_DataWrite(temp); +} +void Enable_PWM0_Inverter(void) +{ + /* + PWM Timer 0 output inverter on/off + Determine the output inverter on/off for Timer 0. + 0 = Inverter off + 1 = Inverter on for PWM0 + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Disable_PWM0_Inverter(void) +{ + /* + PWM Timer 0 output inverter on/off + Determine the output inverter on/off for Timer 0. + 0 = Inverter off + 1 = Inverter on for PWM0 + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Auto_Reload_PWM0(void) +{ + /* + PWM Timer 0 auto reload on/off + Determine auto reload on/off for Timer 0. + 0 = One-shot + 1 = Interval mode(auto reload) + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} +void One_Shot_PWM0(void) +{ + /* + PWM Timer 1 auto reload on/off + Determine auto reload on/off for Timer 1. + 0 = One-shot + 1 = Interval mode(auto reload) + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} +void Start_PWM0(void) +{ + /* + PWM Timer 0 start/stop + Determine start/stop for Timer 0. + 0 = Stop + 1 = Start for Timer 0 + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} +void Stop_PWM0(void) +{ + /* + PWM Timer 0 start/stop + Determine start/stop for Timer 0. + 0 = Stop + 1 = Start for Timer 0 + */ + uint8_t temp; + LCD_CmdWrite(0x86); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} +//[87h]========================================================================= +void Set_Timer0_Dead_Zone_Length(uint8_t temp) +{ + /* + Timer 0 Dead zone length register + These 8 bits determine the dead zone length. The 1 unit time of + the dead zone length is equal to that of timer 0. + */ + LCD_CmdWrite(0x87); + LCD_DataWrite(temp); +} +//[88h][89h]========================================================================= +void Set_Timer0_Compare_Buffer(unsigned short WX) +{ + /* + Timer 0 compare buffer register + Compare buffer register total has 16 bits. + When timer counter equal or less than compare buffer register will cause PWM out + high level if inv_on bit is off. + */ + LCD_CmdWrite(0x88); + LCD_DataWrite(WX); + LCD_CmdWrite(0x89); + LCD_DataWrite(WX >> 8); +} +//[8Ah][8Bh]========================================================================= +void Set_Timer0_Count_Buffer(unsigned short WX) +{ + /* + Timer 0 count buffer register + Count buffer register total has 16 bits. + When timer counter equal to 0 will cause PWM timer reload Count buffer register if reload_en bit set as enable. + It may read back timer counter's real time value when PWM timer start. + */ + LCD_CmdWrite(0x8A); + LCD_DataWrite(WX); + LCD_CmdWrite(0x8B); + LCD_DataWrite(WX >> 8); +} +//[8Ch][8Dh]========================================================================= +void Set_Timer1_Compare_Buffer(unsigned short WX) +{ + /* + Timer 0 compare buffer register + Compare buffer register total has 16 bits. + When timer counter equal or less than compare buffer register will cause PWM out + high level if inv_on bit is off. + */ + LCD_CmdWrite(0x8C); + LCD_DataWrite(WX); + LCD_CmdWrite(0x8D); + LCD_DataWrite(WX >> 8); +} +//[8Eh][8Fh]========================================================================= +void Set_Timer1_Count_Buffer(unsigned short WX) +{ + /* + Timer 0 count buffer register + Count buffer register total has 16 bits. + When timer counter equal to 0 will cause PWM timer reload Count buffer register if reload_en bit set as enable. + It may read back timer counter's real time value when PWM timer start. + */ + LCD_CmdWrite(0x8E); + LCD_DataWrite(WX); + LCD_CmdWrite(0x8F); + LCD_DataWrite(WX >> 8); +} + + +//[90h]~[B5h]========================================================================= + +//[90h]========================================================================= +void BTE_Enable(void) +{ + /* + BTE Function Enable + 0 : BTE Function disable. + 1 : BTE Function enable. + */ + uint8_t temp; + LCD_CmdWrite(0x90); + temp = LCD_DataRead(); + temp |= cSetb4 ; + LCD_DataWrite(temp); +} + +//[90h]========================================================================= +void BTE_Disable(void) +{ + /* + BTE Function Enable + 0 : BTE Function disable. + 1 : BTE Function enable. + */ + uint8_t temp; + LCD_CmdWrite(0x90); + temp = LCD_DataRead(); + temp &= cClrb4 ; + LCD_DataWrite(temp); +} + +//[90h]========================================================================= +void Check_BTE_Busy(void) +{ + /* + BTE Function Status + 0 : BTE Function is idle. + 1 : BTE Function is busy. + */ + uint8_t temp; + + do + { + temp = LCD_StatusRead(); + } + while(temp&0x08); +} +//[90h]========================================================================= +void Pattern_Format_8X8(void) +{ + /* + Pattern Format + 0 : 8X8 + 1 : 16X16 + */ + uint8_t temp; + LCD_CmdWrite(0x90); + temp = LCD_DataRead(); + temp &= cClrb0 ; + LCD_DataWrite(temp); +} +//[90h]========================================================================= +void Pattern_Format_16X16(void) +{ + /* + Pattern Format + 0 : 8X8 + 1 : 16X16 + */ + uint8_t temp; + LCD_CmdWrite(0x90); + temp = LCD_DataRead(); + temp |= cSetb0 ; + LCD_DataWrite(temp); +} + +//[91h]========================================================================= +void BTE_ROP_Code(uint8_t setx) +{ + /* + BTE ROP Code[Bit7:4] + + 0000 : 0(Blackness) + 0001 : ~S0.~S1 or ~ ( S0+S1 ) + 0010 : ~S0.S1 + 0011 : ~S0 + 0100 : S0.~S1 + 0101 : ~S1 + 0110 : S0^S1 + 0111 : ~S0+~S1 or ~ ( S0.S1 ) + 1000 : S0.S1 + 1001 : ~ ( S0^S1 ) + 1010 : S1 + 1011 : ~S0+S1 + 1100 : S0 + 1101 : S0+~S1 + 1110 : S0+S1 + 1111 : 1 ( Whiteness ) + */ + uint8_t temp; + LCD_CmdWrite(0x91); + temp = LCD_DataRead(); + temp &= 0x0f ; + temp |= (setx<<4); + LCD_DataWrite(temp); +} + +//[91h]========================================================================= +void BTE_Operation_Code(uint8_t setx) +{ + /* + BTE Operation Code[Bit3:0] + + 0000 : MPU Write BTE with ROP. + 0001 : MPU Read BTE w/o ROP. + 0010 : Memory copy (move) BTE in positive direction with ROP. + 0011 : Memory copy (move) BTE in negative direction with ROP. + 0100 : MPU Transparent Write BTE. (w/o ROP.) + 0101 : Transparent Memory copy (move) BTE in positive direction (w/o ROP.) + 0110 : Pattern Fill with ROP. + 0111 : Pattern Fill with key-chroma + 1000 : Color Expansion + 1001 : Color Expansion with transparency + 1010 : Move BTE in positive direction with Alpha blending + 1011 : MPU Write BTE with Alpha blending + 1100 : Solid Fill + 1101 : Reserved + 1110 : Reserved + 1111 : Reserved + */ + uint8_t temp; + LCD_CmdWrite(0x91); + temp = LCD_DataRead(); + temp &= 0xf0 ; + temp |= setx ; + LCD_DataWrite(temp); +} +//[92h]========================================================================= +void BTE_S0_Color_8bpp(void) +{ + /* + S0 Color Depth + 00 : 256 Color + 01 : 64k Color + 1x : 16M Color + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp &= cClrb6 ; + temp &= cClrb5 ; + LCD_DataWrite(temp); +} +//[92h]========================================================================= +void BTE_S0_Color_16bpp(void) +{ + /* + S0 Color Depth + 00 : 256 Color + 01 : 64k Color + 1x : 16M Color + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp &= cClrb6 ; + temp |= cSetb5 ; + LCD_DataWrite(temp); +} +//[92h]========================================================================= +void BTE_S0_Color_24bpp(void) +{ + /* + S0 Color Depth + 00 : 256 Color + 01 : 64k Color + 1x : 16M Color + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp |= cSetb6 ; + //temp |= cSetb5 ; + LCD_DataWrite(temp); +} +//[92h]========================================================================= +void BTE_S1_Color_8bpp(void) +{ + /* + S1 Color Depth + 000 : 256 Color + 001 : 64k Color + 010 : 16M Color + 011 : Constant Color + 100 : 8 bit pixel alpha blending + 101 : 16 bit pixel alpha blending + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp &= cClrb4 ; + temp &= cClrb3 ; + temp &= cClrb2 ; + LCD_DataWrite(temp); +} +//[92h]========================================================================= +void BTE_S1_Color_16bpp(void) +{ + /* + S1 Color Depth + 000 : 256 Color + 001 : 64k Color + 010 : 16M Color + 011 : Constant Color + 100 : 8 bit pixel alpha blending + 101 : 16 bit pixel alpha blending + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp &= cClrb4 ; + temp &= cClrb3 ; + temp |= cSetb2 ; + LCD_DataWrite(temp); +} +//[92h]========================================================================= +void BTE_S1_Color_24bpp(void) +{ + /* + S1 Color Depth + 000 : 256 Color + 001 : 64k Color + 010 : 16M Color + 011 : Constant Color + 100 : 8 bit pixel alpha blending + 101 : 16 bit pixel alpha blending + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp &= cClrb4 ; + temp |= cSetb3 ; + temp &= cClrb2 ; + LCD_DataWrite(temp); +} + +//[92h]========================================================================= +void BTE_S1_Color_Constant(void) +{ + /* + S1 Color Depth + 000 : 256 Color + 001 : 64k Color + 010 : 16M Color + 011 : Constant Color + 100 : 8 bit pixel alpha blending + 101 : 16 bit pixel alpha blending + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp &= cClrb4 ; + temp |= cSetb3 ; + temp |= cSetb2 ; + LCD_DataWrite(temp); +} + + + +//[92h]========================================================================= +void BTE_S1_Color_8bit_Alpha(void) +{ + /* + S1 Color Depth + 000 : 256 Color + 001 : 64k Color + 010 : 16M Color + 011 : Constant Color + 100 : 8 bit pixel alpha blending + 101 : 16 bit pixel alpha blending + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp |= cSetb4 ; + temp &= cClrb3 ; + temp &= cClrb2 ; + LCD_DataWrite(temp); +} + +//[92h]========================================================================= +void BTE_S1_Color_16bit_Alpha(void) +{ + /* + S1 Color Depth + 000 : 256 Color + 001 : 64k Color + 010 : 16M Color + 011 : Constant Color + 100 : 8 bit pixel alpha blending + 101 : 16 bit pixel alpha blending + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp |= cSetb4 ; + temp &= cClrb3 ; + temp |= cSetb2 ; + LCD_DataWrite(temp); +} + +//[92h]========================================================================= +void BTE_Destination_Color_8bpp(void) +{ + /* + Destination Color Depth + 00 : 256 Color + 01 : 64k Color + 1x : 16M Color + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp &= cClrb1 ; + temp &= cClrb0 ; + LCD_DataWrite(temp); +} +//[92h]========================================================================= +void BTE_Destination_Color_16bpp(void) +{ + /* + Destination Color Depth + 00 : 256 Color + 01 : 64k Color + 1x : 16M Color + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp &= cClrb1 ; + temp |= cSetb0 ; + LCD_DataWrite(temp); +} +//[92h]========================================================================= +void BTE_Destination_Color_24bpp(void) +{ + /* + Destination Color Depth + 00 : 256 Color + 10 : 64k Color + 1x : 16M Color + */ + uint8_t temp; + LCD_CmdWrite(0x92); + temp = LCD_DataRead(); + temp |= cSetb1 ; + //temp |= cSetb0 ; + LCD_DataWrite(temp); +} + + +//[93h][94h][95h][96h]========================================================================= +void BTE_S0_Memory_Start_Address(uint32_t Addr) +{ + /* + [93h] BTE S0 Memory Start Address [7:0] + [94h] BTE S0 Memory Start Address [15:8] + [95h] BTE S0 Memory Start Address [23:16] + [96h] BTE S0 Memory Start Address [31:24] + Bit [1:0] tie to '0' internally. + */ + LCD_RegisterWrite(0x93,Addr); + LCD_RegisterWrite(0x94,Addr >> 8); + LCD_RegisterWrite(0x95,Addr >> 16); + LCD_RegisterWrite(0x96,Addr >> 24); +} + + +//[97h][98h]========================================================================= +void BTE_S0_Image_Width(unsigned short WX) +{ + /* + [97h] BTE S0 Image Width [7:0] + [98h] BTE S0 Image Width [12:8] + Unit: Pixel. + Bit [1:0] tie to '0' internally. + */ + LCD_RegisterWrite(0x97,WX); + LCD_RegisterWrite(0x98,WX >> 8); +} + + +//[99h][9Ah][9Bh][9Ch]========================================================================= +void BTE_S0_Window_Start_XY(unsigned short WX,unsigned short HY) +{ + /* + [99h] BTE S0 Window Upper-Left corner X-coordination [7:0] + [9Ah] BTE S0 Window Upper-Left corner X-coordination [12:8] + [9Bh] BTE S0 Window Upper-Left corner Y-coordination [7:0] + [9Ch] BTE S0 Window Upper-Left corner Y-coordination [12:8] + */ + LCD_RegisterWrite(0x99,WX); + LCD_RegisterWrite(0x9A,WX >> 8); + LCD_RegisterWrite(0x9B,HY); + LCD_RegisterWrite(0x9C,HY >> 8); +} + + + + +//[9Dh][9Eh][9Fh][A0h]========================================================================= +void BTE_S1_Memory_Start_Address(uint32_t Addr) +{ + /* + [9Dh] BTE S1 Memory Start Address [7:0] + [9Eh] BTE S1 Memory Start Address [15:8] + [9Fh] BTE S1 Memory Start Address [23:16] + [A0h] BTE S1 Memory Start Address [31:24] + Bit [1:0] tie to '0' internally. + */ + LCD_RegisterWrite(0x9D,Addr); + LCD_RegisterWrite(0x9E,Addr >> 8); + LCD_RegisterWrite(0x9F,Addr >> 16); + LCD_RegisterWrite(0xA0,Addr >> 24); +} + + +//Input data format:R3G3B2 +void S1_Constant_color_256(uint8_t temp) +{ + LCD_CmdWrite(0x9D); + LCD_DataWrite(temp); + LCD_CmdWrite(0x9E); + LCD_DataWrite(temp<<3); + LCD_CmdWrite(0x9F); + LCD_DataWrite(temp<<6); +} + +//Input data format:R5G6B6 +void S1_Constant_color_65k(unsigned short temp) +{ + LCD_CmdWrite(0x9D); + LCD_DataWrite(temp >> 8); + LCD_CmdWrite(0x9E); + LCD_DataWrite(temp >> 3); + LCD_CmdWrite(0x9F); + LCD_DataWrite(temp<<3); +} + +//Input data format:R8G8B8 +void S1_Constant_color_16M(uint32_t temp) +{ + LCD_CmdWrite(0x9D); + LCD_DataWrite(temp >> 16); + LCD_CmdWrite(0x9E); + LCD_DataWrite(temp >> 8); + LCD_CmdWrite(0x9F); + LCD_DataWrite(temp); +} + + + + +//[A1h][A2h]========================================================================= +void BTE_S1_Image_Width(unsigned short WX) +{ + /* + [A1h] BTE S1 Image Width [7:0] + [A2h] BTE S1 Image Width [12:8] + Unit: Pixel. + Bit [1:0] tie to '0' internally. + */ + LCD_RegisterWrite(0xA1,WX); + LCD_RegisterWrite(0xA2,WX >> 8); +} + + +//[A3h][A4h][A5h][A6h]========================================================================= +void BTE_S1_Window_Start_XY(unsigned short WX,unsigned short HY) +{ + /* + [A3h] BTE S1 Window Upper-Left corner X-coordination [7:0] + [A4h] BTE S1 Window Upper-Left corner X-coordination [12:8] + [A5h] BTE S1 Window Upper-Left corner Y-coordination [7:0] + [A6h] BTE S1 Window Upper-Left corner Y-coordination [12:8] + */ + LCD_RegisterWrite(0xA3,WX); + LCD_RegisterWrite(0xA4,WX >> 8); + LCD_RegisterWrite(0xA5,HY); + LCD_RegisterWrite(0xA6,HY >> 8); +} + + + + +//[A7h][A8h][A9h][AAh]========================================================================= +void BTE_Destination_Memory_Start_Address(uint32_t Addr) +{ + /* + [A7h] BTE Destination Memory Start Address [7:0] + [A8h] BTE Destination Memory Start Address [15:8] + [A9h] BTE Destination Memory Start Address [23:16] + [AAh] BTE Destination Memory Start Address [31:24] + Bit [1:0] tie to '0' internally. + */ + LCD_RegisterWrite(0xA7,Addr); + LCD_RegisterWrite(0xA8,Addr >> 8); + LCD_RegisterWrite(0xA9,Addr >> 16); + LCD_RegisterWrite(0xAA,Addr >> 24); +} + + +//[ABh][ACh]========================================================================= +void BTE_Destination_Image_Width(unsigned short WX) +{ + /* + [ABh] BTE Destination Image Width [7:0] + [ACh] BTE Destination Image Width [12:8] + Unit: Pixel. + Bit [1:0] tie to '0' internally. + */ + LCD_RegisterWrite(0xAB,WX); + LCD_RegisterWrite(0xAC,WX >> 8); +} + + +//[ADh][AEh][AFh][B0h]========================================================================= +void BTE_Destination_Window_Start_XY(unsigned short WX,unsigned short HY) +{ + /* + [ADh] BTE Destination Window Upper-Left corner X-coordination [7:0] + [AEh] BTE Destination Window Upper-Left corner X-coordination [12:8] + [AFh] BTE Destination Window Upper-Left corner Y-coordination [7:0] + [B0h] BTE Destination Window Upper-Left corner Y-coordination [12:8] + */ + LCD_RegisterWrite(0xAD,WX); + LCD_RegisterWrite(0xAE,WX >> 8); + LCD_RegisterWrite(0xAF,HY); + LCD_RegisterWrite(0xB0,HY >> 8); +} + + +//[B1h][B2h][B3h][B4h]=============================================================== + +void BTE_Window_Size(unsigned short WX, unsigned short WY) + +{ + /* + [B1h] BTE Window Width [7:0] + [B2h] BTE Window Width [12:8] + + [B3h] BTE Window Height [7:0] + [B4h] BTE Window Height [12:8] + */ + LCD_RegisterWrite(0xB1,WX); + LCD_RegisterWrite(0xB2,WX >> 8); + LCD_RegisterWrite(0xB3,WY); + LCD_RegisterWrite(0xB4,WY >> 8); +} + +//[B5h]========================================================================= +void BTE_Alpha_Blending_Effect(uint8_t temp) +{ + /* + Window Alpha Blending effect for S0 & S1 + The value of alpha in the color code ranges from 0.0 to 1.0, + where 0.0 represents a fully transparent color, and 1.0 + represents a fully opaque color. + 00h: 0 + 01h: 1/32 + 02h: 2/32 + : + 1Eh: 30/32 + 1Fh: 31/32 + 2Xh: 1 + Output Effect = (S0 image x (1 - alpha setting value)) + (S1 image x alpha setting value) + */ + LCD_CmdWrite(0xB5); + LCD_DataWrite(temp); +} + + +//[B6h]========================================================================= +void Start_SFI_DMA(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB6); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} + +void Check_Busy_SFI_DMA(void) +{ + LCD_CmdWrite(0xB6); + + do + { + } + while((LCD_DataRead()&0x01)==0x01); +} + + +//[B7h]========================================================================= +void Select_SFI_0(void) +{ + /*[bit7] + Serial Flash/ROM I/F # Select + 0: Serial Flash/ROM 0 I/F is selected. + 1: Serial Flash/ROM 1 I/F is selected. + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void Select_SFI_1(void) +{ + /*[bit7] + Serial Flash/ROM I/F # Select + 0: Serial Flash/ROM 0 I/F is selected. + 1: Serial Flash/ROM 1 I/F is selected. + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void Select_SFI_Font_Mode(void) +{ + /*[bit6] + Serial Flash /ROM Access Mode + 0: Font mode ? for external cgrom + 1: DMA mode ? for cgram , pattern , bootstart image or osd + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Select_SFI_DMA_Mode(void) +{ + /*[bit6] + Serial Flash /ROM Access Mode + 0: Font mode ? for external cgrom + 1: DMA mode ? for cgram , pattern , bootstart image or osd + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Select_SFI_24bit_Address(void) +{ + /*[bit5] + Serial Flash/ROM Address Mode + 0: 24 bits address mode + 1: 32 bits address mode + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} +void Select_SFI_32bit_Address(void) +{ + /*[bit5] + Serial Flash/ROM Address Mode + 0: 24 bits address mode + 1: 32 bits address mode + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} +void Select_SFI_Waveform_Mode_0(void) +{ + /*[bit4] + Serial Flash/ROM Waveform Mode + Mode 0. + Mode 3. + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Select_SFI_Waveform_Mode_3(void) +{ + /*[bit4] + Serial Flash/ROM Waveform Mode + Mode 0. + Mode 3. + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Select_SFI_0_DummyRead(void) +{ + /*[bit3][bit2] + Serial Flash /ROM Read Cycle 0 RW + 00b: no dummy cycle mode + 01b: 1 dummy cycle mode + 10b: 2 dummy cycle mode + 11b: 4 dummy cycle mode + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= 0xF3; + LCD_DataWrite(temp); +} +void Select_SFI_8_DummyRead(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= 0xF3; + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Select_SFI_16_DummyRead(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= 0xF3; + temp |= cSetb3; + LCD_DataWrite(temp); +} +void Select_SFI_24_DummyRead(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp |= 0x0c; + LCD_DataWrite(temp); +} +void Select_SFI_Single_Mode(void) +{ + /*[bit1][bit0] + Serial Flash /ROM I/F Data Latch Mode Select + 0Xb: Single Mode + 10b: Dual Mode 0. + 11b: Dual Mode 1. + */ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= 0xFC; + LCD_DataWrite(temp); +} +void Select_SFI_Dual_Mode0(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp &= 0xFC; + temp |= cSetb1; + LCD_DataWrite(temp); +} +void Select_SFI_Dual_Mode1(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB7); + temp = LCD_DataRead(); + temp |= 0x03; + LCD_DataWrite(temp); +} + +//REG[B8h] SPI master Tx /Rx FIFO Data Register (SPIDR) +uint8_t SPI_Master_FIFO_Data_Put(uint8_t Data) +{ + uint8_t temp; + LCD_CmdWrite(0xB8); + LCD_DataWrite(Data); + + while(Tx_FIFO_Empty_Flag()==0); + + temp = SPI_Master_FIFO_Data_Get(); + return temp; +} + +uint8_t SPI_Master_FIFO_Data_Get(void) +{ + uint8_t temp; + + while(Rx_FIFO_Empty_Flag()==1); + + LCD_CmdWrite(0xB8); + temp = LCD_DataRead(); + //while(Rx_FIFO_full_flag()); + return temp; +} + +//REG[B9h] SPI master Control Register (SPIMCR2) +void Mask_SPI_Master_Interrupt_Flag(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} + +void Select_nSS_drive_on_xnsfcs0(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp &= cClrb5; + LCD_DataWrite(temp); +} + +void Select_nSS_drive_on_xnsfcs1(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp |= cSetb5; + LCD_DataWrite(temp); +} + +//0: inactive (nSS port will goes high) +void nSS_Inactive(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +//1: active (nSS port will goes low) +void nSS_Active(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} + +//Interrupt enable for FIFO overflow error [OVFIRQEN] +void OVFIRQEN_Enable(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} +//Interrupt enable for while Tx FIFO empty & SPI engine/FSM idle +void EMTIRQEN_Enable(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} + + +//At CPOL=0 the base value of the clock is zero +//o For CPHA=0, data are read on the clock's rising edge (low->high transition) and +//data are changed on a falling edge (high->low clock transition). +//o For CPHA=1, data are read on the clock's falling edge and data are changed on a +//rising edge. + +//At CPOL=1 the base value of the clock is one (inversion of CPOL=0) +//o For CPHA=0, data are read on clock's falling edge and data are changed on a +//rising edge. +//o For CPHA=1, data are read on clock's rising edge and data are changed on a +//falling edge. + +void Reset_CPOL(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp &= cClrb1; + LCD_DataWrite(temp); +} + +void Set_CPOL(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp |= cSetb1; + LCD_DataWrite(temp); +} + + +void Reset_CPHA(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp &= cClrb0; + LCD_DataWrite(temp); +} + +void Set_CPHA(void) +{ + uint8_t temp; + LCD_CmdWrite(0xB9); + temp = LCD_DataRead(); + temp |= cSetb0; + LCD_DataWrite(temp); +} + + +//REG[BAh] SPI master Status Register (SPIMSR) +uint8_t Tx_FIFO_Empty_Flag(void) +{ + LCD_CmdWrite(0xBA); + + if((LCD_DataRead()&0x80)==0x80) + { + return 1; + } + else + { + return 0; + } +} + +uint8_t Tx_FIFO_Full_Flag(void) +{ + LCD_CmdWrite(0xBA); + + if((LCD_DataRead()&0x40)==0x40) + { + return 1; + } + else + { + return 0; + } +} + +uint8_t Rx_FIFO_Empty_Flag(void) +{ + LCD_CmdWrite(0xBA); + + if((LCD_DataRead()&0x20)==0x20) + { + return 1; + } + else + { + return 0; + } +} + +uint8_t Rx_FIFO_full_flag(void) +{ + LCD_CmdWrite(0xBA); + + if((LCD_DataRead()&0x10)==0x10) + { + return 1; + } + else + { + return 0; + } +} + +uint8_t OVFI_Flag(void) +{ + LCD_CmdWrite(0xBA); + + if((LCD_DataRead()&0x08)==0x08) + { + return 1; + } + else + { + return 0; + } +} + +void Clear_OVFI_Flag(void) +{ + uint8_t temp; + LCD_CmdWrite(0xBA); + temp = LCD_DataRead(); + temp |= cSetb3; + LCD_DataWrite(temp); +} + +uint8_t EMTI_Flag(void) +{ + LCD_CmdWrite(0xBA); + + if((LCD_DataRead()&0x04)==0x04) + { + return 1; + } + else + { + return 0; + } +} + +void Clear_EMTI_Flag(void) +{ + uint8_t temp; + LCD_CmdWrite(0xBA); + temp = LCD_DataRead(); + temp |= cSetb2; + LCD_DataWrite(temp); +} + + +//REG[BB] SPI Clock period (SPIDIV) +void SPI_Clock_Period(uint8_t temp) +{ + LCD_CmdWrite(0xBB); + LCD_DataWrite(temp); +} + +//[BCh][BDh][BEh][BFh]========================================================================= +void SFI_DMA_Source_Start_Address(uint32_t Addr) +{ + /* + DMA Source START ADDRESS + This bits index serial flash address [7:0][15:8][23:16][31:24] + */ + LCD_CmdWrite(0xBC); + LCD_DataWrite(Addr); + LCD_CmdWrite(0xBD); + LCD_DataWrite(Addr >> 8); + LCD_CmdWrite(0xBE); + LCD_DataWrite(Addr >> 16); + LCD_CmdWrite(0xBF); + LCD_DataWrite(Addr >> 24); +} +//[C0h][C1h][C2h][C3h]========================================================================= +void SFI_DMA_Destination_Start_Address(uint32_t Addr) +{ + /* + DMA Destination START ADDRESS + [1:0]Fix at 0 + This bits index SDRAM address [7:0][15:8][23:16][31:24] + */ + LCD_CmdWrite(0xC0); + LCD_DataWrite(Addr); + LCD_CmdWrite(0xC1); + LCD_DataWrite(Addr >> 8); + LCD_CmdWrite(0xC2); + LCD_DataWrite(Addr >> 16); + LCD_CmdWrite(0xC3); + LCD_DataWrite(Addr >> 24); +} +//[C0h][C1h][C2h][C3h]========================================================================= +void SFI_DMA_Destination_Upper_Left_Corner(unsigned short WX,unsigned short HY) +{ + /* + C0h + This register defines DMA Destination Window Upper-Left corner + X-coordination [7:0] on Canvas area. + When REG DMACR bit 1 = 1 (Block Mode) + This register defines Destination address [7:2] in SDRAM. + C1h + When REG DMACR bit 1 = 0 (Linear Mode) + This register defines DMA Destination Window Upper-Left corner + X-coordination [12:8] on Canvas area. + When REG DMACR bit 1 = 1 (Block Mode) + This register defines Destination address [15:8] in SDRAM. + C2h + When REG DMACR bit 1 = 0 (Linear Mode) + This register defines DMA Destination Window Upper-Left corner + Y-coordination [7:0] on Canvas area. + When REG DMACR bit 1 = 1 (Block Mode) + This register defines Destination address [23:16] in SDRAM. + C3h + When REG DMACR bit 1 = 0 (Linear Mode) + This register defines DMA Destination Window Upper-Left corner + Y-coordination [12:8] on Canvas area. + When REG DMACR bit 1 = 1 (Block Mode) + This register defines Destination address [31:24] in SDRAM. + */ + LCD_CmdWrite(0xC0); + LCD_DataWrite(WX); + LCD_CmdWrite(0xC1); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0xC2); + LCD_DataWrite(HY); + LCD_CmdWrite(0xC3); + LCD_DataWrite(HY >> 8); +} + + + +//[C6h][C7h][C8h][C9h]========================================================================= +void SFI_DMA_Transfer_Number(uint32_t Addr) +{ + /* + Unit : Pixel + When REG DMACR bit 1 = 0 (Linear Mode) + DMA Transfer Number [7:0][15:8][23:16][31:24] + + When REG DMACR bit 1 = 1 (Block Mode) + DMA Block Width [7:0][15:8] + DMA Block HIGH[7:0][15:8] + */ + LCD_CmdWrite(0xC6); + LCD_DataWrite(Addr); + LCD_CmdWrite(0xC7); + LCD_DataWrite(Addr >> 8); + LCD_CmdWrite(0xC8); + LCD_DataWrite(Addr >> 16); + LCD_CmdWrite(0xC9); + LCD_DataWrite(Addr >> 24); +} +void SFI_DMA_Transfer_Width_Height(unsigned short WX,unsigned short HY) +{ + /* + When REG DMACR bit 1 = 0 (Linear Mode) + DMA Transfer Number [7:0][15:8][23:16][31:24] + + When REG DMACR bit 1 = 1 (Block Mode) + DMA Block Width [7:0][15:8] + DMA Block HIGH[7:0][15:8] + */ + LCD_CmdWrite(0xC6); + LCD_DataWrite(WX); + LCD_CmdWrite(0xC7); + LCD_DataWrite(WX >> 8); + LCD_CmdWrite(0xC8); + LCD_DataWrite(HY); + LCD_CmdWrite(0xC9); + LCD_DataWrite(HY >> 8); +} +//[CAh][CBh]========================================================================= +void SFI_DMA_Source_Width(unsigned short WX) +{ + /* + DMA Source Picture Width [7:0][12:8] + Unit: pixel + */ + LCD_CmdWrite(0xCA); + LCD_DataWrite(WX); + LCD_CmdWrite(0xCB); + LCD_DataWrite(WX >> 8); +} + +//[CCh]========================================================================= + +void Font_Select_UserDefine_Mode(void) +{ + /*[bit7-6] + User-defined Font /CGROM Font Selection Bit in Text Mode + 00 : Internal CGROM + 01 : Genitop serial flash + 10 : User-defined Font + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp |= cSetb7; + temp &= cClrb6; + LCD_DataWrite(temp); +} +void CGROM_Select_Internal_CGROM(void) +{ + /*[bit7-6] + User-defined Font /CGROM Font Selection Bit in Text Mode + 00 : Internal CGROM + 01 : Genitop serial flash + 10 : User-defined Font + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp &= cClrb7; + temp &= cClrb6; + LCD_DataWrite(temp); +} +void CGROM_Select_Genitop_FontROM(void) +{ + /*[bit7-6] + User-defined Font /CGROM Font Selection Bit in Text Mode + 00 : Internal CGROM + 01 : Genitop serial flash + 10 : User-defined Font + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp &= cClrb7; + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Font_Select_8x16_16x16(void) +{ + /*[bit5-4] + Font Height Setting + 00b : 8x16 / 16x16. + 01b : 12x24 / 24x24. + 10b : 16x32 / 32x32. + *** User-defined Font width is decided by font code. Genitop + serial flash's font width is decided by font code or GT Font ROM + control register. + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp &= cClrb5; + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Font_Select_12x24_24x24(void) +{ + /*[bit5-4] + Font Height Setting + 00b : 8x16 / 16x16. + 01b : 12x24 / 24x24. + 10b : 16x32 / 32x32. + *** User-defined Font width is decided by font code. Genitop + serial flash's font width is decided by font code or GT Font ROM + control register. + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp &= cClrb5; + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Font_Select_16x32_32x32(void) +{ + /*[bit5-4] + Font Height Setting + 00b : 8x16 / 16x16. + 01b : 12x24 / 24x24. + 10b : 16x32 / 32x32. + *** User-defined Font width is decided by font code. Genitop + serial flash's font width is decided by font code or GT Font ROM + control register. + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp |= cSetb5; + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Internal_CGROM_Select_ISOIEC8859_1(void) +{ + /* + Font Selection for internal CGROM + When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the + 8x16 character sets with the standard coding of ISO/IEC 8859-1~4, + which supports English and most of European country languages. + 00b : ISO/IEC 8859-1. + 01b : ISO/IEC 8859-2. + 10b : ISO/IEC 8859-3. + 11b : ISO/IEC 8859-4. + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp &= cClrb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Internal_CGROM_Select_ISOIEC8859_2(void) +{ + /* + Font Selection for internal CGROM + When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the + 8x16 character sets with the standard coding of ISO/IEC 8859-1~4, + which supports English and most of European country languages. + 00b : ISO/IEC 8859-1. + 01b : ISO/IEC 8859-2. + 10b : ISO/IEC 8859-3. + 11b : ISO/IEC 8859-4. + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp &= cClrb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} +void Internal_CGROM_Select_ISOIEC8859_3(void) +{ + /* + Font Selection for internal CGROM + When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the + 8x16 character sets with the standard coding of ISO/IEC 8859-1~4, + which supports English and most of European country languages. + 00b : ISO/IEC 8859-1. + 01b : ISO/IEC 8859-2. + 10b : ISO/IEC 8859-3. + 11b : ISO/IEC 8859-4. + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp |= cSetb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Internal_CGROM_Select_ISOIEC8859_4(void) +{ + /* + Font Selection for internal CGROM + When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the + 8x16 character sets with the standard coding of ISO/IEC 8859-1~4, + which supports English and most of European country languages. + 00b : ISO/IEC 8859-1. + 01b : ISO/IEC 8859-2. + 10b : ISO/IEC 8859-3. + 11b : ISO/IEC 8859-4. + */ + uint8_t temp; + LCD_CmdWrite(0xCC); + temp = LCD_DataRead(); + temp |= cSetb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} +//[CDh]========================================================================= +void Enable_Font_Alignment(void) +{ + /* + Full Alignment Selection Bit + 0 : Full alignment disable. + 1 : Full alignment enable. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} +void Disable_Font_Alignment(void) +{ + /* + Full Alignment Selection Bit + 0 : Full alignment disable. + 1 : Full alignment enable. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp &= cClrb7; + LCD_DataWrite(temp); +} +void Font_Background_select_Transparency(void) +{ + /* + Font Transparency + 0 : Font with background color. + 1 : Font with background transparency. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} +void Font_Background_select_Color(void) +{ + /* + Font Transparency + 0 : Font with background color. + 1 : Font with background transparency. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp &= cClrb6; + LCD_DataWrite(temp); +} +void Font_0_degree(void) +{ + /* + Font Rotation + 0 : Normal + Text direction from left to right then from top to bottom + 1 : Counterclockwise 90 degree & horizontal flip + Text direction from top to bottom then from left to right + (it should accommodate with set VDIR as 1) + This attribute can be changed only when previous font write + finished (core_busy = 0) + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp &= cClrb4; + LCD_DataWrite(temp); +} +void Font_90_degree(void) +{ + /* + Font Rotation + 0 : Normal + Text direction from left to right then from top to bottom + 1 : Counterclockwise 90 degree & horizontal flip + Text direction from top to bottom then from left to right + (it should accommodate with set VDIR as 1) + This attribute can be changed only when previous font write + finished (core_busy = 0) + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp |= cSetb4; + LCD_DataWrite(temp); +} +void Font_Width_X1(void) +{ + /* + Horizontal Font Enlargement + 00b : X1. + 01b : X2. + 10b : X3. + 11b : X4. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp &= cClrb3; + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Font_Width_X2(void) +{ + /* + Horizontal Font Enlargement + 00b : X1. + 01b : X2. + 10b : X3. + 11b : X4. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp &= cClrb3; + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Font_Width_X3(void) +{ + /* + Horizontal Font Enlargement + 00b : X1. + 01b : X2. + 10b : X3. + 11b : X4. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp |= cSetb3; + temp &= cClrb2; + LCD_DataWrite(temp); +} +void Font_Width_X4(void) +{ + /* + Horizontal Font Enlargement + 00b : X1. + 01b : X2. + 10b : X3. + 11b : X4. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp |= cSetb3; + temp |= cSetb2; + LCD_DataWrite(temp); +} +void Font_Height_X1(void) +{ + /* + Vertical Font Enlargement + 00b : X1. + 01b : X2. + 10b : X3. + 11b : X4. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp &= cClrb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Font_Height_X2(void) +{ + /* + Vertical Font Enlargement + 00b : X1. + 01b : X2. + 10b : X3. + 11b : X4. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp &= cClrb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} +void Font_Height_X3(void) +{ + /* + Vertical Font Enlargement + 00b : X1. + 01b : X2. + 10b : X3. + 11b : X4. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp |= cSetb1; + temp &= cClrb0; + LCD_DataWrite(temp); +} +void Font_Height_X4(void) +{ + /* + Vertical Font Enlargement + 00b : X1. + 01b : X2. + 10b : X3. + 11b : X4. + */ + uint8_t temp; + LCD_CmdWrite(0xCD); + temp = LCD_DataRead(); + temp |= cSetb1; + temp |= cSetb0; + LCD_DataWrite(temp); +} + +//[CEh]========================================================================= +void GTFont_Select_GT21L16TW_GT21H16T1W(void) +{ + /* + GT Serial Font ROM Select + 000b: GT21L16TW / GT21H16T1W + 001b: GT23L16U2W + 010b: GT23L24T3Y / GT23H24T3Y + 011b: GT23L24M1Z + 100b: GT23L32S4W / GT23H32S4W + 101b: GT20L24F6Y + 110b: GT21L24S1W + 111b: GT22L16A1Y + */ + uint8_t temp; + LCD_CmdWrite(0xCE); + temp = LCD_DataRead(); + temp &= cClrb7; + temp &= cClrb6; + temp &= cClrb5; + LCD_DataWrite(temp); +} +void GTFont_Select_GT23L16U2W(void) +{ + /* + GT Serial Font ROM Select + 000b: GT21L16TW / GT21H16T1W + 001b: GT23L16U2W + 010b: GT23L24T3Y / GT23H24T3Y + 011b: GT23L24M1Z + 100b: GT23L32S4W / GT23H32S4W + 101b: GT20L24F6Y + 110b: GT21L24S1W + 111b: GT22L16A1Y + */ + uint8_t temp; + LCD_CmdWrite(0xCE); + temp = LCD_DataRead(); + temp &= cClrb7; + temp &= cClrb6; + temp |= cSetb5; + LCD_DataWrite(temp); +} +void GTFont_Select_GT23L24T3Y_GT23H24T3Y(void) +{ + /* + GT Serial Font ROM Select + 000b: GT21L16TW / GT21H16T1W + 001b: GT23L16U2W + 010b: GT23L24T3Y / GT23H24T3Y + 011b: GT23L24M1Z + 100b: GT23L32S4W / GT23H32S4W + 101b: GT20L24F6Y + 110b: GT21L24S1W + 111b: GT22L16A1Y + */ + uint8_t temp; + LCD_CmdWrite(0xCE); + temp = LCD_DataRead(); + temp &= cClrb7; + temp |= cSetb6; + temp &= cClrb5; + LCD_DataWrite(temp); +} +void GTFont_Select_GT23L24M1Z(void) +{ + /* + GT Serial Font ROM Select + 000b: GT21L16TW / GT21H16T1W + 001b: GT23L16U2W + 010b: GT23L24T3Y / GT23H24T3Y + 011b: GT23L24M1Z + 100b: GT23L32S4W / GT23H32S4W + 101b: GT20L24F6Y + 110b: GT21L24S1W + 111b: GT22L16A1Y + */ + uint8_t temp; + LCD_CmdWrite(0xCE); + temp = LCD_DataRead(); + temp &= cClrb7; + temp |= cSetb6; + temp |= cSetb5; + LCD_DataWrite(temp); +} +void GTFont_Select_GT23L32S4W_GT23H32S4W(void) +{ + /* + GT Serial Font ROM Select + 000b: GT21L16TW / GT21H16T1W + 001b: GT23L16U2W + 010b: GT23L24T3Y / GT23H24T3Y + 011b: GT23L24M1Z + 100b: GT23L32S4W / GT23H32S4W + 101b: GT20L24F6Y + 110b: GT21L24S1W + 111b: GT22L16A1Y + */ + uint8_t temp; + LCD_CmdWrite(0xCE); + temp = LCD_DataRead(); + temp |= cSetb7; + temp &= cClrb6; + temp &= cClrb5; + LCD_DataWrite(temp); +} +void GTFont_Select_GT20L24F6Y(void) +{ + /* + GT Serial Font ROM Select + 000b: GT21L16TW / GT21H16T1W + 001b: GT23L16U2W + 010b: GT23L24T3Y / GT23H24T3Y + 011b: GT23L24M1Z + 100b: GT23L32S4W / GT23H32S4W + 101b: GT20L24F6Y + 110b: GT21L24S1W + 111b: GT22L16A1Y + */ + uint8_t temp; + LCD_CmdWrite(0xCE); + temp = LCD_DataRead(); + temp |= cSetb7; + temp &= cClrb6; + temp |= cSetb5; + LCD_DataWrite(temp); +} +void GTFont_Select_GT21L24S1W(void) +{ + /* + GT Serial Font ROM Select + 000b: GT21L16TW / GT21H16T1W + 001b: GT23L16U2W + 010b: GT23L24T3Y / GT23H24T3Y + 011b: GT23L24M1Z + 100b: GT23L32S4W / GT23H32S4W + 101b: GT20L24F6Y + 110b: GT21L24S1W + 111b: GT22L16A1Y + */ + uint8_t temp; + LCD_CmdWrite(0xCE); + temp = LCD_DataRead(); + temp |= cSetb7; + temp |= cSetb6; + temp &= cClrb5; + LCD_DataWrite(temp); +} +void GTFont_Select_GT22L16A1Y(void) +{ + /* + GT Serial Font ROM Select + 000b: GT21L16TW / GT21H16T1W + 001b: GT23L16U2W + 010b: GT23L24T3Y / GT23H24T3Y + 011b: GT23L24M1Z + 100b: GT23L32S4W / GT23H32S4W + 101b: GT20L24F6Y + 110b: GT21L24S1W + 111b: GT22L16A1Y + */ + uint8_t temp; + LCD_CmdWrite(0xCE); + temp = LCD_DataRead(); + temp |= cSetb7; + temp |= cSetb6; + temp |= cSetb5; + LCD_DataWrite(temp); +} + +//[CFh]========================================================================= +void Set_GTFont_Decoder(uint8_t temp) +{ + /* + [bit7-3] + FONT ROM Coding Setting + For specific GT serial Font ROM, the coding method must be set for decoding. + 00000b: GB2312 + 00001b: GB12345/GB18030 + 00010b: BIG5 + 00011b: UNICODE + 00100b: ASCII + 00101b: UNI-Japanese + 00110b: JIS0208 + 00111b: Latin/Greek/ Cyrillic / Arabic/Thai/Hebrew + 01000b: Korea + 10001b: ISO-8859-1 + 10010b: ISO-8859-2 + 10011b: ISO-8859-3 + 10100b: ISO-8859-4 + 10101b: ISO-8859-5 + 10110b: ISO-8859-6 + 10111b: ISO-8859-7 + 11000b: ISO-8859-8 + 11001b: ISO-8859-9 + 11010b: ISO-8859-10 + 11011b: ISO-8859-11 + 11100b: ISO-8859-12 + 11101b: ISO-8859-13 + 11110b: ISO-8859-14 + 11111b: ISO-8859-15 + + [bit1-0] + ASCII / Latin/Greek/ Cyrillic / Arabic + (ASCII) (Latin/Greek/Cyrillic) (Arabic) + 00b Normal Normal NA + 01b Arial Variable Width Presentation Forms-A + 10b Roman NA Presentation Forms-B + 11b Bold NA NA + */ + LCD_CmdWrite(0xCF); + LCD_DataWrite(temp); +} +//[D0h]========================================================================= +void Font_Line_Distance(uint8_t temp) +{ + /*[bit4-0] + Font Line Distance Setting + Setting the font character line distance when setting memory font + write cursor auto move. (Unit: pixel) + */ + LCD_CmdWrite(0xD0); + LCD_DataWrite(temp); +} +//[D1h]========================================================================= +void Set_Font_to_Font_Width(uint8_t temp) +{ + /*[bit5-0] + Font to Font Width Setting (Unit: pixel) + */ + LCD_CmdWrite(0xD1); + LCD_DataWrite(temp); +} +//[D2h]~[D4h]========================================================================= +void Foreground_RGB(uint8_t RED, uint8_t GREEN, uint8_t BLUE) +{ + /* + [D2h] Foreground Color - Red, for draw, text or color expansion + [D3h] Foreground Color - Green, for draw, text or color expansion + [D4h] Foreground Color - Blue, for draw, text or color expansion + */ + LCD_CmdWrite(0xD2); + LCD_DataWrite(RED); + LCD_CmdWrite(0xD3); + LCD_DataWrite(GREEN); + LCD_CmdWrite(0xD4); + LCD_DataWrite(BLUE); +} + +//Input data format:R3G3B2 +void Foreground_color_256(uint8_t temp) +{ + LCD_CmdWrite(0xD2); + LCD_DataWrite(temp); + LCD_CmdWrite(0xD3); + LCD_DataWrite(temp<<3); + LCD_CmdWrite(0xD4); + LCD_DataWrite(temp<<6); +} + +//Input data format:R5G6B5 +void Foreground_color_65k(unsigned short temp) +{ + LCD_CmdWrite(0xD2); + LCD_DataWrite(temp >> 8); + LCD_CmdWrite(0xD3); + LCD_DataWrite(temp >> 3); + LCD_CmdWrite(0xD4); + LCD_DataWrite(temp<<3); +} + +//Input data format:R8G8B8 +void Foreground_color_16M(uint32_t temp) +{ + LCD_CmdWrite(0xD2); + LCD_DataWrite(temp >> 16); + LCD_CmdWrite(0xD3); + LCD_DataWrite(temp >> 8); + LCD_CmdWrite(0xD4); + LCD_DataWrite(temp); +} + + + +//[D5h]~[D7h]========================================================================= +/* +[D5h] Background Color - Red, for Text or color expansion +[D6h] Background Color - Green, for Text or color expansion +[D7h] Background Color - Blue, for Text or color expansion +*/ +void Background_RGB(uint8_t RED, uint8_t GREEN, uint8_t BLUE) +{ + LCD_CmdWrite(0xD5); + LCD_DataWrite(RED); + LCD_CmdWrite(0xD6); + LCD_DataWrite(GREEN); + LCD_CmdWrite(0xD7); + LCD_DataWrite(BLUE); +} + +//Input data format:R3G3B2 +void Background_color_256(uint8_t temp) +{ + LCD_CmdWrite(0xD5); + LCD_DataWrite(temp); + LCD_CmdWrite(0xD6); + LCD_DataWrite(temp<<3); + LCD_CmdWrite(0xD7); + LCD_DataWrite(temp<<6); +} + +//Input data format:R5G6B6 +void Background_color_65k(unsigned short temp) +{ + LCD_CmdWrite(0xD5); + LCD_DataWrite(temp >> 8); + LCD_CmdWrite(0xD6); + LCD_DataWrite(temp >> 3); + LCD_CmdWrite(0xD7); + LCD_DataWrite(temp<<3); +} + +//Input data format:R8G8B8 +void Background_color_16M(uint32_t temp) +{ + LCD_CmdWrite(0xD5); + LCD_DataWrite(temp >> 16); + LCD_CmdWrite(0xD6); + LCD_DataWrite(temp >> 8); + LCD_CmdWrite(0xD7); + LCD_DataWrite(temp); +} + +//[DBh]~[DEh]========================================================================= +void CGRAM_Start_address(uint32_t Addr) +{ + /* + CGRAM START ADDRESS [31:0] + */ + LCD_CmdWrite(0xDB); + LCD_DataWrite(Addr); + LCD_CmdWrite(0xDC); + LCD_DataWrite(Addr >> 8); + LCD_CmdWrite(0xDD); + LCD_DataWrite(Addr >> 16); + LCD_CmdWrite(0xDE); + LCD_DataWrite(Addr >> 24); +} + +//[DFh]========================================================================= +/* +[bit7] Enter Power saving state +0: Normal state. +1: Enter power saving state. +[bit1][bit0] Power saving Mode definition +00: NA +01: Standby Mode +10: Suspend Mode +11: Sleep Mode +*/ +void Power_Normal_Mode(void) +{ + LCD_CmdWrite(0xDF); + LCD_DataWrite(0x00); +} +void Power_Saving_Standby_Mode(void) +{ + LCD_CmdWrite(0xDF); + LCD_DataWrite(0x01); + LCD_CmdWrite(0xDF); + LCD_DataWrite(0x81); +} +void Power_Saving_Suspend_Mode(void) +{ + LCD_CmdWrite(0xDF); +// LCD_DataWrite(0x02); +// LCD_CmdWrite(0xDF); + LCD_DataWrite(0x82); +} +void Power_Saving_Sleep_Mode(void) +{ + LCD_CmdWrite(0xDF); +// LCD_DataWrite(0x03); +// LCD_CmdWrite(0xDF); + LCD_DataWrite(0x83); +} + + +//[E5h]~[E6h]========================================================================= +void LT768_I2CM_Clock_Prescale(unsigned short WX) +{ + /* + I2C Master Clock Pre-scale [7:0] + I2C Master Clock Pre-scale [15:8] + */ + LCD_CmdWrite(0xE5); + LCD_DataWrite(WX); + LCD_CmdWrite(0xE6); + LCD_DataWrite(WX >> 8); +} +//[E7h]========================================================================= +void LT768_I2CM_Transmit_Data(uint8_t temp) +{ + /* + I2C Master Transmit[7:0] + */ + LCD_CmdWrite(0xE7); + LCD_DataWrite(temp); +} +//[E8h]========================================================================= +uint8_t LT768_I2CM_Receiver_Data(void) +{ + /* + I2C Master Receiver [7:0] + */ + uint8_t temp; + LCD_CmdWrite(0xE8); + temp = LCD_DataRead(); + return temp; +} +//[E9h]========================================================================= +/* +[bit7] START +Generate (repeated) start condition and be cleared by hardware automatically +Note : This bit is always read as 0. +[bit6] STOP +Generate stop condition and be cleared by hardware automatically +Note : This bit is always read as 0. +[bit5] +READ(READ and WRITE can't be used simultaneously) +Read form slave and be cleared by hardware automatically +Note : This bit is always read as 0. +[bit4] +WRITE(READ and WRITE can't be used simultaneously) +Write to slave and be cleared by hardware automatically +Note : This bit is always read as 0. +[bit3] ACKNOWLEDGE +When as a I2C master receiver +0 : Sent ACK. +1 : Sent NACK. +Note : This bit is always read as 0. +[bit0] Noise Filter +0 : Enable. +1 : Disable. +*/ + +#define Disable_I2CM_Noise_Filter + +void LT768_I2CM_Stop(void) +{ + LCD_CmdWrite(0xE9); +#ifdef Disable_I2CM_Noise_Filter + LCD_DataWrite(0x40); +#endif +#ifdef Enable_I2CM_Noise_Filter + LCD_DataWrite(0x41); +#endif +} +void LT768_I2CM_Read_With_Ack(void) +{ + LCD_CmdWrite(0xE9); +#ifdef Disable_I2CM_Noise_Filter + LCD_DataWrite(0x20); +#endif +#ifdef Enable_I2CM_Noise_Filter + LCD_DataWrite(0x21); +#endif +} + +void LT768_I2CM_Read_With_Nack(void) +{ + LCD_CmdWrite(0xE9); +#ifdef Disable_I2CM_Noise_Filter + LCD_DataWrite(0x68); +#endif +#ifdef Enable_I2CM_Noise_Filter + LCD_DataWrite(0x69); +#endif +} + +void LT768_I2CM_Write_With_Start(void) +{ + LCD_CmdWrite(0xE9); +#ifdef Disable_I2CM_Noise_Filter + LCD_DataWrite(0x90); +#endif +#ifdef Enable_I2CM_Noise_Filter + LCD_DataWrite(0x91); +#endif +} + +void LT768_I2CM_Write(void) +{ + LCD_CmdWrite(0xE9); +#ifdef Disable_I2CM_Noise_Filter + LCD_DataWrite(0x10); +#endif +#ifdef Enable_I2CM_Noise_Filter + LCD_DataWrite(0x11); +#endif +} + + + +//[EAh]========================================================================= +/* + 0=Ack + 1=Nack +*/ +uint8_t LT768_I2CM_Check_Slave_ACK(void) +{ + uint8_t temp; + /*[bit7] + Received acknowledge from slave + 0 : Acknowledge received. + 1 : No Acknowledge received. + */ + LCD_CmdWrite(0xEA); + temp = LCD_DataRead(); + + if((temp&0x80)==0x80) + { + return 1; + } + else + { + return 0; + } +} + + +/* + 0=Idle + 1=Busy +*/ +uint8_t LT768_I2CM_Bus_Busy(void) +{ + uint8_t temp; + /*[bit6] + I2C Bus is Busy + 0 : Idle. + 1 : Busy. + */ + LCD_CmdWrite(0xEA); + temp = LCD_DataRead(); + + if((temp&0x40)==0x40) + { + return 1; + } + else + { + return 0; + } +} + +/* + 0=Complete + 1=Transferring +*/ +uint8_t LT768_I2CM_transmit_Progress(void) +{ + uint8_t temp; + /*[bit6] + 0=Complete + 1=Transferring + */ + LCD_CmdWrite(0xEA); + temp = LCD_DataRead(); + + if((temp&0x02)==0x02) + { + return 1; + } + else + { + return 0; + } +} + +/* +0= Arbitration win +1= Arbitration lost +*/ +uint8_t LT768_I2CM_Arbitration(void) +{ + uint8_t temp; + /*[bit6] + I2C Bus is Busy + 0 : Idle. + 1 : Busy. + */ + LCD_CmdWrite(0xEA); + temp = LCD_DataRead(); + temp&=0x01; + return temp; +} + + +//[F0h]========================================================================= +void Set_GPIO_A_In_Out(uint8_t temp) +{ + /* + GPO-A_dir[7:0] : General Purpose I/O direction control. + 0: Output + 1: Input + */ + LCD_CmdWrite(0xF0); + LCD_DataWrite(temp); +} +//[F1h]========================================================================= +void Write_GPIO_A_7_0(uint8_t temp) +{ + /* + GPI-A[7:0] : General Purpose Input, share with DB[15:8] + GPO-A[7:0] : General Purpose Output, share with DB[15:8] + */ + LCD_CmdWrite(0xF1); + LCD_DataWrite(temp); +} +uint8_t Read_GPIO_A_7_0(void) +{ + /* + GPI-A[7:0] : General Purpose Input, share with DB[15:8] + GPO-A[7:0] : General Purpose Output, share with DB[15:8] + */ + uint8_t temp; + LCD_CmdWrite(0xF1); + temp = LCD_DataRead(); + return temp; +} +//[F2h]========================================================================= +void Write_GPIO_B_7_4(uint8_t temp) +{ + /* + GPI-B[7:0] : General Purpose Input ; share with {XKIN[3:0], XA0, XnWR, XnRD, XnCS} + GPO-B[7:4] : General Purpose Output ; share with XKOUT[3:0] ; + */ + LCD_CmdWrite(0xF2); + LCD_DataWrite(temp); +} +uint8_t Read_GPIO_B_7_0(void) +{ + /* + GPI-B[7:0] : General Purpose Input ; share with {XKIN[3:0], XA0, XnWR, XnRD, XnCS} + GPO-B[7:4] : General Purpose Output ; share with XKOUT[3:0] ; + */ + uint8_t temp; + LCD_CmdWrite(0xF2); + temp = LCD_DataRead(); + return temp; +} + +//[F3h]========================================================================= +void Set_GPIO_C_In_Out(uint8_t temp) +{ + /* + GPIO-C_dir[7:0] : General Purpose I/O direction control. + 0: Output + 1: Input + */ + LCD_CmdWrite(0xF3); + LCD_DataWrite(temp); +} +//[F4h]========================================================================= +void Write_GPIO_C_7_0(uint8_t temp) +{ + /* + GPIO-C[7:0] : General Purpose Input / Output + share with {XPWM0, XI2CSDA, XI2CSCL, XnSFCS1, XnSFCS0,XMISO, XMOSI, XSCLK} + */ + LCD_CmdWrite(0xF4); + LCD_DataWrite(temp); +} +uint8_t Read_GPIO_C_7_0(void) +{ + /* + GPIO-C[7:0] : General Purpose Input / Output + share with {XPWM0, XI2CSDA, XI2CSCL, XnSFCS1, XnSFCS0,XMISO, XMOSI, XSCLK} + */ + uint8_t temp; + LCD_CmdWrite(0xF4); + temp = LCD_DataRead(); + return temp; +} +//[F5h]========================================================================= +void Set_GPIO_D_In_Out(uint8_t temp) +{ + /* + GPIO-D_dir[7:0] : General Purpose I/O direction control. + 0: Output + 1: Input + */ + LCD_CmdWrite(0xF5); + LCD_DataWrite(temp); +} +//[F6h]========================================================================= +void Write_GPIO_D_7_0(uint8_t temp) +{ + /* + GPIO-D[7:0] : General Purpose Input/Output + */ + LCD_CmdWrite(0xF6); + LCD_DataWrite(temp); +} +uint8_t Read_GPIO_D_7_0(void) +{ + /* + GPIO-D[7:0] : General Purpose Input/Output + */ + uint8_t temp; + LCD_CmdWrite(0xF6); + temp = LCD_DataRead(); + return temp; +} +//[F7h]========================================================================= +void Set_GPIO_E_In_Out(uint8_t temp) +{ + /* + GPIO-E_dir[7:0] : General Purpose I/O direction control. + 0: Output + 1: Input + */ + LCD_CmdWrite(0xF7); + LCD_DataWrite(temp); +} +//[F8h]========================================================================= +void Write_GPIO_E_7_0(uint8_t temp) +{ + /* + GPIO-E[7:0] : General Purpose Input/Output. + share with {PDAT[23:19], PDAT[15:13]} + */ + LCD_CmdWrite(0xF8); + LCD_DataWrite(temp); +} +uint8_t Read_GPIO_E_7_0(void) +{ + /* + GPIO-E[7:0] : General Purpose Input/Output. + share with {PDAT[23:19], PDAT[15:13]} + */ + uint8_t temp; + LCD_CmdWrite(0xF8); + temp = LCD_DataRead(); + return temp; +} +//[F9h]========================================================================= +void Set_GPIO_F_In_Out(uint8_t temp) +{ + /* + GPIO-F_dir[7:0] : General Purpose I/O direction control. + 0: Output + 1: Input + */ + LCD_CmdWrite(0xF9); + LCD_DataWrite(temp); +} +//[FAh]========================================================================= +void Write_GPIO_F_7_0(uint8_t temp) +{ + /* + GPIO-F[7:0] : General Purpose Input/Output. + share with {XPDAT[12:10], XPDAT[7:3]} + */ + LCD_CmdWrite(0xFA); + LCD_DataWrite(temp); +} +uint8_t Read_GPIO_F_7_0(void) +{ + /* + GPIO-F[7:0] : General Purpose Input/Output. + share with {XPDAT[12:10], XPDAT[7:3]} + */ + uint8_t temp; + LCD_CmdWrite(0xFA); + temp = LCD_DataRead(); + return temp; +} + +//[FBh]========================================================================= + + +void Long_Key_enable(void) +{ + /* + Key-Scan Control Register 1 + [bit6] LongKey Enable Bit + 1 : Enable. Long key period is set by KSCR2 bit4-2. + 0 : Disable. + */ + uint8_t temp; + LCD_CmdWrite(0xFB); + temp = LCD_DataRead(); + temp |= cSetb6; + LCD_DataWrite(temp); +} + + +void Key_Scan_Freg(uint8_t setx) +{ + /*KF2-0: Key-Scan Frequency */ + uint8_t temp; + LCD_CmdWrite(0xFB); + temp = LCD_DataRead(); + temp &= 0xf0; + temp|= (setx&0x07); + LCD_DataWrite(temp); +} + + +//[FCh]========================================================================= + +void Key_Scan_Wakeup_Function_Enable(void) +{ + /* + Key-Scan Controller Register 2 + [bit7] + Key-Scan Wakeup Function Enable Bit + 0: Key-Scan Wakeup function is disabled. + 1: Key-Scan Wakeup function is enabled. + */ + uint8_t temp; + LCD_CmdWrite(0xFC); + temp = LCD_DataRead(); + temp |= cSetb7; + LCD_DataWrite(temp); +} + + +void Long_Key_Timing_Adjustment(uint8_t setx) +{ + /*Long Key Timing Adjustment*/ + uint8_t temp,temp1; + temp = setx & 0x1c; + LCD_CmdWrite(0xFC); + temp1 = LCD_DataRead(); + temp1|=temp; + LCD_DataWrite(temp1); +} + +uint8_t Numbers_of_Key_Hit(void) +{ + uint8_t temp; + LCD_CmdWrite(0xFC); + temp = LCD_DataRead(); //read key touch number + temp = temp & 0x03; + return temp; +} + +//[FDh][FEh][FFh]========================================================================= +uint8_t Read_Key_Strobe_Data_0(void) +{ + /* + Key Strobe Data 0 + The corresponding key code 0 that is pressed. + */ + uint8_t temp; + LCD_CmdWrite(0xFD); + temp = LCD_DataRead(); + return temp; +} +uint8_t Read_Key_Strobe_Data_1(void) +{ + /* + Key Strobe Data 1 + The corresponding key code 1 that is pressed. + */ + uint8_t temp; + LCD_CmdWrite(0xFE); + temp = LCD_DataRead(); + return temp; +} +uint8_t Read_Key_Strobe_Data_2(void) +{ + /* + Key Strobe Data 2 + The corresponding key code 2 that is pressed. + */ + uint8_t temp; + LCD_CmdWrite(0xFF); + temp = LCD_DataRead(); + return temp; +} + +void Show_String(char *str) +{ + Text_Mode(); //text mode + LCD_CmdWrite(0x04); + + while(*str != '\0') + { + LCD_DataWrite(*str); + Check_Mem_WR_FIFO_not_Full(); + ++str; + } + + Check_2D_Busy(); + Graphic_Mode(); //back to graphic mode; +} + + +void Show_picture(uint32_t numbers,const unsigned short *datap) +{ + uint32_t i; + LCD_CmdWrite(0x04); + + for(i=0; i5) - { - temp = temp / 1000000 + 1; - } - else - { - temp = temp / 1000000; - } - - lt768_sclk = temp; - temp = temp * 3; - lt768_mclk = temp; - lt768_cclk = temp; - - if(lt768_cclk > 100) - { - lt768_cclk = 100; - } - - if(lt768_mclk > 100) - { - lt768_mclk = 100; - } - - if(lt768_sclk > 65) - { - lt768_sclk = 65; - } - -#if XI_4M - lpllOD_sclk = 3; - lpllOD_cclk = 2; - lpllOD_mclk = 2; - lpllR_sclk = 2; - lpllR_cclk = 2; - lpllR_mclk = 2; - lpllN_mclk = lt768_mclk; - lpllN_cclk = lt768_cclk; - lpllN_sclk = 2*lt768_sclk; -#endif -#if XI_8M - lpllOD_sclk = 3; - lpllOD_cclk = 2; - lpllOD_mclk = 2; - lpllR_sclk = 2; - lpllR_cclk = 4; - lpllR_mclk = 4; - lpllN_mclk = lt768_mclk; - lpllN_cclk = lt768_cclk; - lpllN_sclk = lt768_sclk; -#endif -#if XI_10M - lpllOD_sclk = 3; - lpllOD_cclk = 2; - lpllOD_mclk = 2; - lpllR_sclk = 5; - lpllR_cclk = 5; - lpllR_mclk = 5; - lpllN_mclk = lt768_mclk; - lpllN_cclk = lt768_cclk; - lpllN_sclk = 2*lt768_sclk; -#endif -#if XI_12M - lpllOD_sclk = 3; - lpllOD_cclk = 2; - lpllOD_mclk = 2; - lpllR_sclk = 3; - lpllR_cclk = 6; - lpllR_mclk = 6; - lpllN_mclk = lt768_mclk; - lpllN_cclk = lt768_cclk; - lpllN_sclk = lt768_sclk; -#endif - LCD_CmdWrite(0x05); - LCD_DataWrite((lpllOD_sclk<<6) | (lpllR_sclk<<1) | ((lpllN_sclk>>8)&0x1)); - LCD_CmdWrite(0x07); - LCD_DataWrite((lpllOD_mclk<<6) | (lpllR_mclk<<1) | ((lpllN_mclk>>8)&0x1)); - LCD_CmdWrite(0x09); - LCD_DataWrite((lpllOD_cclk<<6) | (lpllR_cclk<<1) | ((lpllN_cclk>>8)&0x1)); - LCD_CmdWrite(0x06); - LCD_DataWrite(lpllN_sclk); - LCD_CmdWrite(0x08); - LCD_DataWrite(lpllN_mclk); - LCD_CmdWrite(0x0a); - LCD_DataWrite(lpllN_cclk); - LCD_CmdWrite(0x00); - up_udelay(1); - LCD_DataWrite(0x80); - up_mdelay(1); -} - -void lt768_sdram_init(uint8_t mclk) -{ - uint16_t sdram_itv; - LCD_RegisterWrite(0xe0,0x29); - LCD_RegisterWrite(0xe1,0x03); //CAS:2=0x02?CAS:3=0x03 - sdram_itv = (64000000 / 8192) / (1000 / mclk) ; - sdram_itv-=2; - LCD_RegisterWrite(0xe2,sdram_itv); - LCD_RegisterWrite(0xe3,sdram_itv >>8); - LCD_RegisterWrite(0xe4,0x01); -// Check_SDRAM_Ready(); - up_mdelay(1); -} - -void lt768_set_panel(void) -{ - //**[01h]**// - TFT_16bit(); - //TFT_18bit(); - //TFT_24bit(); -#if STM32_FSMC_8 - Host_Bus_8bit(); //主机总线8bit -#else - Host_Bus_16bit(); //主机总线16bit -#endif - //**[02h]**// - RGB_16b_16bpp(); - //RGB_16b_24bpp_mode1(); - MemWrite_Left_Right_Top_Down(); - //MemWrite_Down_Top_Left_Right(); - //**[03h]**// - Graphic_Mode(); - Memory_Select_SDRAM(); -// PCLK_Falling(); //REG[12h]:下降沿 - PCLK_Rising(); - VSCAN_T_to_B(); //REG[12h]:从上到下 - //VSCAN_B_to_T(); //从下到上 - PDATA_Set_RGB(); //REG[12h]:Select RGB output - //PDATA_Set_RBG(); - //PDATA_Set_GRB(); - //PDATA_Set_GBR(); - //PDATA_Set_BRG(); - //PDATA_Set_BGR(); - HSYNC_Low_Active(); //REG[13h]: - //HSYNC_High_Active(); - VSYNC_Low_Active(); //REG[13h]: - //VSYNC_High_Active(); - DE_High_Active(); //REG[13h]: - //DE_Low_Active(); - LCD_HorizontalWidth_VerticalHeight(LCD_XSIZE_TFT,LCD_YSIZE_TFT); - LCD_Horizontal_Non_Display(LCD_HBPD); - LCD_HSYNC_Start_Position(LCD_HFPD); - LCD_HSYNC_Pulse_Width(LCD_HSPW); - LCD_Vertical_Non_Display(LCD_VBPD); - LCD_VSYNC_Start_Position(LCD_VFPD); - LCD_VSYNC_Pulse_Width(LCD_VSPW); - Memory_XY_Mode(); //Block mode (X-Y coordination addressing);块模式 - Memory_16bpp_Mode(); -} - -void lt768_init(void) -{ - lt768_hw_reset(); - //delay for LT768 power on - up_mdelay(100); - - // check reset ok? - lt768_sys_check(); - - //Initial_Display_test and set SW2 pin2 = 1 - while(LCD_StatusRead() & 0x02); - - lt768_pll_init(); - lt768_sdram_init(lt768_mclk); - lt768_set_panel(); -} - -/*----------------------------------------------------------------------------*/ - -void MPU8_8bpp_Memory_Write -( - uint16_t x // x坐标 - ,uint16_t y // y坐标 - ,uint16_t w // 宽度 - ,uint16_t h // 高度 - ,const uint8_t *data // 数据首地址 -) -{ - uint16_t i,j; - Graphic_Mode(); - Active_Window_XY(x,y); - Active_Window_WH(w,h); - Goto_Pixel_XY(x,y); - LCD_CmdWrite(0x04); - - for(i=0; i< h; i++) - { - for(j=0; j< w; j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite(*data); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); -} - - -void MPU8_16bpp_Memory_Write -( - uint16_t x // x坐标 - ,uint16_t y // y坐标 - ,uint16_t w // 宽度 - ,uint16_t h // 高度 - ,const uint8_t *data // 数据首地址 -) -{ - uint16_t i,j; - Graphic_Mode(); - Active_Window_XY(x,y); - Active_Window_WH(w,h); - Goto_Pixel_XY(x,y); - LCD_CmdWrite(0x04); - - for(i=0; i< h; i++) - { - for(j=0; j< w; j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite(*data); - data++; - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite(*data); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); -} - - -void MPU8_24bpp_Memory_Write -( - uint16_t x // x坐标 - ,uint16_t y // y坐标 - ,uint16_t w // 宽度 - ,uint16_t h // 高度 - ,const uint8_t *data // 数据首地址 -) -{ - uint16_t i,j; - Graphic_Mode(); - Active_Window_XY(x,y); - Active_Window_WH(w,h); - Goto_Pixel_XY(x,y); - LCD_CmdWrite(0x04); - - for(i=0; i< h; i++) - { - for(j=0; j< w; j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite(*data); - data++; - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite(*data); - data++; - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite(*data); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); -} - - - -void MPuint16_t_16bpp_Memory_Write -( - uint16_t x // x坐标 - ,uint16_t y // y坐标 - ,uint16_t w // 宽度 - ,uint16_t h // 高度 - ,const uint16_t *data // 数据首地址 -) -{ - uint16_t i,j; - Graphic_Mode(); - Active_Window_XY(x,y); - Active_Window_WH(w,h); - Goto_Pixel_XY(x,y); - LCD_CmdWrite(0x04); - - for(i=0; i< h; i++) - { - for(j=0; j< w; j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite_Pixel(*data); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); -} - -void MPuint16_t_24bpp_Mode1_Memory_Write -( - uint16_t x // x坐标 - ,uint16_t y // y坐标 - ,uint16_t w // 宽度 - ,uint16_t h // 高度 - ,const uint16_t *data // 数据首地址 -) -{ - uint16_t i,j; - Graphic_Mode(); - Active_Window_XY(x,y); - Active_Window_WH(w,h); - Goto_Pixel_XY(x,y); - LCD_CmdWrite(0x04); - - for(i=0; i< h; i++) - { - for(j=0; j< w/2; j++) - { - LCD_DataWrite_Pixel(*data); - Check_Mem_WR_FIFO_not_Full(); - data++; - LCD_DataWrite_Pixel(*data); - Check_Mem_WR_FIFO_not_Full(); - data++; - LCD_DataWrite_Pixel(*data); - Check_Mem_WR_FIFO_not_Full(); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); -} - - -void MPuint16_t_24bpp_Mode2_Memory_Write -( - uint16_t x // x坐标 - ,uint16_t y // y坐标 - ,uint16_t w // 宽度 - ,uint16_t h // 高度 - ,const uint16_t *data // 数据首地址 -) -{ - uint16_t i,j; - Graphic_Mode(); - Active_Window_XY(x,y); - Active_Window_WH(w,h); - Goto_Pixel_XY(x,y); - LCD_CmdWrite(0x04); - - for(i=0; i< h; i++) - { - for(j=0; j< w; j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite_Pixel(*data); - data++; - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite_Pixel(*data); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); -} -/*----------------------------------------------------------------------------*/ - -//------------------------------------- 线段 ----------------------------------------- -void LT768_DrawLine -( - uint16_t X1 // X1坐标 - ,uint16_t Y1 // Y1坐标 - ,uint16_t X2 // X2坐标 - ,uint16_t Y2 // Y2坐标 - ,unsigned long LineColor // 线段颜色 -) -{ - Foreground_color_65k(LineColor); - Line_Start_XY(X1,Y1); - Line_End_XY(X2,Y2); - Start_Line(); - Check_2D_Busy(); -} - -void LT768_DrawLine_Width -( - uint16_t X1 // X1坐标 - ,uint16_t Y1 // Y1坐标 - ,uint16_t X2 // X2坐标 - ,uint16_t Y2 // Y2坐标 - ,unsigned long LineColor // 线段颜色 - ,uint16_t Width // 线段宽度 -) -{ - uint16_t i = 0; - signed short x = 0, y = 0; - double temp = 0; - x = X2 - X1; - y = Y2 - Y1; - - if(x == 0) - { - temp = 2; - } - else - { - temp = -((double)y/(double)x); - } - - if(temp>=-1&&temp<=1) - { - while(Width--) - { - LT768_DrawLine(X1,Y1+i,X2,Y2+i,LineColor); - i++; - } - } - else - { - while(Width--) - { - LT768_DrawLine(X1+i,Y1,X2+i,Y2,LineColor); - i++; - } - } -} - -//------------------------------------- 圆 ----------------------------------------- -void LT768_DrawCircle -( - uint16_t XCenter // 圆心X位置 - ,uint16_t YCenter // 圆心Y位置 - ,uint16_t R // 半径 - ,unsigned long CircleColor // 画线颜色 -) -{ - Foreground_color_65k(CircleColor); - Circle_Center_XY(XCenter,YCenter); - Circle_Radius_R(R); - Start_Circle_or_Ellipse(); - Check_2D_Busy(); -} - -void LT768_DrawCircle_Fill -( - uint16_t XCenter // 圆心X位置 - ,uint16_t YCenter // 圆心Y位置 - ,uint16_t R // 半径 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Circle_Center_XY(XCenter,YCenter); - Circle_Radius_R(R); - Start_Circle_or_Ellipse_Fill(); - Check_2D_Busy(); -} - -void LT768_DrawCircle_Width -( - uint16_t XCenter // 圆心X位置 - ,uint16_t YCenter // 圆心Y位置 - ,uint16_t R // 半径 - ,unsigned long CircleColor // 画线颜色 - ,unsigned long ForegroundColor // 背景颜色 - ,uint16_t Width // 线宽 -) -{ - LT768_DrawCircle_Fill(XCenter,YCenter,R+Width,CircleColor); - LT768_DrawCircle_Fill(XCenter,YCenter,R,ForegroundColor); -} - -//------------------------------------- 椭圆 ----------------------------------------- -void LT768_DrawEllipse -( - uint16_t XCenter // 椭圆心X位置 - ,uint16_t YCenter // 椭圆心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long EllipseColor // 画线颜色 -) -{ - Foreground_color_65k(EllipseColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Circle_or_Ellipse(); - Check_2D_Busy(); -} - -void LT768_DrawEllipse_Fill -( - uint16_t XCenter // 椭圆心X位置 - ,uint16_t YCenter // 椭圆心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Circle_or_Ellipse_Fill(); - Check_2D_Busy(); -} - -void LT768_DrawEllipse_Width -( - uint16_t XCenter // 椭圆心X位置 - ,uint16_t YCenter // 椭圆心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long EllipseColor // 画线颜色 - ,unsigned long ForegroundColor // 背景颜色 - ,uint16_t Width // 线宽 -) -{ - LT768_DrawEllipse_Fill(XCenter,YCenter,X_R+Width,Y_R+Width,EllipseColor); - LT768_DrawEllipse_Fill(XCenter,YCenter,X_R,Y_R,ForegroundColor); -} - -//------------------------------------- 矩形 ----------------------------------------- -void LT768_DrawSquare -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,unsigned long SquareColor // 画线颜色 -) -{ - Foreground_color_65k(SquareColor); - Square_Start_XY(X1,Y1); - Square_End_XY(X2,Y2); - Start_Square(); - Check_2D_Busy(); -} - -void LT768_DrawSquare_Fill -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Square_Start_XY(X1,Y1); - Square_End_XY(X2,Y2); - Start_Square_Fill(); - Check_2D_Busy(); -} - -void LT768_DrawSquare_Width -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,unsigned long SquareColor // 画线颜色 - ,unsigned long ForegroundColor // 背景颜色 - ,uint16_t Width // 线宽 -) -{ - LT768_DrawSquare_Fill(X1-Width,Y1-Width,X2+Width,Y2+Width,SquareColor); - LT768_DrawSquare_Fill(X1,Y1,X2,Y2,ForegroundColor); -} - -//------------------------------------- 圆角矩形 ----------------------------------------- -void LT768_DrawCircleSquare -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long CircleSquareColor // 画线颜色 -) -{ - Foreground_color_65k(CircleSquareColor); - Square_Start_XY(X1,Y1); - Square_End_XY(X2,Y2); - Circle_Square_Radius_RxRy(X_R,Y_R); - Start_Circle_Square(); - Check_2D_Busy(); -} - -void LT768_DrawCircleSquare_Fill -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long ForegroundColor // 画线颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Square_Start_XY(X1,Y1); - Square_End_XY(X2,Y2); - Circle_Square_Radius_RxRy(X_R,Y_R); - Start_Circle_Square_Fill(); - Check_2D_Busy(); -} - -void LT768_DrawCircleSquare_Width -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long CircleSquareColor // 画线颜色 - ,unsigned long ForegroundColor // 画线颜色 - ,uint16_t Width // 宽度 -) -{ - LT768_DrawCircleSquare_Fill(X1-Width,Y1-Width,X2+Width,Y2+Width,X_R,Y_R,CircleSquareColor); - LT768_DrawCircleSquare_Fill(X1,Y1,X2,Y2,X_R,Y_R,ForegroundColor); -} - -//------------------------------------- 三角形 ----------------------------------------- -void LT768_DrawTriangle -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X3 // X3位置 - ,uint16_t Y3 // Y3位置 - ,unsigned long TriangleColor // 画线颜色 -) -{ - Foreground_color_65k(TriangleColor); - Triangle_Point1_XY(X1,Y1); - Triangle_Point2_XY(X2,Y2); - Triangle_Point3_XY(X3,Y3); - Start_Triangle(); - Check_2D_Busy(); -} - - - -void LT768_DrawTriangle_Fill -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X3 // X3位置 - ,uint16_t Y3 // Y3位置 - ,unsigned long ForegroundColor // 画线颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Triangle_Point1_XY(X1,Y1); - Triangle_Point2_XY(X2,Y2); - Triangle_Point3_XY(X3,Y3); - Start_Triangle_Fill(); - Check_2D_Busy(); -} - -void LT768_DrawTriangle_Frame -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X3 // X3位置 - ,uint16_t Y3 // Y3位置 - ,unsigned long TriangleColor // 画线颜色 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - LT768_DrawTriangle_Fill(X1,Y1,X2,Y2,X3,Y3,ForegroundColor); - LT768_DrawTriangle(X1,Y1,X2,Y2,X3,Y3,TriangleColor); -} - - - -//------------------------------------- 曲线 ----------------------------------------- -void LT768_DrawLeftUpCurve -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long CurveColor // 画线颜色 -) -{ - Foreground_color_65k(CurveColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Left_Up_Curve(); - Check_2D_Busy(); -} - - -void LT768_DrawLeftDownCurve -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long CurveColor // 画线颜色 -) -{ - Foreground_color_65k(CurveColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Left_Down_Curve(); - Check_2D_Busy(); -} - - -void LT768_DrawRightUpCurve -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long CurveColor // 画线颜色 -) -{ - Foreground_color_65k(CurveColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Right_Up_Curve(); - Check_2D_Busy(); -} - - -void LT768_DrawRightDownCurve -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long CurveColor // 画线颜色 -) -{ - Foreground_color_65k(CurveColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Right_Down_Curve(); - Check_2D_Busy(); -} - - -void LT768_SelectDrawCurve -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long CurveColor // 画线颜色 - ,uint16_t Dir // 方向 -) -{ - switch(Dir) - { - case 0: - LT768_DrawLeftDownCurve(XCenter,YCenter,X_R,Y_R,CurveColor); - break; - - case 1: - LT768_DrawLeftUpCurve(XCenter,YCenter,X_R,Y_R,CurveColor); - break; - - case 2: - LT768_DrawRightUpCurve(XCenter,YCenter,X_R,Y_R,CurveColor); - break; - - case 3: - LT768_DrawRightDownCurve(XCenter,YCenter,X_R,Y_R,CurveColor); - break; - - default: - break; - } -} - - -//------------------------------------- 1/4实心椭圆 ----------------------------------------- -void LT768_DrawLeftUpCurve_Fill -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Left_Up_Curve_Fill(); - Check_2D_Busy(); -} - - -void LT768_DrawLeftDownCurve_Fill -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Left_Down_Curve_Fill(); - Check_2D_Busy(); -} - - -void LT768_DrawRightUpCurve_Fill -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Right_Up_Curve_Fill(); - Check_2D_Busy(); -} - - -void LT768_DrawRightDownCurve_Fill -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Ellipse_Center_XY(XCenter,YCenter); - Ellipse_Radius_RxRy(X_R,Y_R); - Start_Right_Down_Curve_Fill(); - Check_2D_Busy(); -} - - -void LT768_SelectDrawCurve_Fill -( - uint16_t XCenter // 曲心X位置 - ,uint16_t YCenter // 曲心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,unsigned long CurveColor // 画线颜色 - ,uint16_t Dir // 方向 -) -{ - switch(Dir) - { - case 0: - LT768_DrawLeftDownCurve_Fill(XCenter,YCenter,X_R,Y_R,CurveColor); - break; - - case 1: - LT768_DrawLeftUpCurve_Fill(XCenter,YCenter,X_R,Y_R,CurveColor); - break; - - case 2: - LT768_DrawRightUpCurve_Fill(XCenter,YCenter,X_R,Y_R,CurveColor); - break; - - case 3: - LT768_DrawRightDownCurve_Fill(XCenter,YCenter,X_R,Y_R,CurveColor); - break; - - default: - break; - } -} - - - -//------------------------------------- 四边形 ----------------------------------------- - -void LT768_DrawQuadrilateral -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X3 // X3位置 - ,uint16_t Y3 // Y3位置 - ,uint16_t X4 // X4位置 - ,uint16_t Y4 // Y4位置 - ,unsigned long ForegroundColor // 画线颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Triangle_Point1_XY(X1,Y1); - Triangle_Point2_XY(X2,Y2); - Triangle_Point3_XY(X3,Y3); - Ellipse_Radius_RxRy(X4,Y4); - LCD_CmdWrite(0x67); - LCD_DataWrite(0x8d); - Check_Busy_Draw(); - Check_2D_Busy(); -} - - -void LT768_DrawQuadrilateral_Fill -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X3 // X3位置 - ,uint16_t Y3 // Y3位置 - ,uint16_t X4 // X4位置 - ,uint16_t Y4 // Y4位置 - ,unsigned long ForegroundColor // 画线颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Triangle_Point1_XY(X1,Y1); - Triangle_Point2_XY(X2,Y2); - Triangle_Point3_XY(X3,Y3); - Ellipse_Radius_RxRy(X4,Y4); - LCD_CmdWrite(0x67); - LCD_DataWrite(0xa7); - Check_Busy_Draw(); - Check_2D_Busy(); -} - - - -//------------------------------------- 五边形 ----------------------------------------- - -void LT768_DrawPentagon -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X3 // X3位置 - ,uint16_t Y3 // Y3位置 - ,uint16_t X4 // X4位置 - ,uint16_t Y4 // Y4位置 - ,uint16_t X5 // X5位置 - ,uint16_t Y5 // Y5位置 - ,unsigned long ForegroundColor // 画线颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Triangle_Point1_XY(X1,Y1); - Triangle_Point2_XY(X2,Y2); - Triangle_Point3_XY(X3,Y3); - Ellipse_Radius_RxRy(X4,Y4); - Ellipse_Center_XY(X5,Y5); - LCD_CmdWrite(0x67); - LCD_DataWrite(0x8F); - Check_Busy_Draw(); - Check_2D_Busy(); -} - - -void LT768_DrawPentagon_Fill -( - uint16_t X1 // X1位置 - ,uint16_t Y1 // Y1位置 - ,uint16_t X2 // X2位置 - ,uint16_t Y2 // Y2位置 - ,uint16_t X3 // X3位置 - ,uint16_t Y3 // Y3位置 - ,uint16_t X4 // X4位置 - ,uint16_t Y4 // Y4位置 - ,uint16_t X5 // X5位置 - ,uint16_t Y5 // Y5位置 - ,unsigned long ForegroundColor // 画线颜色 -) -{ - Foreground_color_65k(ForegroundColor); - Triangle_Point1_XY(X1,Y1); - Triangle_Point2_XY(X2,Y2); - Triangle_Point3_XY(X3,Y3); - Ellipse_Radius_RxRy(X4,Y4); - Ellipse_Center_XY(X5,Y5); - LCD_CmdWrite(0x67); - LCD_DataWrite(0xa9); - Check_Busy_Draw(); - Check_2D_Busy(); -} - - -//------------------------------------- 圆柱 ----------------------------------------- -uint8_t LT768_DrawCylinder -( - uint16_t XCenter // 椭圆心X位置 - ,uint16_t YCenter // 椭圆心Y位置 - ,uint16_t X_R // 宽半径 - ,uint16_t Y_R // 长半径 - ,uint16_t H // 高度 - ,unsigned long CylinderColor // 画线颜色 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - if(YCenter < H) - { - return 1; - } - - //底面椭圆 - LT768_DrawEllipse_Fill(XCenter,YCenter,X_R,Y_R,ForegroundColor); - LT768_DrawEllipse(XCenter,YCenter,X_R,Y_R,CylinderColor); - //中间矩形 - LT768_DrawSquare_Fill(XCenter-X_R,YCenter-H,XCenter+X_R,YCenter,ForegroundColor); - //顶面椭圆 - LT768_DrawEllipse_Fill(XCenter,YCenter-H,X_R,Y_R,ForegroundColor); - LT768_DrawEllipse(XCenter,YCenter-H,X_R,Y_R,CylinderColor); - LT768_DrawLine(XCenter-X_R,YCenter,XCenter-X_R,YCenter-H,CylinderColor); - LT768_DrawLine(XCenter+X_R,YCenter,XCenter+X_R,YCenter-H,CylinderColor); - return 0; -} - - -//------------------------------------- 四棱柱 ----------------------------------------- -void LT768_DrawQuadrangular -( - uint16_t X1 - ,uint16_t Y1 - ,uint16_t X2 - ,uint16_t Y2 - ,uint16_t X3 - ,uint16_t Y3 - ,uint16_t X4 - ,uint16_t Y4 - ,uint16_t X5 - ,uint16_t Y5 - ,uint16_t X6 - ,uint16_t Y6 - ,unsigned long QuadrangularColor // 画线颜色 - ,unsigned long ForegroundColor // 背景颜色 -) -{ - LT768_DrawSquare_Fill(X1,Y1,X5,Y5,ForegroundColor); - LT768_DrawSquare(X1,Y1,X5,Y5,QuadrangularColor); - LT768_DrawQuadrilateral_Fill(X1,Y1,X2,Y2,X3,Y3,X4,Y4,ForegroundColor); - LT768_DrawQuadrilateral(X1,Y1,X2,Y2,X3,Y3,X4,Y4,QuadrangularColor); - LT768_DrawQuadrilateral_Fill(X3,Y3,X4,Y4,X5,Y5,X6,Y6,ForegroundColor); - LT768_DrawQuadrilateral(X3,Y3,X4,Y4,X5,Y5,X6,Y6,QuadrangularColor); -} - - -//--------------------------------------表格------------------------------------ -void LT768_MakeTable -( - uint16_t X1, // 起始位置X1 - uint16_t Y1, // 起始位置X2 - uint16_t W, // 宽度 - uint16_t H, // 高度 - uint16_t Line, // 行数 - uint16_t Row, // 列数 - unsigned long TableColor, // 线框颜色C1 - unsigned long ItemColor, // 项目拦背景色C2 - unsigned long ForegroundColor, // 内部窗口背景色C3 - uint16_t width1, // 内框宽度 - uint16_t width2, // 外框宽度 - uint8_t mode // 0:项目栏纵向 1:项目栏横向 -) -{ - uint16_t i = 0; - uint16_t x2,y2; - x2 = X1 + W * Row; - y2 = Y1 + H * Line; - LT768_DrawSquare_Width(X1,Y1,x2,y2,TableColor,ForegroundColor,width2); - - if(mode == 0) - { - LT768_DrawSquare_Fill(X1,Y1,X1+W,y2,ItemColor); - } - else if(mode == 1) - { - LT768_DrawSquare_Fill(X1,Y1,x2,Y1+H,ItemColor); - } - - for(i = 0 ; i < Line ; i++) - { - LT768_DrawLine_Width(X1,Y1+i*H,x2,Y1+i*H,TableColor,width1); - } - - for(i = 0 ; i < Row ; i++) - { - LT768_DrawLine_Width(X1+i*W,Y1,X1+i*W,y2,TableColor,width1); - } -} - -/*----------------------------------------------------------------------------*/ - -void LT768_Color_Bar_ON(void) -{ - Color_Bar_ON(); -} - -void LT768_Color_Bar_OFF(void) -{ - Color_Bar_OFF(); -} - -/*----------------------------------------------------------------------------*/ - -/*--Flash-->DMA-->SDRAM--*/ -/*address:24bit or 32bit*/ - -void LT768_DMA_24bit_Linear -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long flash_addr // 要从flash读取数据的起始地址 - ,unsigned long memory_addr // 数据要传输到SDRAM的起始地址 - ,unsigned long data_num // 传输的数据量 -) -{ - Enable_SFlash_SPI(); // 使能SPI功能 - - if(SCS == 0) - { - Select_SFI_0(); // 选择外挂的SPI0 - } - - if(SCS == 1) - { - Select_SFI_1(); // 选择外挂的SPI1 - } - - Memory_Linear_Mode(); - Select_SFI_DMA_Mode(); // 设置SPI的DMA模式 - SPI_Clock_Period(Clk); // SPI速率 - SFI_DMA_Destination_Start_Address(memory_addr); // 指定的内存的开始地址 - SFI_DMA_Transfer_Number(data_num); // DMA传输的数量 - SFI_DMA_Source_Start_Address(flash_addr); // flash地址 - Check_Busy_SFI_DMA(); - Start_SFI_DMA(); - Check_Busy_SFI_DMA(); - Memory_XY_Mode(); -} - -void LT768_DMA_32bit_Linear -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long flash_addr // 要从flash读取数据的起始地址 - ,unsigned long memory_addr // 数据要传输到SDRAM的起始地址 - ,unsigned long data_num // 传输的数据量 -) -{ - Enable_SFlash_SPI(); // 使能SPI功能 - - if(SCS == 0) - { - Select_SFI_0(); // 选择外挂的SPI0 - } - - if(SCS == 1) - { - Select_SFI_1(); // 选择外挂的SPI1 - } - - Memory_Linear_Mode(); - Select_SFI_DMA_Mode(); // 设置SPI的DMA模式 - Select_SFI_32bit_Address(); - SPI_Clock_Period(Clk); // SPI速率 - SFI_DMA_Destination_Start_Address(memory_addr); // 指定的内存的开始地址 - SFI_DMA_Transfer_Number(data_num); // DMA传输的数量 - SFI_DMA_Source_Start_Address(flash_addr); // flash地址 - Check_Busy_SFI_DMA(); - Start_SFI_DMA(); - Check_Busy_SFI_DMA(); - Memory_XY_Mode(); -} - -void LT768_DMA_24bit_Block -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,uint16_t X1 // 传输到内存X1的位置 - ,uint16_t Y1 // 传输到内存Y1的位置 - ,uint16_t X_W // DMA传输数据的宽度 - ,uint16_t Y_H // DMA传输数据的高度 - ,uint16_t P_W // 图片的宽度 - ,unsigned long Addr // Flash的地址 -) -{ - Enable_SFlash_SPI(); // 使能SPI功能 - - if(SCS == 0) - { - Select_SFI_0(); // 选择外挂的SPI0 - } - - if(SCS == 1) - { - Select_SFI_1(); // 选择外挂的SPI1 - } - - Select_SFI_DMA_Mode(); // 设置SPI的DMA模式 - SPI_Clock_Period(Clk); // 设置SPI的分频系数 - Goto_Pixel_XY(X1,Y1); // 在图形模式中设置内存的位置 - SFI_DMA_Destination_Upper_Left_Corner(X1,Y1); // DMA传输的目的地(内存的位置) - SFI_DMA_Transfer_Width_Height(X_W,Y_H); // 设置块数据的宽度和高度 - SFI_DMA_Source_Width(P_W); // 设置源数据的宽度 - SFI_DMA_Source_Start_Address(Addr); // 设置源数据在Flash的地址 - Start_SFI_DMA(); // 开始DMA传输 - Check_Busy_SFI_DMA(); // 检测DMA是否传输完成 -} - - - -void LT768_DMA_32bit_Block -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,uint16_t X1 // 内存X1的位置 - ,uint16_t Y1 // 内存Y1的位置 - ,uint16_t X_W // DMA传输数据的宽度 - ,uint16_t Y_H // DMA传输数据的高度 - ,uint16_t P_W // 图片的宽度 - ,unsigned long Addr // Flash的地址 -) -{ - Enable_SFlash_SPI(); - - if(SCS == 0) - { - Select_SFI_0(); - } - - if(SCS == 1) - { - Select_SFI_1(); - } - - Select_SFI_DMA_Mode(); - SPI_Clock_Period(Clk); - Select_SFI_32bit_Address(); - Goto_Pixel_XY(X1,Y1); - SFI_DMA_Destination_Upper_Left_Corner(X1,Y1); - SFI_DMA_Transfer_Width_Height(X_W,Y_H); - SFI_DMA_Source_Width(P_W); - SFI_DMA_Source_Start_Address(Addr); - Start_SFI_DMA(); - Check_Busy_SFI_DMA(); - Select_SFI_24bit_Address(); -} - -/*----------------------------------------------------------------------------*/ -/* 选择内部集成字库初始化 */ -void LT768_Select_Internal_Font_Init -( - uint8_t Size // 设置字体大小 16:16*16 24:24*24 32:32*32 - ,uint8_t XxN // 字体的宽度放大倍数:1~4 - ,uint8_t YxN // 字体的高度放大倍数:1~4 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint8_t Alignment // 0:不字体不对齐 1:字体对齐 -) -{ - if(Size==16) - { - Font_Select_8x16_16x16(); - } - - if(Size==24) - { - Font_Select_12x24_24x24(); - } - - if(Size==32) - { - Font_Select_16x32_32x32(); - } - - //(*) - if(XxN==1) - { - Font_Width_X1(); - } - - if(XxN==2) - { - Font_Width_X2(); - } - - if(XxN==3) - { - Font_Width_X3(); - } - - if(XxN==4) - { - Font_Width_X4(); - } - - //(*) - if(YxN==1) - { - Font_Height_X1(); - } - - if(YxN==2) - { - Font_Height_X2(); - } - - if(YxN==3) - { - Font_Height_X3(); - } - - if(YxN==4) - { - Font_Height_X4(); - } - - //(*) - if(ChromaKey==0) - { - Font_Background_select_Color(); - } - - if(ChromaKey==1) - { - Font_Background_select_Transparency(); - } - - //(*) - if(Alignment==0) - { - Disable_Font_Alignment(); - } - - if(Alignment==1) - { - Enable_Font_Alignment(); - } -} - - -/* 显示内部集成字体 */ -void LT768_Print_Internal_Font_String -( - uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,char *c // 数据缓冲的首地址 -) -{ - Text_Mode(); - CGROM_Select_Internal_CGROM(); - Foreground_color_65k(FontColor); - Background_color_65k(BackGroundColor); - Goto_Text_XY(x,y); - Show_String(c); -} - - -/* 选择外部集成字库初始化 */ -void LT768_Select_Outside_Font_Init -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long FlashAddr // 源地址(Flash) - ,unsigned long MemoryAddr // 目的地址(SDRAM) - ,unsigned long Num // 字库的数据量大小 - ,uint8_t Size // 设置字体大小 16:16*16 24:24*24 32:32*32 - ,uint8_t XxN // 字体的宽度放大倍数:1~4 - ,uint8_t YxN // 字体的高度放大倍数:1~4 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint8_t Alignment // 0:不字体不对齐 1:字体对齐 -) -{ - if(Size==16) - { - Font_Select_8x16_16x16(); - } - - if(Size==24) - { - Font_Select_12x24_24x24(); - } - - if(Size==32) - { - Font_Select_16x32_32x32(); - } - - //(*) - if(XxN==1) - { - Font_Width_X1(); - } - - if(XxN==2) - { - Font_Width_X2(); - } - - if(XxN==3) - { - Font_Width_X3(); - } - - if(XxN==4) - { - Font_Width_X4(); - } - - //(*) - if(YxN==1) - { - Font_Height_X1(); - } - - if(YxN==2) - { - Font_Height_X2(); - } - - if(YxN==3) - { - Font_Height_X3(); - } - - if(YxN==4) - { - Font_Height_X4(); - } - - //(*) - if(ChromaKey==0) - { - Font_Background_select_Color(); - } - - if(ChromaKey==1) - { - Font_Background_select_Transparency(); - } - - //(*) - if(Alignment==0) - { - Disable_Font_Alignment(); - } - - if(Alignment==1) - { - Enable_Font_Alignment(); - } - - LT768_DMA_24bit_Linear(SCS,Clk,FlashAddr,MemoryAddr,Num); - CGRAM_Start_address(MemoryAddr); -} - -/* 显示外部及内部集成字体 */ -void LT768_Print_Outside_Font_String -( - uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint8_t *c // 数据缓冲的首地址 -) -{ - uint16_t temp_H = 0; - uint16_t temp_L = 0; - uint16_t temp = 0; - unsigned long i = 0; - Text_Mode(); - Font_Select_UserDefine_Mode(); - Foreground_color_65k(FontColor); - Background_color_65k(BackGroundColor); - Goto_Text_XY(x,y); - - while(c[i] != '\0') - { - if(c[i] < 0xa1) - { - CGROM_Select_Internal_CGROM(); // 内部CGROM为字符来源 - LCD_CmdWrite(0x04); - LCD_DataWrite(c[i]); - Check_Mem_WR_FIFO_not_Full(); - i += 1; - } - else - { - Font_Select_UserDefine_Mode(); // 自定义字库 - LCD_CmdWrite(0x04); - temp_H = ((c[i] - 0xa1) & 0x00ff) * 94; - temp_L = c[i+1] - 0xa1; - temp = temp_H + temp_L + 0x8000; - LCD_DataWrite((temp>>8)&0xff); - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite(temp&0xff); - Check_Mem_WR_FIFO_not_Full(); - i += 2; - } - } - - Check_2D_Busy(); - Graphic_Mode(); //back to graphic mode;图形模式 -} - -/* 显示外部GBK及内部集成字体 */ -void LT768_Print_Outside_Font_GBK_String -( - uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint8_t *c // 数据缓冲的首地址 -) -{ - uint16_t temp_H = 0; - uint16_t temp_L = 0; - uint16_t temp = 0; - unsigned long i = 0; - Text_Mode(); - Font_Select_UserDefine_Mode(); - Foreground_color_65k(FontColor); - Background_color_65k(BackGroundColor); - Goto_Text_XY(x,y); - - while(c[i] != '\0') - { - if(c[i] < 0x81) - { - CGROM_Select_Internal_CGROM(); // 内部CGROM为字符来源 - LCD_CmdWrite(0x04); - LCD_DataWrite(c[i]); - Check_Mem_WR_FIFO_not_Full(); - i += 1; - } - else - { - Font_Select_UserDefine_Mode(); // 自定义字库 - LCD_CmdWrite(0x04); - temp_H = ((c[i] - 0x81) & 0x00ff) * 191; - temp_L = c[i+1] - 0x40; - temp = temp_H + temp_L + 0x8000; - LCD_DataWrite((temp>>8)&0xff); - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite(temp&0xff); - Check_Mem_WR_FIFO_not_Full(); - i += 2; - } - } - - Check_2D_Busy(); - Graphic_Mode(); //back to graphic mode;图形模式 -} - -/*显示48*48、72*72字库*/ -void LT768_BTE_Memory_Copy_ColorExpansion_8 -( - unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标(显示窗口的起始x坐标) - ,uint16_t YDes // 目的图像的左上方Y坐标(显示窗口的起始y坐标) - ,uint16_t X_W // 显示窗口的宽度 - ,uint16_t Y_H // 显示窗口的长度 - ,unsigned long Foreground_color - ,unsigned long Background_color -) -{ - Foreground_color_256(Foreground_color); - Background_color_256(Background_color); - BTE_ROP_Code(7); - BTE_S0_Color_8bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(Des_W); - BTE_S0_Window_Start_XY(YS0,0); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Operation_Code(0x0e); //BTE Operation: Memory copy (move) with chroma keying (w/o ROP) - BTE_Window_Size(X_W,Y_H); - BTE_Enable(); - Check_BTE_Busy(); -} - -void LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8 -( - unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标(显示窗口的起始x坐标) - ,uint16_t YDes // 目的图像的左上方Y坐标(显示窗口的起始y坐标) - ,uint16_t X_W // 显示窗口的宽度 - ,uint16_t Y_H // 显示窗口的长度 - ,unsigned long Foreground_color -) -{ - Foreground_color_256(Foreground_color); - BTE_ROP_Code(7); - BTE_S0_Color_8bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(Des_W); - BTE_S0_Window_Start_XY(YS0,0); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Operation_Code(0x0f); //BTE Operation: Memory copy (move) with chroma keying (w/o ROP) - BTE_Window_Size(X_W,Y_H); - BTE_Enable(); - Check_BTE_Busy(); -} - -void LT768_Print_Outside_Font_GB2312_48_72 -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long FlashAddr // 字库源地址(Flash) - ,unsigned long MemoryAddr // 目的地址(SDRAM) - ,unsigned long ShowAddr // 显示层的地址 - ,uint16_t width // 显示层的宽度 - ,uint8_t Size // 设置字体大小 48:48*48 72:72*72 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint16_t w // 字体粗细:0:不加粗 1:加粗1级 2:加粗2级 - ,uint16_t s // 行距 - ,uint8_t *c // 数据缓冲的首地址 -) -{ - uint16_t temp_H = 0; - uint16_t temp_L = 0; - uint16_t temp = 0; - unsigned long i = 0; - uint16_t j = 0; - uint16_t k = 0; - uint16_t h = 0; - uint16_t n = 0; - uint16_t m = 0; - uint16_t g = 0; - uint16_t f = 0; - h = x; - k = y; - Memory_8bpp_Mode();//使用8位色深来存储图片 - Canvas_Image_Start_address(MemoryAddr); - Canvas_image_width(width); - - while(c[i] != '\0') - { - temp_H = (c[i] - 0xa1) * 94; - temp_L = c[i+1] - 0xa1; - temp = temp_H + temp_L; - LT768_DMA_24bit_Block(SCS,Clk,Size*j/8,0,Size/8,Size,Size/8,FlashAddr+temp*((Size*Size)/8)); - i+=2; - j++; - } - - Memory_16bpp_Mode(); - Canvas_Image_Start_address(ShowAddr); - Canvas_image_width(width); - j = 0; - i = 0; - - if(w>2) - { - w = 2; - } - - for(g=0; g(width*(n+1)))) - { - m++; - n++; - y=y+Size-1+s; - x = x+((width*n)-(x+Size*j))+g; - f=n; - } - - if(ChromaKey==1) - { - LT768_BTE_Memory_Copy_ColorExpansion_8(MemoryAddr,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor,BackGroundColor - ); - } - - if(ChromaKey==0) - { - LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(MemoryAddr,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor - ); - } - - i+=2; - j++; - } - - ChromaKey=0; - i=0; - j=0; - m=0; - n=0; - f=0; - x=h+g+1; - y=k+g+1; - } -} - - -void LT768_Print_Outside_Font_BIG5_48_72 -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long FlashAddr // 字库源地址(Flash) - ,unsigned long MemoryAddr // 目的地址(SDRAM) - ,unsigned long ShowAddr // 显示层的地址 - ,uint16_t width // 显示层的宽度 - ,uint8_t Size // 设置字体大小 48:48*48 72:72*72 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint16_t w // 字体粗细:0:不加粗 1:加粗1级 2:加粗2级 - ,uint16_t s // 行距 - ,uint8_t *c // 数据缓冲的首地址 -) -{ - uint16_t temp_H = 0; - uint16_t temp_L = 0; - uint16_t temp = 0; - unsigned long i = 0; - uint16_t j = 0; - uint16_t k = 0; - uint16_t h = 0; - uint16_t n = 0; - uint16_t m = 0; - uint16_t g = 0; - uint16_t f = 0; - h = x; - k = y; - Memory_8bpp_Mode();//使用8位色深来存储图片 - Canvas_Image_Start_address(MemoryAddr); - Canvas_image_width(width); - - while(c[i] != '\0') - { - temp_H = (c[i] - 0xa1) * 160; - - if(c[i+1]<0x7f) - { - temp_L = c[i+1] - 0x40; - } - else - { - temp_L = c[i+1] - 0xa0 + 0x40; - } - - temp = temp_H + temp_L; - LT768_DMA_24bit_Block(SCS,Clk,Size*j/8,0,Size/8,Size,Size/8,FlashAddr+temp*((Size*Size)/8)); - i+=2; - j++; - } - - Memory_16bpp_Mode(); // 因为显示是16位的色深,所以需要转为16位色深 - Canvas_Image_Start_address(ShowAddr); - Canvas_image_width(width); - j = 0; - i = 0; - - for(g=0; g(1024*(n+1)))) - { - m++; - n++; - y=y+Size-1+s; - x = x+((1024*n)-(x+Size*j))+g; - f=n; - } - - if(ChromaKey==1) - { - LT768_BTE_Memory_Copy_ColorExpansion_8(MemoryAddr,Size*j/8, - ShowAddr,LCD_XSIZE_TFT,x+Size*j,y, - Size,Size,FontColor,BackGroundColor - ); - } - - if(ChromaKey==0) - { - LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(MemoryAddr,Size*j/8, - ShowAddr,LCD_XSIZE_TFT,x+Size*j,y, - Size,Size,FontColor - ); - } - - i+=2; - j++; - } - - ChromaKey=0; - i=0; - j=0; - m=0; - n=0; - f=0; - x=h+g+1; - y=k+g+1; - } -} - -void LT768_Print_Outside_Font_GBK_48_72 -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long FlashAddr // 字库源地址(Flash) - ,unsigned long MemoryAddr // 目的地址(SDRAM) - ,unsigned long ShowAddr // 显示层的地址 - ,uint16_t width // 显示层的宽度 - ,uint8_t Size // 设置字体大小 48:48*48 72:72*72 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint16_t w // 字体粗细:0:不加粗 1:加粗1级 2:加粗2级 - ,uint16_t s // 行距 - ,uint8_t *c // 数据缓冲的首地址 -) -{ - uint16_t temp_H = 0; - uint16_t temp_L = 0; - uint16_t temp = 0; - unsigned long i = 0; - uint16_t j = 0; - uint16_t k = 0; - uint16_t h = 0; - uint16_t n = 0; - uint16_t m = 0; - uint16_t g = 0; - uint16_t f = 0; - h = x; - k = y; - Memory_8bpp_Mode();//使用8位色深来存储图片 - Canvas_Image_Start_address(MemoryAddr); - Canvas_image_width(width); - - while(c[i] != '\0') - { - temp_H = (c[i] - 0x81) * 191; - temp_L = c[i+1] - 0x40; - temp = temp_H + temp_L; - LT768_DMA_24bit_Block(SCS,Clk,Size*j/8,0,Size/8,Size,Size/8,FlashAddr+temp*((Size*Size)/8)); - i+=2; - j++; - } - - Memory_16bpp_Mode(); - Canvas_Image_Start_address(ShowAddr); - Canvas_image_width(width); - j = 0; - i = 0; - - if(w>2) - { - w = 2; - } - - for(g=0; g(width*(n+1)))) - { - m++; - n++; - y=y+Size-1+s; - x = x+((width*n)-(x+Size*j))+g; - f=n; - } - - if(ChromaKey==1) - { - LT768_BTE_Memory_Copy_ColorExpansion_8(MemoryAddr,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor,BackGroundColor - ); - } - - if(ChromaKey==0) - { - LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(MemoryAddr,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor - ); - } - - i+=2; - j++; - } - - ChromaKey=0; - i=0; - j=0; - m=0; - n=0; - f=0; - x=h+g+1; - y=k+g+1; - } -} - -/*自定义字库*/ -//只能输入中文字 -#define Font_size 200//定义字库大小,200:最多200个字 -#define Font_BYTE Font_size*2 -uint8_t Font_1[Font_BYTE]; - -void clear_Font_1(void) -{ - uint16_t i; - - for(i = 0; i < Font_BYTE; i++) - { - Font_1[i] = 0; - } -} - -int Get_User_Font_P(char chH,char chL) -{ - int i; - - for(i=0; i<(sizeof(Font_1)/2); i++) - { - if((chH == Font_1[i*2])&&(chL == Font_1[i*2+1])) - { - return i; - } - } - - return -1; -} - -void LT768_Print_Outside_UserDefineFont_GB2312 -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long FlashAddr // 字库源地址(Flash) - ,unsigned long MemoryAddr // 目的地址(SDRAM) - ,unsigned long ShowAddr // 显示层的地址 - ,uint16_t width // 显示层的宽度 - ,uint8_t Size // 设置字体大小 48:48*48 72:72*72 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint16_t w // 字体粗细:0:不加粗 1:加粗1级 2:加粗2级 - ,uint16_t s // 行距 - ,uint8_t *c // 数据缓冲的首地址 -) -{ - short temp = 0; - unsigned long i = 0; - uint16_t j = 0; - uint16_t k = 0; - uint16_t h = 0; - uint16_t n = 0; - uint16_t m = 0; - uint16_t g = 0; - uint16_t f = 0; - uint8_t temp1[2] = {0}; - uint32_t fontNum = 0; - clear_Font_1(); - LT768_SPI_Init(SCS,1); - LT_W25QXX_Read(temp1,FlashAddr+8,2); - fontNum = (temp1[0]<<8)+temp1[1]; - LT_W25QXX_Read(Font_1,FlashAddr + 0xc,fontNum * 2); - h = x; - k = y; - Memory_8bpp_Mode();//使用8位色深来存储图片 - Canvas_Image_Start_address(MemoryAddr); - Canvas_image_width(width); - - while(c[i] != '\0') - { - temp = Get_User_Font_P(c[i],c[i+1]); - - if(temp>-1) - { - LT768_DMA_24bit_Block(SCS,Clk,Size*j/8,0,Size/8,Size,Size/8,FlashAddr+temp*((Size*Size)/8)+0x0c+fontNum*2); - } - - i+=2; - j++; - } - - Memory_16bpp_Mode(); - Canvas_Image_Start_address(ShowAddr); - Canvas_image_width(width); - j = 0; - i = 0; - - if(w>2) - { - w = 2; - } - - for(g=0; g(width*(n+1)))) - { - m++; - n++; - y=y+Size-1+s; - x = x+((width*n)-(x+Size*j))+g; - f=n; - } - - if(ChromaKey==1) - { - LT768_BTE_Memory_Copy_ColorExpansion_8(MemoryAddr,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor,BackGroundColor - ); - } - - if(ChromaKey==0) - { - LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(MemoryAddr,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor - ); - } - - i+=2; - j++; - } - - ChromaKey=0; - i=0; - j=0; - m=0; - n=0; - f=0; - x=h+g+1; - y=k+g+1; - } -} - -/*----------------------------------------------------------------------------*/ - -void LT768_Text_cursor_Init -( - uint8_t On_Off_Blinking // 0:禁止光标闪烁 1:使能光标闪烁 - ,uint16_t Blinking_Time // 设置文字光标闪烁时间 - ,uint16_t X_W // 文字光标水平大小 - ,uint16_t Y_W // 文字光标垂直大小 -) -{ - if(On_Off_Blinking == 0) - { - Disable_Text_Cursor_Blinking(); - } - - if(On_Off_Blinking == 1) - { - Enable_Text_Cursor_Blinking(); - } - - Blinking_Time_Frames(Blinking_Time); - //[3E][3Fh] - Text_Cursor_H_V(X_W,Y_W); - Enable_Text_Cursor(); -} - - -void LT768_Enable_Text_Cursor(void) -{ - Enable_Text_Cursor(); -} - - -void LT768_Disable_Text_Cursor(void) -{ - Disable_Text_Cursor(); -} - - -void LT768_Graphic_cursor_Init -( - uint8_t Cursor_N // 选择光标 1:光标1 2:光标2 3:光标3 4:光标4 - ,uint8_t Color1 // 颜色1 - ,uint8_t Color2 // 颜色2 - ,uint16_t X_Pos // 显示坐标X - ,uint16_t Y_Pos // 显示坐标Y - ,uint8_t *Cursor_Buf // 光标数据的缓冲首地址 -) -{ - uint32_t i ; - Memory_Select_Graphic_Cursor_RAM(); - Graphic_Mode(); - - switch(Cursor_N) - { - case 1: - Select_Graphic_Cursor_1(); - break; - - case 2: - Select_Graphic_Cursor_2(); - break; - - case 3: - Select_Graphic_Cursor_3(); - break; - - case 4: - Select_Graphic_Cursor_4(); - break; - - default: - break; - } - - LCD_CmdWrite(0x04); - - for(i=0; i<256; i++) - { - LCD_DataWrite(Cursor_Buf[i]); - } - - Memory_Select_SDRAM();//写完后切回SDRAM - Set_Graphic_Cursor_Color_1(Color1); - Set_Graphic_Cursor_Color_2(Color2); - Graphic_Cursor_XY(X_Pos,Y_Pos); - Enable_Graphic_Cursor(); -} - - -void LT768_Set_Graphic_cursor_Pos -( - uint8_t Cursor_N // 选择光标 1:光标1 2:光标2 3:光标3 4:光标4 - ,uint16_t X_Pos // 显示坐标X - ,uint16_t Y_Pos // 显示坐标Y -) -{ - Graphic_Cursor_XY(X_Pos,Y_Pos); - - switch(Cursor_N) - { - case 1: - Select_Graphic_Cursor_1(); - break; - - case 2: - Select_Graphic_Cursor_2(); - break; - - case 3: - Select_Graphic_Cursor_3(); - break; - - case 4: - Select_Graphic_Cursor_4(); - break; - - default: - break; - } -} - - -void LT768_Enable_Graphic_Cursor(void) -{ - Enable_Graphic_Cursor(); -} - - -void LT768_Disable_Graphic_Cursor(void) -{ - Disable_Graphic_Cursor(); -} - -/*----------------------------------------------------------------------------*/ - -void LT768_PIP_Init -( - uint8_t On_Off // 0 : 禁止 PIP 1 : 使能 PIP 2 : 保持原来的状态 - ,uint8_t Select_PIP // 1 : 使用 PIP1 2 : 使用 PIP2 - ,unsigned long PAddr // PIP的开始地址 - ,uint16_t XP // PIP窗口的X坐标,必须被4整除 - ,uint16_t YP // PIP窗口的Y坐标,必须被4整除 - ,unsigned long ImageWidth // 底图的宽度 - ,uint16_t X_Dis // 显示窗口的X坐标 - ,uint16_t Y_Dis // 显示窗口的Y坐标 - ,uint16_t X_W // 显示窗口的宽度,必须被4整除 - ,uint16_t Y_H // 显示窗口的长度,必须被4整除 -) -{ - if(Select_PIP == 1) - { - Select_PIP1_Window_16bpp(); - Select_PIP1_Parameter(); - } - - if(Select_PIP == 2) - { - Select_PIP2_Window_16bpp(); - Select_PIP2_Parameter(); - } - - PIP_Display_Start_XY(X_Dis,Y_Dis); - PIP_Image_Start_Address(PAddr); - PIP_Image_Width(ImageWidth); - PIP_Window_Image_Start_XY(XP,YP); - PIP_Window_Width_Height(X_W,Y_H); - - if(On_Off == 0) - { - if(Select_PIP == 1) - { - Disable_PIP1(); - } - - if(Select_PIP == 2) - { - Disable_PIP2(); - } - } - - if(On_Off == 1) - { - if(Select_PIP == 1) - { - Enable_PIP1(); - } - - if(Select_PIP == 2) - { - Enable_PIP2(); - } - } -} - - -void LT768_Set_DisWindowPos -( - uint8_t On_Off // 0 : 禁止 PIP, 1 : 使能 PIP, 2 : 保持原来的状态 - ,uint8_t Select_PIP // 1 : 使用 PIP1 , 2 : 使用 PIP2 - ,uint16_t X_Dis // 显示窗口的X坐标 - ,uint16_t Y_Dis // 显示窗口的Y坐标 -) -{ - if(Select_PIP == 1) - { - Select_PIP1_Parameter(); - } - - if(Select_PIP == 2) - { - Select_PIP2_Parameter(); - } - - if(On_Off == 0) - { - if(Select_PIP == 1) - { - Disable_PIP1(); - } - - if(Select_PIP == 2) - { - Disable_PIP2(); - } - } - - if(On_Off == 1) - { - if(Select_PIP == 1) - { - Enable_PIP1(); - } - - if(Select_PIP == 2) - { - Enable_PIP2(); - } - } - - PIP_Display_Start_XY(X_Dis,Y_Dis); -} - -/*----------------------------------------------------------------------------*/ - -void BTE_Solid_Fill -( - unsigned long Des_Addr // 填充的目的地址 - ,uint16_t Des_W // 目的地址图片宽度 - ,uint16_t XDes // x坐标 - ,uint16_t YDes // y坐标 - ,uint16_t color // 填充的颜色 - ,uint16_t X_W // 填充的长度 - ,uint16_t Y_H // 填充的宽度 -) -{ - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Window_Size(X_W,Y_H); - Foreground_color_65k(color); - BTE_Operation_Code(0x0c); - BTE_Enable(); - Check_BTE_Busy(); -} - -/* 结合光栅操作的BTE内存复制 */ -void LT768_BTE_Memory_Copy -( - unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t S0_W // S0图像的宽度 - ,uint16_t XS0 // S0图像的左上方X坐标 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long S1_Addr // S1图像的内存起始地址 - ,uint16_t S1_W // S1图像的宽度 - ,uint16_t XS1 // S1图像的左上方X坐标 - ,uint16_t YS1 // S1图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方Y坐标 - ,uint32_t ROP_Code // 光栅操作模式 - /*ROP_Code : - 0000b 0(Blackness) - 0001b ~S0!E~S1 or ~(S0+S1) - 0010b ~S0!ES1 - 0011b ~S0 - 0100b S0!E~S1 - 0101b ~S1 - 0110b S0^S1 - 0111b ~S0 + ~S1 or ~(S0 + S1) - 1000b S0!ES1 - 1001b ~(S0^S1) - 1010b S1 - 1011b ~S0+S1 - 1100b S0 - 1101b S0+~S1 - 1110b S0+S1 - 1111b 1(whiteness)*/ - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 -) -{ - BTE_S0_Color_16bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(S0_W); - BTE_S0_Window_Start_XY(XS0,YS0); - BTE_S1_Color_16bpp(); - BTE_S1_Memory_Start_Address(S1_Addr); - BTE_S1_Image_Width(S1_W); - BTE_S1_Window_Start_XY(XS1,YS1); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_ROP_Code(ROP_Code); - BTE_Operation_Code(0x02); //BTE Operation: Memory copy (move) with ROP. - BTE_Window_Size(X_W,Y_H); - BTE_Enable(); - Check_BTE_Busy(); -} - - -/* 结合 Chroma Key 的内存复制(不含 ROP) */ -void LT768_BTE_Memory_Copy_Chroma_key -( - unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t S0_W // S0图像的宽度 - ,uint16_t XS0 // S0图像的左上方X坐标 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方X坐标 - ,unsigned long Background_color // 透明色 - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 -) -{ - Background_color_65k(Background_color); - BTE_S0_Color_16bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(S0_W); - BTE_S0_Window_Start_XY(XS0,YS0); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Operation_Code(0x05); //BTE Operation: Memory copy (move) with chroma keying (w/o ROP) - BTE_Window_Size(X_W,Y_H); - BTE_Enable(); - Check_BTE_Busy(); -} - - -void LT768_BTE_Pattern_Fill -( - uint8_t P_8x8_or_16x16 // 0 : use 8x8 Icon , 1 : use 16x16 Icon. - ,unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t S0_W // S0图像的宽度 - ,uint16_t XS0 // S0图像的左上方X坐标 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - , uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方X坐标 - ,uint32_t ROP_Code // 光栅操作模式 - /*ROP_Code : - 0000b 0(Blackness) - 0001b ~S0!E~S1 or ~(S0+S1) - 0010b ~S0!ES1 - 0011b ~S0 - 0100b S0!E~S1 - 0101b ~S1 - 0110b S0^S1 - 0111b ~S0 + ~S1 or ~(S0 + S1) - 1000b S0!ES1 - 1001b ~(S0^S1) - 1010b S1 - 1011b ~S0+S1 - 1100b S0 - 1101b S0+~S1 - 1110b S0+S1 - 1111b 1(whiteness)*/ - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 -) -{ - if(P_8x8_or_16x16 == 0) - { - Pattern_Format_8X8(); - } - - if(P_8x8_or_16x16 == 1) - { - Pattern_Format_16X16(); - } - - BTE_S0_Color_16bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(S0_W); - BTE_S0_Window_Start_XY(XS0,YS0); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_ROP_Code(ROP_Code); - BTE_Operation_Code(0x06); //BTE Operation: Pattern Fill with ROP. - BTE_Window_Size(X_W,Y_H); - BTE_Enable(); - Check_BTE_Busy(); -} - - - -void LT768_BTE_Pattern_Fill_With_Chroma_key -( - uint8_t P_8x8_or_16x16 // 0 : use 8x8 Icon , 1 : use 16x16 Icon. - ,unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t S0_W // S0图像的宽度 - ,uint16_t XS0 // S0图像的左上方X坐标 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方Y坐标 - ,uint32_t ROP_Code // 光栅操作模式 - /*ROP_Code : - 0000b 0(Blackness) - 0001b ~S0!E~S1 or ~(S0+S1) - 0010b ~S0!ES1 - 0011b ~S0 - 0100b S0!E~S1 - 0101b ~S1 - 0110b S0^S1 - 0111b ~S0 + ~S1 or ~(S0 + S1) - 1000b S0!ES1 - 1001b ~(S0^S1) - 1010b S1 - 1011b ~S0+S1 - 1100b S0 - 1101b S0+~S1 - 1110b S0+S1 - 1111b 1(whiteness)*/ - ,unsigned long Background_color // 透明色 - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 -) -{ - Background_color_65k(Background_color); - - if(P_8x8_or_16x16 == 0) - { - Pattern_Format_8X8(); - } - - if(P_8x8_or_16x16 == 1) - { - Pattern_Format_16X16(); - } - - BTE_S0_Color_16bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(S0_W); - BTE_S0_Window_Start_XY(XS0,YS0); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_ROP_Code(ROP_Code); - BTE_Operation_Code(0x07); //BTE Operation: Pattern Fill with Chroma key. - BTE_Window_Size(X_W,Y_H); - BTE_Enable(); - Check_BTE_Busy(); -} - - - -void LT768_BTE_MCU_Write_MCU_16bit -( - unsigned long S1_Addr // S1图像的内存起始地址 - ,uint16_t S1_W // S1图像的宽度 - ,uint16_t XS1 // S1图像的左上方X坐标 - ,uint16_t YS1 // S1图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方Y坐标 - ,uint32_t ROP_Code // 光栅操作模式 - /*ROP_Code : - 0000b 0(Blackness) - 0001b ~S0!E~S1 or ~(S0+S1) - 0010b ~S0!ES1 - 0011b ~S0 - 0100b S0!E~S1 - 0101b ~S1 - 0110b S0^S1 - 0111b ~S0 + ~S1 or ~(S0 + S1) - 1000b S0!ES1 - 1001b ~(S0^S1) - 1010b S1 - 1011b ~S0+S1 - 1100b S0 - 1101b S0+~S1 - 1110b S0+S1 - 1111b 1(whiteness)*/ - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 - ,const uint16_t *data // S0的数据首地址 -) -{ - uint16_t i,j; - BTE_S1_Color_16bpp(); - BTE_S1_Memory_Start_Address(S1_Addr); - BTE_S1_Image_Width(S1_W); - BTE_S1_Window_Start_XY(XS1,YS1); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Window_Size(X_W,Y_H); - BTE_ROP_Code(ROP_Code); - BTE_Operation_Code(0x00); //BTE Operation: MPU Write with ROP. - BTE_Enable(); - BTE_S0_Color_16bpp(); - LCD_CmdWrite(0x04); //Memory Data Read/Write Port - - //MCU_16bit_ColorDepth_16bpp - for(i=0; i< Y_H; i++) - { - for(j=0; j< (X_W); j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite_Pixel((*data)); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); - Check_BTE_Busy(); -} - - - -void LT768_BTE_MCU_Write_Chroma_key_MCU_16bit -( - unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方Y坐标 - ,unsigned long Background_color // 透明色 - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 - ,const uint16_t *data // S0的数据收地址 -) -{ - uint32_t i,j; - Background_color_65k(Background_color); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Window_Size(X_W,Y_H); - BTE_Operation_Code(0x04); //BTE Operation: MPU Write with chroma keying (w/o ROP) - BTE_Enable(); - BTE_S0_Color_16bpp(); - LCD_CmdWrite(0x04); //Memory Data Read/Write Port - - //MCU_16bit_ColorDepth_16bpp - for(i=0; i< Y_H; i++) - { - for(j=0; j< (X_W); j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite_Pixel((*data)); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); - Check_BTE_Busy(); -} - - -/* 结合扩展色彩的 MPU 寫入 */ -void LT768_BTE_MCU_Write_ColorExpansion_MCU_16bit -( - unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方Y坐标 - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 - ,unsigned long Foreground_color // 前景色 - /*Foreground_color : The source (1bit map picture) map data 1 translate to Foreground color by color expansion*/ - ,unsigned long Background_color // 背景色 - /*Background_color : The source (1bit map picture) map data 0 translate to Background color by color expansion*/ - ,const uint16_t *data // 数据缓存首地址 -) -{ - uint16_t i,j; - RGB_16b_16bpp(); - Foreground_color_65k(Foreground_color); - Background_color_65k(Background_color); - BTE_ROP_Code(15); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Window_Size(X_W,Y_H); - BTE_Operation_Code(0x8); //BTE Operation: MPU Write with Color Expansion (w/o ROP) - BTE_Enable(); - LCD_CmdWrite(0x04); //Memory Data Read/Write Port - - for(i=0; i< Y_H; i++) - { - for(j=0; j< X_W/16; j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite_Pixel(*data); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); - Check_BTE_Busy(); -} - -/* 结合扩展色彩与 Chroma key 的 MPU 寫入 */ -void LT768_BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_16bit -( - unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方Y坐标 - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 - ,unsigned long Foreground_color // 前景色 - /*Foreground_color : The source (1bit map picture) map data 1 translate to Foreground color by color expansion*/ - ,const uint16_t *data // 数据缓存首地址 -) -{ - uint16_t i,j; - RGB_16b_16bpp(); - Foreground_color_65k(Foreground_color); - BTE_ROP_Code(15); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Window_Size(X_W,Y_H); - BTE_Operation_Code(0x9); //BTE Operation: MPU Write with Color Expansion and chroma keying (w/o ROP) - BTE_Enable(); - LCD_CmdWrite(0x04); //Memory Data Read/Write Port - - for(i=0; i< Y_H; i++) - { - for(j=0; j< X_W/16; j++) - { - Check_Mem_WR_FIFO_not_Full(); - LCD_DataWrite_Pixel(*data); - data++; - } - } - - Check_Mem_WR_FIFO_Empty(); - Check_BTE_Busy(); -} - -/* 结合透明度的内存复制 */ -void BTE_Alpha_Blending -( - unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t S0_W // S0图像的宽度 - ,uint16_t XS0 // S0图像的左上方X坐标 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long S1_Addr // S1图像的内存起始地址 - ,uint16_t S1_W // S1图像的宽度 - ,uint16_t XS1 // S1图像的左上方X坐标 - ,uint16_t YS1 // S1图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方X坐标 - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 - ,uint8_t alpha // 透明度等级(32等级) -) -{ - BTE_S0_Color_16bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(S0_W); - BTE_S0_Window_Start_XY(XS0,YS0); - BTE_S1_Color_16bpp(); - BTE_S1_Memory_Start_Address(S1_Addr); - BTE_S1_Image_Width(S1_W); - BTE_S1_Window_Start_XY(XS1,YS1); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Window_Size(X_W,Y_H); - BTE_Operation_Code(0x0A); //BTE Operation: Memory write with opacity (w/o ROP) - BTE_Alpha_Blending_Effect(alpha); - BTE_Enable(); - Check_BTE_Busy(); -} - -void BTE_Pixel_8bpp_Alpha_Blending -( - unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t S0_W // S0图像的宽度 - ,uint16_t XS0 // S0图像的左上方X坐标 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long S1_Addr // S1图像的内存起始地址 - ,uint16_t S1_W // S1图像的宽度 - ,uint16_t XS1 // S1图像的左上方X坐标 - ,uint16_t YS1 // S1图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方X坐标 - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 -) -{ - BTE_S0_Color_8bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(S0_W); - BTE_S0_Window_Start_XY(XS0,YS0); - BTE_S1_Color_8bit_Alpha(); - BTE_S1_Memory_Start_Address(S1_Addr); - BTE_S1_Image_Width(S1_W); - BTE_S1_Window_Start_XY(XS1,YS1); - BTE_Destination_Color_8bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Window_Size(X_W,Y_H); - BTE_Operation_Code(0x0A); //BTE Operation: Memory write with opacity (w/o ROP) - BTE_Enable(); - Check_BTE_Busy(); -} - -void BTE_Pixel_16bpp_Alpha_Blending -( - unsigned long S0_Addr // SO图像的内存起始地址 - ,uint16_t S0_W // S0图像的宽度 - ,uint16_t XS0 // S0图像的左上方X坐标 - ,uint16_t YS0 // S0图像的左上方Y坐标 - ,unsigned long S1_Addr // S1图像的内存起始地址 - ,uint16_t S1_W // S1图像的宽度 - ,uint16_t XS1 // S1图像的左上方X坐标 - ,uint16_t YS1 // S1图像的左上方Y坐标 - ,unsigned long Des_Addr // 目的图像的内存起始地址 - ,uint16_t Des_W // 目的图像的宽度 - ,uint16_t XDes // 目的图像的左上方X坐标 - ,uint16_t YDes // 目的图像的左上方X坐标 - ,uint16_t X_W // 活动窗口的宽度 - ,uint16_t Y_H // 活动窗口的长度 -) -{ - BTE_S0_Color_16bpp(); - BTE_S0_Memory_Start_Address(S0_Addr); - BTE_S0_Image_Width(S0_W); - BTE_S0_Window_Start_XY(XS0,YS0); - BTE_S1_Color_16bit_Alpha(); - BTE_S1_Memory_Start_Address(S1_Addr); - BTE_S1_Image_Width(S1_W); - BTE_S1_Window_Start_XY(XS1,YS1); - BTE_Destination_Color_16bpp(); - BTE_Destination_Memory_Start_Address(Des_Addr); - BTE_Destination_Image_Width(Des_W); - BTE_Destination_Window_Start_XY(XDes,YDes); - BTE_Window_Size(X_W,Y_H); - BTE_Operation_Code(0x0A); //BTE Operation: Memory write with opacity (w/o ROP) - BTE_Enable(); - Check_BTE_Busy(); -} - -/*----------------------------------------------------------------------------*/ - -void LT768_PWM0_Init -( - uint8_t on_off // 0:禁止PWM0 1:使能PWM0 - ,uint8_t Clock_Divided // PWM时钟分频 取值范围 0~3(1,1/2,1/4,1/8) - ,uint8_t Prescalar // 时钟分频 取值范围 1~256 - ,uint16_t Count_Buffer // 设置PWM的输出周期 - ,uint16_t Compare_Buffer // 设置占空比 -) -{ - Select_PWM0(); - Set_PWM_Prescaler_1_to_256(Prescalar); - - if(Clock_Divided ==0) - { - Select_PWM0_Clock_Divided_By_1(); - } - - if(Clock_Divided ==1) - { - Select_PWM0_Clock_Divided_By_2(); - } - - if(Clock_Divided ==2) - { - Select_PWM0_Clock_Divided_By_4(); - } - - if(Clock_Divided ==3) - { - Select_PWM0_Clock_Divided_By_8(); - } - - Set_Timer0_Count_Buffer(Count_Buffer); - Set_Timer0_Compare_Buffer(Compare_Buffer); - - if(on_off == 1) - { - Start_PWM0(); - } - - if(on_off == 0) - { - Stop_PWM0(); - } -} - - -void LT768_PWM0_Duty(uint16_t Compare_Buffer) -{ - Set_Timer0_Compare_Buffer(Compare_Buffer); -} - -void LT768_PWM1_Init -( - uint8_t on_off // 0:禁止PWM0 1:使能PWM0 - ,uint8_t Clock_Divided // PWM时钟分频 取值范围 0~3(1,1/2,1/4,1/8) - ,uint8_t Prescalar // 时钟分频 取值范围 1~256 - ,uint16_t Count_Buffer // 设置PWM的输出周期 - ,uint16_t Compare_Buffer // 设置占空比 -) -{ - Select_PWM1(); - Set_PWM_Prescaler_1_to_256(Prescalar); - - if(Clock_Divided ==0) - { - Select_PWM1_Clock_Divided_By_1(); - } - - if(Clock_Divided ==1) - { - Select_PWM1_Clock_Divided_By_2(); - } - - if(Clock_Divided ==2) - { - Select_PWM1_Clock_Divided_By_4(); - } - - if(Clock_Divided ==3) - { - Select_PWM1_Clock_Divided_By_8(); - } - - Set_Timer1_Count_Buffer(Count_Buffer); - Set_Timer1_Compare_Buffer(Compare_Buffer); - - if(on_off == 1) - { - Start_PWM1(); - } - - if(on_off == 0) - { - Stop_PWM1(); - } -} - - -void LT768_PWM1_Duty(uint16_t Compare_Buffer) -{ - Set_Timer1_Compare_Buffer(Compare_Buffer); -} - -/*----------------------------------------------------------------------------*/ - -// LT768进入待命模式 -void LT768_Standby(void) -{ - Power_Saving_Standby_Mode(); - Check_Power_is_Saving(); -} -// 从待命模式中唤醒 -void LT768_Wkup_Standby(void) -{ - Power_Normal_Mode(); - Check_Power_is_Normal(); -} - - -// LT768进入暂停模式 -void LT768_Suspend(void) -{ - lt768_sdram_init(10); - Power_Saving_Suspend_Mode(); - Check_Power_is_Saving(); -} -// 从暂停模式中唤醒 -void LT768_Wkup_Suspend(void) -{ - Power_Normal_Mode(); - Check_Power_is_Normal(); - lt768_sdram_init(lt768_mclk); -} - - -// LT768进入休眠模式 -void LT768_SleepMode(void) -{ - Power_Saving_Sleep_Mode(); - Check_Power_is_Saving(); -} -// 从休眠模式中唤醒 -void LT768_Wkup_Sleep(void) -{ - Power_Normal_Mode(); - Check_Power_is_Normal(); -} - -/*----------------------------------------------------------------------------*/ - -void LT768_SPI_Init(uint8_t cs,uint8_t div) -{ - if(cs == 0) - { - Select_SFI_0(); - Select_nSS_drive_on_xnsfcs0(); - } - else - { - Select_SFI_1(); - Select_nSS_drive_on_xnsfcs1(); - } - - SPI_Clock_Period(div); - Enable_SFlash_SPI(); -} - -void W25QXX_Enter_4Byte_AddressMode(void)//val:选择外挂的SPI: SCS:0 SCS:1 -{ - nSS_Active(); - SPI_Master_FIFO_Data_Put(0xB7); - nSS_Inactive(); -} - -void LT_W25QXX_Read(uint8_t *pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead) -{ - uint16_t i; - nSS_Active(); - SPI_Master_FIFO_Data_Put(0x03); - SPI_Master_FIFO_Data_Put((uint8_t)((ReadAddr)>>16)); - SPI_Master_FIFO_Data_Put((uint8_t)((ReadAddr)>>8)); - SPI_Master_FIFO_Data_Put((uint8_t)ReadAddr); - - for(i=0; i>8)); - SPI_Master_FIFO_Data_Put((uint8_t)page); - nSS_Inactive(); - W25N01GV_Wait_Busy(); -} - -void W25N01GV_ReadPageAddr_Data(uint8_t *pBuffer,uint32_t PageNum,uint32_t PageAddr,uint16_t NumByteToRead) -{ - uint16_t i; - //------从flash读数据到BUFF----- - nSS_Active(); //使能器件 - SPI_Master_FIFO_Data_Put(0x13); - SPI_Master_FIFO_Data_Put(0x00); - SPI_Master_FIFO_Data_Put((uint8_t)((PageNum)>>8)); //发送16bit地址 - SPI_Master_FIFO_Data_Put((uint8_t)(PageNum)); - nSS_Inactive(); - W25N01GV_Wait_Busy(); - W25N01GV_Write_SR(0xb0,W25N01GV_ReadSR(0xb0) | 0x08); //设定从BUFF的哪个位置开始读 - //------再从BUFF读数据到单片机内----- - nSS_Active(); - SPI_Master_FIFO_Data_Put(0x03); - SPI_Master_FIFO_Data_Put((PageAddr)>>8); - SPI_Master_FIFO_Data_Put(PageAddr); - SPI_Master_FIFO_Data_Put(0x00); - - for(i=0; iLCD_XSIZE_TFT) - { - x1 = x1-LCD_XSIZE_TFT; - y1++; - } - } -} - -void LT768_Print_Outside_Font_GB2312_48_72_Nand -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long FlashAddr // 字库源地址(Flash) - ,unsigned long MemoryAddr1 // 缓冲层1的地址(SDRAM) - ,unsigned long MemoryAddr2 // 缓冲层1的地址(SDRAM) - ,unsigned long ShowAddr // 显示层的地址 - ,uint16_t width // 显示层的宽度 - ,uint8_t Size // 设置字体大小 48:48*48 72:72*72 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint16_t w // 字体粗细:0:不加粗 1:加粗1级 2:加粗2级 - ,uint16_t s // 行距 - ,uint8_t *c // 数据缓冲的首地址 -) -{ - uint16_t temp_H = 0; - uint16_t temp_L = 0; - uint16_t temp = 0; - unsigned long i = 0; - uint16_t j = 0; - uint16_t k = 0; - uint16_t h = 0; - uint16_t n = 0; - uint16_t m = 0; - uint16_t g = 0; - uint16_t f = 0; - h = x; - k = y; - Memory_8bpp_Mode(); //使用8位色深来存储图片 - Canvas_Image_Start_address(MemoryAddr1); - Canvas_image_width(width); - - while((c[i] != '\0')&&(c[i]>=0xa0)) // 遇见不是汉字编码的自动退出 - { - temp_H = (c[i] - 0xa1) * 94; - temp_L = c[i+1] - 0xa1; - temp = temp_H + temp_L; - LT768_Nand_8bpp_font(1,0,Size*j/8,0,Size/8,Size,FlashAddr+temp*((Size*Size)/8),MemoryAddr1,MemoryAddr2); //2019 - i+=2; - j++; - } - - Memory_16bpp_Mode(); - Canvas_Image_Start_address(ShowAddr); - Canvas_image_width(width); - j = 0; - i = 0; - - if(w>2) - { - w = 2; - } - - for(g=0; g=0xa0)) // 遇见不是汉字编码的自动退出 - { - if((f == m)&&((x+Size*j+Size)>(width*(n+1)))) - { - m++; - n++; - y=y+Size-1+s; - x = x+((width*n)-(x+Size*j))+g; - f=n; - } - - if(ChromaKey==0) - { - LT768_BTE_Memory_Copy_ColorExpansion_8(MemoryAddr2,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor,BackGroundColor - ); - } - - if(ChromaKey==1) - { - LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(MemoryAddr2,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor); - } - - i+=2; - j++; - } - - i=0; - j=0; - m=0; - n=0; - f=0; - x=h+g+1; - y=k+g+1; - } -} - -void LT768_Print_Outside_Font_GBK_48_72_Nand -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long FlashAddr // 字库源地址(Flash) - ,unsigned long MemoryAddr1 // 缓冲层1的地址(SDRAM) - ,unsigned long MemoryAddr2 // 缓冲层1的地址(SDRAM) - ,unsigned long ShowAddr // 显示层的地址 - ,uint16_t width // 显示层的宽度 - ,uint8_t Size // 设置字体大小 48:48*48 72:72*72 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint16_t w // 字体粗细:0:不加粗 1:加粗1级 2:加粗2级 - ,uint16_t s // 行距 - ,uint8_t *c // 数据缓冲的首地址 -) -{ - uint16_t temp_H = 0; - uint16_t temp_L = 0; - uint16_t temp = 0; - unsigned long i = 0; - uint16_t j = 0; - uint16_t k = 0; - uint16_t h = 0; - uint16_t n = 0; - uint16_t m = 0; - uint16_t g = 0; - uint16_t f = 0; - h = x; - k = y; - Memory_8bpp_Mode(); //使用8位色深来存储图片 - Canvas_Image_Start_address(MemoryAddr1); - Canvas_image_width(width); - - while((c[i] != '\0')&&(c[i]>=0xa0)) // 遇见不是汉字编码的自动退出 - { - temp_H = (c[i] - 0x81) * 191; - temp_L = c[i+1] - 0x40; - temp = temp_H + temp_L; - LT768_Nand_8bpp_font(1,0,Size*j/8,0,Size/8,Size,FlashAddr+temp*((Size*Size)/8),MemoryAddr1,MemoryAddr2); //2019 - i+=2; - j++; - } - - Memory_16bpp_Mode(); - Canvas_Image_Start_address(ShowAddr); - Canvas_image_width(width); - j = 0; - i = 0; - - if(w>2) - { - w = 2; - } - - for(g=0; g=0xa0)) // 遇见不是汉字编码的自动退出 - { - if((f == m)&&((x+Size*j+Size)>(width*(n+1)))) - { - m++; - n++; - y=y+Size-1+s; - x = x+((width*n)-(x+Size*j))+g; - f=n; - } - - if(ChromaKey==0) - { - LT768_BTE_Memory_Copy_ColorExpansion_8(MemoryAddr2,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor,BackGroundColor - ); - } - - if(ChromaKey==1) - { - LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(MemoryAddr2,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor); - } - - i+=2; - j++; - } - - i=0; - j=0; - m=0; - n=0; - f=0; - x=h+g+1; - y=k+g+1; - } -} - -void LT768_Print_Outside_UserDefineFont_GB2312_Nand -( - uint8_t SCS // 选择外挂的SPI : SCS:0 SCS:1 - ,uint8_t Clk // SPI时钟分频参数 : SPI Clock = System Clock /{(Clk+1)*2} - ,unsigned long FlashAddr // 字库源地址(Flash) - ,unsigned long MemoryAddr1 // 缓冲层1的地址(SDRAM) - ,unsigned long MemoryAddr2 // 缓冲层1的地址(SDRAM) - ,unsigned long ShowAddr // 显示层的地址 - ,uint16_t width // 显示层的宽度 - ,uint8_t Size // 设置字体大小 48:48*48 72:72*72 - ,uint8_t ChromaKey // 0:字体背景色透明 1:可以设置字体的背景色 - ,uint16_t x // 字体开始显示的x位置 - ,uint16_t y // 字体开始显示的y位置 - ,unsigned long FontColor // 字体的颜色 - ,unsigned long BackGroundColor // 字体的背景色(注意:当字体背景初始化成透明时,设置该值无效) - ,uint16_t w // 字体粗细:0:不加粗 1:加粗1级 2:加粗2级 - ,uint16_t s // 行距 - ,uint8_t *c // 数据缓冲的首地址 -) -{ - short temp = 0; - unsigned long i = 0; - uint16_t j = 0; - uint16_t k = 0; - uint16_t h = 0; - uint16_t n = 0; - uint16_t m = 0; - uint16_t g = 0; - uint16_t f = 0; - uint8_t temp1[2] = {0}; - uint32_t fontNum = 0; - clear_Font_1(); - LT768_SPI_Init(SCS,1); - LT_W25N01GV_Read(temp1,FlashAddr+8,2); - fontNum = (temp1[0]<<8)+temp1[1]; - LT_W25N01GV_Read(Font_1,FlashAddr + 0xc,fontNum * 2); - h = x; - k = y; - Memory_8bpp_Mode();//使用8位色深来存储图片 - Canvas_Image_Start_address(MemoryAddr1); - Canvas_image_width(width); - - while(c[i + 1] != '\0') - { - temp = Get_User_Font_P(c[i],c[i+1]); - - if(temp != -1) - { - LT768_Nand_8bpp_font(SCS,Clk,Size*j/8,0,Size/8,Size,FlashAddr+temp*((Size*Size)/8)+0x0c+fontNum*2,MemoryAddr1,MemoryAddr2); //2019 - } - else - { - break; - } - - i+=2; - j++; - } - - Memory_16bpp_Mode(); - Canvas_Image_Start_address(ShowAddr); - Canvas_image_width(width); - j = 0; - i = 0; - - if(w>2) - { - w = 2; - } - - for(g=0; g(width*(n+1)))) - { - m++; - n++; - y=y+Size-1+s; - x = x+((width*n)-(x+Size*j))+g; - f=n; - } - - if(ChromaKey==1) - { - LT768_BTE_Memory_Copy_ColorExpansion_8(MemoryAddr2,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor,BackGroundColor - ); - } - - if(ChromaKey==0) - { - LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(MemoryAddr2,Size*j/8, - ShowAddr,width,x+Size*j,y, - Size,Size,FontColor - ); - } - - i+=2; - j++; - } - - ChromaKey=0; - i=0; - j=0; - m=0; - n=0; - f=0; - x=h+g+1; - y=k+g+1; - } -} - +/* +* Copyright (c) 2022 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file lt768_lib.c + * @brief lt768 register relative driver, inherit from Levetop Electronics + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.9.19 + */ + +#include "nuttx/arch.h" +#include "nuttx/lcd/lt768_lib.h" + +/*----------------------------------------------------------------------------*/ + +uint8_t lt768_cclk; // LT768 clock frequnce +uint8_t lt768_mclk; // SDRAM clock frequnce +uint8_t lt768_sclk; // LCD scan clock frequence + +/*----------------------------------------------------------------------------*/ + +void lt768_pll_init(void) +{ + uint32_t temp = 0; + uint32_t temp1; + uint16_t lpllOD_sclk, lpllOD_cclk, lpllOD_mclk; + uint16_t lpllR_sclk, lpllR_cclk, lpllR_mclk; + uint16_t lpllN_sclk, lpllN_cclk, lpllN_mclk; + temp = (LCD_HBPD + LCD_HFPD + LCD_HSPW + LCD_XSIZE_TFT) * + (LCD_VBPD + LCD_VFPD + LCD_VSPW + LCD_YSIZE_TFT) * 60; + temp1 = (temp % 1000000) / 100000; + + if(temp1 > 5) + { + temp = temp / 1000000 + 1; + } + else + { + temp = temp / 1000000; + } + + lt768_sclk = temp; + temp = temp * 3; + lt768_mclk = temp; + lt768_cclk = temp; + + if(lt768_cclk > 100) + { + lt768_cclk = 100; + } + + if(lt768_mclk > 100) + { + lt768_mclk = 100; + } + + if(lt768_sclk > 65) + { + lt768_sclk = 65; + } + +#if XI_4M + lpllOD_sclk = 3; + lpllOD_cclk = 2; + lpllOD_mclk = 2; + lpllR_sclk = 2; + lpllR_cclk = 2; + lpllR_mclk = 2; + lpllN_mclk = lt768_mclk; + lpllN_cclk = lt768_cclk; + lpllN_sclk = 2*lt768_sclk; +#endif +#if XI_8M + lpllOD_sclk = 3; + lpllOD_cclk = 2; + lpllOD_mclk = 2; + lpllR_sclk = 2; + lpllR_cclk = 4; + lpllR_mclk = 4; + lpllN_mclk = lt768_mclk; + lpllN_cclk = lt768_cclk; + lpllN_sclk = lt768_sclk; +#endif +#if XI_10M + lpllOD_sclk = 3; + lpllOD_cclk = 2; + lpllOD_mclk = 2; + lpllR_sclk = 5; + lpllR_cclk = 5; + lpllR_mclk = 5; + lpllN_mclk = lt768_mclk; + lpllN_cclk = lt768_cclk; + lpllN_sclk = 2*lt768_sclk; +#endif +#if XI_12M + lpllOD_sclk = 3; + lpllOD_cclk = 2; + lpllOD_mclk = 2; + lpllR_sclk = 3; + lpllR_cclk = 6; + lpllR_mclk = 6; + lpllN_mclk = lt768_mclk; + lpllN_cclk = lt768_cclk; + lpllN_sclk = lt768_sclk; +#endif + LCD_CmdWrite(0x05); + LCD_DataWrite((lpllOD_sclk << 6) | (lpllR_sclk << 1) | ((lpllN_sclk >> 8) & 0x1)); + LCD_CmdWrite(0x07); + LCD_DataWrite((lpllOD_mclk << 6) | (lpllR_mclk << 1) | ((lpllN_mclk >> 8) & 0x1)); + LCD_CmdWrite(0x09); + LCD_DataWrite((lpllOD_cclk << 6) | (lpllR_cclk << 1) | ((lpllN_cclk >> 8) & 0x1)); + LCD_CmdWrite(0x06); + LCD_DataWrite(lpllN_sclk); + LCD_CmdWrite(0x08); + LCD_DataWrite(lpllN_mclk); + LCD_CmdWrite(0x0a); + LCD_DataWrite(lpllN_cclk); + LCD_CmdWrite(0x00); + up_udelay(1); + LCD_DataWrite(0x80); + up_mdelay(1); +} + +void lt768_sdram_init(uint8_t mclk) +{ + uint16_t sdram_itv; + LCD_RegisterWrite(0xe0, 0x29); + LCD_RegisterWrite(0xe1, 0x03); //CAS:2=0x02?CAS:3=0x03 + sdram_itv = (64000000 / 8192) / (1000 / mclk) ; + sdram_itv -= 2; + LCD_RegisterWrite(0xe2, sdram_itv); + LCD_RegisterWrite(0xe3, sdram_itv >> 8); + LCD_RegisterWrite(0xe4, 0x01); +// Check_SDRAM_Ready(); + up_mdelay(1); +} + +void lt768_set_panel(void) +{ +//**[01h]**// + TFT_16bit(); +//TFT_18bit(); +//TFT_24bit(); +#if STM32_FSMC_8 + Host_Bus_8bit(); //host bus 8bit +#else + Host_Bus_16bit(); //host bus 16bit +#endif +//**[02h]**// + RGB_16b_16bpp(); +//RGB_16b_24bpp_mode1(); + MemWrite_Left_Right_Top_Down(); +//MemWrite_Down_Top_Left_Right(); +//**[03h]**// + Graphic_Mode(); + Memory_Select_SDRAM(); +// PCLK_Falling(); //REG[12h]:falling + PCLK_Rising(); + VSCAN_T_to_B(); //REG[12h]:from top to bottom +//VSCAN_B_to_T(); //from bottom to top + PDATA_Set_RGB(); //REG[12h]:Select RGB output +//PDATA_Set_RBG(); +//PDATA_Set_GRB(); +//PDATA_Set_GBR(); +//PDATA_Set_BRG(); +//PDATA_Set_BGR(); + HSYNC_Low_Active(); //REG[13h]: +//HSYNC_High_Active(); + VSYNC_Low_Active(); //REG[13h]: +//VSYNC_High_Active(); + DE_High_Active(); //REG[13h]: +//DE_Low_Active(); + LCD_HorizontalWidth_VerticalHeight(LCD_XSIZE_TFT, LCD_YSIZE_TFT); + LCD_Horizontal_Non_Display(LCD_HBPD); + LCD_HSYNC_Start_Position(LCD_HFPD); + LCD_HSYNC_Pulse_Width(LCD_HSPW); + LCD_Vertical_Non_Display(LCD_VBPD); + LCD_VSYNC_Start_Position(LCD_VFPD); + LCD_VSYNC_Pulse_Width(LCD_VSPW); + Memory_XY_Mode(); //Block mode (X-Y coordination addressing); + Memory_16bpp_Mode(); +} + +void lt768_init(void) +{ +//Initial_Display_test and set SW2 pin2 = 1 + while(LCD_StatusRead() & 0x02); + + lt768_pll_init(); + lt768_sdram_init(lt768_mclk); + lt768_set_panel(); +} + +/*----------------------------------------------------------------------------*/ + +void MPU8_8bpp_Memory_Write +( + uint16_t x + , uint16_t y + , uint16_t w + , uint16_t h + , const uint8_t *data +) +{ + uint16_t i, j; + Graphic_Mode(); + Active_Window_XY(x, y); + Active_Window_WH(w, h); + Goto_Pixel_XY(x, y); + LCD_CmdWrite(0x04); + + for(i = 0; i < h; i ++) + { + for(j = 0; j < w; j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite(*data); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); +} + + +void MPU8_16bpp_Memory_Write +( + uint16_t x + , uint16_t y + , uint16_t w + , uint16_t h + , const uint8_t *data +) +{ + uint16_t i, j; + Graphic_Mode(); + Active_Window_XY(x, y); + Active_Window_WH(w, h); + Goto_Pixel_XY(x, y); + LCD_CmdWrite(0x04); + + for(i = 0; i < h; i ++) + { + for(j = 0; j < w; j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite(*data); + data ++; + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite(*data); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); +} + + +void MPU8_24bpp_Memory_Write +( + uint16_t x + , uint16_t y + , uint16_t w + , uint16_t h + , const uint8_t *data +) +{ + uint16_t i, j; + Graphic_Mode(); + Active_Window_XY(x, y); + Active_Window_WH(w, h); + Goto_Pixel_XY(x, y); + LCD_CmdWrite(0x04); + + for(i = 0; i < h; i ++) + { + for(j = 0; j < w; j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite(*data); + data ++; + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite(*data); + data ++; + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite(*data); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); +} + + + +void MPuint16_t_16bpp_Memory_Write +( + uint16_t x + , uint16_t y + , uint16_t w + , uint16_t h + , const uint16_t *data +) +{ + uint16_t i, j; + Graphic_Mode(); + Active_Window_XY(x, y); + Active_Window_WH(w, h); + Goto_Pixel_XY(x, y); + LCD_CmdWrite(0x04); + + for(i = 0; i < h; i ++) + { + for(j = 0; j < w; j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite_Pixel(*data); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); +} + +void MPuint16_t_24bpp_Mode1_Memory_Write +( + uint16_t x + , uint16_t y + , uint16_t w + , uint16_t h + , const uint16_t *data +) +{ + uint16_t i, j; + Graphic_Mode(); + Active_Window_XY(x, y); + Active_Window_WH(w, h); + Goto_Pixel_XY(x, y); + LCD_CmdWrite(0x04); + + for(i = 0; i < h; i ++) + { + for(j = 0; j < w/2; j ++) + { + LCD_DataWrite_Pixel(*data); + Check_Mem_WR_FIFO_not_Full(); + data ++; + LCD_DataWrite_Pixel(*data); + Check_Mem_WR_FIFO_not_Full(); + data ++; + LCD_DataWrite_Pixel(*data); + Check_Mem_WR_FIFO_not_Full(); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); +} + + +void MPuint16_t_24bpp_Mode2_Memory_Write +( + uint16_t x + , uint16_t y + , uint16_t w + , uint16_t h + , const uint16_t *data +) +{ + uint16_t i, j; + Graphic_Mode(); + Active_Window_XY(x, y); + Active_Window_WH(w, h); + Goto_Pixel_XY(x, y); + LCD_CmdWrite(0x04); + + for(i = 0; i < h; i ++) + { + for(j = 0; j < w; j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite_Pixel(*data); + data ++; + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite_Pixel(*data); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); +} +/*----------------------------------------------------------------------------*/ + +//------------------------------------- line ----------------------------------------- +void LT768_DrawLine +( + uint16_t X1 // X1 coordination + , uint16_t Y1 // Y1 coordination + , uint16_t X2 // X2 coordination + , uint16_t Y2 // Y2 coordination + , uint32_t LineColor // line color +) +{ + Foreground_color_65k(LineColor); + Line_Start_XY(X1, Y1); + Line_End_XY(X2, Y2); + Start_Line(); + Check_2D_Busy(); +} + +void LT768_DrawLine_Width +( + uint16_t X1 // X1 coordination + , uint16_t Y1 // Y1 coordination + , uint16_t X2 // X2 coordination + , uint16_t Y2 // Y2 coordination + , uint32_t LineColor // line color + , uint16_t Width // line width +) +{ + uint16_t i = 0; + signed short x = 0, y = 0; + double temp = 0; + x = X2 - X1; + y = Y2 - Y1; + + if(x == 0) + { + temp = 2; + } + else + { + temp = -((double)y/(double)x); + } + + if(temp >= -1 && temp <= 1) + { + while(Width--) + { + LT768_DrawLine(X1, Y1 + i, X2, Y2 + i, LineColor); + i ++; + } + } + else + { + while(Width--) + { + LT768_DrawLine(X1 + i, Y1, X2 + i, Y2, LineColor); + i ++; + } + } +} + +//------------------------------------- circle ----------------------------------------- +void LT768_DrawCircle +( + uint16_t XCenter // center x + , uint16_t YCenter // center y + , uint16_t R // radius + , uint32_t CircleColor // line color +) +{ + Foreground_color_65k(CircleColor); + Circle_Center_XY(XCenter, YCenter); + Circle_Radius_R(R); + Start_Circle_or_Ellipse(); + Check_2D_Busy(); +} + +void LT768_DrawCircle_Fill +( + uint16_t XCenter // center x + , uint16_t YCenter // center y + , uint16_t R // radius + , uint32_t ForegroundColor // foreground color +) +{ + Foreground_color_65k(ForegroundColor); + Circle_Center_XY(XCenter, YCenter); + Circle_Radius_R(R); + Start_Circle_or_Ellipse_Fill(); + Check_2D_Busy(); +} + +void LT768_DrawCircle_Width +( + uint16_t XCenter // center x + , uint16_t YCenter // center y + , uint16_t R // radius + , uint32_t CircleColor // line color + , uint32_t ForegroundColor // background color + , uint16_t Width // line width +) +{ + LT768_DrawCircle_Fill(XCenter, YCenter, R + Width, CircleColor); + LT768_DrawCircle_Fill(XCenter, YCenter, R, ForegroundColor); +} + +//------------------------------------- ellipse ----------------------------------------- +void LT768_DrawEllipse +( + uint16_t XCenter // ellipse center x + , uint16_t YCenter // ellipse center y + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t EllipseColor // line color +) +{ + Foreground_color_65k(EllipseColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Circle_or_Ellipse(); + Check_2D_Busy(); +} + +void LT768_DrawEllipse_Fill +( + uint16_t XCenter // ellipse center x + , uint16_t YCenter // ellipse center y + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t ForegroundColor // background color +) +{ + Foreground_color_65k(ForegroundColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Circle_or_Ellipse_Fill(); + Check_2D_Busy(); +} + +void LT768_DrawEllipse_Width +( + uint16_t XCenter // ellipse center x + , uint16_t YCenter // ellipse center y + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t EllipseColor // line color + , uint32_t ForegroundColor // background color + , uint16_t Width // line width +) +{ + LT768_DrawEllipse_Fill(XCenter, YCenter, X_R + Width, Y_R + Width, EllipseColor); + LT768_DrawEllipse_Fill(XCenter, YCenter, X_R, Y_R, ForegroundColor); +} + +//------------------------------------- rectangle ----------------------------------------- +void LT768_DrawSquare +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint32_t SquareColor // line color +) +{ + Foreground_color_65k(SquareColor); + Square_Start_XY(X1, Y1); + Square_End_XY(X2, Y2); + Start_Square(); + Check_2D_Busy(); +} + +void LT768_DrawSquare_Fill +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint32_t ForegroundColor // background color +) +{ + Foreground_color_65k(ForegroundColor); + Square_Start_XY(X1, Y1); + Square_End_XY(X2, Y2); + Start_Square_Fill(); + Check_2D_Busy(); +} + +void LT768_DrawSquare_Width +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint32_t SquareColor // line color + , uint32_t ForegroundColor // background color + , uint16_t Width // line width +) +{ + LT768_DrawSquare_Fill(X1-Width, Y1-Width, X2 + Width, Y2 + Width, SquareColor); + LT768_DrawSquare_Fill(X1, Y1, X2, Y2, ForegroundColor); +} + +//------------------------------------- round corner rectangle ----------------------------------------- +void LT768_DrawCircleSquare +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t CircleSquareColor // line color +) +{ + Foreground_color_65k(CircleSquareColor); + Square_Start_XY(X1, Y1); + Square_End_XY(X2, Y2); + Circle_Square_Radius_RxRy(X_R, Y_R); + Start_Circle_Square(); + Check_2D_Busy(); +} + +void LT768_DrawCircleSquare_Fill +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t ForegroundColor // line color +) +{ + Foreground_color_65k(ForegroundColor); + Square_Start_XY(X1, Y1); + Square_End_XY(X2, Y2); + Circle_Square_Radius_RxRy(X_R, Y_R); + Start_Circle_Square_Fill(); + Check_2D_Busy(); +} + +void LT768_DrawCircleSquare_Width +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t CircleSquareColor // line color + , uint32_t ForegroundColor // line color + , uint16_t Width +) +{ + LT768_DrawCircleSquare_Fill(X1-Width, Y1-Width, X2 + Width, Y2 + Width, X_R, Y_R, CircleSquareColor); + LT768_DrawCircleSquare_Fill(X1, Y1, X2, Y2, X_R, Y_R, ForegroundColor); +} + +//------------------------------------- triangle ----------------------------------------- +void LT768_DrawTriangle +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X3 // X3 position + , uint16_t Y3 // Y3 position + , uint32_t TriangleColor // line color +) +{ + Foreground_color_65k(TriangleColor); + Triangle_Point1_XY(X1, Y1); + Triangle_Point2_XY(X2, Y2); + Triangle_Point3_XY(X3, Y3); + Start_Triangle(); + Check_2D_Busy(); +} + +void LT768_DrawTriangle_Fill +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X3 // X3 position + , uint16_t Y3 // Y3 position + , uint32_t ForegroundColor // line color +) +{ + Foreground_color_65k(ForegroundColor); + Triangle_Point1_XY(X1, Y1); + Triangle_Point2_XY(X2, Y2); + Triangle_Point3_XY(X3, Y3); + Start_Triangle_Fill(); + Check_2D_Busy(); +} + +void LT768_DrawTriangle_Frame +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X3 // X3 position + , uint16_t Y3 // Y3 position + , uint32_t TriangleColor // line color + , uint32_t ForegroundColor // background color +) +{ + LT768_DrawTriangle_Fill(X1, Y1, X2, Y2, X3, Y3, ForegroundColor); + LT768_DrawTriangle(X1, Y1, X2, Y2, X3, Y3, TriangleColor); +} + +//------------------------------------- curve ----------------------------------------- +void LT768_DrawLeftUpCurve +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t CurveColor // line color +) +{ + Foreground_color_65k(CurveColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Left_Up_Curve(); + Check_2D_Busy(); +} + + +void LT768_DrawLeftDownCurve +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t CurveColor // line color +) +{ + Foreground_color_65k(CurveColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Left_Down_Curve(); + Check_2D_Busy(); +} + + +void LT768_DrawRightUpCurve +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t CurveColor // line color +) +{ + Foreground_color_65k(CurveColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Right_Up_Curve(); + Check_2D_Busy(); +} + + +void LT768_DrawRightDownCurve +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t CurveColor // line color +) +{ + Foreground_color_65k(CurveColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Right_Down_Curve(); + Check_2D_Busy(); +} + + +void LT768_SelectDrawCurve +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t CurveColor // line color + , uint16_t Dir // direction +) +{ + switch(Dir) + { + case 0: + LT768_DrawLeftDownCurve(XCenter, YCenter, X_R, Y_R, CurveColor); + break; + + case 1: + LT768_DrawLeftUpCurve(XCenter, YCenter, X_R, Y_R, CurveColor); + break; + + case 2: + LT768_DrawRightUpCurve(XCenter, YCenter, X_R, Y_R, CurveColor); + break; + + case 3: + LT768_DrawRightDownCurve(XCenter, YCenter, X_R, Y_R, CurveColor); + break; + + default: + break; + } +} + + +//------------------------------------- 1/4 filled ellipse ----------------------------------------- +void LT768_DrawLeftUpCurve_Fill +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t ForegroundColor // background color +) +{ + Foreground_color_65k(ForegroundColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Left_Up_Curve_Fill(); + Check_2D_Busy(); +} + + +void LT768_DrawLeftDownCurve_Fill +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t ForegroundColor // background color +) +{ + Foreground_color_65k(ForegroundColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Left_Down_Curve_Fill(); + Check_2D_Busy(); +} + + +void LT768_DrawRightUpCurve_Fill +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t ForegroundColor // background color +) +{ + Foreground_color_65k(ForegroundColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Right_Up_Curve_Fill(); + Check_2D_Busy(); +} + + +void LT768_DrawRightDownCurve_Fill +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t ForegroundColor // background color +) +{ + Foreground_color_65k(ForegroundColor); + Ellipse_Center_XY(XCenter, YCenter); + Ellipse_Radius_RxRy(X_R, Y_R); + Start_Right_Down_Curve_Fill(); + Check_2D_Busy(); +} + + +void LT768_SelectDrawCurve_Fill +( + uint16_t XCenter // center X position + , uint16_t YCenter // center Y position + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint32_t CurveColor // line color + , uint16_t Dir // direction +) +{ + switch(Dir) + { + case 0: + LT768_DrawLeftDownCurve_Fill(XCenter, YCenter, X_R, Y_R, CurveColor); + break; + + case 1: + LT768_DrawLeftUpCurve_Fill(XCenter, YCenter, X_R, Y_R, CurveColor); + break; + + case 2: + LT768_DrawRightUpCurve_Fill(XCenter, YCenter, X_R, Y_R, CurveColor); + break; + + case 3: + LT768_DrawRightDownCurve_Fill(XCenter, YCenter, X_R, Y_R, CurveColor); + break; + + default: + break; + } +} + + + +//------------------------------------- quadrilateral ----------------------------------------- + +void LT768_DrawQuadrilateral +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X3 // X3 position + , uint16_t Y3 // Y3 position + , uint16_t X4 // X4 position + , uint16_t Y4 // Y4 position + , uint32_t ForegroundColor // line color +) +{ + Foreground_color_65k(ForegroundColor); + Triangle_Point1_XY(X1, Y1); + Triangle_Point2_XY(X2, Y2); + Triangle_Point3_XY(X3, Y3); + Ellipse_Radius_RxRy(X4, Y4); + LCD_CmdWrite(0x67); + LCD_DataWrite(0x8d); + Check_Busy_Draw(); + Check_2D_Busy(); +} + + +void LT768_DrawQuadrilateral_Fill +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X3 // X3 position + , uint16_t Y3 // Y3 position + , uint16_t X4 // X4 position + , uint16_t Y4 // Y4 position + , uint32_t ForegroundColor // line color +) +{ + Foreground_color_65k(ForegroundColor); + Triangle_Point1_XY(X1, Y1); + Triangle_Point2_XY(X2, Y2); + Triangle_Point3_XY(X3, Y3); + Ellipse_Radius_RxRy(X4, Y4); + LCD_CmdWrite(0x67); + LCD_DataWrite(0xa7); + Check_Busy_Draw(); + Check_2D_Busy(); +} + + +//------------------------------------- pentagon ----------------------------------------- + +void LT768_DrawPentagon +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X3 // X3 position + , uint16_t Y3 // Y3 position + , uint16_t X4 // X4 position + , uint16_t Y4 // Y4 position + , uint16_t X5 // X5 position + , uint16_t Y5 // Y5 position + , uint32_t ForegroundColor // line color +) +{ + Foreground_color_65k(ForegroundColor); + Triangle_Point1_XY(X1, Y1); + Triangle_Point2_XY(X2, Y2); + Triangle_Point3_XY(X3, Y3); + Ellipse_Radius_RxRy(X4, Y4); + Ellipse_Center_XY(X5, Y5); + LCD_CmdWrite(0x67); + LCD_DataWrite(0x8F); + Check_Busy_Draw(); + Check_2D_Busy(); +} + + +void LT768_DrawPentagon_Fill +( + uint16_t X1 // X1 position + , uint16_t Y1 // Y1 position + , uint16_t X2 // X2 position + , uint16_t Y2 // Y2 position + , uint16_t X3 // X3 position + , uint16_t Y3 // Y3 position + , uint16_t X4 // X4 position + , uint16_t Y4 // Y4 position + , uint16_t X5 // X5 position + , uint16_t Y5 // Y5 position + , uint32_t ForegroundColor // line color +) +{ + Foreground_color_65k(ForegroundColor); + Triangle_Point1_XY(X1, Y1); + Triangle_Point2_XY(X2, Y2); + Triangle_Point3_XY(X3, Y3); + Ellipse_Radius_RxRy(X4, Y4); + Ellipse_Center_XY(X5, Y5); + LCD_CmdWrite(0x67); + LCD_DataWrite(0xa9); + Check_Busy_Draw(); + Check_2D_Busy(); +} + + +//------------------------------------- cylinder ----------------------------------------- +uint8_t LT768_DrawCylinder +( + uint16_t XCenter // ellipse center x + , uint16_t YCenter // ellipse center y + , uint16_t X_R // radius width + , uint16_t Y_R // radius length + , uint16_t H + , uint32_t CylinderColor // line color + , uint32_t ForegroundColor // background color +) +{ + if(YCenter < H) + { + return 1; + } + +//bottom ellipse + LT768_DrawEllipse_Fill(XCenter, YCenter, X_R, Y_R, ForegroundColor); + LT768_DrawEllipse(XCenter, YCenter, X_R, Y_R, CylinderColor); +//middle rectangle + LT768_DrawSquare_Fill(XCenter-X_R, YCenter-H, XCenter + X_R, YCenter, ForegroundColor); +//top ellipse + LT768_DrawEllipse_Fill(XCenter, YCenter-H, X_R, Y_R, ForegroundColor); + LT768_DrawEllipse(XCenter, YCenter-H, X_R, Y_R, CylinderColor); + LT768_DrawLine(XCenter-X_R, YCenter, XCenter-X_R, YCenter-H, CylinderColor); + LT768_DrawLine(XCenter + X_R, YCenter, XCenter + X_R, YCenter-H, CylinderColor); + return 0; +} + + +//------------------------------------- quadrangular ----------------------------------------- +void LT768_DrawQuadrangular +( + uint16_t X1 + , uint16_t Y1 + , uint16_t X2 + , uint16_t Y2 + , uint16_t X3 + , uint16_t Y3 + , uint16_t X4 + , uint16_t Y4 + , uint16_t X5 + , uint16_t Y5 + , uint16_t X6 + , uint16_t Y6 + , uint32_t QuadrangularColor // line color + , uint32_t ForegroundColor // background color +) +{ + LT768_DrawSquare_Fill(X1, Y1, X5, Y5, ForegroundColor); + LT768_DrawSquare(X1, Y1, X5, Y5, QuadrangularColor); + LT768_DrawQuadrilateral_Fill(X1, Y1, X2, Y2, X3, Y3, X4, Y4, ForegroundColor); + LT768_DrawQuadrilateral(X1, Y1, X2, Y2, X3, Y3, X4, Y4, QuadrangularColor); + LT768_DrawQuadrilateral_Fill(X3, Y3, X4, Y4, X5, Y5, X6, Y6, ForegroundColor); + LT768_DrawQuadrilateral(X3, Y3, X4, Y4, X5, Y5, X6, Y6, QuadrangularColor); +} + + +//-------------------------------------- table ------------------------------------ +void LT768_MakeTable +( + uint16_t X1, // start position X1 + uint16_t Y1, // start position X2 + uint16_t W, + uint16_t H, + uint16_t Line, // line number + uint16_t Row, // row number + uint32_t TableColor, // table color C1 + uint32_t ItemColor, // item background color C2 + uint32_t ForegroundColor, // foreground color C3 + uint16_t width1, // internal width + uint16_t width2, // out-side width + uint8_t mode // 0: vertical 1: cross +) +{ + uint16_t i = 0; + uint16_t x2, y2; + x2 = X1 + W * Row; + y2 = Y1 + H * Line; + LT768_DrawSquare_Width(X1, Y1, x2, y2, TableColor, ForegroundColor, width2); + + if(mode == 0) + { + LT768_DrawSquare_Fill(X1, Y1, X1 + W, y2, ItemColor); + } + else if(mode == 1) + { + LT768_DrawSquare_Fill(X1, Y1, x2, Y1 + H, ItemColor); + } + + for(i = 0 ; i < Line ; i ++) + { + LT768_DrawLine_Width(X1, Y1 + i*H, x2, Y1 + i*H, TableColor, width1); + } + + for(i = 0 ; i < Row ; i ++) + { + LT768_DrawLine_Width(X1 + i*W, Y1, X1 + i*W, y2, TableColor, width1); + } +} + +/*----------------------------------------------------------------------------*/ + +void LT768_Color_Bar_ON(void) +{ + Color_Bar_ON(); +} + +void LT768_Color_Bar_OFF(void) +{ + Color_Bar_OFF(); +} + +/*----------------------------------------------------------------------------*/ + +/*--Flash-->DMA-->SDRAM--*/ +/*address:24bit or 32bit*/ + +void LT768_DMA_24bit_Linear +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t flash_addr // flash start address + , uint32_t memory_addr // memory start address + , uint32_t data_num // data number +) +{ + Enable_SFlash_SPI(); // enable SPI + + if(SCS == 0) + { + Select_SFI_0(); // select extern SPI0 + } + + if(SCS == 1) + { + Select_SFI_1(); // select extern SPI1 + } + + Memory_Linear_Mode(); + Select_SFI_DMA_Mode(); // set SPI DMA mode + SPI_Clock_Period(Clk); // SPI speed + SFI_DMA_Destination_Start_Address(memory_addr); // destination start address + SFI_DMA_Transfer_Number(data_num); // DMA transport number + SFI_DMA_Source_Start_Address(flash_addr); // flash address + Check_Busy_SFI_DMA(); + Start_SFI_DMA(); + Check_Busy_SFI_DMA(); + Memory_XY_Mode(); +} + +void LT768_DMA_32bit_Linear +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t flash_addr // flash start address + , uint32_t memory_addr // memory start address + , uint32_t data_num // data number +) +{ + Enable_SFlash_SPI(); // enable SPI + + if(SCS == 0) + { + Select_SFI_0(); // select extern SPI0 + } + + if(SCS == 1) + { + Select_SFI_1(); // select extern SPI1 + } + + Memory_Linear_Mode(); + Select_SFI_DMA_Mode(); // set SPI DMA mode + Select_SFI_32bit_Address(); + SPI_Clock_Period(Clk); // SPI speed + SFI_DMA_Destination_Start_Address(memory_addr); // destination start address + SFI_DMA_Transfer_Number(data_num); // DMA transport number + SFI_DMA_Source_Start_Address(flash_addr); // flash address + Check_Busy_SFI_DMA(); + Start_SFI_DMA(); + Check_Busy_SFI_DMA(); + Memory_XY_Mode(); +} + +void LT768_DMA_24bit_Block +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint16_t X1 // transport X1 address + , uint16_t Y1 // transport Y1 address + , uint16_t X_W // DMA transport width + , uint16_t Y_H // DMA transport length + , uint16_t P_W // picture width + , uint32_t Addr // flash address +) +{ + Enable_SFlash_SPI(); // enable SPI + + if(SCS == 0) + { + Select_SFI_0(); // select extern SPI0 + } + + if(SCS == 1) + { + Select_SFI_1(); // select extern SPI1 + } + + Select_SFI_DMA_Mode(); // set SPI DMA mode + SPI_Clock_Period(Clk); // set SPI clock frequence divsion factor + Goto_Pixel_XY(X1, Y1); // set memory address + SFI_DMA_Destination_Upper_Left_Corner(X1, Y1); // DMA destination address + SFI_DMA_Transfer_Width_Height(X_W, Y_H); // set block width and length + SFI_DMA_Source_Width(P_W); // set source data width + SFI_DMA_Source_Start_Address(Addr); // set source data in flash address + Start_SFI_DMA(); // start DMA transport + Check_Busy_SFI_DMA(); // check DMA transport finish +} + + +void LT768_DMA_32bit_Block +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint16_t X1 // X1 address + , uint16_t Y1 // Y1 address + , uint16_t X_W // DMA transport width + , uint16_t Y_H // DMA transport length + , uint16_t P_W // picture width + , uint32_t Addr // flash address +) +{ + Enable_SFlash_SPI(); + + if(SCS == 0) + { + Select_SFI_0(); + } + + if(SCS == 1) + { + Select_SFI_1(); + } + + Select_SFI_DMA_Mode(); + SPI_Clock_Period(Clk); + Select_SFI_32bit_Address(); + Goto_Pixel_XY(X1, Y1); + SFI_DMA_Destination_Upper_Left_Corner(X1, Y1); + SFI_DMA_Transfer_Width_Height(X_W, Y_H); + SFI_DMA_Source_Width(P_W); + SFI_DMA_Source_Start_Address(Addr); + Start_SFI_DMA(); + Check_Busy_SFI_DMA(); + Select_SFI_24bit_Address(); +} + +/*----------------------------------------------------------------------------*/ +/* select integrated font initialization */ +void LT768_Select_Internal_Font_Init +( + uint8_t Size // set word size 16:16*16 24:24*24 32:32*32 + , uint8_t XxN // word width enlargement factor: 1~4 + , uint8_t YxN // word length enlargement factor: 1~4 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint8_t Alignment // 0:no font no align 1:font align +) +{ + if(Size == 16) + { + Font_Select_8x16_16x16(); + } + + if(Size == 24) + { + Font_Select_12x24_24x24(); + } + + if(Size == 32) + { + Font_Select_16x32_32x32(); + } + +//(*) + if(XxN == 1) + { + Font_Width_X1(); + } + + if(XxN == 2) + { + Font_Width_X2(); + } + + if(XxN == 3) + { + Font_Width_X3(); + } + + if(XxN == 4) + { + Font_Width_X4(); + } + +//(*) + if(YxN == 1) + { + Font_Height_X1(); + } + + if(YxN == 2) + { + Font_Height_X2(); + } + + if(YxN == 3) + { + Font_Height_X3(); + } + + if(YxN == 4) + { + Font_Height_X4(); + } + +//(*) + if(ChromaKey == 0) + { + Font_Background_select_Color(); + } + + if(ChromaKey == 1) + { + Font_Background_select_Transparency(); + } + +//(*) + if(Alignment == 0) + { + Disable_Font_Alignment(); + } + + if(Alignment == 1) + { + Enable_Font_Alignment(); + } +} + + +/* print integrated font*/ +void LT768_Print_Internal_Font_String +( + uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color(when font background is transparent, it is invalid) + , char *c // data start address +) +{ + Text_Mode(); + CGROM_Select_Internal_CGROM(); + Foreground_color_65k(FontColor); + Background_color_65k(BackGroundColor); + Goto_Text_XY(x, y); + Show_String(c); +} + + +/* select integrated font initialization */ +void LT768_Select_Outside_Font_Init +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t FlashAddr // source address(Flash) + , uint32_t MemoryAddr // destination address(SDRAM) + , uint32_t Num // word lib size + , uint8_t Size // set word size 16:16*16 24:24*24 32:32*32 + , uint8_t XxN // word width enlargement factor: 1~4 + , uint8_t YxN // word length enlargement factor: 1~4 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint8_t Alignment // 0:no font no align 1:font align +) +{ + if(Size == 16) + { + Font_Select_8x16_16x16(); + } + + if(Size == 24) + { + Font_Select_12x24_24x24(); + } + + if(Size == 32) + { + Font_Select_16x32_32x32(); + } + +//(*) + if(XxN == 1) + { + Font_Width_X1(); + } + + if(XxN == 2) + { + Font_Width_X2(); + } + + if(XxN == 3) + { + Font_Width_X3(); + } + + if(XxN == 4) + { + Font_Width_X4(); + } + +//(*) + if(YxN == 1) + { + Font_Height_X1(); + } + + if(YxN == 2) + { + Font_Height_X2(); + } + + if(YxN == 3) + { + Font_Height_X3(); + } + + if(YxN == 4) + { + Font_Height_X4(); + } + +//(*) + if(ChromaKey == 0) + { + Font_Background_select_Color(); + } + + if(ChromaKey == 1) + { + Font_Background_select_Transparency(); + } + +//(*) + if(Alignment == 0) + { + Disable_Font_Alignment(); + } + + if(Alignment == 1) + { + Enable_Font_Alignment(); + } + + LT768_DMA_24bit_Linear(SCS, Clk, FlashAddr, MemoryAddr, Num); + CGRAM_Start_address(MemoryAddr); +} + +/* print outsize and integrated font */ +void LT768_Print_Outside_Font_String +( + uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint8_t *c // data start address +) +{ + uint16_t temp_H = 0; + uint16_t temp_L = 0; + uint16_t temp = 0; + uint32_t i = 0; + Text_Mode(); + Font_Select_UserDefine_Mode(); + Foreground_color_65k(FontColor); + Background_color_65k(BackGroundColor); + Goto_Text_XY(x, y); + + while(c[i] != '\0') + { + if(c[i] < 0xa1) + { + CGROM_Select_Internal_CGROM(); // fond source use inside CGROM + LCD_CmdWrite(0x04); + LCD_DataWrite(c[i]); + Check_Mem_WR_FIFO_not_Full(); + i += 1; + } + else + { + Font_Select_UserDefine_Mode(); // user define font + LCD_CmdWrite(0x04); + temp_H = ((c[i] - 0xa1) & 0x00ff) * 94; + temp_L = c[i + 1] - 0xa1; + temp = temp_H + temp_L + 0x8000; + LCD_DataWrite((temp>>8)&0xff); + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite(temp&0xff); + Check_Mem_WR_FIFO_not_Full(); + i += 2; + } + } + + Check_2D_Busy(); + Graphic_Mode(); //back to graphic mode; +} + +/* print external GBK and integrated font */ +void LT768_Print_Outside_Font_GBK_String +( + uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint8_t *c // data start address +) +{ + uint16_t temp_H = 0; + uint16_t temp_L = 0; + uint16_t temp = 0; + uint32_t i = 0; + Text_Mode(); + Font_Select_UserDefine_Mode(); + Foreground_color_65k(FontColor); + Background_color_65k(BackGroundColor); + Goto_Text_XY(x, y); + + while(c[i] != '\0') + { + if(c[i] < 0x81) + { + CGROM_Select_Internal_CGROM(); // fond source use inside CGROM + LCD_CmdWrite(0x04); + LCD_DataWrite(c[i]); + Check_Mem_WR_FIFO_not_Full(); + i += 1; + } + else + { + Font_Select_UserDefine_Mode(); // user define font + LCD_CmdWrite(0x04); + temp_H = ((c[i] - 0x81) & 0x00ff) * 191; + temp_L = c[i + 1] - 0x40; + temp = temp_H + temp_L + 0x8000; + LCD_DataWrite((temp>>8)&0xff); + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite(temp&0xff); + Check_Mem_WR_FIFO_not_Full(); + i += 2; + } + } + + Check_2D_Busy(); + Graphic_Mode(); //back to graphic mode; +} + +/*print 48*48,72*72 font */ +void LT768_BTE_Memory_Copy_ColorExpansion_8 +( + uint32_t S0_Addr // SO memory start address + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X(show window start X) + , uint16_t YDes // destination top-left Y(show window start y) + , uint16_t X_W // show window width + , uint16_t Y_H // show window length + , uint32_t Foreground_color + , uint32_t Background_color +) +{ + Foreground_color_256(Foreground_color); + Background_color_256(Background_color); + BTE_ROP_Code(7); + BTE_S0_Color_8bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(Des_W); + BTE_S0_Window_Start_XY(YS0, 0); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Operation_Code(0x0e); //BTE Operation: Memory copy (move) with chroma keying (w/o ROP) + BTE_Window_Size(X_W, Y_H); + BTE_Enable(); + Check_BTE_Busy(); +} + +void LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8 +( + uint32_t S0_Addr // SO memory start address + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X(show window start X) + , uint16_t YDes // destination top-left Y(show window start y) + , uint16_t X_W // show window width + , uint16_t Y_H // show window length + , uint32_t Foreground_color +) +{ + Foreground_color_256(Foreground_color); + BTE_ROP_Code(7); + BTE_S0_Color_8bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(Des_W); + BTE_S0_Window_Start_XY(YS0, 0); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Operation_Code(0x0f); //BTE Operation: Memory copy (move) with chroma keying (w/o ROP) + BTE_Window_Size(X_W, Y_H); + BTE_Enable(); + Check_BTE_Busy(); +} + +void LT768_Print_Outside_Font_GB2312_48_72 +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t FlashAddr // font source address(Flash) + , uint32_t MemoryAddr // destination address(SDRAM) + , uint32_t ShowAddr // show layer address + , uint16_t width // show layer width + , uint8_t Size // set word size 48:48*48 72:72*72 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint16_t w // font thinkness: 0: not overstriking 1: 1 overstriking 2: 2 overstriking + , uint16_t s // linewidth + , uint8_t *c // data start address +) +{ + uint16_t temp_H = 0; + uint16_t temp_L = 0; + uint16_t temp = 0; + uint32_t i = 0; + uint16_t j = 0; + uint16_t k = 0; + uint16_t h = 0; + uint16_t n = 0; + uint16_t m = 0; + uint16_t g = 0; + uint16_t f = 0; + h = x; + k = y; + Memory_8bpp_Mode();//save picture with 8bit color depth + Canvas_Image_Start_address(MemoryAddr); + Canvas_image_width(width); + + while(c[i] != '\0') + { + temp_H = (c[i] - 0xa1) * 94; + temp_L = c[i + 1] - 0xa1; + temp = temp_H + temp_L; + LT768_DMA_24bit_Block(SCS, Clk, Size * j / 8, 0, Size / 8, Size, Size / 8, + FlashAddr + temp * ((Size * Size) / 8)); + i += 2; + j ++; + } + + Memory_16bpp_Mode(); + Canvas_Image_Start_address(ShowAddr); + Canvas_image_width(width); + j = 0; + i = 0; + + if(w > 2) + { + w = 2; + } + + for(g=0; g(width*(n + 1)))) + { + m ++; + n ++; + y=y + Size-1 + s; + x = x + ((width*n)-(x + Size*j)) + g; + f=n; + } + + if(ChromaKey == 1) + { + LT768_BTE_Memory_Copy_ColorExpansion_8( + MemoryAddr, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor, BackGroundColor + ); + } + + if(ChromaKey == 0) + { + LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8( + MemoryAddr, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor + ); + } + + i += 2; + j ++; + } + + ChromaKey=0; + i = 0; + j = 0; + m = 0; + n = 0; + f = 0; + x = h + g + 1; + y = k + g + 1; + } +} + + +void LT768_Print_Outside_Font_BIG5_48_72 +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t FlashAddr // font source address(Flash) + , uint32_t MemoryAddr // destination address(SDRAM) + , uint32_t ShowAddr // show layer address + , uint16_t width // show layer width + , uint8_t Size // set word size 48:48*48 72:72*72 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint16_t w // font thinkness: 0: not overstriking 1: 1 overstriking 2: 2 overstriking + , uint16_t s // linewidth + , uint8_t *c // data start address +) +{ + uint16_t temp_H = 0; + uint16_t temp_L = 0; + uint16_t temp = 0; + uint32_t i = 0; + uint16_t j = 0; + uint16_t k = 0; + uint16_t h = 0; + uint16_t n = 0; + uint16_t m = 0; + uint16_t g = 0; + uint16_t f = 0; + h = x; + k = y; + Memory_8bpp_Mode();//save picture with 8bit color depth + Canvas_Image_Start_address(MemoryAddr); + Canvas_image_width(width); + + while(c[i] != '\0') + { + temp_H = (c[i] - 0xa1) * 160; + + if(c[i + 1]<0x7f) + { + temp_L = c[i + 1] - 0x40; + } + else + { + temp_L = c[i + 1] - 0xa0 + 0x40; + } + + temp = temp_H + temp_L; + LT768_DMA_24bit_Block(SCS, Clk, Size * j / 8, 0, Size / 8, Size, Size / 8, + FlashAddr + temp * ((Size * Size) / 8)); + i += 2; + j ++; + } + + Memory_16bpp_Mode(); // print 16bits color depth + Canvas_Image_Start_address(ShowAddr); + Canvas_image_width(width); + j = 0; + i = 0; + + for(g=0; g(1024*(n + 1)))) + { + m ++; + n ++; + y=y + Size-1 + s; + x = x + ((1024*n)-(x + Size*j)) + g; + f=n; + } + + if(ChromaKey == 1) + { + LT768_BTE_Memory_Copy_ColorExpansion_8( + MemoryAddr, Size * j / 8, + ShowAddr, LCD_XSIZE_TFT, x + Size * j, y, + Size, Size, FontColor, BackGroundColor + ); + } + + if(ChromaKey == 0) + { + LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8( + MemoryAddr, Size * j / 8, + ShowAddr, LCD_XSIZE_TFT, x + Size * j, y, + Size, Size, FontColor + ); + } + + i += 2; + j ++; + } + + ChromaKey=0; + i = 0; + j = 0; + m = 0; + n = 0; + f = 0; + x = h + g + 1; + y = k + g + 1; + } +} + +void LT768_Print_Outside_Font_GBK_48_72 +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t FlashAddr // font source address(Flash) + , uint32_t MemoryAddr // destination address(SDRAM) + , uint32_t ShowAddr // show layer address + , uint16_t width // show layer width + , uint8_t Size // set word size 48:48*48 72:72*72 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint16_t w // font thinkness: 0: not overstriking 1: 1 overstriking 2: 2 overstriking + , uint16_t s // linewidth + , uint8_t *c // data start address +) +{ + uint16_t temp_H = 0; + uint16_t temp_L = 0; + uint16_t temp = 0; + uint32_t i = 0; + uint16_t j = 0; + uint16_t k = 0; + uint16_t h = 0; + uint16_t n = 0; + uint16_t m = 0; + uint16_t g = 0; + uint16_t f = 0; + h = x; + k = y; + Memory_8bpp_Mode();//save picture with 8bit color depth + Canvas_Image_Start_address(MemoryAddr); + Canvas_image_width(width); + + while(c[i] != '\0') + { + temp_H = (c[i] - 0x81) * 191; + temp_L = c[i + 1] - 0x40; + temp = temp_H + temp_L; + LT768_DMA_24bit_Block(SCS, Clk, Size * j / 8, 0, Size / 8, Size, Size / 8, + FlashAddr + temp * ((Size * Size) / 8)); + i += 2; + j ++; + } + + Memory_16bpp_Mode(); + Canvas_Image_Start_address(ShowAddr); + Canvas_image_width(width); + j = 0; + i = 0; + + if(w > 2) + { + w = 2; + } + + for(g=0; g(width*(n + 1)))) + { + m ++; + n ++; + y=y + Size-1 + s; + x = x + ((width*n)-(x + Size*j)) + g; + f=n; + } + + if(ChromaKey == 1) + { + LT768_BTE_Memory_Copy_ColorExpansion_8( + MemoryAddr, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor, BackGroundColor + ); + } + + if(ChromaKey == 0) + { + LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8( + MemoryAddr, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor + ); + } + + i += 2; + j ++; + } + + ChromaKey = 0; + i = 0; + j = 0; + m = 0; + n = 0; + f = 0; + x = h + g + 1; + y = k + g + 1; + } +} + +/*user-defined font*/ +//only input chinese font +#define Font_size 200 //define font size +#define Font_BYTE Font_size * 2 +uint8_t Font_1[Font_BYTE]; + +void clear_Font_1(void) +{ + uint16_t i; + + for(i = 0; i < Font_BYTE; i ++) + { + Font_1[i] = 0; + } +} + +int Get_User_Font_P(char chH, char chL) +{ + int i; + + for(i = 0; i <(sizeof(Font_1)/2); i ++) + { + if((chH == Font_1[i * 2]) && (chL == Font_1[i * 2 + 1])) + { + return i; + } + } + + return -1; +} + +void LT768_Print_Outside_UserDefineFont_GB2312 +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t FlashAddr // font source address(Flash) + , uint32_t MemoryAddr // destination address(SDRAM) + , uint32_t ShowAddr // show layer address + , uint16_t width // show layer width + , uint8_t Size // set word size 48:48*48 72:72*72 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint16_t w // font thinkness: 0: not overstriking 1: 1 overstriking 2: 2 overstriking + , uint16_t s // linewidth + , uint8_t *c // data start address +) +{ + short temp = 0; + uint32_t i = 0; + uint16_t j = 0; + uint16_t k = 0; + uint16_t h = 0; + uint16_t n = 0; + uint16_t m = 0; + uint16_t g = 0; + uint16_t f = 0; + uint8_t temp1[2] = {0}; + uint32_t fontNum = 0; + clear_Font_1(); + LT768_SPI_Init(SCS, 1); + LT_W25QXX_Read(temp1, FlashAddr + 8, 2); + fontNum = (temp1[0] << 8) + temp1[1]; + LT_W25QXX_Read(Font_1, FlashAddr + 0xc, fontNum * 2); + h = x; + k = y; + Memory_8bpp_Mode();//save picture with 8bit color depth + Canvas_Image_Start_address(MemoryAddr); + Canvas_image_width(width); + + while(c[i] != '\0') + { + temp = Get_User_Font_P(c[i], c[i + 1]); + + if(temp>-1) + { + LT768_DMA_24bit_Block(SCS, Clk, Size * j / 8, 0, Size / 8, Size, Size / 8, + FlashAddr + temp*((Size*Size)/8) + 0x0c + fontNum*2); + } + + i += 2; + j ++; + } + + Memory_16bpp_Mode(); + Canvas_Image_Start_address(ShowAddr); + Canvas_image_width(width); + j = 0; + i = 0; + + if(w > 2) + { + w = 2; + } + + for(g=0; g(width*(n + 1)))) + { + m ++; + n ++; + y=y + Size-1 + s; + x = x + ((width*n)-(x + Size*j)) + g; + f=n; + } + + if(ChromaKey == 1) + { + LT768_BTE_Memory_Copy_ColorExpansion_8( + MemoryAddr, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor, BackGroundColor + ); + } + + if(ChromaKey == 0) + { + LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8( + MemoryAddr, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor + ); + } + + i += 2; + j ++; + } + + ChromaKey = 0; + i = 0; + j = 0; + m = 0; + n = 0; + f = 0; + x = h + g + 1; + y = k + g + 1; + } +} + +/*----------------------------------------------------------------------------*/ + +void LT768_Text_cursor_Init +( + uint8_t On_Off_Blinking // 0: disable 1: enable blink + , uint16_t Blinking_Time // set time of blink + , uint16_t X_W // font cursor width + , uint16_t Y_W // font cursor length +) +{ + if(On_Off_Blinking == 0) + { + Disable_Text_Cursor_Blinking(); + } + + if(On_Off_Blinking == 1) + { + Enable_Text_Cursor_Blinking(); + } + + Blinking_Time_Frames(Blinking_Time); +//[3E][3Fh] + Text_Cursor_H_V(X_W, Y_W); + Enable_Text_Cursor(); +} + + +void LT768_Enable_Text_Cursor(void) +{ + Enable_Text_Cursor(); +} + + +void LT768_Disable_Text_Cursor(void) +{ + Disable_Text_Cursor(); +} + + +void LT768_Graphic_cursor_Init +( + uint8_t Cursor_N // select cursor 1 2 3 4 + , uint8_t Color1 // color1 + , uint8_t Color2 // color2 + , uint16_t X_Pos // print coordinationX + , uint16_t Y_Pos // print coordinationY + , uint8_t *Cursor_Buf // cursor buffer start address +) +{ + uint32_t i ; + Memory_Select_Graphic_Cursor_RAM(); + Graphic_Mode(); + + switch(Cursor_N) + { + case 1: + Select_Graphic_Cursor_1(); + break; + + case 2: + Select_Graphic_Cursor_2(); + break; + + case 3: + Select_Graphic_Cursor_3(); + break; + + case 4: + Select_Graphic_Cursor_4(); + break; + + default: + break; + } + + LCD_CmdWrite(0x04); + + for(i = 0; i < 256; i ++) + { + LCD_DataWrite(Cursor_Buf[i]); + } + + Memory_Select_SDRAM();//go back to SDRAM after write finish + Set_Graphic_Cursor_Color_1(Color1); + Set_Graphic_Cursor_Color_2(Color2); + Graphic_Cursor_XY(X_Pos, Y_Pos); + Enable_Graphic_Cursor(); +} + + +void LT768_Set_Graphic_cursor_Pos +( + uint8_t Cursor_N // select cursor 1 2 3 4 + , uint16_t X_Pos // print coordinationX + , uint16_t Y_Pos // print coordinationY +) +{ + Graphic_Cursor_XY(X_Pos, Y_Pos); + + switch(Cursor_N) + { + case 1: + Select_Graphic_Cursor_1(); + break; + + case 2: + Select_Graphic_Cursor_2(); + break; + + case 3: + Select_Graphic_Cursor_3(); + break; + + case 4: + Select_Graphic_Cursor_4(); + break; + + default: + break; + } +} + + +void LT768_Enable_Graphic_Cursor(void) +{ + Enable_Graphic_Cursor(); +} + + +void LT768_Disable_Graphic_Cursor(void) +{ + Disable_Graphic_Cursor(); +} + +/*----------------------------------------------------------------------------*/ + +void LT768_PIP_Init +( + uint8_t On_Off // 0 : disable PIP 1 : enable PIP 2 : keep + , uint8_t Select_PIP // 1 : use PIP1 2 : use PIP2 + , uint32_t PAddr // PIP start address + , uint16_t XP // PIP window X coordiation must divisible by 4 + , uint16_t YP // // PIP window Y coordiation must divisible by 4 + , uint32_t ImageWidth // image width + , uint16_t X_Dis // print windows X coordination + , uint16_t Y_Dis // print windows Y coordination + , uint16_t X_W // show window width, must be divisible by 4 + , uint16_t Y_H // show window length, must be divisible by 4 +) +{ + if(Select_PIP == 1) + { + Select_PIP1_Window_16bpp(); + Select_PIP1_Parameter(); + } + + if(Select_PIP == 2) + { + Select_PIP2_Window_16bpp(); + Select_PIP2_Parameter(); + } + + PIP_Display_Start_XY(X_Dis, Y_Dis); + PIP_Image_Start_Address(PAddr); + PIP_Image_Width(ImageWidth); + PIP_Window_Image_Start_XY(XP, YP); + PIP_Window_Width_Height(X_W, Y_H); + + if(On_Off == 0) + { + if(Select_PIP == 1) + { + Disable_PIP1(); + } + + if(Select_PIP == 2) + { + Disable_PIP2(); + } + } + + if(On_Off == 1) + { + if(Select_PIP == 1) + { + Enable_PIP1(); + } + + if(Select_PIP == 2) + { + Enable_PIP2(); + } + } +} + + +void LT768_Set_DisWindowPos +( + uint8_t On_Off // 0: disable PIP, 1: enable PIP, 2: keep + , uint8_t Select_PIP // 1: use PIP1, 2: use PIP2 + , uint16_t X_Dis // print windows X coordination + , uint16_t Y_Dis // print windows Y coordination +) +{ + if(Select_PIP == 1) + { + Select_PIP1_Parameter(); + } + + if(Select_PIP == 2) + { + Select_PIP2_Parameter(); + } + + if(On_Off == 0) + { + if(Select_PIP == 1) + { + Disable_PIP1(); + } + + if(Select_PIP == 2) + { + Disable_PIP2(); + } + } + + if(On_Off == 1) + { + if(Select_PIP == 1) + { + Enable_PIP1(); + } + + if(Select_PIP == 2) + { + Enable_PIP2(); + } + } + + PIP_Display_Start_XY(X_Dis, Y_Dis); +} + +/*----------------------------------------------------------------------------*/ + +void BTE_Solid_Fill +( + uint32_t Des_Addr // fill destination address + , uint16_t Des_W // destination picture width + , uint16_t XDes + , uint16_t YDes + , uint16_t color // fill color + , uint16_t X_W // fill length + , uint16_t Y_H // fill width +) +{ + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Window_Size(X_W, Y_H); + Foreground_color_65k(color); + BTE_Operation_Code(0x0c); + BTE_Enable(); + Check_BTE_Busy(); +} + +/* BTE memory copy with raster operation*/ +void LT768_BTE_Memory_Copy +( + uint32_t S0_Addr // SO memory start address + , uint16_t S0_W // SO memory width + , uint16_t XS0 // SO top-left X coordinate + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t S1_Addr // S1 memory start address + , uint16_t S1_W // S1 width + , uint16_t XS1 // S1 top-left X + , uint16_t YS1 // S1 top-left Y + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left Y + , uint32_t ROP_Code // raster operation mode + /*ROP_Code : + 0000b 0(Blackness) + 0001b ~S0!E~S1 or ~(S0 + S1) + 0010b ~S0!ES1 + 0011b ~S0 + 0100b S0!E~S1 + 0101b ~S1 + 0110b S0^S1 + 0111b ~S0 + ~S1 or ~(S0 + S1) + 1000b S0!ES1 + 1001b ~(S0^S1) + 1010b S1 + 1011b ~S0 + S1 + 1100b S0 + 1101b S0 + ~S1 + 1110b S0 + S1 + 1111b 1(whiteness)*/ + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length +) +{ + BTE_S0_Color_16bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(S0_W); + BTE_S0_Window_Start_XY(XS0, YS0); + BTE_S1_Color_16bpp(); + BTE_S1_Memory_Start_Address(S1_Addr); + BTE_S1_Image_Width(S1_W); + BTE_S1_Window_Start_XY(XS1, YS1); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_ROP_Code(ROP_Code); + BTE_Operation_Code(0x02); //BTE Operation: Memory copy (move) with ROP. + BTE_Window_Size(X_W, Y_H); + BTE_Enable(); + Check_BTE_Busy(); +} + + +/* memory copy with Chroma Key (not include ROP) */ +void LT768_BTE_Memory_Copy_Chroma_key +( + uint32_t S0_Addr // SO memory start address + , uint16_t S0_W // SO memory width + , uint16_t XS0 // SO top-left X coordinate + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left X + , uint32_t Background_color // transparent color + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length +) +{ + Background_color_65k(Background_color); + BTE_S0_Color_16bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(S0_W); + BTE_S0_Window_Start_XY(XS0, YS0); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Operation_Code(0x05); //BTE Operation: Memory copy (move) with chroma keying (w/o ROP) + BTE_Window_Size(X_W, Y_H); + BTE_Enable(); + Check_BTE_Busy(); +} + + +void LT768_BTE_Pattern_Fill +( + uint8_t P_8x8_or_16x16 // 0 : use 8x8 Icon , 1 : use 16x16 Icon. + , uint32_t S0_Addr // SO memory start address + , uint16_t S0_W // SO memory width + , uint16_t XS0 // SO top-left X coordinate + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left X + , uint32_t ROP_Code // raster operation mode + /*ROP_Code : + 0000b 0(Blackness) + 0001b ~S0!E~S1 or ~(S0 + S1) + 0010b ~S0!ES1 + 0011b ~S0 + 0100b S0!E~S1 + 0101b ~S1 + 0110b S0^S1 + 0111b ~S0 + ~S1 or ~(S0 + S1) + 1000b S0!ES1 + 1001b ~(S0^S1) + 1010b S1 + 1011b ~S0 + S1 + 1100b S0 + 1101b S0 + ~S1 + 1110b S0 + S1 + 1111b 1(whiteness)*/ + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length +) +{ + if(P_8x8_or_16x16 == 0) + { + Pattern_Format_8X8(); + } + + if(P_8x8_or_16x16 == 1) + { + Pattern_Format_16X16(); + } + + BTE_S0_Color_16bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(S0_W); + BTE_S0_Window_Start_XY(XS0, YS0); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_ROP_Code(ROP_Code); + BTE_Operation_Code(0x06); //BTE Operation: Pattern Fill with ROP. + BTE_Window_Size(X_W, Y_H); + BTE_Enable(); + Check_BTE_Busy(); +} + + +void LT768_BTE_Pattern_Fill_With_Chroma_key +( + uint8_t P_8x8_or_16x16 // 0 : use 8x8 Icon , 1 : use 16x16 Icon. + , uint32_t S0_Addr // SO memory start address + , uint16_t S0_W // SO memory width + , uint16_t XS0 // SO top-left X coordinate + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left Y + , uint32_t ROP_Code // raster operation mode + /*ROP_Code : + 0000b 0(Blackness) + 0001b ~S0!E~S1 or ~(S0 + S1) + 0010b ~S0!ES1 + 0011b ~S0 + 0100b S0!E~S1 + 0101b ~S1 + 0110b S0^S1 + 0111b ~S0 + ~S1 or ~(S0 + S1) + 1000b S0!ES1 + 1001b ~(S0^S1) + 1010b S1 + 1011b ~S0 + S1 + 1100b S0 + 1101b S0 + ~S1 + 1110b S0 + S1 + 1111b 1(whiteness)*/ + , uint32_t Background_color // transparent color + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length +) +{ + Background_color_65k(Background_color); + + if(P_8x8_or_16x16 == 0) + { + Pattern_Format_8X8(); + } + + if(P_8x8_or_16x16 == 1) + { + Pattern_Format_16X16(); + } + + BTE_S0_Color_16bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(S0_W); + BTE_S0_Window_Start_XY(XS0, YS0); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_ROP_Code(ROP_Code); + BTE_Operation_Code(0x07); //BTE Operation: Pattern Fill with Chroma key. + BTE_Window_Size(X_W, Y_H); + BTE_Enable(); + Check_BTE_Busy(); +} + +void LT768_BTE_MCU_Write_MCU_16bit +( + uint32_t S1_Addr // S1 memory start address + , uint16_t S1_W // S1 width + , uint16_t XS1 // S1 top-left X + , uint16_t YS1 // S1 top-left Y + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left Y + , uint32_t ROP_Code // raster operation mode + /*ROP_Code : + 0000b 0(Blackness) + 0001b ~S0!E~S1 or ~(S0 + S1) + 0010b ~S0!ES1 + 0011b ~S0 + 0100b S0!E~S1 + 0101b ~S1 + 0110b S0^S1 + 0111b ~S0 + ~S1 or ~(S0 + S1) + 1000b S0!ES1 + 1001b ~(S0^S1) + 1010b S1 + 1011b ~S0 + S1 + 1100b S0 + 1101b S0 + ~S1 + 1110b S0 + S1 + 1111b 1(whiteness)*/ + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length + , const uint16_t *data // S0 start address +) +{ + uint16_t i, j; + BTE_S1_Color_16bpp(); + BTE_S1_Memory_Start_Address(S1_Addr); + BTE_S1_Image_Width(S1_W); + BTE_S1_Window_Start_XY(XS1, YS1); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Window_Size(X_W, Y_H); + BTE_ROP_Code(ROP_Code); + BTE_Operation_Code(0x00); //BTE Operation: MPU Write with ROP. + BTE_Enable(); + BTE_S0_Color_16bpp(); + LCD_CmdWrite(0x04); //Memory Data Read/Write Port + +//MCU_16bit_ColorDepth_16bpp + for(i = 0; i < Y_H; i ++) + { + for(j = 0; j < (X_W); j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite_Pixel((*data)); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); + Check_BTE_Busy(); +} + + +void LT768_BTE_MCU_Write_Chroma_key_MCU_16bit +( + uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left Y + , uint32_t Background_color // transparent color + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length + , const uint16_t *data // S0 receive address +) +{ + uint32_t i, j; + Background_color_65k(Background_color); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Window_Size(X_W, Y_H); + BTE_Operation_Code(0x04); //BTE Operation: MPU Write with chroma keying (w/o ROP) + BTE_Enable(); + BTE_S0_Color_16bpp(); + LCD_CmdWrite(0x04); //Memory Data Read/Write Port + +//MCU_16bit_ColorDepth_16bpp + for(i = 0; i < Y_H; i ++) + { + for(j = 0; j < (X_W); j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite_Pixel((*data)); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); + Check_BTE_Busy(); +} + + +/* MPU write with expansion color */ +void LT768_BTE_MCU_Write_ColorExpansion_MCU_16bit +( + uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left Y + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length + , uint32_t Foreground_color // foreground color + /*Foreground_color : The source (1bit map picture) map data 1 translate to Foreground color by color expansion*/ + , uint32_t Background_color // background color + /*Background_color : The source (1bit map picture) map data 0 translate to Background color by color expansion*/ + , const uint16_t *data // buffer start address +) +{ + uint16_t i, j; + RGB_16b_16bpp(); + Foreground_color_65k(Foreground_color); + Background_color_65k(Background_color); + BTE_ROP_Code(15); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Window_Size(X_W, Y_H); + BTE_Operation_Code(0x8); //BTE Operation: MPU Write with Color Expansion (w/o ROP) + BTE_Enable(); + LCD_CmdWrite(0x04); //Memory Data Read/Write Port + + for(i = 0; i < Y_H; i ++) + { + for(j = 0; j < X_W/16; j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite_Pixel(*data); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); + Check_BTE_Busy(); +} + +/* MPU write with expansion color and chroma key */ +void LT768_BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_16bit +( + uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left Y + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length + , uint32_t Foreground_color // foreground color + /*Foreground_color : The source (1bit map picture) map data 1 translate to Foreground color by color expansion*/ + , const uint16_t *data // buffer start address +) +{ + uint16_t i, j; + RGB_16b_16bpp(); + Foreground_color_65k(Foreground_color); + BTE_ROP_Code(15); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Window_Size(X_W, Y_H); + BTE_Operation_Code(0x9); //BTE Operation: MPU Write with Color Expansion and chroma keying (w/o ROP) + BTE_Enable(); + LCD_CmdWrite(0x04); //Memory Data Read/Write Port + + for(i = 0; i < Y_H; i ++) + { + for(j = 0; j < X_W/16; j ++) + { + Check_Mem_WR_FIFO_not_Full(); + LCD_DataWrite_Pixel(*data); + data ++; + } + } + + Check_Mem_WR_FIFO_Empty(); + Check_BTE_Busy(); +} + +/* memory copy with transparent */ +void BTE_Alpha_Blending +( + uint32_t S0_Addr // SO memory start address + , uint16_t S0_W // SO memory width + , uint16_t XS0 // SO top-left X coordinate + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t S1_Addr // S1 memory start address + , uint16_t S1_W // S1 width + , uint16_t XS1 // S1 top-left X + , uint16_t YS1 // S1 top-left Y + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left X + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length + , uint8_t alpha // transparent grade (32) +) +{ + BTE_S0_Color_16bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(S0_W); + BTE_S0_Window_Start_XY(XS0, YS0); + BTE_S1_Color_16bpp(); + BTE_S1_Memory_Start_Address(S1_Addr); + BTE_S1_Image_Width(S1_W); + BTE_S1_Window_Start_XY(XS1, YS1); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Window_Size(X_W, Y_H); + BTE_Operation_Code(0x0A); //BTE Operation: Memory write with opacity (w/o ROP) + BTE_Alpha_Blending_Effect(alpha); + BTE_Enable(); + Check_BTE_Busy(); +} + +void BTE_Pixel_8bpp_Alpha_Blending +( + uint32_t S0_Addr // SO memory start address + , uint16_t S0_W // SO memory width + , uint16_t XS0 // SO top-left X coordinate + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t S1_Addr // S1 memory start address + , uint16_t S1_W // S1 width + , uint16_t XS1 // S1 top-left X + , uint16_t YS1 // S1 top-left Y + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left X + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length +) +{ + BTE_S0_Color_8bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(S0_W); + BTE_S0_Window_Start_XY(XS0, YS0); + BTE_S1_Color_8bit_Alpha(); + BTE_S1_Memory_Start_Address(S1_Addr); + BTE_S1_Image_Width(S1_W); + BTE_S1_Window_Start_XY(XS1, YS1); + BTE_Destination_Color_8bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Window_Size(X_W, Y_H); + BTE_Operation_Code(0x0A); //BTE Operation: Memory write with opacity (w/o ROP) + BTE_Enable(); + Check_BTE_Busy(); +} + +void BTE_Pixel_16bpp_Alpha_Blending +( + uint32_t S0_Addr // SO memory start address + , uint16_t S0_W // SO memory width + , uint16_t XS0 // SO top-left X coordinate + , uint16_t YS0 // SO top-left Y coordinate + , uint32_t S1_Addr // S1 memory start address + , uint16_t S1_W // S1 width + , uint16_t XS1 // S1 top-left X + , uint16_t YS1 // S1 top-left Y + , uint32_t Des_Addr // destination memory start address + , uint16_t Des_W // destination memory width + , uint16_t XDes // destination top-left X + , uint16_t YDes // destination top-left X + , uint16_t X_W // active windows width + , uint16_t Y_H // active windows length +) +{ + BTE_S0_Color_16bpp(); + BTE_S0_Memory_Start_Address(S0_Addr); + BTE_S0_Image_Width(S0_W); + BTE_S0_Window_Start_XY(XS0, YS0); + BTE_S1_Color_16bit_Alpha(); + BTE_S1_Memory_Start_Address(S1_Addr); + BTE_S1_Image_Width(S1_W); + BTE_S1_Window_Start_XY(XS1, YS1); + BTE_Destination_Color_16bpp(); + BTE_Destination_Memory_Start_Address(Des_Addr); + BTE_Destination_Image_Width(Des_W); + BTE_Destination_Window_Start_XY(XDes, YDes); + BTE_Window_Size(X_W, Y_H); + BTE_Operation_Code(0x0A); //BTE Operation: Memory write with opacity (w/o ROP) + BTE_Enable(); + Check_BTE_Busy(); +} + +/*----------------------------------------------------------------------------*/ + +void LT768_PWM0_Init +( + uint8_t on_off // 0: enable PWM0 1: enable PWM0 + , uint8_t Clock_Divided // PWM clock frequency division range 0~3(1, 1/2, 1/4, 1/8) + , uint8_t Prescalar // clock frequency range 1~256 + , uint16_t Count_Buffer // PWM output period + , uint16_t Compare_Buffer // set duty ratio +) +{ + Select_PWM0(); + Set_PWM_Prescaler_1_to_256(Prescalar); + + if(Clock_Divided == 0) + { + Select_PWM0_Clock_Divided_By_1(); + } + + if(Clock_Divided == 1) + { + Select_PWM0_Clock_Divided_By_2(); + } + + if(Clock_Divided == 2) + { + Select_PWM0_Clock_Divided_By_4(); + } + + if(Clock_Divided == 3) + { + Select_PWM0_Clock_Divided_By_8(); + } + + Set_Timer0_Count_Buffer(Count_Buffer); + Set_Timer0_Compare_Buffer(Compare_Buffer); + + if(on_off == 1) + { + Start_PWM0(); + } + + if(on_off == 0) + { + Stop_PWM0(); + } +} + + +void LT768_PWM0_Duty(uint16_t Compare_Buffer) +{ + Set_Timer0_Compare_Buffer(Compare_Buffer); +} + +void LT768_PWM1_Init +( + uint8_t on_off // 0: enable PWM0 1: enable PWM0 + , uint8_t Clock_Divided // PWM clock frequency division range 0~3(1, 1/2, 1/4, 1/8) + , uint8_t Prescalar // clock frequency range 1~256 + , uint16_t Count_Buffer // PWM output period + , uint16_t Compare_Buffer // set duty ratio +) +{ + Select_PWM1(); + Set_PWM_Prescaler_1_to_256(Prescalar); + + if(Clock_Divided == 0) + { + Select_PWM1_Clock_Divided_By_1(); + } + + if(Clock_Divided == 1) + { + Select_PWM1_Clock_Divided_By_2(); + } + + if(Clock_Divided == 2) + { + Select_PWM1_Clock_Divided_By_4(); + } + + if(Clock_Divided == 3) + { + Select_PWM1_Clock_Divided_By_8(); + } + + Set_Timer1_Count_Buffer(Count_Buffer); + Set_Timer1_Compare_Buffer(Compare_Buffer); + + if(on_off == 1) + { + Start_PWM1(); + } + + if(on_off == 0) + { + Stop_PWM1(); + } +} + + +void LT768_PWM1_Duty(uint16_t Compare_Buffer) +{ + Set_Timer1_Compare_Buffer(Compare_Buffer); +} + +/*----------------------------------------------------------------------------*/ + +// LT768 enter standby mode +void LT768_Standby(void) +{ + Power_Saving_Standby_Mode(); + Check_Power_is_Saving(); +} + +// wakeup from standby mode +void LT768_Wkup_Standby(void) +{ + Power_Normal_Mode(); + Check_Power_is_Normal(); +} + +// LT768 enter suspend mode +void LT768_Suspend(void) +{ + lt768_sdram_init(10); + Power_Saving_Suspend_Mode(); + Check_Power_is_Saving(); +} + +//wakeup from suspend mode +void LT768_Wkup_Suspend(void) +{ + Power_Normal_Mode(); + Check_Power_is_Normal(); + lt768_sdram_init(lt768_mclk); +} + +// LT768 enter sleep mode +void LT768_SleepMode(void) +{ + Power_Saving_Sleep_Mode(); + Check_Power_is_Saving(); +} + +// wakeup from sleep mode +void LT768_Wkup_Sleep(void) +{ + Power_Normal_Mode(); + Check_Power_is_Normal(); +} + +/*----------------------------------------------------------------------------*/ + +void LT768_SPI_Init(uint8_t cs, uint8_t div) +{ + if(cs == 0) + { + Select_SFI_0(); + Select_nSS_drive_on_xnsfcs0(); + } + else + { + Select_SFI_1(); + Select_nSS_drive_on_xnsfcs1(); + } + + SPI_Clock_Period(div); + Enable_SFlash_SPI(); +} + +void W25QXX_Enter_4Byte_AddressMode(void)//val:select external SPI: SCS:0 SCS:1 +{ + nSS_Active(); + SPI_Master_FIFO_Data_Put(0xB7); + nSS_Inactive(); +} + +void LT_W25QXX_Read(uint8_t *pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead) +{ + uint16_t i; + nSS_Active(); + SPI_Master_FIFO_Data_Put(0x03); + SPI_Master_FIFO_Data_Put((uint8_t)((ReadAddr)>>16)); + SPI_Master_FIFO_Data_Put((uint8_t)((ReadAddr)>>8)); + SPI_Master_FIFO_Data_Put((uint8_t)ReadAddr); + + for(i = 0; i > 8)); + SPI_Master_FIFO_Data_Put((uint8_t)page); + nSS_Inactive(); + W25N01GV_Wait_Busy(); +} + +void W25N01GV_ReadPageAddr_Data(uint8_t *pBuffer, uint32_t PageNum, uint32_t PageAddr, uint16_t NumByteToRead) +{ + uint16_t i; +//------read data from flash to buffer----- + nSS_Active(); //enable + SPI_Master_FIFO_Data_Put(0x13); + SPI_Master_FIFO_Data_Put(0x00); + SPI_Master_FIFO_Data_Put((uint8_t)((PageNum) >> 8)); //send 16bit address + SPI_Master_FIFO_Data_Put((uint8_t)(PageNum)); + nSS_Inactive(); + W25N01GV_Wait_Busy(); + W25N01GV_Write_SR(0xb0, W25N01GV_ReadSR(0xb0) | 0x08); //set read position of buffer +//------read data from buffer to MCU----- + nSS_Active(); + SPI_Master_FIFO_Data_Put(0x03); + SPI_Master_FIFO_Data_Put((PageAddr)>>8); + SPI_Master_FIFO_Data_Put(PageAddr); + SPI_Master_FIFO_Data_Put(0x00); + + for(i = 0; i LCD_XSIZE_TFT) + { + x1 = x1-LCD_XSIZE_TFT; + y1 ++; + } + } +} + +void LT768_Print_Outside_Font_GB2312_48_72_Nand +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t FlashAddr // font source address(Flash) + , uint32_t MemoryAddr1 // cache layer address(sdram) + , uint32_t MemoryAddr2 // cache layer address(sdram) + , uint32_t ShowAddr // show layer address + , uint16_t width // show layer width + , uint8_t Size // set word size 48:48*48 72:72*72 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint16_t w // font thinkness: 0: not overstriking 1: 1 overstriking 2: 2 overstriking + , uint16_t s // linewidth + , uint8_t *c // data start address +) +{ + uint16_t temp_H = 0; + uint16_t temp_L = 0; + uint16_t temp = 0; + uint32_t i = 0; + uint16_t j = 0; + uint16_t k = 0; + uint16_t h = 0; + uint16_t n = 0; + uint16_t m = 0; + uint16_t g = 0; + uint16_t f = 0; + h = x; + k = y; + Memory_8bpp_Mode(); //save picture with 8bit color depth + Canvas_Image_Start_address(MemoryAddr1); + Canvas_image_width(width); + + while((c[i] != '\0') && (c[i] >= 0xa0)) // if not chinese code, exit + { + temp_H = (c[i] - 0xa1) * 94; + temp_L = c[i + 1] - 0xa1; + temp = temp_H + temp_L; + LT768_Nand_8bpp_font(1, 0, Size * j / 8, 0, Size / 8, Size, + FlashAddr + temp * ((Size * Size) / 8), MemoryAddr1, MemoryAddr2); + i += 2; + j ++; + } + + Memory_16bpp_Mode(); + Canvas_Image_Start_address(ShowAddr); + Canvas_image_width(width); + j = 0; + i = 0; + + if(w > 2) + { + w = 2; + } + + for(g=0; g= 0xa0)) // if not chinese code, exit + { + if((f == m) && ((x + Size*j + Size)>(width*(n + 1)))) + { + m ++; + n ++; + y=y + Size-1 + s; + x = x + ((width*n)-(x + Size*j)) + g; + f=n; + } + + if(ChromaKey == 0) + { + LT768_BTE_Memory_Copy_ColorExpansion_8( + MemoryAddr2, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor, BackGroundColor + ); + } + + if(ChromaKey == 1) + { + LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8( + MemoryAddr2, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor + ); + } + + i += 2; + j ++; + } + + i = 0; + j = 0; + m = 0; + n = 0; + f = 0; + x = h + g + 1; + y = k + g + 1; + } +} + +void LT768_Print_Outside_Font_GBK_48_72_Nand +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t FlashAddr // font source address(Flash) + , uint32_t MemoryAddr1 // cache layer address(sdram) + , uint32_t MemoryAddr2 // cache layer address(sdram) + , uint32_t ShowAddr // show layer address + , uint16_t width // show layer width + , uint8_t Size // set word size 48:48*48 72:72*72 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint16_t w // font thinkness: 0: not overstriking 1: 1 overstriking 2: 2 overstriking + , uint16_t s // linewidth + , uint8_t *c // data start address +) +{ + uint16_t temp_H = 0; + uint16_t temp_L = 0; + uint16_t temp = 0; + uint32_t i = 0; + uint16_t j = 0; + uint16_t k = 0; + uint16_t h = 0; + uint16_t n = 0; + uint16_t m = 0; + uint16_t g = 0; + uint16_t f = 0; + h = x; + k = y; + Memory_8bpp_Mode(); //save picture with 8bit color depth + Canvas_Image_Start_address(MemoryAddr1); + Canvas_image_width(width); + + while((c[i] != '\0') && (c[i] >= 0xa0)) // if not chinese code, exit + { + temp_H = (c[i] - 0x81) * 191; + temp_L = c[i + 1] - 0x40; + temp = temp_H + temp_L; + LT768_Nand_8bpp_font(1, 0, Size * j / 8, 0, Size / 8, Size, + FlashAddr + temp * ((Size * Size)/8), + MemoryAddr1, MemoryAddr2); + i += 2; + j ++; + } + + Memory_16bpp_Mode(); + Canvas_Image_Start_address(ShowAddr); + Canvas_image_width(width); + j = 0; + i = 0; + + if(w > 2) + { + w = 2; + } + + for(g = 0; g < w + 1; g ++) + { + while((c[i] != '\0') && (c[i] >= 0xa0)) // if not chinese code, exit + { + if((f == m) && ((x + Size * j + Size) > (width * (n + 1)))) + { + m ++; + n ++; + y = y + Size - 1 + s; + x = x + ((width * n) - (x + Size * j)) + g; + f = n; + } + + if(ChromaKey == 0) + { + LT768_BTE_Memory_Copy_ColorExpansion_8( + MemoryAddr2, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor, BackGroundColor + ); + } + + if(ChromaKey == 1) + { + LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8( + MemoryAddr2, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor); + } + + i += 2; + j ++; + } + + i = 0; + j = 0; + m = 0; + n = 0; + f = 0; + x = h + g + 1; + y = k + g + 1; + } +} + +void LT768_Print_Outside_UserDefineFont_GB2312_Nand +( + uint8_t SCS // select SPI: 0 1 + , uint8_t Clk // SPI clock frequence divison : SPI Clock = System Clock /{(Clk + 1)*2} + , uint32_t FlashAddr // font source address(Flash) + , uint32_t MemoryAddr1 // cache layer address(sdram) + , uint32_t MemoryAddr2 // cache layer address(sdram) + , uint32_t ShowAddr // show layer address + , uint16_t width // show layer width + , uint8_t Size // set word size 48:48*48 72:72*72 + , uint8_t ChromaKey // 0:font background color transparent 1:set font background color + , uint16_t x // font start x + , uint16_t y // font start y + , uint32_t FontColor // font color + , uint32_t BackGroundColor // font background color((when font background is transparent, it is invalid)) + , uint16_t w // font thinkness: 0: not overstriking 1: 1 overstriking 2: 2 overstriking + , uint16_t s // linewidth + , uint8_t *c // data start address +) +{ + short temp = 0; + uint32_t i = 0; + uint16_t j = 0; + uint16_t k = 0; + uint16_t h = 0; + uint16_t n = 0; + uint16_t m = 0; + uint16_t g = 0; + uint16_t f = 0; + uint8_t temp1[2] = {0}; + uint32_t fontNum = 0; + clear_Font_1(); + LT768_SPI_Init(SCS, 1); + LT_W25N01GV_Read(temp1, FlashAddr + 8, 2); + fontNum = (temp1[0] << 8) + temp1[1]; + LT_W25N01GV_Read(Font_1, FlashAddr + 0xc, fontNum * 2); + h = x; + k = y; + Memory_8bpp_Mode();//save picture with 8bit color depth + Canvas_Image_Start_address(MemoryAddr1); + Canvas_image_width(width); + + while(c[i + 1] != '\0') + { + temp = Get_User_Font_P(c[i], c[i + 1]); + + if(temp != -1) + { + LT768_Nand_8bpp_font(SCS, Clk, Size * j / 8, 0, Size / 8, Size, + FlashAddr + temp * ((Size * Size) / 8) + 0x0c + fontNum * 2, + MemoryAddr1, MemoryAddr2); + } + else + { + break; + } + + i += 2; + j ++; + } + + Memory_16bpp_Mode(); + Canvas_Image_Start_address(ShowAddr); + Canvas_image_width(width); + j = 0; + i = 0; + + if(w > 2) + { + w = 2; + } + + for(g = 0; g < w + 1; g ++) + { + while(c[i + 1] != '\0') + { + temp = Get_User_Font_P(c[i], c[i + 1]); + + if(temp == -1) + { + break; + } + + if((f == m) && ((x + Size * j + Size) > (width * (n + 1)))) + { + m ++; + n ++; + y = y + Size - 1 + s; + x = x + ((width * n) - (x + Size * j)) + g; + f = n; + } + + if(ChromaKey == 1) + { + LT768_BTE_Memory_Copy_ColorExpansion_8( + MemoryAddr2, Size * j / 8, + ShowAddr, width, x + Size * j, y, + Size, Size, FontColor, BackGroundColor + ); + } + + if(ChromaKey == 0) + { + LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8( + MemoryAddr2, Size * j / 8, + ShowAddr, width, x + Size*j, y, + Size, Size, FontColor + ); + } + + i += 2; + j ++; + } + + ChromaKey = 0; + i = 0; + j = 0; + m = 0; + n = 0; + f = 0; + x = h + g + 1; + y = k + g + 1; + } +} + diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/lcd/lt768.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/lcd/lt768.h index 9dd5817ec..f60fdf799 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/lcd/lt768.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/lcd/lt768.h @@ -1,685 +1,704 @@ -/******************** COPYRIGHT ******************** -* File Name : LT768.h -* Author : Levetop Electronics -* Version : V1.0 -* Date : 2017-8-25 -* Description : 操作LT768的寄存器函数 -****************************************************/ - -#ifndef _LT768_h -#define _LT768_h - -#define cSetb0 0x01 -#define cSetb1 0x02 -#define cSetb2 0x04 -#define cSetb3 0x08 -#define cSetb4 0x10 -#define cSetb5 0x20 -#define cSetb6 0x40 -#define cSetb7 0x80 - -#define cClrb0 0xfe -#define cClrb1 0xfd -#define cClrb2 0xfb -#define cClrb3 0xf7 -#define cClrb4 0xef -#define cClrb5 0xdf -#define cClrb6 0xbf -#define cClrb7 0x7f - - -void LCD_RegisterWrite(unsigned char Cmd,unsigned char Data); -unsigned char LCD_RegisterRead(unsigned char Cmd); - -//**Staus**// -void Check_Mem_WR_FIFO_not_Full(void); -void Check_Mem_WR_FIFO_Empty(void); -void Check_Mem_RD_FIFO_not_Full(void); -void Check_Mem_RD_FIFO_not_Empty(void); -void Check_2D_Busy(void); -void Check_SDRAM_Ready(void); -unsigned char Power_Saving_Status(void); -void Check_Power_is_Normal(void); -void Check_Power_is_Saving(void); -void Check_NO_Interrupt(void); -void Check_Interrupt_Occur(void); - -void Check_Busy_Draw(void); -void Check_Busy_SFI_DMA(void); - -//**[00h]**// -void LT768_SW_Reset(void); -//**[01h]**// -void Enable_PLL(void); -void LT768_Sleep(void); -void LT768_WakeUp(void); -void TFT_24bit(void); -void TFT_18bit(void); -void TFT_16bit(void); -void TFT_LVDS(void); -void Key_Scan_Enable(void); -void Key_Scan_Disable(void); -void LT768_I2CM_Enable(void); -void LT768_I2CM_Disable(void); -void Enable_SFlash_SPI(void); -void Disable_SFlash_SPI(void); -void Host_Bus_8bit(void); -void Host_Bus_16bit(void); -//**[02h]**// - -void RGB_8b_8bpp(void); -void RGB_8b_16bpp(void); -void RGB_8b_24bpp(void); - -void RGB_16b_8bpp(void); -void RGB_16b_16bpp(void); -void RGB_16b_24bpp_mode1(void); -void RGB_16b_24bpp_mode2(void); - -void MemRead_Left_Right_Top_Down(void); -void MemRead_Right_Left_Top_Down(void); -void MemRead_Top_Down_Left_Right(void); -void MemRead_Down_Top_Left_Right(void); - -void MemWrite_Left_Right_Top_Down(void); -void MemWrite_Right_Left_Top_Down(void); -void MemWrite_Top_Down_Left_Right(void); -void MemWrite_Down_Top_Left_Right(void); -//**[03h]**// -void Interrupt_Active_Low(void); -void Interrupt_Active_High(void); -void ExtInterrupt_Debounce(void); -void ExtInterrupt_Nodebounce(void); -void ExtInterrupt_Input_Low_Level_Trigger(void); -void ExtInterrupt_Input_High_Level_Trigger(void); -void ExtInterrupt_Input_Falling_Edge_Trigger(void); -void ExtInterrupt_Input_Rising_Edge_Trigger(void); -void LVDS_Format1(void); -void LVDS_Format2(void); -void Graphic_Mode(void); -void Text_Mode(void); -void Memory_Select_SDRAM(void); -void Memory_Select_Graphic_Cursor_RAM(void); -void Memory_Select_Color_Palette_RAM(void); -//**[05h]**// -//**[06h]**// -//**[07h]**// -//**[09h]**// -//**[0Ah]**// -//**[0Bh]**// -void Enable_Resume_Interrupt(void); -void Disable_Resume_Interrupt(void); -void Enable_ExtInterrupt_Input(void); -void Disable_ExtInterrupt_Input(void); -void Enable_I2CM_Interrupt(void); -void Disable_I2CM_Interrupt(void); -void Enable_Vsync_Interrupt(void); -void Disable_Vsync_Interrupt(void); -void Enable_KeyScan_Interrupt(void); -void Disable_KeyScan_Interrupt(void); -void Enable_DMA_Draw_BTE_Interrupt(void); -void Disable_DMA_Draw_BTE_Interrupt(void); -void Enable_PWM1_Interrupt(void); -void Disable_PWM1_Interrupt(void); -void Enable_PWM0_Interrupt(void); -void Disable_PWM0_Interrupt(void); -//**[0Ch]**// -unsigned char Read_Interrupt_status(void); -void Clear_Resume_Interrupt_Flag(void); -void Clear_ExtInterrupt_Input_Flag(void); -void Clear_I2CM_Interrupt_Flag(void); -void Clear_Vsync_Interrupt_Flag(void); -void Clear_KeyScan_Interrupt_Flag(void); -void Clear_DMA_Draw_BTE_Interrupt_Flag(void); -void Clear_PWM1_Interrupt_Flag(void); -void Clear_PWM0_Interrupt_Flag(void); -//**[0Dh]**// -void Mask_Resume_Interrupt_Flag(void); -void Mask_ExtInterrupt_Input_Flag(void); -void Mask_I2CM_Interrupt_Flag(void); -void Mask_Vsync_Interrupt_Flag(void); -void Mask_KeyScan_Interrupt_Flag(void); -void Mask_DMA_Draw_BTE_Interrupt_Flag(void); -void Mask_PWM1_Interrupt_Flag(void); -void Mask_PWM0_Interrupt_Flag(void); -// -void Enable_Resume_Interrupt_Flag(void); -void Enable_ExtInterrupt_Input_Flag(void); -void Enable_I2CM_Interrupt_Flag(void); -void Enable_Vsync_Interrupt_Flag(void); -void Enable_KeyScan_Interrupt_Flag(void); -void Enable_DMA_Draw_BTE_Interrupt_Flag(void); -void Enable_PWM1_Interrupt_Flag(void); -void Enable_PWM0_Interrupt_Flag(void); -//**[0Eh]**// -void Enable_GPIOF_PullUp(void); -void Enable_GPIOE_PullUp(void); -void Enable_GPIOD_PullUp(void); -void Enable_GPIOC_PullUp(void); -void Enable_XDB15_8_PullUp(void); -void Enable_XDB7_0_PullUp(void); -void Disable_GPIOF_PullUp(void); -void Disable_GPIOE_PullUp(void); -void Disable_GPIOD_PullUp(void); -void Disable_GPIOC_PullUp(void); -void Disable_XDB15_8_PullUp(void); -void Disable_XDB7_0_PullUp(void); - -//**[0Fh]**// -void XPDAT18_Set_GPIO_D7(void); -void XPDAT18_Set_KOUT4(void); -void XPDAT17_Set_GPIO_D5(void); -void XPDAT17_Set_KOUT2(void); -void XPDAT16_Set_GPIO_D4(void); -void XPDAT16_Set_KOUT1(void); -void XPDAT9_Set_GPIO_D3(void); -void XPDAT9_Set_KOUT3(void); -void XPDAT8_Set_GPIO_D2(void); -void XPDAT8_Set_KIN3(void); -void XPDAT2_Set_GPIO_D6(void); -void XPDAT2_Set_KIN4(void); -void XPDAT1_Set_GPIO_D1(void); -void XPDAT1_Set_KIN2(void); -void XPDAT0_Set_GPIO_D0(void); -void XPDAT0_Set_KIN1(void); - -//**[10h]**// -void Enable_PIP1(void); -void Disable_PIP1(void); -void Enable_PIP2(void); -void Disable_PIP2(void); -void Select_PIP1_Parameter(void); -void Select_PIP2_Parameter(void); -void Select_Main_Window_8bpp(void); -void Select_Main_Window_16bpp(void); -void Select_Main_Window_24bpp(void); -//**[11h]**// -void Select_PIP1_Window_8bpp(void); -void Select_PIP1_Window_16bpp(void); -void Select_PIP1_Window_24bpp(void); -void Select_PIP2_Window_8bpp(void); -void Select_PIP2_Window_16bpp(void); -void Select_PIP2_Window_24bpp(void); -//**[12h]**// -void PCLK_Rising(void); -void PCLK_Falling(void); -void Display_ON(void); -void Display_OFF(void); -void Color_Bar_ON(void); -void Color_Bar_OFF(void); -void HSCAN_L_to_R(void); -void HSCAN_R_to_L(void); -void VSCAN_T_to_B(void); -void VSCAN_B_to_T(void); -void PDATA_Set_RGB(void); -void PDATA_Set_RBG(void); -void PDATA_Set_GRB(void); -void PDATA_Set_GBR(void); -void PDATA_Set_BRG(void); -void PDATA_Set_BGR(void); -void PDATA_IDLE_STATE(void); - -//**[13h]**// -void HSYNC_Low_Active(void); -void HSYNC_High_Active(void); -void VSYNC_Low_Active(void); -void VSYNC_High_Active(void); -void DE_Low_Active(void); -void DE_High_Active(void); -void Idle_DE_Low(void); -void Idle_DE_High(void); -void Idle_PCLK_Low(void); -void Idle_PCLK_High(void); -void Idle_PDAT_Low(void); -void Idle_PDAT_High(void); -void Idle_HSYNC_Low(void); -void Idle_HSYNC_High(void); -void Idle_VSYNC_Low(void); -void Idle_VSYNC_High(void); -//**[14h][15h][1Ah][1Bh]**// -void LCD_HorizontalWidth_VerticalHeight(unsigned short WX,unsigned short HY); -//**[16h][17h]**// -void LCD_Horizontal_Non_Display(unsigned short WX); -//**[18h]**// -void LCD_HSYNC_Start_Position(unsigned short WX); -//**[19h]**// -void LCD_HSYNC_Pulse_Width(unsigned short WX); -//**[1Ch][1Dh]**// -void LCD_Vertical_Non_Display(unsigned short HY); -//**[1Eh]**// -void LCD_VSYNC_Start_Position(unsigned short HY); -//**[1Fh]**// -void LCD_VSYNC_Pulse_Width(unsigned short HY); -//**[20h][21h][22h][23h]**// -void Main_Image_Start_Address(unsigned long Addr); -//**[24h][25h]**// -void Main_Image_Width(unsigned short WX); -//**[26h][27h][28h][29h]**// -void Main_Window_Start_XY(unsigned short WX,unsigned short HY); -//**[2Ah][2Bh][2Ch][2Dh]**// -void PIP_Display_Start_XY(unsigned short WX,unsigned short HY); -//**[2Eh][2Fh][30h][31h]**// -void PIP_Image_Start_Address(unsigned long Addr); -//**[32h][33h]**// -void PIP_Image_Width(unsigned short WX); -//**[34h][35h][36h][37h]**// -void PIP_Window_Image_Start_XY(unsigned short WX,unsigned short HY); -//**[38h][39h][3Ah][3Bh]**// -void PIP_Window_Width_Height(unsigned short WX,unsigned short HY); -//**[3C]**// -void Enable_Graphic_Cursor(void); -void Disable_Graphic_Cursor(void); -void Select_Graphic_Cursor_1(void); -void Select_Graphic_Cursor_2(void); -void Select_Graphic_Cursor_3(void); -void Select_Graphic_Cursor_4(void); -void Enable_Text_Cursor(void); -void Disable_Text_Cursor(void); -void Enable_Text_Cursor_Blinking(void); -void Disable_Text_Cursor_Blinking(void); -//**[3D]**// -void Blinking_Time_Frames(unsigned char temp); -//**[3E][3Fh]**// -void Text_Cursor_H_V(unsigned short WX,unsigned short HY); -//**[40h][41h][42h][43h]**// -void Graphic_Cursor_XY(unsigned short WX,unsigned short HY); -//**[44]**// -void Set_Graphic_Cursor_Color_1(unsigned char temp); -//**[45]**// -void Set_Graphic_Cursor_Color_2(unsigned char temp); -//**[50h][51h][52h][53h]**// -void Canvas_Image_Start_address(unsigned long Addr); -//**[54h][55h]**// -void Canvas_image_width(unsigned short WX); -//**[56h][57h][58h][59h]**// -void Active_Window_XY(unsigned short WX,unsigned short HY); -//**[5Ah][5Bh][5Ch][5Dh]**// -void Active_Window_WH(unsigned short WX,unsigned short HY); -//**[5E]**// -void Select_Write_Data_Position(void); -void Select_Read_Data_Position(void); -void Memory_XY_Mode(void); -void Memory_Linear_Mode(void); -void Memory_8bpp_Mode(void); -void Memory_16bpp_Mode(void); -void Memory_24bpp_Mode(void); -//**[5Fh][60h][61h][62h]**// -void Goto_Pixel_XY(unsigned short WX,unsigned short HY); -void Goto_Linear_Addr(unsigned long Addr); -//**[63h][64h][65h][66h]**// -void Goto_Text_XY(unsigned short WX,unsigned short HY); - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : Draw ] ****//// -//**[67h]**// -void Start_Line(void); -void Start_Triangle(void); -void Start_Triangle_Fill(void); -//**[68h]~[73h]**// -void Line_Start_XY(unsigned short WX,unsigned short HY); -void Line_End_XY(unsigned short WX,unsigned short HY); -void Triangle_Point1_XY(unsigned short WX,unsigned short HY); -void Triangle_Point2_XY(unsigned short WX,unsigned short HY); -void Triangle_Point3_XY (unsigned short WX,unsigned short HY); -void Square_Start_XY(unsigned short WX,unsigned short HY); -void Square_End_XY(unsigned short WX,unsigned short HY); -//**[76h]**// -void Start_Circle_or_Ellipse(void); -void Start_Circle_or_Ellipse_Fill(void); -void Start_Left_Down_Curve(void); -void Start_Left_Up_Curve(void); -void Start_Right_Up_Curve(void); -void Start_Right_Down_Curve(void); -void Start_Left_Down_Curve_Fill(void); -void Start_Left_Up_Curve_Fill(void); -void Start_Right_Up_Curve_Fill(void); -void Start_Right_Down_Curve_Fill(void); -void Start_Square(void); -void Start_Square_Fill(void); -void Start_Circle_Square(void); -void Start_Circle_Square_Fill(void); -//**[77h]~[7Eh]**// -void Circle_Center_XY(unsigned short WX,unsigned short HY); -void Ellipse_Center_XY(unsigned short WX,unsigned short HY); -void Circle_Radius_R(unsigned short WX); -void Ellipse_Radius_RxRy(unsigned short WX,unsigned short HY); -void Circle_Square_Radius_RxRy(unsigned short WX,unsigned short HY); - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : PWM ] ****//// -//**[84h]**// -void Set_PWM_Prescaler_1_to_256(unsigned short WX); -//**[85h]**// -void Select_PWM1_Clock_Divided_By_1(void); -void Select_PWM1_Clock_Divided_By_2(void); -void Select_PWM1_Clock_Divided_By_4(void); -void Select_PWM1_Clock_Divided_By_8(void); -void Select_PWM0_Clock_Divided_By_1(void); -void Select_PWM0_Clock_Divided_By_2(void); -void Select_PWM0_Clock_Divided_By_4(void); -void Select_PWM0_Clock_Divided_By_8(void); -//[85h].[bit3][bit2] -void Select_PWM1_is_ErrorFlag(void); -void Select_PWM1(void); -void Select_PWM1_is_Osc_Clock(void); -//[85h].[bit1][bit0] -void Select_PWM0_is_GPIO_C7(void); -void Select_PWM0(void); -void Select_PWM0_is_Core_Clock(void); -//**[86h]**// -//[86h]PWM1 -void Enable_PWM1_Inverter(void); -void Disable_PWM1_Inverter(void); -void Auto_Reload_PWM1(void); -void One_Shot_PWM1(void); -void Start_PWM1(void); -void Stop_PWM1(void); -//[86h]PWM0 -void Enable_PWM0_Dead_Zone(void); -void Disable_PWM0_Dead_Zone(void); -void Enable_PWM0_Inverter(void); -void Disable_PWM0_Inverter(void); -void Auto_Reload_PWM0(void); -void One_Shot_PWM0(void); -void Start_PWM0(void); -void Stop_PWM0(void); -//**[87h]**// -void Set_Timer0_Dead_Zone_Length(unsigned char temp); -//**[88h][89h]**// -void Set_Timer0_Compare_Buffer(unsigned short WX); -//**[8Ah][8Bh]**// -void Set_Timer0_Count_Buffer(unsigned short WX); -//**[8Ch][8Dh]**// -void Set_Timer1_Compare_Buffer(unsigned short WX); -//**[8Eh][8Fh]**// -void Set_Timer1_Count_Buffer(unsigned short WX); - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : BTE ] ****//// -//**[90h]**// - -//[90h]========================================================================= -void BTE_Enable(void); -void BTE_Disable(void); - -void Check_BTE_Busy(void); - -void Pattern_Format_8X8(void); -void Pattern_Format_16X16(void); - -//[91h]========================================================================= -void BTE_ROP_Code(unsigned char setx); -void BTE_Operation_Code(unsigned char setx); - -//[92h]========================================================================= -void BTE_S0_Color_8bpp(void); -void BTE_S0_Color_16bpp(void); -void BTE_S0_Color_24bpp(void); - -void BTE_S1_Color_8bpp(void); -void BTE_S1_Color_16bpp(void); -void BTE_S1_Color_24bpp(void); -void BTE_S1_Color_Constant(void); -void BTE_S1_Color_8bit_Alpha(void); -void BTE_S1_Color_16bit_Alpha(void); - -void BTE_Destination_Color_8bpp(void); -void BTE_Destination_Color_16bpp(void); -void BTE_Destination_Color_24bpp(void); - -//[93h][94h][95h][96h]========================================================================= -void BTE_S0_Memory_Start_Address(unsigned long Addr); - -//[97h][98h]========================================================================= -void BTE_S0_Image_Width(unsigned short WX); - -//[99h][9Ah][9Bh][9Ch]========================================================================= -void BTE_S0_Window_Start_XY(unsigned short WX,unsigned short HY); - -//[9Dh][9Eh][9Fh][A0h]========================================================================= -void BTE_S1_Memory_Start_Address(unsigned long Addr); -void S1_Constant_color_256(unsigned char temp); -void S1_Constant_color_65k(unsigned short temp); -void S1_Constant_color_16M(unsigned long temp); - -//[A1h][A2h]========================================================================= -void BTE_S1_Image_Width(unsigned short WX); - -//[A3h][A4h][A5h][A6h]========================================================================= -void BTE_S1_Window_Start_XY(unsigned short WX,unsigned short HY); - -//[A7h][A8h][A9h][AAh]========================================================================= -void BTE_Destination_Memory_Start_Address(unsigned long Addr); - -//[ABh][ACh]========================================================================= -void BTE_Destination_Image_Width(unsigned short WX); - -//[ADh][AEh][AFh][B0h]========================================================================= -void BTE_Destination_Window_Start_XY(unsigned short WX,unsigned short HY); - -//[B1h][B2h][B3h][B4h]========================================================================= -void BTE_Window_Size(unsigned short WX, unsigned short WY); - -//[B5h]========================================================================= -void BTE_Alpha_Blending_Effect(unsigned char temp); - - -//**[B5h]**// - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : Serial Flash ] ****//// - - -//REG[B6h] Serial flash DMA Controller REG (DMA_CTRL) -void Start_SFI_DMA(void); -void Check_Busy_SFI_DMA(void); - -//REG[B7h] Serial Flash/ROM Controller Register (SFL_CTRL) -void Select_SFI_0(void); -void Select_SFI_1(void); -void Select_SFI_Font_Mode(void); -void Select_SFI_DMA_Mode(void); -void Select_SFI_24bit_Address(void); -void Select_SFI_32bit_Address(void); -void Select_SFI_Waveform_Mode_0(void); -void Select_SFI_Waveform_Mode_3(void); -void Select_SFI_0_DummyRead(void); -void Select_SFI_8_DummyRead(void); -void Select_SFI_16_DummyRead(void); -void Select_SFI_24_DummyRead(void); -void Select_SFI_Single_Mode(void); -void Select_SFI_Dual_Mode0(void); -void Select_SFI_Dual_Mode1(void); - -//REG[B8h] SPI master Tx /Rx FIFO Data Register (SPIDR) -unsigned char SPI_Master_FIFO_Data_Put(unsigned char Data); -unsigned char SPI_Master_FIFO_Data_Get(void); - -//REG[B9h] SPI master Control Register (SPIMCR2) -void Mask_SPI_Master_Interrupt_Flag(void); -void Select_nSS_drive_on_xnsfcs0(void); -void Select_nSS_drive_on_xnsfcs1(void); -void nSS_Inactive(void); -void nSS_Active(void); -void OVFIRQEN_Enable(void); -void EMTIRQEN_Enable(void); -void Reset_CPOL(void); -void Set_CPOL(void); -void Reset_CPHA(void); -void Set_CPHA(void); - -//REG[BAh] SPI master Status Register (SPIMSR) -unsigned char Tx_FIFO_Empty_Flag(void); -unsigned char Tx_FIFO_Full_Flag(void); -unsigned char Rx_FIFO_Empty_Flag(void); -unsigned char Rx_FIFO_full_flag(void); -unsigned char OVFI_Flag(void); -void Clear_OVFI_Flag(void); -unsigned char EMTI_Flag(void); -void Clear_EMTI_Flag(void); - -//REG[BB] SPI Clock period (SPIDIV) -void SPI_Clock_Period(unsigned char temp); - - -//**[BCh][BDh][BEh][BFh]**// -void SFI_DMA_Source_Start_Address(unsigned long Addr); -//**[C0h][C1h][C2h][C3h]**// -void SFI_DMA_Destination_Start_Address(unsigned long Addr); -void SFI_DMA_Destination_Upper_Left_Corner(unsigned short WX,unsigned short HY); -//**[C4h][C5h]**// -void SFI_DMA_Destination_Width(unsigned short WX); -//**[C6h][C7h][C8h][C9h]**// -void SFI_DMA_Transfer_Number(unsigned long Addr); -void SFI_DMA_Transfer_Width_Height(unsigned short WX,unsigned short HY); -//**[CAh][CBh]**// -void SFI_DMA_Source_Width(unsigned short WX); - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : Font ] ****//// -//**[CCh]**// - -void Font_Select_UserDefine_Mode(void); -void CGROM_Select_Internal_CGROM(void); -void CGROM_Select_Genitop_FontROM(void); -void Font_Select_8x16_16x16(void); -void Font_Select_12x24_24x24(void); -void Font_Select_16x32_32x32(void); -void Internal_CGROM_Select_ISOIEC8859_1(void); -void Internal_CGROM_Select_ISOIEC8859_2(void); -void Internal_CGROM_Select_ISOIEC8859_3(void); -void Internal_CGROM_Select_ISOIEC8859_4(void); -//**[CDh]**// -void Enable_Font_Alignment(void); -void Disable_Font_Alignment(void); -void Font_Background_select_Transparency(void); -void Font_Background_select_Color(void); -void Font_0_degree(void); -void Font_90_degree(void); -void Font_Width_X1(void); -void Font_Width_X2(void); -void Font_Width_X3(void); -void Font_Width_X4(void); -void Font_Height_X1(void); -void Font_Height_X2(void); -void Font_Height_X3(void); -void Font_Height_X4(void); -//**[CEh]**// -void GTFont_Select_GT21L16TW_GT21H16T1W(void); -void GTFont_Select_GT23L16U2W(void); -void GTFont_Select_GT23L24T3Y_GT23H24T3Y(void); -void GTFont_Select_GT23L24M1Z(void); -void GTFont_Select_GT23L32S4W_GT23H32S4W(void); -void GTFont_Select_GT20L24F6Y(void); -void GTFont_Select_GT21L24S1W(void); -void GTFont_Select_GT22L16A1Y(void); -//**[CFh]**// -void Set_GTFont_Decoder(unsigned char temp); -//**[D0h]**// -void Font_Line_Distance(unsigned char temp); -//**[D1h]**// -void Set_Font_to_Font_Width(unsigned char temp); -//**[D2h]~[D4h]**// -void Foreground_RGB(unsigned char RED,unsigned char GREEN,unsigned char BLUE); -void Foreground_color_256(unsigned char temp); -void Foreground_color_65k(unsigned short temp); -void Foreground_color_16M(unsigned long temp); -//**[D5h]~[D7h]**// -void Background_RGB(unsigned char RED,unsigned char GREEN,unsigned char BLUE); -void Background_color_256(unsigned char temp); -void Background_color_65k(unsigned short temp); -void Background_color_16M(unsigned long temp); -//**[DBh]~[DEh]**// -void CGRAM_Start_address(unsigned long Addr); -//**[DFh]**// -void Power_Normal_Mode(void); -void Power_Saving_Standby_Mode(void); -void Power_Saving_Suspend_Mode(void); -void Power_Saving_Sleep_Mode(void); - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : SDRAM ] ****//// -//**[E0h]~[E4h]**// -// LT768_Select_SDRAM(); - - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : I2C ] ****//// -//**[E5h]~[EAh]**// -void LT768_I2CM_Clock_Prescale(unsigned short WX); -//**[E7h]**// -void LT768_I2CM_Transmit_Data(unsigned char temp); -//**[E8h]**// -unsigned char LT768_I2CM_Receiver_Data(void); -//**[E9h]**// - -void LT768_I2CM_Read_With_Ack(void); -void LT768_I2CM_Read_With_Nack(void); -void LT768_I2CM_Write_With_Start(void); -void LT768_I2CM_Write(void); -void LT768_I2CM_Stop(void); - - -//**[EAh]**// -unsigned char LT768_I2CM_Check_Slave_ACK(void); -unsigned char LT768_I2CM_Bus_Busy(void); -unsigned char LT768_I2CM_transmit_Progress(void); -unsigned char LT768_I2CM_Arbitration(void); - - - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : GPIO ] ****//// -//[F0h][F1h] -void Set_GPIO_A_In_Out(unsigned char temp); -void Write_GPIO_A_7_0(unsigned char temp); -unsigned char Read_GPIO_A_7_0(void); -//[F2h] -void Write_GPIO_B_7_4(unsigned char temp); -unsigned char Read_GPIO_B_7_0(void); -//[F3h][F4h] -void Set_GPIO_C_In_Out(unsigned char temp); -void Write_GPIO_C_7_0(unsigned char temp); -unsigned char Read_GPIO_C_7_0(void); -//[F5h][F6h] -void Set_GPIO_D_In_Out(unsigned char temp); -void Write_GPIO_D_7_0(unsigned char temp); -unsigned char Read_GPIO_D_7_0(void); -//[F7h][F8h] -void Set_GPIO_E_In_Out(unsigned char temp); -void Write_GPIO_E_7_0(unsigned char temp); -unsigned char Read_GPIO_E_7_0(void); -//[F9h][FAh] -void Set_GPIO_F_In_Out(unsigned char temp); -void Write_GPIO_F_7_0(unsigned char temp); -unsigned char Read_GPIO_F_7_0(void); - - -//////////////////////////////////////////////////////////////////////// -////**** [ Function : Key ] ****//// -//**[FBh]~[FFh]**// -//[FBh] -void Long_Key_enable(void); -void Key_Scan_Freg(unsigned char temp); //set bit2~0 - -//[FCh] -void Key_Scan_Wakeup_Function_Enable(void); -void Long_Key_Timing_Adjustment(unsigned char setx);//set bit5~3 -unsigned char Numbers_of_Key_Hit(void); - -//[FDh][FEh][FFh] -unsigned char Read_Key_Strobe_Data_0(void); -unsigned char Read_Key_Strobe_Data_1(void); -unsigned char Read_Key_Strobe_Data_2(void); - -void Show_String(char *str); -void Show_picture(unsigned long numbers,const unsigned short *data); - -void PWM0_ON(void); //开PWM0 - -void lt768_hw_reset(void); -void System_Check_Temp(void); -void Enable_SPI_Flash_DMA(unsigned char val); - -#endif - +/* +* Copyright (c) 2022 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file lt768.h + * @brief lt768 register relative driver, inherit from Levetop Electronics + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.9.19 + */ + +#ifndef __LT768_H_ +#define __LT768_H_ + +#define cSetb0 0x01 +#define cSetb1 0x02 +#define cSetb2 0x04 +#define cSetb3 0x08 +#define cSetb4 0x10 +#define cSetb5 0x20 +#define cSetb6 0x40 +#define cSetb7 0x80 + +#define cClrb0 0xfe +#define cClrb1 0xfd +#define cClrb2 0xfb +#define cClrb3 0xf7 +#define cClrb4 0xef +#define cClrb5 0xdf +#define cClrb6 0xbf +#define cClrb7 0x7f + + +#define STM32_FSMC_8 0 //16bits bus + +void LCD_CmdWrite(uint8_t cmd); +void LCD_DataWrite(uint8_t data); +uint8_t LCD_StatusRead(void); +uint8_t LCD_DataRead(void); +void LCD_DataWrite_Pixel(uint8_t data); + +void LCD_RegisterWrite(uint8_t Cmd, uint8_t Data); +uint8_t LCD_RegisterRead(uint8_t Cmd); + +void Check_Mem_WR_FIFO_not_Full(void); +void Check_Mem_WR_FIFO_Empty(void); +void Check_Mem_RD_FIFO_not_Full(void); +void Check_Mem_RD_FIFO_not_Empty(void); +void Check_2D_Busy(void); +void Check_SDRAM_Ready(void); +uint8_t Power_Saving_Status(void); +void Check_Power_is_Normal(void); +void Check_Power_is_Saving(void); +void Check_NO_Interrupt(void); +void Check_Interrupt_Occur(void); + +void Check_Busy_Draw(void); +void Check_Busy_SFI_DMA(void); + +//**[00h]**// +void LT768_SW_Reset(void); +//**[01h]**// +void Enable_PLL(void); +void LT768_Sleep(void); +void LT768_WakeUp(void); +void TFT_24bit(void); +void TFT_18bit(void); +void TFT_16bit(void); +void TFT_LVDS(void); +void Key_Scan_Enable(void); +void Key_Scan_Disable(void); +void LT768_I2CM_Enable(void); +void LT768_I2CM_Disable(void); +void Enable_SFlash_SPI(void); +void Disable_SFlash_SPI(void); +void Host_Bus_8bit(void); +void Host_Bus_16bit(void); +//**[02h]**// + +void RGB_8b_8bpp(void); +void RGB_8b_16bpp(void); +void RGB_8b_24bpp(void); + +void RGB_16b_8bpp(void); +void RGB_16b_16bpp(void); +void RGB_16b_24bpp_mode1(void); +void RGB_16b_24bpp_mode2(void); + +void MemRead_Left_Right_Top_Down(void); +void MemRead_Right_Left_Top_Down(void); +void MemRead_Top_Down_Left_Right(void); +void MemRead_Down_Top_Left_Right(void); + +void MemWrite_Left_Right_Top_Down(void); +void MemWrite_Right_Left_Top_Down(void); +void MemWrite_Top_Down_Left_Right(void); +void MemWrite_Down_Top_Left_Right(void); +//**[03h]**// +void Interrupt_Active_Low(void); +void Interrupt_Active_High(void); +void ExtInterrupt_Debounce(void); +void ExtInterrupt_Nodebounce(void); +void ExtInterrupt_Input_Low_Level_Trigger(void); +void ExtInterrupt_Input_High_Level_Trigger(void); +void ExtInterrupt_Input_Falling_Edge_Trigger(void); +void ExtInterrupt_Input_Rising_Edge_Trigger(void); +void LVDS_Format1(void); +void LVDS_Format2(void); +void Graphic_Mode(void); +void Text_Mode(void); +void Memory_Select_SDRAM(void); +void Memory_Select_Graphic_Cursor_RAM(void); +void Memory_Select_Color_Palette_RAM(void); +//**[05h]**// +//**[06h]**// +//**[07h]**// +//**[09h]**// +//**[0Ah]**// +//**[0Bh]**// +void Enable_Resume_Interrupt(void); +void Disable_Resume_Interrupt(void); +void Enable_ExtInterrupt_Input(void); +void Disable_ExtInterrupt_Input(void); +void Enable_I2CM_Interrupt(void); +void Disable_I2CM_Interrupt(void); +void Enable_Vsync_Interrupt(void); +void Disable_Vsync_Interrupt(void); +void Enable_KeyScan_Interrupt(void); +void Disable_KeyScan_Interrupt(void); +void Enable_DMA_Draw_BTE_Interrupt(void); +void Disable_DMA_Draw_BTE_Interrupt(void); +void Enable_PWM1_Interrupt(void); +void Disable_PWM1_Interrupt(void); +void Enable_PWM0_Interrupt(void); +void Disable_PWM0_Interrupt(void); +//**[0Ch]**// +uint8_t Read_Interrupt_status(void); +void Clear_Resume_Interrupt_Flag(void); +void Clear_ExtInterrupt_Input_Flag(void); +void Clear_I2CM_Interrupt_Flag(void); +void Clear_Vsync_Interrupt_Flag(void); +void Clear_KeyScan_Interrupt_Flag(void); +void Clear_DMA_Draw_BTE_Interrupt_Flag(void); +void Clear_PWM1_Interrupt_Flag(void); +void Clear_PWM0_Interrupt_Flag(void); +//**[0Dh]**// +void Mask_Resume_Interrupt_Flag(void); +void Mask_ExtInterrupt_Input_Flag(void); +void Mask_I2CM_Interrupt_Flag(void); +void Mask_Vsync_Interrupt_Flag(void); +void Mask_KeyScan_Interrupt_Flag(void); +void Mask_DMA_Draw_BTE_Interrupt_Flag(void); +void Mask_PWM1_Interrupt_Flag(void); +void Mask_PWM0_Interrupt_Flag(void); +// +void Enable_Resume_Interrupt_Flag(void); +void Enable_ExtInterrupt_Input_Flag(void); +void Enable_I2CM_Interrupt_Flag(void); +void Enable_Vsync_Interrupt_Flag(void); +void Enable_KeyScan_Interrupt_Flag(void); +void Enable_DMA_Draw_BTE_Interrupt_Flag(void); +void Enable_PWM1_Interrupt_Flag(void); +void Enable_PWM0_Interrupt_Flag(void); +//**[0Eh]**// +void Enable_GPIOF_PullUp(void); +void Enable_GPIOE_PullUp(void); +void Enable_GPIOD_PullUp(void); +void Enable_GPIOC_PullUp(void); +void Enable_XDB15_8_PullUp(void); +void Enable_XDB7_0_PullUp(void); +void Disable_GPIOF_PullUp(void); +void Disable_GPIOE_PullUp(void); +void Disable_GPIOD_PullUp(void); +void Disable_GPIOC_PullUp(void); +void Disable_XDB15_8_PullUp(void); +void Disable_XDB7_0_PullUp(void); + +//**[0Fh]**// +void XPDAT18_Set_GPIO_D7(void); +void XPDAT18_Set_KOUT4(void); +void XPDAT17_Set_GPIO_D5(void); +void XPDAT17_Set_KOUT2(void); +void XPDAT16_Set_GPIO_D4(void); +void XPDAT16_Set_KOUT1(void); +void XPDAT9_Set_GPIO_D3(void); +void XPDAT9_Set_KOUT3(void); +void XPDAT8_Set_GPIO_D2(void); +void XPDAT8_Set_KIN3(void); +void XPDAT2_Set_GPIO_D6(void); +void XPDAT2_Set_KIN4(void); +void XPDAT1_Set_GPIO_D1(void); +void XPDAT1_Set_KIN2(void); +void XPDAT0_Set_GPIO_D0(void); +void XPDAT0_Set_KIN1(void); + +//**[10h]**// +void Enable_PIP1(void); +void Disable_PIP1(void); +void Enable_PIP2(void); +void Disable_PIP2(void); +void Select_PIP1_Parameter(void); +void Select_PIP2_Parameter(void); +void Select_Main_Window_8bpp(void); +void Select_Main_Window_16bpp(void); +void Select_Main_Window_24bpp(void); +//**[11h]**// +void Select_PIP1_Window_8bpp(void); +void Select_PIP1_Window_16bpp(void); +void Select_PIP1_Window_24bpp(void); +void Select_PIP2_Window_8bpp(void); +void Select_PIP2_Window_16bpp(void); +void Select_PIP2_Window_24bpp(void); +//**[12h]**// +void PCLK_Rising(void); +void PCLK_Falling(void); +void Display_ON(void); +void Display_OFF(void); +void Color_Bar_ON(void); +void Color_Bar_OFF(void); +void HSCAN_L_to_R(void); +void HSCAN_R_to_L(void); +void VSCAN_T_to_B(void); +void VSCAN_B_to_T(void); +void PDATA_Set_RGB(void); +void PDATA_Set_RBG(void); +void PDATA_Set_GRB(void); +void PDATA_Set_GBR(void); +void PDATA_Set_BRG(void); +void PDATA_Set_BGR(void); +void PDATA_IDLE_STATE(void); + +//**[13h]**// +void HSYNC_Low_Active(void); +void HSYNC_High_Active(void); +void VSYNC_Low_Active(void); +void VSYNC_High_Active(void); +void DE_Low_Active(void); +void DE_High_Active(void); +void Idle_DE_Low(void); +void Idle_DE_High(void); +void Idle_PCLK_Low(void); +void Idle_PCLK_High(void); +void Idle_PDAT_Low(void); +void Idle_PDAT_High(void); +void Idle_HSYNC_Low(void); +void Idle_HSYNC_High(void); +void Idle_VSYNC_Low(void); +void Idle_VSYNC_High(void); +//**[14h][15h][1Ah][1Bh]**// +void LCD_HorizontalWidth_VerticalHeight(uint16_t WX, uint16_t HY); +//**[16h][17h]**// +void LCD_Horizontal_Non_Display(uint16_t WX); +//**[18h]**// +void LCD_HSYNC_Start_Position(uint16_t WX); +//**[19h]**// +void LCD_HSYNC_Pulse_Width(uint16_t WX); +//**[1Ch][1Dh]**// +void LCD_Vertical_Non_Display(uint16_t HY); +//**[1Eh]**// +void LCD_VSYNC_Start_Position(uint16_t HY); +//**[1Fh]**// +void LCD_VSYNC_Pulse_Width(uint16_t HY); +//**[20h][21h][22h][23h]**// +void Main_Image_Start_Address(uint32_t Addr); +//**[24h][25h]**// +void Main_Image_Width(uint16_t WX); +//**[26h][27h][28h][29h]**// +void Main_Window_Start_XY(uint16_t WX, uint16_t HY); +//**[2Ah][2Bh][2Ch][2Dh]**// +void PIP_Display_Start_XY(uint16_t WX, uint16_t HY); +//**[2Eh][2Fh][30h][31h]**// +void PIP_Image_Start_Address(uint32_t Addr); +//**[32h][33h]**// +void PIP_Image_Width(uint16_t WX); +//**[34h][35h][36h][37h]**// +void PIP_Window_Image_Start_XY(uint16_t WX, uint16_t HY); +//**[38h][39h][3Ah][3Bh]**// +void PIP_Window_Width_Height(uint16_t WX, uint16_t HY); +//**[3C]**// +void Enable_Graphic_Cursor(void); +void Disable_Graphic_Cursor(void); +void Select_Graphic_Cursor_1(void); +void Select_Graphic_Cursor_2(void); +void Select_Graphic_Cursor_3(void); +void Select_Graphic_Cursor_4(void); +void Enable_Text_Cursor(void); +void Disable_Text_Cursor(void); +void Enable_Text_Cursor_Blinking(void); +void Disable_Text_Cursor_Blinking(void); +//**[3D]**// +void Blinking_Time_Frames(uint8_t temp); +//**[3E][3Fh]**// +void Text_Cursor_H_V(uint16_t WX, uint16_t HY); +//**[40h][41h][42h][43h]**// +void Graphic_Cursor_XY(uint16_t WX, uint16_t HY); +//**[44]**// +void Set_Graphic_Cursor_Color_1(uint8_t temp); +//**[45]**// +void Set_Graphic_Cursor_Color_2(uint8_t temp); +//**[50h][51h][52h][53h]**// +void Canvas_Image_Start_address(uint32_t Addr); +//**[54h][55h]**// +void Canvas_image_width(uint16_t WX); +//**[56h][57h][58h][59h]**// +void Active_Window_XY(uint16_t WX, uint16_t HY); +//**[5Ah][5Bh][5Ch][5Dh]**// +void Active_Window_WH(uint16_t WX, uint16_t HY); +//**[5E]**// +void Select_Write_Data_Position(void); +void Select_Read_Data_Position(void); +void Memory_XY_Mode(void); +void Memory_Linear_Mode(void); +void Memory_8bpp_Mode(void); +void Memory_16bpp_Mode(void); +void Memory_24bpp_Mode(void); +//**[5Fh][60h][61h][62h]**// +void Goto_Pixel_XY(uint16_t WX, uint16_t HY); +void Goto_Linear_Addr(uint32_t Addr); +//**[63h][64h][65h][66h]**// +void Goto_Text_XY(uint16_t WX, uint16_t HY); + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : Draw ] ****//// +//**[67h]**// +void Start_Line(void); +void Start_Triangle(void); +void Start_Triangle_Fill(void); +//**[68h]~[73h]**// +void Line_Start_XY(uint16_t WX, uint16_t HY); +void Line_End_XY(uint16_t WX, uint16_t HY); +void Triangle_Point1_XY(uint16_t WX, uint16_t HY); +void Triangle_Point2_XY(uint16_t WX, uint16_t HY); +void Triangle_Point3_XY (uint16_t WX, uint16_t HY); +void Square_Start_XY(uint16_t WX, uint16_t HY); +void Square_End_XY(uint16_t WX, uint16_t HY); +//**[76h]**// +void Start_Circle_or_Ellipse(void); +void Start_Circle_or_Ellipse_Fill(void); +void Start_Left_Down_Curve(void); +void Start_Left_Up_Curve(void); +void Start_Right_Up_Curve(void); +void Start_Right_Down_Curve(void); +void Start_Left_Down_Curve_Fill(void); +void Start_Left_Up_Curve_Fill(void); +void Start_Right_Up_Curve_Fill(void); +void Start_Right_Down_Curve_Fill(void); +void Start_Square(void); +void Start_Square_Fill(void); +void Start_Circle_Square(void); +void Start_Circle_Square_Fill(void); +//**[77h]~[7Eh]**// +void Circle_Center_XY(uint16_t WX, uint16_t HY); +void Ellipse_Center_XY(uint16_t WX, uint16_t HY); +void Circle_Radius_R(uint16_t WX); +void Ellipse_Radius_RxRy(uint16_t WX, uint16_t HY); +void Circle_Square_Radius_RxRy(uint16_t WX, uint16_t HY); + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : PWM ] ****//// +//**[84h]**// +void Set_PWM_Prescaler_1_to_256(uint16_t WX); +//**[85h]**// +void Select_PWM1_Clock_Divided_By_1(void); +void Select_PWM1_Clock_Divided_By_2(void); +void Select_PWM1_Clock_Divided_By_4(void); +void Select_PWM1_Clock_Divided_By_8(void); +void Select_PWM0_Clock_Divided_By_1(void); +void Select_PWM0_Clock_Divided_By_2(void); +void Select_PWM0_Clock_Divided_By_4(void); +void Select_PWM0_Clock_Divided_By_8(void); +//[85h].[bit3][bit2] +void Select_PWM1_is_ErrorFlag(void); +void Select_PWM1(void); +void Select_PWM1_is_Osc_Clock(void); +//[85h].[bit1][bit0] +void Select_PWM0_is_GPIO_C7(void); +void Select_PWM0(void); +void Select_PWM0_is_Core_Clock(void); +//**[86h]**// +//[86h]PWM1 +void Enable_PWM1_Inverter(void); +void Disable_PWM1_Inverter(void); +void Auto_Reload_PWM1(void); +void One_Shot_PWM1(void); +void Start_PWM1(void); +void Stop_PWM1(void); +//[86h]PWM0 +void Enable_PWM0_Dead_Zone(void); +void Disable_PWM0_Dead_Zone(void); +void Enable_PWM0_Inverter(void); +void Disable_PWM0_Inverter(void); +void Auto_Reload_PWM0(void); +void One_Shot_PWM0(void); +void Start_PWM0(void); +void Stop_PWM0(void); +//**[87h]**// +void Set_Timer0_Dead_Zone_Length(uint8_t temp); +//**[88h][89h]**// +void Set_Timer0_Compare_Buffer(uint16_t WX); +//**[8Ah][8Bh]**// +void Set_Timer0_Count_Buffer(uint16_t WX); +//**[8Ch][8Dh]**// +void Set_Timer1_Compare_Buffer(uint16_t WX); +//**[8Eh][8Fh]**// +void Set_Timer1_Count_Buffer(uint16_t WX); + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : BTE ] ****//// +//**[90h]**// + +//[90h]========================================================================= +void BTE_Enable(void); +void BTE_Disable(void); + +void Check_BTE_Busy(void); + +void Pattern_Format_8X8(void); +void Pattern_Format_16X16(void); + +//[91h]========================================================================= +void BTE_ROP_Code(uint8_t setx); +void BTE_Operation_Code(uint8_t setx); + +//[92h]========================================================================= +void BTE_S0_Color_8bpp(void); +void BTE_S0_Color_16bpp(void); +void BTE_S0_Color_24bpp(void); + +void BTE_S1_Color_8bpp(void); +void BTE_S1_Color_16bpp(void); +void BTE_S1_Color_24bpp(void); +void BTE_S1_Color_Constant(void); +void BTE_S1_Color_8bit_Alpha(void); +void BTE_S1_Color_16bit_Alpha(void); + +void BTE_Destination_Color_8bpp(void); +void BTE_Destination_Color_16bpp(void); +void BTE_Destination_Color_24bpp(void); + +//[93h][94h][95h][96h]========================================================================= +void BTE_S0_Memory_Start_Address(uint32_t Addr); + +//[97h][98h]========================================================================= +void BTE_S0_Image_Width(uint16_t WX); + +//[99h][9Ah][9Bh][9Ch]========================================================================= +void BTE_S0_Window_Start_XY(uint16_t WX, uint16_t HY); + +//[9Dh][9Eh][9Fh][A0h]========================================================================= +void BTE_S1_Memory_Start_Address(uint32_t Addr); +void S1_Constant_color_256(uint8_t temp); +void S1_Constant_color_65k(uint16_t temp); +void S1_Constant_color_16M(uint32_t temp); + +//[A1h][A2h]========================================================================= +void BTE_S1_Image_Width(uint16_t WX); + +//[A3h][A4h][A5h][A6h]========================================================================= +void BTE_S1_Window_Start_XY(uint16_t WX, uint16_t HY); + +//[A7h][A8h][A9h][AAh]========================================================================= +void BTE_Destination_Memory_Start_Address(uint32_t Addr); + +//[ABh][ACh]========================================================================= +void BTE_Destination_Image_Width(uint16_t WX); + +//[ADh][AEh][AFh][B0h]========================================================================= +void BTE_Destination_Window_Start_XY(uint16_t WX, uint16_t HY); + +//[B1h][B2h][B3h][B4h]========================================================================= +void BTE_Window_Size(uint16_t WX, uint16_t WY); + +//[B5h]========================================================================= +void BTE_Alpha_Blending_Effect(uint8_t temp); + + +//**[B5h]**// + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : Serial Flash ] ****//// + + +//REG[B6h] Serial flash DMA Controller REG (DMA_CTRL) +void Start_SFI_DMA(void); +void Check_Busy_SFI_DMA(void); + +//REG[B7h] Serial Flash/ROM Controller Register (SFL_CTRL) +void Select_SFI_0(void); +void Select_SFI_1(void); +void Select_SFI_Font_Mode(void); +void Select_SFI_DMA_Mode(void); +void Select_SFI_24bit_Address(void); +void Select_SFI_32bit_Address(void); +void Select_SFI_Waveform_Mode_0(void); +void Select_SFI_Waveform_Mode_3(void); +void Select_SFI_0_DummyRead(void); +void Select_SFI_8_DummyRead(void); +void Select_SFI_16_DummyRead(void); +void Select_SFI_24_DummyRead(void); +void Select_SFI_Single_Mode(void); +void Select_SFI_Dual_Mode0(void); +void Select_SFI_Dual_Mode1(void); + +//REG[B8h] SPI master Tx /Rx FIFO Data Register (SPIDR) +uint8_t SPI_Master_FIFO_Data_Put(uint8_t Data); +uint8_t SPI_Master_FIFO_Data_Get(void); + +//REG[B9h] SPI master Control Register (SPIMCR2) +void Mask_SPI_Master_Interrupt_Flag(void); +void Select_nSS_drive_on_xnsfcs0(void); +void Select_nSS_drive_on_xnsfcs1(void); +void nSS_Inactive(void); +void nSS_Active(void); +void OVFIRQEN_Enable(void); +void EMTIRQEN_Enable(void); +void Reset_CPOL(void); +void Set_CPOL(void); +void Reset_CPHA(void); +void Set_CPHA(void); + +//REG[BAh] SPI master Status Register (SPIMSR) +uint8_t Tx_FIFO_Empty_Flag(void); +uint8_t Tx_FIFO_Full_Flag(void); +uint8_t Rx_FIFO_Empty_Flag(void); +uint8_t Rx_FIFO_full_flag(void); +uint8_t OVFI_Flag(void); +void Clear_OVFI_Flag(void); +uint8_t EMTI_Flag(void); +void Clear_EMTI_Flag(void); + +//REG[BB] SPI Clock period (SPIDIV) +void SPI_Clock_Period(uint8_t temp); + + +//**[BCh][BDh][BEh][BFh]**// +void SFI_DMA_Source_Start_Address(uint32_t Addr); +//**[C0h][C1h][C2h][C3h]**// +void SFI_DMA_Destination_Start_Address(uint32_t Addr); +void SFI_DMA_Destination_Upper_Left_Corner(uint16_t WX, uint16_t HY); +//**[C4h][C5h]**// +void SFI_DMA_Destination_Width(uint16_t WX); +//**[C6h][C7h][C8h][C9h]**// +void SFI_DMA_Transfer_Number(uint32_t Addr); +void SFI_DMA_Transfer_Width_Height(uint16_t WX, uint16_t HY); +//**[CAh][CBh]**// +void SFI_DMA_Source_Width(uint16_t WX); + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : Font ] ****//// +//**[CCh]**// + +void Font_Select_UserDefine_Mode(void); +void CGROM_Select_Internal_CGROM(void); +void CGROM_Select_Genitop_FontROM(void); +void Font_Select_8x16_16x16(void); +void Font_Select_12x24_24x24(void); +void Font_Select_16x32_32x32(void); +void Internal_CGROM_Select_ISOIEC8859_1(void); +void Internal_CGROM_Select_ISOIEC8859_2(void); +void Internal_CGROM_Select_ISOIEC8859_3(void); +void Internal_CGROM_Select_ISOIEC8859_4(void); +//**[CDh]**// +void Enable_Font_Alignment(void); +void Disable_Font_Alignment(void); +void Font_Background_select_Transparency(void); +void Font_Background_select_Color(void); +void Font_0_degree(void); +void Font_90_degree(void); +void Font_Width_X1(void); +void Font_Width_X2(void); +void Font_Width_X3(void); +void Font_Width_X4(void); +void Font_Height_X1(void); +void Font_Height_X2(void); +void Font_Height_X3(void); +void Font_Height_X4(void); +//**[CEh]**// +void GTFont_Select_GT21L16TW_GT21H16T1W(void); +void GTFont_Select_GT23L16U2W(void); +void GTFont_Select_GT23L24T3Y_GT23H24T3Y(void); +void GTFont_Select_GT23L24M1Z(void); +void GTFont_Select_GT23L32S4W_GT23H32S4W(void); +void GTFont_Select_GT20L24F6Y(void); +void GTFont_Select_GT21L24S1W(void); +void GTFont_Select_GT22L16A1Y(void); +//**[CFh]**// +void Set_GTFont_Decoder(uint8_t temp); +//**[D0h]**// +void Font_Line_Distance(uint8_t temp); +//**[D1h]**// +void Set_Font_to_Font_Width(uint8_t temp); +//**[D2h]~[D4h]**// +void Foreground_RGB(uint8_t RED, uint8_t GREEN, uint8_t BLUE); +void Foreground_color_256(uint8_t temp); +void Foreground_color_65k(uint16_t temp); +void Foreground_color_16M(uint32_t temp); +//**[D5h]~[D7h]**// +void Background_RGB(uint8_t RED, uint8_t GREEN, uint8_t BLUE); +void Background_color_256(uint8_t temp); +void Background_color_65k(uint16_t temp); +void Background_color_16M(uint32_t temp); +//**[DBh]~[DEh]**// +void CGRAM_Start_address(uint32_t Addr); +//**[DFh]**// +void Power_Normal_Mode(void); +void Power_Saving_Standby_Mode(void); +void Power_Saving_Suspend_Mode(void); +void Power_Saving_Sleep_Mode(void); + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : SDRAM ] ****//// +//**[E0h]~[E4h]**// +// LT768_Select_SDRAM(); + + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : I2C ] ****//// +//**[E5h]~[EAh]**// +void LT768_I2CM_Clock_Prescale(uint16_t WX); +//**[E7h]**// +void LT768_I2CM_Transmit_Data(uint8_t temp); +//**[E8h]**// +uint8_t LT768_I2CM_Receiver_Data(void); +//**[E9h]**// + +void LT768_I2CM_Read_With_Ack(void); +void LT768_I2CM_Read_With_Nack(void); +void LT768_I2CM_Write_With_Start(void); +void LT768_I2CM_Write(void); +void LT768_I2CM_Stop(void); + + +//**[EAh]**// +uint8_t LT768_I2CM_Check_Slave_ACK(void); +uint8_t LT768_I2CM_Bus_Busy(void); +uint8_t LT768_I2CM_transmit_Progress(void); +uint8_t LT768_I2CM_Arbitration(void); + + + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : GPIO ] ****//// +//[F0h][F1h] +void Set_GPIO_A_In_Out(uint8_t temp); +void Write_GPIO_A_7_0(uint8_t temp); +uint8_t Read_GPIO_A_7_0(void); +//[F2h] +void Write_GPIO_B_7_4(uint8_t temp); +uint8_t Read_GPIO_B_7_0(void); +//[F3h][F4h] +void Set_GPIO_C_In_Out(uint8_t temp); +void Write_GPIO_C_7_0(uint8_t temp); +uint8_t Read_GPIO_C_7_0(void); +//[F5h][F6h] +void Set_GPIO_D_In_Out(uint8_t temp); +void Write_GPIO_D_7_0(uint8_t temp); +uint8_t Read_GPIO_D_7_0(void); +//[F7h][F8h] +void Set_GPIO_E_In_Out(uint8_t temp); +void Write_GPIO_E_7_0(uint8_t temp); +uint8_t Read_GPIO_E_7_0(void); +//[F9h][FAh] +void Set_GPIO_F_In_Out(uint8_t temp); +void Write_GPIO_F_7_0(uint8_t temp); +uint8_t Read_GPIO_F_7_0(void); + + +//////////////////////////////////////////////////////////////////////// +////**** [ Function : Key ] ****//// +//**[FBh]~[FFh]**// +//[FBh] +void Long_Key_enable(void); +void Key_Scan_Freg(uint8_t temp); //set bit2~0 + +//[FCh] +void Key_Scan_Wakeup_Function_Enable(void); +void Long_Key_Timing_Adjustment(uint8_t setx);//set bit5~3 +uint8_t Numbers_of_Key_Hit(void); + +//[FDh][FEh][FFh] +uint8_t Read_Key_Strobe_Data_0(void); +uint8_t Read_Key_Strobe_Data_1(void); +uint8_t Read_Key_Strobe_Data_2(void); + +void Show_String(char *str); +void Show_picture(uint32_t numbers, const uint16_t *data); + +void PWM0_ON(void); //PWM0 + +void lt768_hw_reset(void); +void System_Check_Temp(void); +void Enable_SPI_Flash_DMA(uint8_t val); + +#endif + diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/lcd/lt768_lib.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/lcd/lt768_lib.h index 6c6adaf1f..345eb2e58 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/lcd/lt768_lib.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/lcd/lt768_lib.h @@ -1,306 +1,913 @@ -/********************* COPYRIGHT ********************** -* File Name : lt768_lib.h -* Author : Levetop Electronics -* Version : V1.3 -* Date : 2019-5-14 -* Description : LT768x所有功能函数 -********************************************************/ - -#ifndef _LT768_Lib_H -#define _LT768_Lib_H -#include "lt768.h" - -//外部晶振 -#define XI_4M 0 -#define XI_8M 1 -#define XI_10M 0 -#define XI_12M 0 - -//分辨率 -#define LCD_XSIZE_TFT 480 -#define LCD_YSIZE_TFT 272 - -//参数 -#define LCD_VBPD 20 -#define LCD_VFPD 12 -#define LCD_VSPW 3 -#define LCD_HBPD 140 -#define LCD_HFPD 160 -#define LCD_HSPW 20 - -#define color256_black 0x00 -#define color256_white 0xff -#define color256_red 0xe0 -#define color256_green 0x1c -#define color256_blue 0x03 -#define color256_yellow color256_red|color256_green -#define color256_cyan color256_green|color256_blue -#define color256_purple color256_red|color256_blue - -#define color65k_black 0x0000 -#define color65k_white 0xffff -#define color65k_red 0xf800 -#define color65k_green 0x07e0 -#define color65k_blue 0x001f -#define color65k_yellow color65k_red|color65k_green -#define color65k_cyan color65k_green|color65k_blue -#define color65k_purple color65k_red|color65k_blue - -#define color65k_grayscale1 2113 -#define color65k_grayscale2 2113*2 -#define color65k_grayscale3 2113*3 -#define color65k_grayscale4 2113*4 -#define color65k_grayscale5 2113*5 -#define color65k_grayscale6 2113*6 -#define color65k_grayscale7 2113*7 -#define color65k_grayscale8 2113*8 -#define color65k_grayscale9 2113*9 -#define color65k_grayscale10 2113*10 -#define color65k_grayscale11 2113*11 -#define color65k_grayscale12 2113*12 -#define color65k_grayscale13 2113*13 -#define color65k_grayscale14 2113*14 -#define color65k_grayscale15 2113*15 -#define color65k_grayscale16 2113*16 -#define color65k_grayscale17 2113*17 -#define color65k_grayscale18 2113*18 -#define color65k_grayscale19 2113*19 -#define color65k_grayscale20 2113*20 -#define color65k_grayscale21 2113*21 -#define color65k_grayscale22 2113*22 -#define color65k_grayscale23 2113*23 -#define color65k_grayscale24 2113*24 -#define color65k_grayscale25 2113*25 -#define color65k_grayscale26 2113*26 -#define color65k_grayscale27 2113*27 -#define color65k_grayscale28 2113*28 -#define color65k_grayscale29 2113*29 -#define color65k_grayscale30 2113*30 - -#define color16M_black 0x00000000 -#define color16M_white 0x00ffffff -#define color16M_red 0x00ff0000 -#define color16M_green 0x0000ff00 -#define color16M_blue 0x000000ff -#define color16M_yellow color16M_red|color16M_green -#define color16M_cyan color16M_green|color16M_blue -#define color16M_purple color16M_red|color16M_blue - -/* LCD color */ -#define White 0xFFFF -#define Black 0x0000 -#define Grey 0xF7DE -#define Blue 0x001F -#define Blue2 0x051F -#define Red 0xF800 -#define Magenta 0xF81F -#define Green 0x07E0 -#define Cyan 0x7FFF -#define Yellow 0xFFE0 - -#define Line0 0 -#define Line1 24 -#define Line2 48 -#define Line3 72 -#define Line4 96 -#define Line5 120 -#define Line6 144 -#define Line7 168 -#define Line8 192 -#define Line9 216 -#define Line10 240 -#define Line11 264 -#define Line12 288 -#define Line13 312 -#define Line14 336 -#define Line15 360 -#define Line16 384 -#define Line17 408 -#define Line18 432 -#define Line19 456 -#define Line20 480 -#define Line21 504 -#define Line22 528 -#define Line23 552 -#define Line24 576 -#define Line25 600 - -void lt768_init(void); - -/* 写数据到内存 */ -void MPuint8_t_8bpp_Memory_Write(unsigned short x,unsigned short y,unsigned short w,unsigned short h,const unsigned char *data); -void MPuint8_t_16bpp_Memory_Write(unsigned short x,unsigned short y,unsigned short w,unsigned short h,const unsigned char *data); -void MPuint8_t_24bpp_Memory_Write(unsigned short x,unsigned short y,unsigned short w,unsigned short h,const unsigned char *data); -void MPuint16_t_16bpp_Memory_Write(unsigned short x,unsigned short y,unsigned short w,unsigned short h,const unsigned short *data); -void MPuint16_t_24bpp_Mode1_Memory_Write(unsigned short x,unsigned short y,unsigned short w,unsigned short h,const unsigned short *data); -void MPuint16_t_24bpp_Mode2_Memory_Write(unsigned short x,unsigned short y,unsigned short w,unsigned short h,const unsigned short *data); - -/* 硬件画线段 */ -void LT768_DrawLine(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned long LineColor); -void LT768_DrawLine_Width(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned long LineColor,unsigned short Width); - -/* 硬件画圆 */ -void LT768_DrawCircle(unsigned short XCenter,unsigned short YCenter,unsigned short R,unsigned long CircleColor); -void LT768_DrawCircle_Fill(unsigned short XCenter,unsigned short YCenter,unsigned short R,unsigned long ForegroundColor); -void LT768_DrawCircle_Width(unsigned short XCenter,unsigned short YCenter,unsigned short R,unsigned long CircleColor,unsigned long ForegroundColor,unsigned short Width); - -/* 硬件画椭圆 */ -void LT768_DrawEllipse(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long EllipseColor); -void LT768_DrawEllipse_Fill(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long ForegroundColor); -void LT768_DrawEllipse_Width(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long EllipseColor,unsigned long ForegroundColor,unsigned short Width); - -/* 硬件画矩形 */ -void LT768_DrawSquare(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned long SquareColor); -void LT768_DrawSquare_Fill(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned long ForegroundColor); -void LT768_DrawSquare_Width(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned long SquareColor,unsigned long ForegroundColor,unsigned short Width); - -/* 硬件画圆角矩形 */ -void LT768_DrawCircleSquare(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X_R,unsigned short Y_R,unsigned long CircleSquareColor); -void LT768_DrawCircleSquare_Fill(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X_R,unsigned short Y_R,unsigned long ForegroundColor); -void LT768_DrawCircleSquare_Width(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X_R,unsigned short Y_R,unsigned long CircleSquareColor,unsigned long ForegroundColor,unsigned short Width); - -/* 硬件画三角形 */ -void LT768_DrawTriangle(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned long TriangleColor); -void LT768_DrawTriangle_Fill(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned long ForegroundColor); -void LT768_DrawTriangle_Frame(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned long TriangleColor,unsigned long ForegroundColor); - -/* 硬件画四边形 */ -void LT768_DrawQuadrilateral(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned short X4,unsigned short Y4,unsigned long ForegroundColor); -void LT768_DrawQuadrilateral_Fill(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned short X4,unsigned short Y4,unsigned long ForegroundColor); -void LT768_DrawTriangle_Frame(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned long TriangleColor ,unsigned long ForegroundColor); - -/* 硬件画五边形 */ -void LT768_DrawPentagon(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned short X4,unsigned short Y4,unsigned short X5,unsigned short Y5,unsigned long ForegroundColor); -void LT768_DrawPentagon_Fill(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned short X4,unsigned short Y4,unsigned short X5,unsigned short Y5,unsigned long ForegroundColor); - -/* 硬件画曲线 */ -void LT768_DrawLeftUpCurve(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long CurveColor); -void LT768_DrawLeftDownCurve(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long CurveColor); -void LT768_DrawRightUpCurve(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long CurveColor); -void LT768_DrawRightDownCurve(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long CurveColor); -void LT768_SelectDrawCurve(unsigned short XCenter ,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long CurveColor,unsigned short Dir); - -/* 硬件画1/4椭圆 */ -void LT768_DrawLeftUpCurve_Fill(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long ForegroundColor); -void LT768_DrawLeftDownCurve_Fill(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long ForegroundColor); -void LT768_DrawRightUpCurve_Fill(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long ForegroundColor); -void LT768_DrawRightDownCurve_Fill(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long ForegroundColor); -void LT768_SelectDrawCurve_Fill(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned long CurveColor,unsigned short Dir); - -/* 硬件画圆柱 */ -unsigned char LT768_DrawCylinder(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned short H,unsigned long CylinderColor,unsigned long ForegroundColor); - -/* 硬件画四棱柱 */ -void LT768_DrawQuadrangular(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned short X4,unsigned short Y4,unsigned short X5,unsigned short Y5,unsigned short X6,unsigned short Y6,unsigned long QuadrangularColor,unsigned long ForegroundColor); - -/* 表格 */ -void LT768_MakeTable(unsigned short X1,unsigned short Y1,unsigned short W,unsigned short H,unsigned short Line,unsigned short Row,unsigned long TableColor,unsigned long ItemColor,unsigned long ForegroundColor,unsigned short width1,unsigned short width2,unsigned char mode); - -/* 线性模式下DMA传输数据到SDRAM中 */ -void LT768_DMA_24bit_Linear(unsigned char SCS,unsigned char Clk,unsigned long flash_addr,unsigned long memory_ad,unsigned long data_num); -void LT768_DMA_32bit_Linear(unsigned char SCS,unsigned char Clk,unsigned long flash_addr,unsigned long memory_ad,unsigned long data_num); - -/* 区块模式下DMA传输数据到SDRAM中 */ -void LT768_DMA_24bit_Block(unsigned char SCS,unsigned char Clk,unsigned short X1,unsigned short Y1 ,unsigned short X_W,unsigned short Y_H,unsigned short P_W,unsigned long Addr); -void LT768_DMA_32bit_Block(unsigned char SCS,unsigned char Clk,unsigned short X1,unsigned short Y1 ,unsigned short X_W,unsigned short Y_H,unsigned short P_W,unsigned long Addr); - -/* 使用内建字库 */ -void LT768_Select_Internal_Font_Init(unsigned char Size,unsigned char XxN,unsigned char YxN,unsigned char ChromaKey,unsigned char Alignment); -void LT768_Print_Internal_Font_String(unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor ,char *c); - -/* nor flash使用外建字库 */ -/* 16*16 24*24 32*32 */ -void LT768_Select_Outside_Font_Init(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr,unsigned long Num,unsigned char Size,unsigned char XxN,unsigned char YxN,unsigned char ChromaKey,unsigned char Alignment); -void LT768_Print_Outside_Font_String(unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned char *c); -void LT768_Print_Outside_Font_GBK_String(unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned char *c); -/* 48*48 72*72全角 */ -void LT768_BTE_Memory_Copy_ColorExpansion_8(unsigned long S0_Addr,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color,unsigned long Background_color); -void LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(unsigned long S0_Addr,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color); -void LT768_Print_Outside_Font_GB2312_48_72(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr,unsigned long ShowAddr,unsigned short width,unsigned char Size,unsigned char ChromaKey,unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned short w,unsigned short s,unsigned char *c); -void LT768_Print_Outside_Font_BIG5_48_72(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr,unsigned long ShowAddr,unsigned short width,unsigned char Size,unsigned char ChromaKey,unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned short w,unsigned short s,unsigned char *c); -void LT768_Print_Outside_Font_GBK_48_72(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr,unsigned long ShowAddr,unsigned short width,unsigned char Size,unsigned char ChromaKey,unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned short w,unsigned short s,unsigned char *c); - -/* nor flash使用自定义字库 */ -/* 16*16 24*24 32*32 48*48 72*72全角 */ -int Get_User_Font_P(char chH,char chL); -void LT768_Print_Outside_UserDefineFont_GB2312(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr,unsigned long ShowAddr,unsigned short width,unsigned char Size,unsigned char ChromaKey,unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned short w,unsigned short s,unsigned char *c); - -/* 文字光标 */ -void LT768_Text_cursor_Init(unsigned char On_Off_Blinking,unsigned short Blinking_Time,unsigned short X_W,unsigned short Y_W); -void LT768_Enable_Text_Cursor(void); -void LT768_Disable_Text_Cursor(void); - -/* 图像光标 */ -void LT768_Graphic_cursor_Init(unsigned char Cursor_N,unsigned char Color1,unsigned char Color2,unsigned short X_Pos,unsigned short Y_Pos,unsigned char *Cursor_Buf); -void LT768_Set_Graphic_cursor_Pos(unsigned char Cursor_N,unsigned short X_Pos,unsigned short Y_Pos); -void LT768_Enable_Graphic_Cursor(void); -void LT768_Disable_Graphic_Cursor(void); - -/* 区块传输引擎(BitBLT) */ -void BTE_Solid_Fill(unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short color,unsigned short X_W,unsigned short Y_H); -void LT768_BTE_Memory_Copy(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned short X_W,unsigned short Y_H); -void LT768_BTE_Memory_Copy_Chroma_key(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned long Background_color,unsigned short X_W,unsigned short Y_H); -void LT768_BTE_Pattern_Fill(unsigned char P_8x8_or_16x16,unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned int ROP_Code ,unsigned short X_W,unsigned short Y_H); -void LT768_BTE_Pattern_Fill_With_Chroma_key(unsigned char P_8x8_or_16x16,unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned long Background_color,unsigned short X_W,unsigned short Y_H); -void LT768_BTE_MCU_Write_MCU_16bit(unsigned long S1_Addr,unsigned short S1_W,unsigned short XS,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned short X_W,unsigned short Y_H ,const unsigned short *data); -void LT768_BTE_MCU_Write_Chroma_key_MCU_16bit(unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned long Background_color,unsigned short X_W,unsigned short Y_H,const unsigned short *data); -void LT768_BTE_MCU_Write_ColorExpansion_MCU_16bit(unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color ,unsigned long Background_color ,const unsigned short *data); -void LT768_BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_16bit(unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color,const unsigned short *data); -void BTE_Alpha_Blending(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned char alpha); -void BTE_Pixel_8bpp_Alpha_Blending(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H); -void BTE_Pixel_16bpp_Alpha_Blending(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H); - -/* PIP */ -void LT768_PIP_Init(unsigned char On_Off,unsigned char Select_PIP,unsigned long PAddr,unsigned short XP,unsigned short YP,unsigned long ImageWidth,unsigned short X_Dis,unsigned short Y_Dis,unsigned short X_W,unsigned short Y_H); -void LT768_Set_DisWindowPos(unsigned char On_Off,unsigned char Select_PIP,unsigned short X_Dis,unsigned short Y_Dis); - -/* PWM */ -void LT768_PWM0_Init(unsigned char on_off,unsigned char Clock_Divided,unsigned char Prescalar,unsigned short Count_Buffer,unsigned short Compare_Buffer); -void LT768_PWM1_Init(unsigned char on_off,unsigned char Clock_Divided,unsigned char Prescalar,unsigned short Count_Buffer,unsigned short Compare_Buffer); -void LT768_PWM0_Duty(unsigned short Compare_Buffer); -void LT768_PWM1_Duty(unsigned short Compare_Buffer); - -/* Standby Mode */ -void LT768_Standby(void); -void LT768_Wkup_Standby(void); - -/* Suspend Mode */ -void LT768_Suspend(void); -void LT768_Wkup_Suspend(void); - -/* Sleep Mode */ -void LT768_SleepMode(void); -void LT768_Wkup_Sleep(void); - -/* W25QXX */ -void LT768_SPI_Init(uint8_t cs,uint8_t div); -void W25QXX_Enter_4Byte_AddressMode(void); -void LT_W25QXX_Read(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead); - -/* nand flash W25N01GV */ -uint8_t W25N01GV_ReadSR(uint8_t reg); -void W25N01GV_Write_SR(uint8_t reg,uint8_t val); -void W25N01GV_Wait_Busy(void); -void W25N01GV_ContinuousRead_Mode(void); -void W25N01GV_Write_Page(uint16_t page); -void W25N01GV_ReadPageAddr_Data(uint8_t* pBuffer,uint32_t PageNum,uint32_t PageAddr,uint16_t NumByteToRead); -void LT_W25N01GV_Read(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead); - -/* nand flash显示图片 */ -void LT768_Nand_Pic(unsigned char SCS,unsigned short X1,unsigned short Y1,unsigned short X_W,unsigned short Y_H,unsigned long Addr,unsigned long lay0,unsigned long lay1); - -/* nand flash使用外建字库初始化 */ -/* 16*16 24*24 32*32 */ -void NandFlash_Select_Outside_Font_Init(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr,unsigned long Num,unsigned char Size,unsigned char XxN,unsigned char YxN,unsigned char ChromaKey,unsigned char Alignment); - -/* nand flash使用外建字库 */ -/* 48*48 72*72全角 */ -void LT768_BTE_Memory_Copy_8(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned short X_W,unsigned short Y_H); -void LT768_Nand_8bpp_font(unsigned char SCS,unsigned char Clk,unsigned short X1,unsigned short Y1,unsigned short X_W,unsigned short Y_H,unsigned long Addr,unsigned long lay1,unsigned long lay2); -void LT768_Print_Outside_Font_GB2312_48_72_Nand(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr1,unsigned long MemoryAddr2,unsigned long ShowAddr,unsigned short width,unsigned char Size,unsigned char ChromaKey,unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned short w,unsigned short s,unsigned char *c); -void LT768_Print_Outside_Font_GBK_48_72_Nand(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr1,unsigned long MemoryAddr2,unsigned long ShowAddr,unsigned short width,unsigned char Size,unsigned char ChromaKey,unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned short w,unsigned short s,unsigned char *c); - -/* nand flash使用自定义字库 */ -/* 16*16 24*24 32*32 48*48 72*72全角 */ -void LT768_Print_Outside_UserDefineFont_GB2312_Nand(unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr1,unsigned long MemoryAddr2,unsigned long ShowAddr,unsigned short width,unsigned char Size,unsigned char ChromaKey,unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned short w,unsigned short s,unsigned char *c); -#endif +/* +* Copyright (c) 2022 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file lt768_lib.h + * @brief lt768 register relative driver, inherit from Levetop Electronics + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.9.19 + */ + +#ifndef __LT768_LIB_H_ +#define __LT768_LIB_H_ +#include "lt768.h" + +//external OSC +#define XI_4M 0 +#define XI_8M 1 +#define XI_10M 0 +#define XI_12M 0 + +//resolution +#define LCD_XSIZE_TFT 480 +#define LCD_YSIZE_TFT 272 + +//parameter +#define LCD_VBPD 20 +#define LCD_VFPD 12 +#define LCD_VSPW 3 +#define LCD_HBPD 140 +#define LCD_HFPD 160 +#define LCD_HSPW 20 + +#define color256_black 0x00 +#define color256_white 0xff +#define color256_red 0xe0 +#define color256_green 0x1c +#define color256_blue 0x03 +#define color256_yellow color256_red|color256_green +#define color256_cyan color256_green|color256_blue +#define color256_purple color256_red|color256_blue + +#define color65k_black 0x0000 +#define color65k_white 0xffff +#define color65k_red 0xf800 +#define color65k_green 0x07e0 +#define color65k_blue 0x001f +#define color65k_yellow color65k_red|color65k_green +#define color65k_cyan color65k_green|color65k_blue +#define color65k_purple color65k_red|color65k_blue + +#define color65k_grayscale1 2113 +#define color65k_grayscale2 2113*2 +#define color65k_grayscale3 2113*3 +#define color65k_grayscale4 2113*4 +#define color65k_grayscale5 2113*5 +#define color65k_grayscale6 2113*6 +#define color65k_grayscale7 2113*7 +#define color65k_grayscale8 2113*8 +#define color65k_grayscale9 2113*9 +#define color65k_grayscale10 2113*10 +#define color65k_grayscale11 2113*11 +#define color65k_grayscale12 2113*12 +#define color65k_grayscale13 2113*13 +#define color65k_grayscale14 2113*14 +#define color65k_grayscale15 2113*15 +#define color65k_grayscale16 2113*16 +#define color65k_grayscale17 2113*17 +#define color65k_grayscale18 2113*18 +#define color65k_grayscale19 2113*19 +#define color65k_grayscale20 2113*20 +#define color65k_grayscale21 2113*21 +#define color65k_grayscale22 2113*22 +#define color65k_grayscale23 2113*23 +#define color65k_grayscale24 2113*24 +#define color65k_grayscale25 2113*25 +#define color65k_grayscale26 2113*26 +#define color65k_grayscale27 2113*27 +#define color65k_grayscale28 2113*28 +#define color65k_grayscale29 2113*29 +#define color65k_grayscale30 2113*30 + +#define color16M_black 0x00000000 +#define color16M_white 0x00ffffff +#define color16M_red 0x00ff0000 +#define color16M_green 0x0000ff00 +#define color16M_blue 0x000000ff +#define color16M_yellow color16M_red|color16M_green +#define color16M_cyan color16M_green|color16M_blue +#define color16M_purple color16M_red|color16M_blue + +/* LCD color */ +#define White 0xFFFF +#define Black 0x0000 +#define Grey 0xF7DE +#define Blue 0x001F +#define Blue2 0x051F +#define Red 0xF800 +#define Magenta 0xF81F +#define Green 0x07E0 +#define Cyan 0x7FFF +#define Yellow 0xFFE0 + +#define Line0 0 +#define Line1 24 +#define Line2 48 +#define Line3 72 +#define Line4 96 +#define Line5 120 +#define Line6 144 +#define Line7 168 +#define Line8 192 +#define Line9 216 +#define Line10 240 +#define Line11 264 +#define Line12 288 +#define Line13 312 +#define Line14 336 +#define Line15 360 +#define Line16 384 +#define Line17 408 +#define Line18 432 +#define Line19 456 +#define Line20 480 +#define Line21 504 +#define Line22 528 +#define Line23 552 +#define Line24 576 +#define Line25 600 + +void lt768_init(void); + +/* write to memory */ +void MPuint8_t_8bpp_Memory_Write(uint16_t x, + uint16_t y, + uint16_t w, + uint16_t h, + const uint8_t *data); +void MPuint8_t_16bpp_Memory_Write(uint16_t x, + uint16_t y, + uint16_t w, + uint16_t h, + const uint8_t *data); +void MPuint8_t_24bpp_Memory_Write(uint16_t x, + uint16_t y, + uint16_t w, + uint16_t h, + const uint8_t *data); +void MPuint16_t_16bpp_Memory_Write(uint16_t x, + uint16_t y, + uint16_t w, + uint16_t h, + const uint16_t *data); +void MPuint16_t_24bpp_Mode1_Memory_Write(uint16_t x, + uint16_t y, + uint16_t w, + uint16_t h, + const uint16_t *data); +void MPuint16_t_24bpp_Mode2_Memory_Write(uint16_t x, + uint16_t y, + uint16_t w, + uint16_t h, + const uint16_t *data); + +/* draw line */ +void LT768_DrawLine(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint32_t LineColor); +void LT768_DrawLine_Width(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint32_t LineColor, + uint16_t Width); + +/* draw circle */ +void LT768_DrawCircle(uint16_t XCenter, + uint16_t YCenter, + uint16_t R, + uint32_t CircleColor); +void LT768_DrawCircle_Fill(uint16_t XCenter, + uint16_t YCenter, + uint16_t R, + uint32_t ForegroundColor); +void LT768_DrawCircle_Width(uint16_t XCenter, + uint16_t YCenter, + uint16_t R, + uint32_t CircleColor, + uint32_t ForegroundColor, + uint16_t Width); + +/* draw elipse */ +void LT768_DrawEllipse(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t EllipseColor); +void LT768_DrawEllipse_Fill(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t ForegroundColor); +void LT768_DrawEllipse_Width(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t EllipseColor, + uint32_t ForegroundColor, + uint16_t Width); + +/* draw square */ +void LT768_DrawSquare(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint32_t SquareColor); +void LT768_DrawSquare_Fill(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint32_t ForegroundColor); +void LT768_DrawSquare_Width(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint32_t SquareColor, + uint32_t ForegroundColor, + uint16_t Width); + +/* draw circle square */ +void LT768_DrawCircleSquare(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X_R, + uint16_t Y_R, + uint32_t CircleSquareColor); +void LT768_DrawCircleSquare_Fill(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X_R, + uint16_t Y_R, + uint32_t ForegroundColor); +void LT768_DrawCircleSquare_Width(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X_R, + uint16_t Y_R, + uint32_t CircleSquareColor, + uint32_t ForegroundColor, + uint16_t Width); + +/* draw triangle */ +void LT768_DrawTriangle(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint32_t TriangleColor); +void LT768_DrawTriangle_Fill(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint32_t ForegroundColor); +void LT768_DrawTriangle_Frame(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint32_t TriangleColor, + uint32_t ForegroundColor); + +/* draw quadrilateral */ +void LT768_DrawQuadrilateral(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint16_t X4, + uint16_t Y4, + uint32_t ForegroundColor); +void LT768_DrawQuadrilateral_Fill(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint16_t X4, + uint16_t Y4, + uint32_t ForegroundColor); +void LT768_DrawTriangle_Frame(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint32_t TriangleColor, + uint32_t ForegroundColor); + +/* draw pentagon */ +void LT768_DrawPentagon(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint16_t X4, + uint16_t Y4, + uint16_t X5, + uint16_t Y5, + uint32_t ForegroundColor); +void LT768_DrawPentagon_Fill(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint16_t X4, + uint16_t Y4, + uint16_t X5, + uint16_t Y5, + uint32_t ForegroundColor); + +/* draw curve */ +void LT768_DrawLeftUpCurve(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t CurveColor); +void LT768_DrawLeftDownCurve(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t CurveColor); +void LT768_DrawRightUpCurve(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t CurveColor); +void LT768_DrawRightDownCurve(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t CurveColor); +void LT768_SelectDrawCurve(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t CurveColor, + uint16_t Dir); + +/* draw 1/4 filled curve */ +void LT768_DrawLeftUpCurve_Fill(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t ForegroundColor); +void LT768_DrawLeftDownCurve_Fill(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t ForegroundColor); +void LT768_DrawRightUpCurve_Fill(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t ForegroundColor); +void LT768_DrawRightDownCurve_Fill(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t ForegroundColor); +void LT768_SelectDrawCurve_Fill(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint32_t CurveColor, + uint16_t Dir); + +/* draw cylinders */ +uint8_t LT768_DrawCylinder(uint16_t XCenter, + uint16_t YCenter, + uint16_t X_R, + uint16_t Y_R, + uint16_t H, + uint32_t CylinderColor, + uint32_t ForegroundColor); + +/* draw quadrangular */ +void LT768_DrawQuadrangular(uint16_t X1, + uint16_t Y1, + uint16_t X2, + uint16_t Y2, + uint16_t X3, + uint16_t Y3, + uint16_t X4, + uint16_t Y4, + uint16_t X5, + uint16_t Y5, + uint16_t X6, + uint16_t Y6, + uint32_t QuadrangularColor, + uint32_t ForegroundColor); + +/* table */ +void LT768_MakeTable(uint16_t X1, + uint16_t Y1, + uint16_t W, + uint16_t H, + uint16_t Line, + uint16_t Row, + uint32_t TableColor, + uint32_t ItemColor, + uint32_t ForegroundColor, + uint16_t width1, + uint16_t width2, + uint8_t mode); + +/* linear DMA transport to SDRAM */ +void LT768_DMA_24bit_Linear(uint8_t SCS, + uint8_t Clk, + uint32_t flash_addr, + uint32_t memory_ad, + uint32_t data_num); +void LT768_DMA_32bit_Linear(uint8_t SCS, + uint8_t Clk, + uint32_t flash_addr, + uint32_t memory_ad, + uint32_t data_num); + +/* DMA transport to SDRAM */ +void LT768_DMA_24bit_Block(uint8_t SCS, + uint8_t Clk, + uint16_t X1, + uint16_t Y1, + uint16_t X_W, + uint16_t Y_H, + uint16_t P_W, + uint32_t Addr); +void LT768_DMA_32bit_Block(uint8_t SCS, + uint8_t Clk, + uint16_t X1, + uint16_t Y1, + uint16_t X_W, + uint16_t Y_H, + uint16_t P_W, + uint32_t Addr); + +/* use internal font */ +void LT768_Select_Internal_Font_Init(uint8_t Size, + uint8_t XxN, + uint8_t YxN, + uint8_t ChromaKey, + uint8_t Alignment); +void LT768_Print_Internal_Font_String(uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + char *c); + +/* nor flash use outside font */ +/* 16*16 24*24 32*32 */ +void LT768_Select_Outside_Font_Init(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr, + uint32_t Num, + uint8_t Size, + uint8_t XxN, + uint8_t YxN, + uint8_t ChromaKey, + uint8_t Alignment); +void LT768_Print_Outside_Font_String(uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint8_t *c); +void LT768_Print_Outside_Font_GBK_String(uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint8_t *c); +/* 48*48 72*72 SBC case */ +void LT768_BTE_Memory_Copy_ColorExpansion_8(uint32_t S0_Addr, + uint16_t YS0, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint16_t X_W, + uint16_t Y_H, + uint32_t Foreground_color, + uint32_t Background_color); +void LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8(uint32_t S0_Addr, + uint16_t YS0, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint16_t X_W, + uint16_t Y_H, + uint32_t Foreground_color); +void LT768_Print_Outside_Font_GB2312_48_72(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr, + uint32_t ShowAddr, + uint16_t width, + uint8_t Size, + uint8_t ChromaKey, + uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint16_t w, + uint16_t s, + uint8_t *c); +void LT768_Print_Outside_Font_BIG5_48_72(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr, + uint32_t ShowAddr, + uint16_t width, + uint8_t Size, + uint8_t ChromaKey, + uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint16_t w, + uint16_t s, + uint8_t *c); +void LT768_Print_Outside_Font_GBK_48_72(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr, + uint32_t ShowAddr, + uint16_t width, + uint8_t Size, + uint8_t ChromaKey, + uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint16_t w, + uint16_t s, + uint8_t *c); + +/* nor flash used define font */ +/* 16*16 24*24 32*32 48*48 72*72 SBC case */ +int Get_User_Font_P(char chH, + char chL); +void LT768_Print_Outside_UserDefineFont_GB2312(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr, + uint32_t ShowAddr, + uint16_t width, + uint8_t Size, + uint8_t ChromaKey, + uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint16_t w, + uint16_t s, + uint8_t *c); + +/* text cursor */ +void LT768_Text_cursor_Init(uint8_t On_Off_Blinking, + uint16_t Blinking_Time, + uint16_t X_W, + uint16_t Y_W); +void LT768_Enable_Text_Cursor(void); +void LT768_Disable_Text_Cursor(void); + +/* graphic cursor */ +void LT768_Graphic_cursor_Init(uint8_t Cursor_N, + uint8_t Color1, + uint8_t Color2, + uint16_t X_Pos, + uint16_t Y_Pos, + uint8_t *Cursor_Buf); +void LT768_Set_Graphic_cursor_Pos(uint8_t Cursor_N, + uint16_t X_Pos, + uint16_t Y_Pos); +void LT768_Enable_Graphic_Cursor(void); +void LT768_Disable_Graphic_Cursor(void); + +/* block transport enginer (BitBLT) */ +void BTE_Solid_Fill(uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint16_t color, + uint16_t X_W, + uint16_t Y_H); +void LT768_BTE_Memory_Copy(uint32_t S0_Addr, + uint16_t S0_W, + uint16_t XS0, + uint16_t YS0, + uint32_t S1_Addr, + uint16_t S1_W, + uint16_t XS1, + uint16_t YS1, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + unsigned int ROP_Code, + uint16_t X_W, + uint16_t Y_H); +void LT768_BTE_Memory_Copy_Chroma_key(uint32_t S0_Addr, + uint16_t S0_W, + uint16_t XS0, + uint16_t YS0, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint32_t Background_color, + uint16_t X_W, + uint16_t Y_H); +void LT768_BTE_Pattern_Fill(uint8_t P_8x8_or_16x16, + uint32_t S0_Addr, + uint16_t S0_W, + uint16_t XS0, + uint16_t YS0, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + unsigned int ROP_Code, + uint16_t X_W, + uint16_t Y_H); +void LT768_BTE_Pattern_Fill_With_Chroma_key(uint8_t P_8x8_or_16x16, + uint32_t S0_Addr, + uint16_t S0_W, + uint16_t XS0, + uint16_t YS0, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + unsigned int ROP_Code, + uint32_t Background_color, + uint16_t X_W, + uint16_t Y_H); +void LT768_BTE_MCU_Write_MCU_16bit(uint32_t S1_Addr, + uint16_t S1_W, + uint16_t XS, + uint16_t YS1, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + unsigned int ROP_Code, + uint16_t X_W, + uint16_t Y_H, + const uint16_t *data); +void LT768_BTE_MCU_Write_Chroma_key_MCU_16bit(uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint32_t Background_color, + uint16_t X_W, + uint16_t Y_H, + const uint16_t *data); +void LT768_BTE_MCU_Write_ColorExpansion_MCU_16bit(uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint16_t X_W, + uint16_t Y_H, + uint32_t Foreground_color, + uint32_t Background_color, + const uint16_t *data); +void LT768_BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_16bit(uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint16_t X_W, + uint16_t Y_H, + uint32_t Foreground_color, + const uint16_t *data); +void BTE_Alpha_Blending(uint32_t S0_Addr, + uint16_t S0_W, + uint16_t XS0, + uint16_t YS0, + uint32_t S1_Addr, + uint16_t S1_W, + uint16_t XS1, + uint16_t YS1, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint16_t X_W, + uint16_t Y_H, + uint8_t alpha); +void BTE_Pixel_8bpp_Alpha_Blending(uint32_t S0_Addr, + uint16_t S0_W, + uint16_t XS0, + uint16_t YS0, + uint32_t S1_Addr, + uint16_t S1_W, + uint16_t XS1, + uint16_t YS1, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint16_t X_W, + uint16_t Y_H); +void BTE_Pixel_16bpp_Alpha_Blending(uint32_t S0_Addr, + uint16_t S0_W, + uint16_t XS0, + uint16_t YS0, + uint32_t S1_Addr, + uint16_t S1_W, + uint16_t XS1, + uint16_t YS1, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + uint16_t X_W, + uint16_t Y_H); + +/* PIP */ +void LT768_PIP_Init(uint8_t On_Off, + uint8_t Select_PIP, + uint32_t PAddr, + uint16_t XP, + uint16_t YP, + uint32_t ImageWidth, + uint16_t X_Dis, + uint16_t Y_Dis, + uint16_t X_W, + uint16_t Y_H); +void LT768_Set_DisWindowPos(uint8_t On_Off, + uint8_t Select_PIP, + uint16_t X_Dis, + uint16_t Y_Dis); + +/* PWM */ +void LT768_PWM0_Init(uint8_t on_off, + uint8_t Clock_Divided, + uint8_t Prescalar, + uint16_t Count_Buffer, + uint16_t Compare_Buffer); +void LT768_PWM1_Init(uint8_t on_off, + uint8_t Clock_Divided, + uint8_t Prescalar, + uint16_t Count_Buffer, + uint16_t Compare_Buffer); +void LT768_PWM0_Duty(uint16_t Compare_Buffer); +void LT768_PWM1_Duty(uint16_t Compare_Buffer); + +/* Standby Mode */ +void LT768_Standby(void); +void LT768_Wkup_Standby(void); + +/* Suspend Mode */ +void LT768_Suspend(void); +void LT768_Wkup_Suspend(void); + +/* Sleep Mode */ +void LT768_SleepMode(void); +void LT768_Wkup_Sleep(void); + +/* W25QXX */ +void LT768_SPI_Init(uint8_t cs, + uint8_t div); +void W25QXX_Enter_4Byte_AddressMode(void); +void LT_W25QXX_Read(uint8_t *pBuffer, + uint32_t ReadAddr, + uint16_t NumByteToRead); + +/* nand flash W25N01GV */ +uint8_t W25N01GV_ReadSR(uint8_t reg); +void W25N01GV_Write_SR(uint8_t reg, + uint8_t val); +void W25N01GV_Wait_Busy(void); +void W25N01GV_ContinuousRead_Mode(void); +void W25N01GV_Write_Page(uint16_t page); +void W25N01GV_ReadPageAddr_Data(uint8_t *pBuffer, + uint32_t PageNum, + uint32_t PageAddr, + uint16_t NumByteToRead); +void LT_W25N01GV_Read(uint8_t *pBuffer, + uint32_t ReadAddr, + uint16_t NumByteToRead); + +/* nand flash draw picture */ +void LT768_Nand_Pic(uint8_t SCS, + uint16_t X1, + uint16_t Y1, + uint16_t X_W, + uint16_t Y_H, + uint32_t Addr, + uint32_t lay0, + uint32_t lay1); + +/* nand flash use outside font */ +/* 16*16 24*24 32*32 */ +void NandFlash_Select_Outside_Font_Init(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr, + uint32_t Num, + uint8_t Size, + uint8_t XxN, + uint8_t YxN, + uint8_t ChromaKey, + uint8_t Alignment); + +/* nand flash use outside font */ +/* 48*48 72*72 SBC case */ +void LT768_BTE_Memory_Copy_8(uint32_t S0_Addr, + uint16_t S0_W, + uint16_t XS0, + uint16_t YS0, + uint32_t S1_Addr, + uint16_t S1_W, + uint16_t XS1, + uint16_t YS1, + uint32_t Des_Addr, + uint16_t Des_W, + uint16_t XDes, + uint16_t YDes, + unsigned int ROP_Code, + uint16_t X_W, + uint16_t Y_H); +void LT768_Nand_8bpp_font(uint8_t SCS, + uint8_t Clk, + uint16_t X1, + uint16_t Y1, + uint16_t X_W, + uint16_t Y_H, + uint32_t Addr, + uint32_t lay1, + uint32_t lay2); +void LT768_Print_Outside_Font_GB2312_48_72_Nand(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr1, + uint32_t MemoryAddr2, + uint32_t ShowAddr, + uint16_t width, + uint8_t Size, + uint8_t ChromaKey, + uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint16_t w, + uint16_t s, + uint8_t *c); +void LT768_Print_Outside_Font_GBK_48_72_Nand(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr1, + uint32_t MemoryAddr2, + uint32_t ShowAddr, + uint16_t width, + uint8_t Size, + uint8_t ChromaKey, + uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint16_t w, + uint16_t s, + uint8_t *c); + +/* nand flash user defined font */ +/* 16*16 24*24 32*32 48*48 72*72 SBC case */ +void LT768_Print_Outside_UserDefineFont_GB2312_Nand(uint8_t SCS, + uint8_t Clk, + uint32_t FlashAddr, + uint32_t MemoryAddr1, + uint32_t MemoryAddr2, + uint32_t ShowAddr, + uint16_t width, + uint8_t Size, + uint8_t ChromaKey, + uint16_t x, + uint16_t y, + uint32_t FontColor, + uint32_t BackGroundColor, + uint16_t w, + uint16_t s, + uint8_t *c); +#endif From 281389af1cb1de2c83adeb0483ef79a69b47f990 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 27 Sep 2022 20:54:22 +0800 Subject: [PATCH 05/30] support uart1-uart3 for k210 on Nuttx --- .../xidatong-riscv64/include/board.h | 20 + .../xidatong-riscv64/src/k210_bringup.c | 28 + .../nuttx/arch/risc-v/include/k210/irq.h | 49 + .../nuttx/arch/risc-v/src/k210/Kconfig | 267 + .../nuttx/arch/risc-v/src/k210/Make.defs | 4 +- .../nuttx/arch/risc-v/src/k210/fpioa.c | 4932 +++++++++++++++++ .../nuttx/arch/risc-v/src/k210/fpioa.h | 1035 ++++ .../arch/risc-v/src/k210/k210_clockconfig.c | 20 +- .../nuttx/arch/risc-v/src/k210/k210_fpioa.c | 42 +- .../nuttx/arch/risc-v/src/k210/k210_fpioa.h | 330 +- .../nuttx/arch/risc-v/src/k210/k210_serial.c | 733 +++ .../arch/risc-v/src/k210/k210_uart_16550.c | 1002 ++++ .../arch/risc-v/src/k210/k210_uart_16550.h | 340 ++ 13 files changed, 8683 insertions(+), 119 deletions(-) create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/include/k210/irq.h create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.c create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.h create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_serial.c create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.c create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.h diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h index 9435e91c8..03564ace5 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h @@ -79,6 +79,26 @@ extern "C" #define EXTERN extern #endif + +#define GPIO_CAN_RXD 18 +#define GPIO_CAN_TXD 19 + +#define GPIO_EC200T_RXD 21 +#define GPIO_EC200T_TXD 20 + +#define GPIO_CH376T_RXD 22 +#define GPIO_CH376T_TXD 23 + + +#define FPOA_USART1_RX K210_IO_FUNC_UART1_RX +#define FPOA_USART1_TX K210_IO_FUNC_UART1_TX + +#define FPOA_USART2_RX K210_IO_FUNC_UART2_RX +#define FPOA_USART2_TX K210_IO_FUNC_UART2_TX + +#define FPOA_USART3_RX K210_IO_FUNC_UART3_RX +#define FPOA_USART3_TX K210_IO_FUNC_UART3_TX + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c index bc90e372b..227696b1e 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c @@ -36,6 +36,8 @@ #include "k210.h" #include "k210_clockconfig.h" #include "xidatong-riscv64.h" +#include +#include "k210_sysctl.h" #ifdef CONFIG_BSP_USING_CH438 # include "k210_ch438.h" @@ -85,5 +87,31 @@ int k210_bringup(void) } #endif +#ifdef CONFIG_K210_16550_UART1 + sysctl_clock_enable(SYSCTL_CLOCK_UART1); + sysctl_reset(SYSCTL_RESET_UART1); + fpioa_set_function(GPIO_CAN_RXD, FPOA_USART1_RX); + fpioa_set_function(GPIO_CAN_TXD, FPOA_USART1_TX); +#endif + +#ifdef CONFIG_K210_16550_UART2 + sysctl_clock_enable(SYSCTL_CLOCK_UART2); + sysctl_reset(SYSCTL_RESET_UART2); + fpioa_set_function(GPIO_EC200T_RXD, FPOA_USART2_RX); + fpioa_set_function(GPIO_EC200T_TXD, FPOA_USART2_TX); +#endif + +#ifdef CONFIG_K210_16550_UART3 + sysctl_clock_enable(SYSCTL_CLOCK_UART3); + sysctl_reset(SYSCTL_RESET_UART3); + fpioa_set_function(GPIO_CH376T_RXD, FPOA_USART3_RX); + fpioa_set_function(GPIO_CH376T_TXD, FPOA_USART3_TX); +#endif + +#ifdef CONFIG_BSP_USING_ENET + k210_sysctl_init(); + board_enet_initialize(); +#endif + return ret; } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/include/k210/irq.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/include/k210/irq.h new file mode 100644 index 000000000..a800588bb --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/include/k210/irq.h @@ -0,0 +1,49 @@ +/**************************************************************************** + * arch/risc-v/include/k210/irq.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_RISCV_INCLUDE_K210_IRQ_H +#define __ARCH_RISCV_INCLUDE_K210_IRQ_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Map RISC-V exception code to NuttX IRQ */ + +#ifdef CONFIG_K210_WITH_QEMU +#define K210_IRQ_UART0 (RISCV_IRQ_MEXT + 4) +#else +#define K210_IRQ_UART0 (RISCV_IRQ_MEXT + 33) +#define K210_IRQ_UART1 (RISCV_IRQ_MEXT + 11) +#define K210_IRQ_UART2 (RISCV_IRQ_MEXT + 12) +#define K210_IRQ_UART3 (RISCV_IRQ_MEXT + 13) +#endif + +/* Total number of IRQs */ + +#define NR_IRQS (64 + 16 +16) + +#endif /* __ARCH_RISCV_INCLUDE_K210_IRQ_H */ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/Kconfig index 0502d2b18..bc34095b5 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/Kconfig @@ -40,6 +40,273 @@ config K210_LCD_BACKLIGHT endmenu +menuconfig K210_16550_UART + bool "K210 16550 UART Chip support" + select ARCH_HAVE_SERIAL_TERMIOS + default n + +if K210_16550_UART + config K210_16550_SERIAL_DISABLE_REORDERING + bool "Disable reordering of ttySx devices." + default n + ---help--- + NuttX per default reorders the serial ports (/dev/ttySx) so that the + console is always on /dev/ttyS0. If more than one UART is in use this + can, however, have the side-effect that all port mappings + (hardware USART1 -> /dev/ttyS0) change if the console is moved to another + UART. This option disables that re-ordering for 16550 UARTs. + + config K210_16550_UART1 + bool "K210 16550 UART1" + default n + + if K210_16550_UART1 + + config K210_16550_UART1_BASE + hex "K210 16550 UART1 base address" + default 0x50210000 + + config K210_16550_UART1_CLOCK + int "K210 16550 UART1 clock" + default 195000000 + + + config K210_16550_UART1_IRQ + int "K210 16550 UART1 IRQ number" + default 38 + + config K210_16550_UART1_BAUD + int "K210 16550 UART1 BAUD" + default 115200 + + config K210_16550_UART1_PARITY + int "K210 16550 UART1 parity" + default 0 + range 0 2 + ---help--- + K210 16550 UART1 parity. 0=None, 1=Odd, 2=Even. Default: None + + config K210_16550_UART1_BITS + int "K210 16550 UART1 number of bits" + default 8 + ---help--- + K210 16550 UART1 number of bits. Default: 8 + + config K210_16550_UART1_2STOP + int "K210 16550 UART1 two stop bits" + default 0 + ---help--- + 0=1 stop bit, 1=Two stop bits. Default: 1 stop bit + + config K210_16550_UART1_RXBUFSIZE + int "K210 16550 UART1 Rx buffer size" + default 256 + ---help--- + K210 16550 UART1 Rx buffer size. Default: 128 + + config K210_16550_UART1_TXBUFSIZE + int "K210 16550 UART1 Tx buffer size" + default 256 + ---help--- + K210 16550 UART1 Tx buffer size. Default: 128 + + config K210_16550_UART1_IFLOWCONTROL + bool "K210 16550 UART1 RTS flow control" + default n + select SERIAL_IFLOWCONTROL + ---help--- + Enable K210 16550 UART1 RTS flow control + + config K210_16550_UART1_OFLOWCONTROL + bool "K210 16550 UART1 CTS flow control" + default n + select SERIAL_OFLOWCONTROL + ---help--- + Enable K210 16550 UART1 CTS flow control + + endif # K210_16550_UART1 + + config K210_16550_UART2 + bool "K210 16550 UART2" + default n + + if K210_16550_UART2 + + config K210_16550_UART2_BASE + hex "K210 16550 UART2 base address" + default 0x50220000 + + config K210_16550_UART2_CLOCK + int "K210 16550 UART2 clock" + default 195000000 + + config K210_16550_UART2_IRQ + int "K210 16550 UART2 IRQ number" + default 39 + + config K210_16550_UART2_BAUD + int "K210 16550 UART2 BAUD" + default 115200 + + config K210_16550_UART2_PARITY + int "K210 16550 UART2 parity" + default 0 + range 0 2 + ---help--- + K210 16550 UART2 parity. 0=None, 1=Odd, 2=Even. Default: None + + config K210_16550_UART2_BITS + int "K210 16550 UART2 number of bits" + default 8 + ---help--- + K210 16550 UART2 number of bits. Default: 8 + + config K210_16550_UART2_2STOP + int "K210 16550 UART2 two stop bits" + default 0 + ---help--- + 0=1 stop bit, 1=Two stop bits. Default: 1 stop bit + + config K210_16550_UART2_RXBUFSIZE + int "K210 16550 UART2 Rx buffer size" + default 256 + ---help--- + K210 16550 UART2 Rx buffer size. Default: 128 + + config K210_16550_UART2_TXBUFSIZE + int "K210 16550 UART2 Tx buffer size" + default 256 + ---help--- + K210 16550 UART2 Tx buffer size. Default: 128 + + config K210_16550_UART2_IFLOWCONTROL + bool "K210 16550 UART2 RTS flow control" + default n + select SERIAL_IFLOWCONTROL + ---help--- + Enable K210 16550 UART2 RTS flow control + + config K210_16550_UART2_OFLOWCONTROL + bool "K210 16550 UART2 CTS flow control" + default n + select SERIAL_OFLOWCONTROL + ---help--- + Enable K210 16550 UART2 CTS flow control + + endif # K210_16550_UART2 + + config K210_16550_UART3 + bool "K210 16550 UART3" + default n + + if K210_16550_UART3 + + config K210_16550_UART3_BASE + hex "K210 16550 UART3 base address" + default 0x50230000 + + config K210_16550_UART3_CLOCK + int "K210 16550 UART3 clock" + default 195000000 + + config K210_16550_UART3_IRQ + int "K210 16550 UART3 IRQ number" + default 40 + + config K210_16550_UART3_BAUD + int "K210 16550 UART3 BAUD" + default 115200 + + config K210_16550_UART3_PARITY + int "K210 16550 UART3 parity" + default 0 + range 0 2 + ---help--- + K210 16550 UART3 parity. 0=None, 1=Odd, 2=Even. Default: None + + config K210_16550_UART3_BITS + int "K210 16550 UART3 number of bits" + default 8 + ---help--- + K210 16550 UART3 number of bits. Default: 8 + + config K210_16550_UART3_2STOP + int "K210 16550 UART3 two stop bits" + default 0 + ---help--- + 0=1 stop bit, 1=Two stop bits. Default: 1 stop bit + + config K210_16550_UART3_RXBUFSIZE + int "K210 16550 UART3 Rx buffer size" + default 256 + ---help--- + K210 16550 UART3 Rx buffer size. Default: 128 + + config K210_16550_UART3_TXBUFSIZE + int "K210 16550 UART3 Tx buffer size" + default 256 + ---help--- + K210 16550 UART3 Tx buffer size. Default: 128 + + config K210_16550_UART3_IFLOWCONTROL + bool "K210 16550 UART3 RTS flow control" + default n + select SERIAL_IFLOWCONTROL + ---help--- + Enable K210 16550 UART3 RTS flow control + + config K210_16550_UART3_OFLOWCONTROL + bool "K210 16550 UART3 CTS flow control" + default n + select SERIAL_OFLOWCONTROL + ---help--- + Enable K210 16550 UART3 CTS flow control + + endif # K210_16550_UART3 + + config K210_16550_SUPRESS_CONFIG + bool "Suppress K210 16550 configuration" + default n + + config K210_16550_SUPRESS_INITIAL_CONFIG + bool "Suppress initial K210 16550 configuration" + depends on !K210_16550_SUPRESS_CONFIG + default y + ---help--- + This option is useful, for example, if you are using a bootloader + that configures the K210_16550_UART. In that case, you may want to + just leave the existing console configuration in place. Default: n + + config SERIAL_UART_ARCH_MMIO + bool "Platform access register through the memory mapping" + default y + + config SERIAL_UART_ARCH_IOCTL + bool "Platform has own custom IOCTL" + default n + + config K210_16550_REGINCR + int "Address increment between K210 16550 registers" + default 4 + ---help--- + The address increment between K210 16550 registers. Options are 1, 2, or 4. + Default: 1 + + config K210_16550_REGWIDTH + int "Bit width of K210 16550 registers" + default 32 + ---help--- + The bit width of registers. Options are 8, 16, or 32. Default: 32 + + config K210_16550_ADDRWIDTH + int "Address width of K210 16550 registers" + default 32 + ---help--- + The bit width of registers. Options are 0, 8, 16, or 32. + Default: 32 + Note: 0 means auto detect address size (uintptr_t) +endif + menu "K210 Others" config K210_WITH_QEMU diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/Make.defs b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/Make.defs index 63dbba19a..4089b0be4 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/Make.defs +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/Make.defs @@ -55,9 +55,9 @@ endif # Specify our C code within this directory to be included CHIP_CSRCS = k210_allocateheap.c k210_clockconfig.c CHIP_CSRCS += k210_irq.c k210_irq_dispatch.c k210_systemreset.c -CHIP_CSRCS += k210_lowputc.c k210_serial.c k210_fpioa.c +CHIP_CSRCS += k210_lowputc.c k210_serial.c k210_fpioa.c fpioa.c CHIP_CSRCS += k210_start.c k210_timerisr.c k210_gpiohs.c k210_gpio.c -CHIP_CSRCS += k210_sysctl.c +CHIP_CSRCS += k210_sysctl.c k210_uart_16550.c ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += riscv_task_start.c riscv_pthread_start.c diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.c new file mode 100644 index 000000000..093ae74ec --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.c @@ -0,0 +1,4932 @@ +/* Copyright 2018 Canaan Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "fpioa.h" +#include "k210_fpioa.h" +#include "k210_sysctl.h" +#include "k210_memorymap.h" + +volatile fpioa_t *const fpioa = (volatile fpioa_t *)K210_FPIOA_BASE; + +/** + * @brief Internal used FPIOA function initialize cell + * + * This is NOT fpioa_io_config_t, can't assign directly + * + */ +typedef struct _fpioa_assign_t +{ + uint32_t ch_sel : 8; + /* Channel select from 256 input. */ + uint32_t ds : 4; + /* Driving selector. */ + uint32_t oe_en : 1; + /* Static output enable, will AND with OE_INV. */ + uint32_t oe_inv : 1; + /* Invert output enable. */ + uint32_t do_sel : 1; + /* Data output select: 0 for DO, 1 for OE. */ + uint32_t do_inv : 1; + /* Invert the result of data output select (DO_SEL). */ + uint32_t pu : 1; + /* Pull up enable. 0 for nothing, 1 for pull up. */ + uint32_t pd : 1; + /* Pull down enable. 0 for nothing, 1 for pull down. */ + uint32_t resv0 : 1; + /* Reserved bits. */ + uint32_t sl : 1; + /* Slew rate control enable. */ + uint32_t ie_en : 1; + /* Static input enable, will AND with IE_INV. */ + uint32_t ie_inv : 1; + /* Invert input enable. */ + uint32_t di_inv : 1; + /* Invert Data input. */ + uint32_t st : 1; + /* Schmitt trigger. */ + uint32_t tie_en : 1; + /* Input tie enable, 1 for enable, 0 for disable. */ + uint32_t tie_val : 1; + /* Input tie value, 1 for high, 0 for low. */ + uint32_t resv1 : 5; + /* Reserved bits. */ + uint32_t pad_di : 1; + /* Read current PAD's data input. */ +} __attribute__((packed, aligned(4))) fpioa_assign_t; + +/* Function list */ +static const fpioa_assign_t function_config[FUNC_MAX] = + { + {.ch_sel = FUNC_JTAG_TCLK, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_JTAG_TDI, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_JTAG_TMS, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_JTAG_TDO, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_D0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_D1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_D2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_D3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_D4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_D5, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_D6, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_D7, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_SS0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_SS1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_SS2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_SS3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_ARB, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 1, + .tie_val = 1, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI0_SCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UARTHS_RX, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UARTHS_TX, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_RESV6, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_RESV7, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CLK_SPI1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CLK_I2C1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS5, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS6, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS7, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS8, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS9, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS10, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS11, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS12, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS13, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS14, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS15, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS16, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS17, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS18, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS19, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS20, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS21, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS22, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS23, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS24, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS25, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS26, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS27, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS28, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS29, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS30, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIOHS31, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIO0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIO1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIO2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIO3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIO4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIO5, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIO6, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_GPIO7, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_RX, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_TX, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_RX, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_TX, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_RX, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_TX, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_D0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_D1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_D2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_D3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_D4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_D5, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_D6, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_D7, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_SS0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_SS1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_SS2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_SS3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_ARB, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 1, + .tie_val = 1, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI1_SCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI_SLAVE_D0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 1, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI_SLAVE_SS, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SPI_SLAVE_SCLK, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_MCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_SCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_WS, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_IN_D0, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_IN_D1, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_IN_D2, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_IN_D3, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_OUT_D0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_OUT_D1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_OUT_D2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S0_OUT_D3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_MCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_SCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_WS, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_IN_D0, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_IN_D1, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_IN_D2, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_IN_D3, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_OUT_D0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_OUT_D1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_OUT_D2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S1_OUT_D3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_MCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_SCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_WS, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_IN_D0, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_IN_D1, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_IN_D2, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_IN_D3, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_OUT_D0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_OUT_D1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_OUT_D2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2S2_OUT_D3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_RESV0, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_RESV1, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_RESV2, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_RESV3, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_RESV4, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_RESV5, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2C0_SCLK, + .ds = 0x0, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2C0_SDA, + .ds = 0x0, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2C1_SCLK, + .ds = 0x0, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2C1_SDA, + .ds = 0x0, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2C2_SCLK, + .ds = 0x0, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_I2C2_SDA, + .ds = 0x0, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_XCLK, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_RST, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_PWDN, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_VSYNC, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_HREF, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_PCLK, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_D0, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_D1, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_D2, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_D3, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_D4, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_D5, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_D6, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CMOS_D7, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SCCB_SCLK, + .ds = 0x0, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_SCCB_SDA, + .ds = 0x0, + .oe_en = 1, + .oe_inv = 1, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_CTS, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_DSR, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_DCD, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_RI, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_SIR_IN, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_DTR, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_RTS, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_OUT2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_OUT1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_SIR_OUT, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_BAUD, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_RE, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_DE, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART1_RS485_EN, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_CTS, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_DSR, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_DCD, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_RI, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_SIR_IN, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_DTR, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_RTS, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_OUT2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_OUT1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_SIR_OUT, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_BAUD, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_RE, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_DE, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART2_RS485_EN, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_CTS, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_DSR, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_DCD, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_RI, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_SIR_IN, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_DTR, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_RTS, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_OUT2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_OUT1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_SIR_OUT, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_BAUD, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_RE, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_DE, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_UART3_RS485_EN, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER0_TOGGLE1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER0_TOGGLE2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER0_TOGGLE3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER0_TOGGLE4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER1_TOGGLE1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER1_TOGGLE2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER1_TOGGLE3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER1_TOGGLE4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER2_TOGGLE1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER2_TOGGLE2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER2_TOGGLE3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_TIMER2_TOGGLE4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CLK_SPI2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CLK_I2C2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL5, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL6, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL7, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL8, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL9, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL10, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL11, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL12, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL13, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL14, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 1, + .pd = 0, + .resv1 = 0, + .sl = 1, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL15, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL16, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL17, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_CONSTANT, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_INTERNAL18, + .ds = 0x0, + .oe_en = 0, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 1, + .ie_inv = 0, + .di_inv = 0, + .st = 1, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG0, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG1, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG2, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG3, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG4, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG5, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG6, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG7, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG8, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG9, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG10, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG11, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG12, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG13, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG14, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG15, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG16, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG17, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG18, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG19, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG20, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG21, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG22, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG23, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG24, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG25, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG26, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG27, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG28, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG29, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG30, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, + {.ch_sel = FUNC_DEBUG31, + .ds = 0xf, + .oe_en = 1, + .oe_inv = 0, + .do_sel = 0, + .do_inv = 0, + .pu = 0, + .pd = 0, + .resv1 = 0, + .sl = 0, + .ie_en = 0, + .ie_inv = 0, + .di_inv = 0, + .st = 0, + .tie_en = 0, + .tie_val = 0, + .resv0 = 0, + .pad_di = 0}, +}; + +int fpioa_init(void) +{ + int i = 0; + + /* Enable fpioa clock in system controller */ + sysctl_clock_enable(SYSCTL_CLOCK_FPIOA); + + /* Initialize tie */ + fpioa_tie_t tie = {0}; + + /* Set tie enable and tie value */ + for(i = 0; i < FUNC_MAX; i++) + { + tie.en[i / 32] |= (function_config[i].tie_en << (i % 32)); + tie.val[i / 32] |= (function_config[i].tie_val << (i % 32)); + } + + /* Atomic write every 32bit register to fpioa function */ + for(i = 0; i < FUNC_MAX / 32; i++) + { + /* Set value before enable */ + fpioa->tie.val[i] = tie.val[i]; + fpioa->tie.en[i] = tie.en[i]; + } + + return 0; +} + +int fpioa_get_io(int number, fpioa_io_config_t *cfg) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO || cfg == NULL) + return -1; + /* Atomic read register */ + *cfg = fpioa->io[number]; + return 0; +} + +int fpioa_set_io(int number, fpioa_io_config_t *cfg) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO || cfg == NULL) + return -1; + /* Atomic write register */ + fpioa->io[number] = *cfg; + return 0; +} + +int fpioa_set_io_pull(int number, fpioa_pull_t pull) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO || pull >= FPIOA_PULL_MAX) + return -1; + + /* Atomic read register */ + fpioa_io_config_t cfg = fpioa->io[number]; + + switch(pull) + { + case FPIOA_PULL_NONE: + cfg.pu = 0; + cfg.pd = 0; + break; + case FPIOA_PULL_DOWN: + cfg.pu = 0; + cfg.pd = 1; + break; + case FPIOA_PULL_UP: + cfg.pu = 1; + cfg.pd = 0; + break; + default: + break; + } + /* Atomic write register */ + fpioa->io[number] = cfg; + return 0; +} + +int fpioa_get_io_pull(int number) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO) + return -1; + + fpioa_pull_t pull; + /* Atomic read register */ + fpioa_io_config_t cfg = fpioa->io[number]; + + if(cfg.pu == 0 && cfg.pd == 1) + pull = FPIOA_PULL_DOWN; + else if(cfg.pu == 1 && cfg.pd == 0) + pull = FPIOA_PULL_UP; + else + pull = FPIOA_PULL_NONE; + return pull; +} + +int fpioa_set_io_driving(int number, fpioa_driving_t driving) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO || driving >= FPIOA_DRIVING_MAX) + return -1; + + /* Atomic read register */ + fpioa_io_config_t cfg = fpioa->io[number]; + /* Set IO driving */ + cfg.ds = driving; + /* Atomic write register */ + fpioa->io[number] = cfg; + return 0; +} + +int fpioa_set_sl(int number, uint8_t sl_enable) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO) + return -1; + + /* Atomic read register */ + fpioa_io_config_t cfg = fpioa->io[number]; + /* Set IO slew rate */ + cfg.sl = sl_enable; + /* Atomic write register */ + fpioa->io[number] = cfg; + return 0; +} + +int fpioa_set_st(int number, uint8_t st_enable) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO) + return -1; + + /* Atomic read register */ + fpioa_io_config_t cfg = fpioa->io[number]; + /* Set IO schmitt trigger */ + cfg.st = st_enable; + /* Atomic write register */ + fpioa->io[number] = cfg; + return 0; +} + +int fpioa_set_oe_inv(int number, uint8_t inv_enable) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO) + return -1; + + /* Atomic read register */ + fpioa_io_config_t cfg = fpioa->io[number]; + /* Set IO schmitt trigger */ + cfg.oe_inv = inv_enable; + /* Atomic write register */ + fpioa->io[number] = cfg; + return 0; +} + +int fpioa_get_io_driving(int number) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO) + return -1; + + return fpioa->io[number].ds; +} + +int fpioa_set_function_raw(int number, fpioa_function_t function) +{ + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO || function < 0 || function >= FUNC_MAX) + return -1; + /* Atomic write register */ + fpioa->io[number] = (const fpioa_io_config_t){ + .ch_sel = function_config[function].ch_sel, + .ds = function_config[function].ds, + .oe_en = function_config[function].oe_en, + .oe_inv = function_config[function].oe_inv, + .do_sel = function_config[function].do_sel, + .do_inv = function_config[function].do_inv, + .pu = function_config[function].pu, + .pd = function_config[function].pd, + .sl = function_config[function].sl, + .ie_en = function_config[function].ie_en, + .ie_inv = function_config[function].ie_inv, + .di_inv = function_config[function].di_inv, + .st = function_config[function].st, + /* resv and pad_di do not need initialization */ + }; + return 0; +} + +int fpioa_set_function(int number, fpioa_function_t function) +{ + uint8_t index = 0; + /* Check parameters */ + if(number < 0 || number >= FPIOA_NUM_IO || function < 0 || function >= FUNC_MAX) + return -1; + if(function == FUNC_RESV0) + { + fpioa_set_function_raw(number, FUNC_RESV0); + return 0; + } + /* Compare all IO */ + for(index = 0; index < FPIOA_NUM_IO; index++) + { + if((fpioa->io[index].ch_sel == function) && (index != number)) + fpioa_set_function_raw(index, FUNC_RESV0); + } + fpioa_set_function_raw(number, function); + return 0; +} + +int fpioa_set_tie_enable(fpioa_function_t function, int enable) +{ + /* Check parameters */ + if(function < 0 || function >= FUNC_MAX) + return -1; + /* Set tie enable */ + if(enable) + fpioa->tie.en[function / 32] |= (1UL << (function % 32)); + else + fpioa->tie.en[function / 32] &= (~(1UL << (function % 32))); + return 0; +} + +int fpioa_set_tie_value(fpioa_function_t function, int value) +{ + /* Check parameters */ + if(function < 0 || function >= FUNC_MAX) + return -1; + /* Set tie value */ + if(value) + fpioa->tie.val[function / 32] |= (1UL << (function % 32)); + else + fpioa->tie.val[function / 32] &= (~(1UL << (function % 32))); + return 0; +} + +int fpioa_get_io_by_function(fpioa_function_t function) +{ + int index = 0; + for(index = 0; index < FPIOA_NUM_IO; index++) + { + if(fpioa->io[index].ch_sel == function) + return index; + } + + return -1; +} diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.h new file mode 100644 index 000000000..15e86eaea --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.h @@ -0,0 +1,1035 @@ +/* Copyright 2018 Canaan Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief Field Programmable GPIO Array (FPIOA) + * + * The FPIOA peripheral supports the following features: + * + * - 48 IO with 256 functions + * + * - Schmitt trigger + * + * - Invert input and output + * + * - Pull up and pull down + * + * - Driving selector + * + * - Static input and output + * + */ + +#ifndef _DRIVER_FPIOA_H +#define _DRIVER_FPIOA_H + +#include +//#include "platform.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* clang-format off */ +/* Pad number settings */ +#define FPIOA_NUM_IO (48) +/* clang-format on */ + +/** + * @brief FPIOA IO functions + * + * @note FPIOA pin function table + * + * | Function | Name | Description | + * |-----------|------------------|-----------------------------------| + * | 0 | JTAG_TCLK | JTAG Test Clock | + * | 1 | JTAG_TDI | JTAG Test Data In | + * | 2 | JTAG_TMS | JTAG Test Mode Select | + * | 3 | JTAG_TDO | JTAG Test Data Out | + * | 4 | SPI0_D0 | SPI0 Data 0 | + * | 5 | SPI0_D1 | SPI0 Data 1 | + * | 6 | SPI0_D2 | SPI0 Data 2 | + * | 7 | SPI0_D3 | SPI0 Data 3 | + * | 8 | SPI0_D4 | SPI0 Data 4 | + * | 9 | SPI0_D5 | SPI0 Data 5 | + * | 10 | SPI0_D6 | SPI0 Data 6 | + * | 11 | SPI0_D7 | SPI0 Data 7 | + * | 12 | SPI0_SS0 | SPI0 Chip Select 0 | + * | 13 | SPI0_SS1 | SPI0 Chip Select 1 | + * | 14 | SPI0_SS2 | SPI0 Chip Select 2 | + * | 15 | SPI0_SS3 | SPI0 Chip Select 3 | + * | 16 | SPI0_ARB | SPI0 Arbitration | + * | 17 | SPI0_SCLK | SPI0 Serial Clock | + * | 18 | UARTHS_RX | UART High speed Receiver | + * | 19 | UARTHS_TX | UART High speed Transmitter | + * | 20 | RESV6 | Reserved function | + * | 21 | RESV7 | Reserved function | + * | 22 | CLK_SPI1 | Clock SPI1 | + * | 23 | CLK_I2C1 | Clock I2C1 | + * | 24 | GPIOHS0 | GPIO High speed 0 | + * | 25 | GPIOHS1 | GPIO High speed 1 | + * | 26 | GPIOHS2 | GPIO High speed 2 | + * | 27 | GPIOHS3 | GPIO High speed 3 | + * | 28 | GPIOHS4 | GPIO High speed 4 | + * | 29 | GPIOHS5 | GPIO High speed 5 | + * | 30 | GPIOHS6 | GPIO High speed 6 | + * | 31 | GPIOHS7 | GPIO High speed 7 | + * | 32 | GPIOHS8 | GPIO High speed 8 | + * | 33 | GPIOHS9 | GPIO High speed 9 | + * | 34 | GPIOHS10 | GPIO High speed 10 | + * | 35 | GPIOHS11 | GPIO High speed 11 | + * | 36 | GPIOHS12 | GPIO High speed 12 | + * | 37 | GPIOHS13 | GPIO High speed 13 | + * | 38 | GPIOHS14 | GPIO High speed 14 | + * | 39 | GPIOHS15 | GPIO High speed 15 | + * | 40 | GPIOHS16 | GPIO High speed 16 | + * | 41 | GPIOHS17 | GPIO High speed 17 | + * | 42 | GPIOHS18 | GPIO High speed 18 | + * | 43 | GPIOHS19 | GPIO High speed 19 | + * | 44 | GPIOHS20 | GPIO High speed 20 | + * | 45 | GPIOHS21 | GPIO High speed 21 | + * | 46 | GPIOHS22 | GPIO High speed 22 | + * | 47 | GPIOHS23 | GPIO High speed 23 | + * | 48 | GPIOHS24 | GPIO High speed 24 | + * | 49 | GPIOHS25 | GPIO High speed 25 | + * | 50 | GPIOHS26 | GPIO High speed 26 | + * | 51 | GPIOHS27 | GPIO High speed 27 | + * | 52 | GPIOHS28 | GPIO High speed 28 | + * | 53 | GPIOHS29 | GPIO High speed 29 | + * | 54 | GPIOHS30 | GPIO High speed 30 | + * | 55 | GPIOHS31 | GPIO High speed 31 | + * | 56 | GPIO0 | GPIO pin 0 | + * | 57 | GPIO1 | GPIO pin 1 | + * | 58 | GPIO2 | GPIO pin 2 | + * | 59 | GPIO3 | GPIO pin 3 | + * | 60 | GPIO4 | GPIO pin 4 | + * | 61 | GPIO5 | GPIO pin 5 | + * | 62 | GPIO6 | GPIO pin 6 | + * | 63 | GPIO7 | GPIO pin 7 | + * | 64 | UART1_RX | UART1 Receiver | + * | 65 | UART1_TX | UART1 Transmitter | + * | 66 | UART2_RX | UART2 Receiver | + * | 67 | UART2_TX | UART2 Transmitter | + * | 68 | UART3_RX | UART3 Receiver | + * | 69 | UART3_TX | UART3 Transmitter | + * | 70 | SPI1_D0 | SPI1 Data 0 | + * | 71 | SPI1_D1 | SPI1 Data 1 | + * | 72 | SPI1_D2 | SPI1 Data 2 | + * | 73 | SPI1_D3 | SPI1 Data 3 | + * | 74 | SPI1_D4 | SPI1 Data 4 | + * | 75 | SPI1_D5 | SPI1 Data 5 | + * | 76 | SPI1_D6 | SPI1 Data 6 | + * | 77 | SPI1_D7 | SPI1 Data 7 | + * | 78 | SPI1_SS0 | SPI1 Chip Select 0 | + * | 79 | SPI1_SS1 | SPI1 Chip Select 1 | + * | 80 | SPI1_SS2 | SPI1 Chip Select 2 | + * | 81 | SPI1_SS3 | SPI1 Chip Select 3 | + * | 82 | SPI1_ARB | SPI1 Arbitration | + * | 83 | SPI1_SCLK | SPI1 Serial Clock | + * | 84 | SPI_SLAVE_D0 | SPI Slave Data 0 | + * | 85 | SPI_SLAVE_SS | SPI Slave Select | + * | 86 | SPI_SLAVE_SCLK | SPI Slave Serial Clock | + * | 87 | I2S0_MCLK | I2S0 Master Clock | + * | 88 | I2S0_SCLK | I2S0 Serial Clock(BCLK) | + * | 89 | I2S0_WS | I2S0 Word Select(LRCLK) | + * | 90 | I2S0_IN_D0 | I2S0 Serial Data Input 0 | + * | 91 | I2S0_IN_D1 | I2S0 Serial Data Input 1 | + * | 92 | I2S0_IN_D2 | I2S0 Serial Data Input 2 | + * | 93 | I2S0_IN_D3 | I2S0 Serial Data Input 3 | + * | 94 | I2S0_OUT_D0 | I2S0 Serial Data Output 0 | + * | 95 | I2S0_OUT_D1 | I2S0 Serial Data Output 1 | + * | 96 | I2S0_OUT_D2 | I2S0 Serial Data Output 2 | + * | 97 | I2S0_OUT_D3 | I2S0 Serial Data Output 3 | + * | 98 | I2S1_MCLK | I2S1 Master Clock | + * | 99 | I2S1_SCLK | I2S1 Serial Clock(BCLK) | + * | 100 | I2S1_WS | I2S1 Word Select(LRCLK) | + * | 101 | I2S1_IN_D0 | I2S1 Serial Data Input 0 | + * | 102 | I2S1_IN_D1 | I2S1 Serial Data Input 1 | + * | 103 | I2S1_IN_D2 | I2S1 Serial Data Input 2 | + * | 104 | I2S1_IN_D3 | I2S1 Serial Data Input 3 | + * | 105 | I2S1_OUT_D0 | I2S1 Serial Data Output 0 | + * | 106 | I2S1_OUT_D1 | I2S1 Serial Data Output 1 | + * | 107 | I2S1_OUT_D2 | I2S1 Serial Data Output 2 | + * | 108 | I2S1_OUT_D3 | I2S1 Serial Data Output 3 | + * | 109 | I2S2_MCLK | I2S2 Master Clock | + * | 110 | I2S2_SCLK | I2S2 Serial Clock(BCLK) | + * | 111 | I2S2_WS | I2S2 Word Select(LRCLK) | + * | 112 | I2S2_IN_D0 | I2S2 Serial Data Input 0 | + * | 113 | I2S2_IN_D1 | I2S2 Serial Data Input 1 | + * | 114 | I2S2_IN_D2 | I2S2 Serial Data Input 2 | + * | 115 | I2S2_IN_D3 | I2S2 Serial Data Input 3 | + * | 116 | I2S2_OUT_D0 | I2S2 Serial Data Output 0 | + * | 117 | I2S2_OUT_D1 | I2S2 Serial Data Output 1 | + * | 118 | I2S2_OUT_D2 | I2S2 Serial Data Output 2 | + * | 119 | I2S2_OUT_D3 | I2S2 Serial Data Output 3 | + * | 120 | RESV0 | Reserved function | + * | 121 | RESV1 | Reserved function | + * | 122 | RESV2 | Reserved function | + * | 123 | RESV3 | Reserved function | + * | 124 | RESV4 | Reserved function | + * | 125 | RESV5 | Reserved function | + * | 126 | I2C0_SCLK | I2C0 Serial Clock | + * | 127 | I2C0_SDA | I2C0 Serial Data | + * | 128 | I2C1_SCLK | I2C1 Serial Clock | + * | 129 | I2C1_SDA | I2C1 Serial Data | + * | 130 | I2C2_SCLK | I2C2 Serial Clock | + * | 131 | I2C2_SDA | I2C2 Serial Data | + * | 132 | CMOS_XCLK | DVP System Clock | + * | 133 | CMOS_RST | DVP System Reset | + * | 134 | CMOS_PWDN | DVP Power Down Mode | + * | 135 | CMOS_VSYNC | DVP Vertical Sync | + * | 136 | CMOS_HREF | DVP Horizontal Reference output | + * | 137 | CMOS_PCLK | Pixel Clock | + * | 138 | CMOS_D0 | Data Bit 0 | + * | 139 | CMOS_D1 | Data Bit 1 | + * | 140 | CMOS_D2 | Data Bit 2 | + * | 141 | CMOS_D3 | Data Bit 3 | + * | 142 | CMOS_D4 | Data Bit 4 | + * | 143 | CMOS_D5 | Data Bit 5 | + * | 144 | CMOS_D6 | Data Bit 6 | + * | 145 | CMOS_D7 | Data Bit 7 | + * | 146 | SCCB_SCLK | SCCB Serial Clock | + * | 147 | SCCB_SDA | SCCB Serial Data | + * | 148 | UART1_CTS | UART1 Clear To Send | + * | 149 | UART1_DSR | UART1 Data Set Ready | + * | 150 | UART1_DCD | UART1 Data Carrier Detect | + * | 151 | UART1_RI | UART1 Ring Indicator | + * | 152 | UART1_SIR_IN | UART1 Serial Infrared Input | + * | 153 | UART1_DTR | UART1 Data Terminal Ready | + * | 154 | UART1_RTS | UART1 Request To Send | + * | 155 | UART1_OUT2 | UART1 User-designated Output 2 | + * | 156 | UART1_OUT1 | UART1 User-designated Output 1 | + * | 157 | UART1_SIR_OUT | UART1 Serial Infrared Output | + * | 158 | UART1_BAUD | UART1 Transmit Clock Output | + * | 159 | UART1_RE | UART1 Receiver Output Enable | + * | 160 | UART1_DE | UART1 Driver Output Enable | + * | 161 | UART1_RS485_EN | UART1 RS485 Enable | + * | 162 | UART2_CTS | UART2 Clear To Send | + * | 163 | UART2_DSR | UART2 Data Set Ready | + * | 164 | UART2_DCD | UART2 Data Carrier Detect | + * | 165 | UART2_RI | UART2 Ring Indicator | + * | 166 | UART2_SIR_IN | UART2 Serial Infrared Input | + * | 167 | UART2_DTR | UART2 Data Terminal Ready | + * | 168 | UART2_RTS | UART2 Request To Send | + * | 169 | UART2_OUT2 | UART2 User-designated Output 2 | + * | 170 | UART2_OUT1 | UART2 User-designated Output 1 | + * | 171 | UART2_SIR_OUT | UART2 Serial Infrared Output | + * | 172 | UART2_BAUD | UART2 Transmit Clock Output | + * | 173 | UART2_RE | UART2 Receiver Output Enable | + * | 174 | UART2_DE | UART2 Driver Output Enable | + * | 175 | UART2_RS485_EN | UART2 RS485 Enable | + * | 176 | UART3_CTS | UART3 Clear To Send | + * | 177 | UART3_DSR | UART3 Data Set Ready | + * | 178 | UART3_DCD | UART3 Data Carrier Detect | + * | 179 | UART3_RI | UART3 Ring Indicator | + * | 180 | UART3_SIR_IN | UART3 Serial Infrared Input | + * | 181 | UART3_DTR | UART3 Data Terminal Ready | + * | 182 | UART3_RTS | UART3 Request To Send | + * | 183 | UART3_OUT2 | UART3 User-designated Output 2 | + * | 184 | UART3_OUT1 | UART3 User-designated Output 1 | + * | 185 | UART3_SIR_OUT | UART3 Serial Infrared Output | + * | 186 | UART3_BAUD | UART3 Transmit Clock Output | + * | 187 | UART3_RE | UART3 Receiver Output Enable | + * | 188 | UART3_DE | UART3 Driver Output Enable | + * | 189 | UART3_RS485_EN | UART3 RS485 Enable | + * | 190 | TIMER0_TOGGLE1 | TIMER0 Toggle Output 1 | + * | 191 | TIMER0_TOGGLE2 | TIMER0 Toggle Output 2 | + * | 192 | TIMER0_TOGGLE3 | TIMER0 Toggle Output 3 | + * | 193 | TIMER0_TOGGLE4 | TIMER0 Toggle Output 4 | + * | 194 | TIMER1_TOGGLE1 | TIMER1 Toggle Output 1 | + * | 195 | TIMER1_TOGGLE2 | TIMER1 Toggle Output 2 | + * | 196 | TIMER1_TOGGLE3 | TIMER1 Toggle Output 3 | + * | 197 | TIMER1_TOGGLE4 | TIMER1 Toggle Output 4 | + * | 198 | TIMER2_TOGGLE1 | TIMER2 Toggle Output 1 | + * | 199 | TIMER2_TOGGLE2 | TIMER2 Toggle Output 2 | + * | 200 | TIMER2_TOGGLE3 | TIMER2 Toggle Output 3 | + * | 201 | TIMER2_TOGGLE4 | TIMER2 Toggle Output 4 | + * | 202 | CLK_SPI2 | Clock SPI2 | + * | 203 | CLK_I2C2 | Clock I2C2 | + * | 204 | INTERNAL0 | Internal function signal 0 | + * | 205 | INTERNAL1 | Internal function signal 1 | + * | 206 | INTERNAL2 | Internal function signal 2 | + * | 207 | INTERNAL3 | Internal function signal 3 | + * | 208 | INTERNAL4 | Internal function signal 4 | + * | 209 | INTERNAL5 | Internal function signal 5 | + * | 210 | INTERNAL6 | Internal function signal 6 | + * | 211 | INTERNAL7 | Internal function signal 7 | + * | 212 | INTERNAL8 | Internal function signal 8 | + * | 213 | INTERNAL9 | Internal function signal 9 | + * | 214 | INTERNAL10 | Internal function signal 10 | + * | 215 | INTERNAL11 | Internal function signal 11 | + * | 216 | INTERNAL12 | Internal function signal 12 | + * | 217 | INTERNAL13 | Internal function signal 13 | + * | 218 | INTERNAL14 | Internal function signal 14 | + * | 219 | INTERNAL15 | Internal function signal 15 | + * | 220 | INTERNAL16 | Internal function signal 16 | + * | 221 | INTERNAL17 | Internal function signal 17 | + * | 222 | CONSTANT | Constant function | + * | 223 | INTERNAL18 | Internal function signal 18 | + * | 224 | DEBUG0 | Debug function 0 | + * | 225 | DEBUG1 | Debug function 1 | + * | 226 | DEBUG2 | Debug function 2 | + * | 227 | DEBUG3 | Debug function 3 | + * | 228 | DEBUG4 | Debug function 4 | + * | 229 | DEBUG5 | Debug function 5 | + * | 230 | DEBUG6 | Debug function 6 | + * | 231 | DEBUG7 | Debug function 7 | + * | 232 | DEBUG8 | Debug function 8 | + * | 233 | DEBUG9 | Debug function 9 | + * | 234 | DEBUG10 | Debug function 10 | + * | 235 | DEBUG11 | Debug function 11 | + * | 236 | DEBUG12 | Debug function 12 | + * | 237 | DEBUG13 | Debug function 13 | + * | 238 | DEBUG14 | Debug function 14 | + * | 239 | DEBUG15 | Debug function 15 | + * | 240 | DEBUG16 | Debug function 16 | + * | 241 | DEBUG17 | Debug function 17 | + * | 242 | DEBUG18 | Debug function 18 | + * | 243 | DEBUG19 | Debug function 19 | + * | 244 | DEBUG20 | Debug function 20 | + * | 245 | DEBUG21 | Debug function 21 | + * | 246 | DEBUG22 | Debug function 22 | + * | 247 | DEBUG23 | Debug function 23 | + * | 248 | DEBUG24 | Debug function 24 | + * | 249 | DEBUG25 | Debug function 25 | + * | 250 | DEBUG26 | Debug function 26 | + * | 251 | DEBUG27 | Debug function 27 | + * | 252 | DEBUG28 | Debug function 28 | + * | 253 | DEBUG29 | Debug function 29 | + * | 254 | DEBUG30 | Debug function 30 | + * | 255 | DEBUG31 | Debug function 31 | + * + * Any IO of FPIOA have 256 functions, it is a IO-function matrix. + * All IO have default reset function, after reset, re-configure + * IO function is required. + */ + +/* clang-format off */ +typedef enum _fpioa_function +{ + FUNC_JTAG_TCLK = 0, /*!< JTAG Test Clock */ + FUNC_JTAG_TDI = 1, /*!< JTAG Test Data In */ + FUNC_JTAG_TMS = 2, /*!< JTAG Test Mode Select */ + FUNC_JTAG_TDO = 3, /*!< JTAG Test Data Out */ + FUNC_SPI0_D0 = 4, /*!< SPI0 Data 0 */ + FUNC_SPI0_D1 = 5, /*!< SPI0 Data 1 */ + FUNC_SPI0_D2 = 6, /*!< SPI0 Data 2 */ + FUNC_SPI0_D3 = 7, /*!< SPI0 Data 3 */ + FUNC_SPI0_D4 = 8, /*!< SPI0 Data 4 */ + FUNC_SPI0_D5 = 9, /*!< SPI0 Data 5 */ + FUNC_SPI0_D6 = 10, /*!< SPI0 Data 6 */ + FUNC_SPI0_D7 = 11, /*!< SPI0 Data 7 */ + FUNC_SPI0_SS0 = 12, /*!< SPI0 Chip Select 0 */ + FUNC_SPI0_SS1 = 13, /*!< SPI0 Chip Select 1 */ + FUNC_SPI0_SS2 = 14, /*!< SPI0 Chip Select 2 */ + FUNC_SPI0_SS3 = 15, /*!< SPI0 Chip Select 3 */ + FUNC_SPI0_ARB = 16, /*!< SPI0 Arbitration */ + FUNC_SPI0_SCLK = 17, /*!< SPI0 Serial Clock */ + FUNC_UARTHS_RX = 18, /*!< UART High speed Receiver */ + FUNC_UARTHS_TX = 19, /*!< UART High speed Transmitter */ + FUNC_RESV6 = 20, /*!< Reserved function */ + FUNC_RESV7 = 21, /*!< Reserved function */ + FUNC_CLK_SPI1 = 22, /*!< Clock SPI1 */ + FUNC_CLK_I2C1 = 23, /*!< Clock I2C1 */ + FUNC_GPIOHS0 = 24, /*!< GPIO High speed 0 */ + FUNC_GPIOHS1 = 25, /*!< GPIO High speed 1 */ + FUNC_GPIOHS2 = 26, /*!< GPIO High speed 2 */ + FUNC_GPIOHS3 = 27, /*!< GPIO High speed 3 */ + FUNC_GPIOHS4 = 28, /*!< GPIO High speed 4 */ + FUNC_GPIOHS5 = 29, /*!< GPIO High speed 5 */ + FUNC_GPIOHS6 = 30, /*!< GPIO High speed 6 */ + FUNC_GPIOHS7 = 31, /*!< GPIO High speed 7 */ + FUNC_GPIOHS8 = 32, /*!< GPIO High speed 8 */ + FUNC_GPIOHS9 = 33, /*!< GPIO High speed 9 */ + FUNC_GPIOHS10 = 34, /*!< GPIO High speed 10 */ + FUNC_GPIOHS11 = 35, /*!< GPIO High speed 11 */ + FUNC_GPIOHS12 = 36, /*!< GPIO High speed 12 */ + FUNC_GPIOHS13 = 37, /*!< GPIO High speed 13 */ + FUNC_GPIOHS14 = 38, /*!< GPIO High speed 14 */ + FUNC_GPIOHS15 = 39, /*!< GPIO High speed 15 */ + FUNC_GPIOHS16 = 40, /*!< GPIO High speed 16 */ + FUNC_GPIOHS17 = 41, /*!< GPIO High speed 17 */ + FUNC_GPIOHS18 = 42, /*!< GPIO High speed 18 */ + FUNC_GPIOHS19 = 43, /*!< GPIO High speed 19 */ + FUNC_GPIOHS20 = 44, /*!< GPIO High speed 20 */ + FUNC_GPIOHS21 = 45, /*!< GPIO High speed 21 */ + FUNC_GPIOHS22 = 46, /*!< GPIO High speed 22 */ + FUNC_GPIOHS23 = 47, /*!< GPIO High speed 23 */ + FUNC_GPIOHS24 = 48, /*!< GPIO High speed 24 */ + FUNC_GPIOHS25 = 49, /*!< GPIO High speed 25 */ + FUNC_GPIOHS26 = 50, /*!< GPIO High speed 26 */ + FUNC_GPIOHS27 = 51, /*!< GPIO High speed 27 */ + FUNC_GPIOHS28 = 52, /*!< GPIO High speed 28 */ + FUNC_GPIOHS29 = 53, /*!< GPIO High speed 29 */ + FUNC_GPIOHS30 = 54, /*!< GPIO High speed 30 */ + FUNC_GPIOHS31 = 55, /*!< GPIO High speed 31 */ + FUNC_GPIO0 = 56, /*!< GPIO pin 0 */ + FUNC_GPIO1 = 57, /*!< GPIO pin 1 */ + FUNC_GPIO2 = 58, /*!< GPIO pin 2 */ + FUNC_GPIO3 = 59, /*!< GPIO pin 3 */ + FUNC_GPIO4 = 60, /*!< GPIO pin 4 */ + FUNC_GPIO5 = 61, /*!< GPIO pin 5 */ + FUNC_GPIO6 = 62, /*!< GPIO pin 6 */ + FUNC_GPIO7 = 63, /*!< GPIO pin 7 */ + FUNC_UART1_RX = 64, /*!< UART1 Receiver */ + FUNC_UART1_TX = 65, /*!< UART1 Transmitter */ + FUNC_UART2_RX = 66, /*!< UART2 Receiver */ + FUNC_UART2_TX = 67, /*!< UART2 Transmitter */ + FUNC_UART3_RX = 68, /*!< UART3 Receiver */ + FUNC_UART3_TX = 69, /*!< UART3 Transmitter */ + FUNC_SPI1_D0 = 70, /*!< SPI1 Data 0 */ + FUNC_SPI1_D1 = 71, /*!< SPI1 Data 1 */ + FUNC_SPI1_D2 = 72, /*!< SPI1 Data 2 */ + FUNC_SPI1_D3 = 73, /*!< SPI1 Data 3 */ + FUNC_SPI1_D4 = 74, /*!< SPI1 Data 4 */ + FUNC_SPI1_D5 = 75, /*!< SPI1 Data 5 */ + FUNC_SPI1_D6 = 76, /*!< SPI1 Data 6 */ + FUNC_SPI1_D7 = 77, /*!< SPI1 Data 7 */ + FUNC_SPI1_SS0 = 78, /*!< SPI1 Chip Select 0 */ + FUNC_SPI1_SS1 = 79, /*!< SPI1 Chip Select 1 */ + FUNC_SPI1_SS2 = 80, /*!< SPI1 Chip Select 2 */ + FUNC_SPI1_SS3 = 81, /*!< SPI1 Chip Select 3 */ + FUNC_SPI1_ARB = 82, /*!< SPI1 Arbitration */ + FUNC_SPI1_SCLK = 83, /*!< SPI1 Serial Clock */ + FUNC_SPI_SLAVE_D0 = 84, /*!< SPI Slave Data 0 */ + FUNC_SPI_SLAVE_SS = 85, /*!< SPI Slave Select */ + FUNC_SPI_SLAVE_SCLK = 86, /*!< SPI Slave Serial Clock */ + FUNC_I2S0_MCLK = 87, /*!< I2S0 Master Clock */ + FUNC_I2S0_SCLK = 88, /*!< I2S0 Serial Clock(BCLK) */ + FUNC_I2S0_WS = 89, /*!< I2S0 Word Select(LRCLK) */ + FUNC_I2S0_IN_D0 = 90, /*!< I2S0 Serial Data Input 0 */ + FUNC_I2S0_IN_D1 = 91, /*!< I2S0 Serial Data Input 1 */ + FUNC_I2S0_IN_D2 = 92, /*!< I2S0 Serial Data Input 2 */ + FUNC_I2S0_IN_D3 = 93, /*!< I2S0 Serial Data Input 3 */ + FUNC_I2S0_OUT_D0 = 94, /*!< I2S0 Serial Data Output 0 */ + FUNC_I2S0_OUT_D1 = 95, /*!< I2S0 Serial Data Output 1 */ + FUNC_I2S0_OUT_D2 = 96, /*!< I2S0 Serial Data Output 2 */ + FUNC_I2S0_OUT_D3 = 97, /*!< I2S0 Serial Data Output 3 */ + FUNC_I2S1_MCLK = 98, /*!< I2S1 Master Clock */ + FUNC_I2S1_SCLK = 99, /*!< I2S1 Serial Clock(BCLK) */ + FUNC_I2S1_WS = 100, /*!< I2S1 Word Select(LRCLK) */ + FUNC_I2S1_IN_D0 = 101, /*!< I2S1 Serial Data Input 0 */ + FUNC_I2S1_IN_D1 = 102, /*!< I2S1 Serial Data Input 1 */ + FUNC_I2S1_IN_D2 = 103, /*!< I2S1 Serial Data Input 2 */ + FUNC_I2S1_IN_D3 = 104, /*!< I2S1 Serial Data Input 3 */ + FUNC_I2S1_OUT_D0 = 105, /*!< I2S1 Serial Data Output 0 */ + FUNC_I2S1_OUT_D1 = 106, /*!< I2S1 Serial Data Output 1 */ + FUNC_I2S1_OUT_D2 = 107, /*!< I2S1 Serial Data Output 2 */ + FUNC_I2S1_OUT_D3 = 108, /*!< I2S1 Serial Data Output 3 */ + FUNC_I2S2_MCLK = 109, /*!< I2S2 Master Clock */ + FUNC_I2S2_SCLK = 110, /*!< I2S2 Serial Clock(BCLK) */ + FUNC_I2S2_WS = 111, /*!< I2S2 Word Select(LRCLK) */ + FUNC_I2S2_IN_D0 = 112, /*!< I2S2 Serial Data Input 0 */ + FUNC_I2S2_IN_D1 = 113, /*!< I2S2 Serial Data Input 1 */ + FUNC_I2S2_IN_D2 = 114, /*!< I2S2 Serial Data Input 2 */ + FUNC_I2S2_IN_D3 = 115, /*!< I2S2 Serial Data Input 3 */ + FUNC_I2S2_OUT_D0 = 116, /*!< I2S2 Serial Data Output 0 */ + FUNC_I2S2_OUT_D1 = 117, /*!< I2S2 Serial Data Output 1 */ + FUNC_I2S2_OUT_D2 = 118, /*!< I2S2 Serial Data Output 2 */ + FUNC_I2S2_OUT_D3 = 119, /*!< I2S2 Serial Data Output 3 */ + FUNC_RESV0 = 120, /*!< Reserved function */ + FUNC_RESV1 = 121, /*!< Reserved function */ + FUNC_RESV2 = 122, /*!< Reserved function */ + FUNC_RESV3 = 123, /*!< Reserved function */ + FUNC_RESV4 = 124, /*!< Reserved function */ + FUNC_RESV5 = 125, /*!< Reserved function */ + FUNC_I2C0_SCLK = 126, /*!< I2C0 Serial Clock */ + FUNC_I2C0_SDA = 127, /*!< I2C0 Serial Data */ + FUNC_I2C1_SCLK = 128, /*!< I2C1 Serial Clock */ + FUNC_I2C1_SDA = 129, /*!< I2C1 Serial Data */ + FUNC_I2C2_SCLK = 130, /*!< I2C2 Serial Clock */ + FUNC_I2C2_SDA = 131, /*!< I2C2 Serial Data */ + FUNC_CMOS_XCLK = 132, /*!< DVP System Clock */ + FUNC_CMOS_RST = 133, /*!< DVP System Reset */ + FUNC_CMOS_PWDN = 134, /*!< DVP Power Down Mode */ + FUNC_CMOS_VSYNC = 135, /*!< DVP Vertical Sync */ + FUNC_CMOS_HREF = 136, /*!< DVP Horizontal Reference output */ + FUNC_CMOS_PCLK = 137, /*!< Pixel Clock */ + FUNC_CMOS_D0 = 138, /*!< Data Bit 0 */ + FUNC_CMOS_D1 = 139, /*!< Data Bit 1 */ + FUNC_CMOS_D2 = 140, /*!< Data Bit 2 */ + FUNC_CMOS_D3 = 141, /*!< Data Bit 3 */ + FUNC_CMOS_D4 = 142, /*!< Data Bit 4 */ + FUNC_CMOS_D5 = 143, /*!< Data Bit 5 */ + FUNC_CMOS_D6 = 144, /*!< Data Bit 6 */ + FUNC_CMOS_D7 = 145, /*!< Data Bit 7 */ + FUNC_SCCB_SCLK = 146, /*!< SCCB Serial Clock */ + FUNC_SCCB_SDA = 147, /*!< SCCB Serial Data */ + FUNC_UART1_CTS = 148, /*!< UART1 Clear To Send */ + FUNC_UART1_DSR = 149, /*!< UART1 Data Set Ready */ + FUNC_UART1_DCD = 150, /*!< UART1 Data Carrier Detect */ + FUNC_UART1_RI = 151, /*!< UART1 Ring Indicator */ + FUNC_UART1_SIR_IN = 152, /*!< UART1 Serial Infrared Input */ + FUNC_UART1_DTR = 153, /*!< UART1 Data Terminal Ready */ + FUNC_UART1_RTS = 154, /*!< UART1 Request To Send */ + FUNC_UART1_OUT2 = 155, /*!< UART1 User-designated Output 2 */ + FUNC_UART1_OUT1 = 156, /*!< UART1 User-designated Output 1 */ + FUNC_UART1_SIR_OUT = 157, /*!< UART1 Serial Infrared Output */ + FUNC_UART1_BAUD = 158, /*!< UART1 Transmit Clock Output */ + FUNC_UART1_RE = 159, /*!< UART1 Receiver Output Enable */ + FUNC_UART1_DE = 160, /*!< UART1 Driver Output Enable */ + FUNC_UART1_RS485_EN = 161, /*!< UART1 RS485 Enable */ + FUNC_UART2_CTS = 162, /*!< UART2 Clear To Send */ + FUNC_UART2_DSR = 163, /*!< UART2 Data Set Ready */ + FUNC_UART2_DCD = 164, /*!< UART2 Data Carrier Detect */ + FUNC_UART2_RI = 165, /*!< UART2 Ring Indicator */ + FUNC_UART2_SIR_IN = 166, /*!< UART2 Serial Infrared Input */ + FUNC_UART2_DTR = 167, /*!< UART2 Data Terminal Ready */ + FUNC_UART2_RTS = 168, /*!< UART2 Request To Send */ + FUNC_UART2_OUT2 = 169, /*!< UART2 User-designated Output 2 */ + FUNC_UART2_OUT1 = 170, /*!< UART2 User-designated Output 1 */ + FUNC_UART2_SIR_OUT = 171, /*!< UART2 Serial Infrared Output */ + FUNC_UART2_BAUD = 172, /*!< UART2 Transmit Clock Output */ + FUNC_UART2_RE = 173, /*!< UART2 Receiver Output Enable */ + FUNC_UART2_DE = 174, /*!< UART2 Driver Output Enable */ + FUNC_UART2_RS485_EN = 175, /*!< UART2 RS485 Enable */ + FUNC_UART3_CTS = 176, /*!< UART3 Clear To Send */ + FUNC_UART3_DSR = 177, /*!< UART3 Data Set Ready */ + FUNC_UART3_DCD = 178, /*!< UART3 Data Carrier Detect */ + FUNC_UART3_RI = 179, /*!< UART3 Ring Indicator */ + FUNC_UART3_SIR_IN = 180, /*!< UART3 Serial Infrared Input */ + FUNC_UART3_DTR = 181, /*!< UART3 Data Terminal Ready */ + FUNC_UART3_RTS = 182, /*!< UART3 Request To Send */ + FUNC_UART3_OUT2 = 183, /*!< UART3 User-designated Output 2 */ + FUNC_UART3_OUT1 = 184, /*!< UART3 User-designated Output 1 */ + FUNC_UART3_SIR_OUT = 185, /*!< UART3 Serial Infrared Output */ + FUNC_UART3_BAUD = 186, /*!< UART3 Transmit Clock Output */ + FUNC_UART3_RE = 187, /*!< UART3 Receiver Output Enable */ + FUNC_UART3_DE = 188, /*!< UART3 Driver Output Enable */ + FUNC_UART3_RS485_EN = 189, /*!< UART3 RS485 Enable */ + FUNC_TIMER0_TOGGLE1 = 190, /*!< TIMER0 Toggle Output 1 */ + FUNC_TIMER0_TOGGLE2 = 191, /*!< TIMER0 Toggle Output 2 */ + FUNC_TIMER0_TOGGLE3 = 192, /*!< TIMER0 Toggle Output 3 */ + FUNC_TIMER0_TOGGLE4 = 193, /*!< TIMER0 Toggle Output 4 */ + FUNC_TIMER1_TOGGLE1 = 194, /*!< TIMER1 Toggle Output 1 */ + FUNC_TIMER1_TOGGLE2 = 195, /*!< TIMER1 Toggle Output 2 */ + FUNC_TIMER1_TOGGLE3 = 196, /*!< TIMER1 Toggle Output 3 */ + FUNC_TIMER1_TOGGLE4 = 197, /*!< TIMER1 Toggle Output 4 */ + FUNC_TIMER2_TOGGLE1 = 198, /*!< TIMER2 Toggle Output 1 */ + FUNC_TIMER2_TOGGLE2 = 199, /*!< TIMER2 Toggle Output 2 */ + FUNC_TIMER2_TOGGLE3 = 200, /*!< TIMER2 Toggle Output 3 */ + FUNC_TIMER2_TOGGLE4 = 201, /*!< TIMER2 Toggle Output 4 */ + FUNC_CLK_SPI2 = 202, /*!< Clock SPI2 */ + FUNC_CLK_I2C2 = 203, /*!< Clock I2C2 */ + FUNC_INTERNAL0 = 204, /*!< Internal function signal 0 */ + FUNC_INTERNAL1 = 205, /*!< Internal function signal 1 */ + FUNC_INTERNAL2 = 206, /*!< Internal function signal 2 */ + FUNC_INTERNAL3 = 207, /*!< Internal function signal 3 */ + FUNC_INTERNAL4 = 208, /*!< Internal function signal 4 */ + FUNC_INTERNAL5 = 209, /*!< Internal function signal 5 */ + FUNC_INTERNAL6 = 210, /*!< Internal function signal 6 */ + FUNC_INTERNAL7 = 211, /*!< Internal function signal 7 */ + FUNC_INTERNAL8 = 212, /*!< Internal function signal 8 */ + FUNC_INTERNAL9 = 213, /*!< Internal function signal 9 */ + FUNC_INTERNAL10 = 214, /*!< Internal function signal 10 */ + FUNC_INTERNAL11 = 215, /*!< Internal function signal 11 */ + FUNC_INTERNAL12 = 216, /*!< Internal function signal 12 */ + FUNC_INTERNAL13 = 217, /*!< Internal function signal 13 */ + FUNC_INTERNAL14 = 218, /*!< Internal function signal 14 */ + FUNC_INTERNAL15 = 219, /*!< Internal function signal 15 */ + FUNC_INTERNAL16 = 220, /*!< Internal function signal 16 */ + FUNC_INTERNAL17 = 221, /*!< Internal function signal 17 */ + FUNC_CONSTANT = 222, /*!< Constant function */ + FUNC_INTERNAL18 = 223, /*!< Internal function signal 18 */ + FUNC_DEBUG0 = 224, /*!< Debug function 0 */ + FUNC_DEBUG1 = 225, /*!< Debug function 1 */ + FUNC_DEBUG2 = 226, /*!< Debug function 2 */ + FUNC_DEBUG3 = 227, /*!< Debug function 3 */ + FUNC_DEBUG4 = 228, /*!< Debug function 4 */ + FUNC_DEBUG5 = 229, /*!< Debug function 5 */ + FUNC_DEBUG6 = 230, /*!< Debug function 6 */ + FUNC_DEBUG7 = 231, /*!< Debug function 7 */ + FUNC_DEBUG8 = 232, /*!< Debug function 8 */ + FUNC_DEBUG9 = 233, /*!< Debug function 9 */ + FUNC_DEBUG10 = 234, /*!< Debug function 10 */ + FUNC_DEBUG11 = 235, /*!< Debug function 11 */ + FUNC_DEBUG12 = 236, /*!< Debug function 12 */ + FUNC_DEBUG13 = 237, /*!< Debug function 13 */ + FUNC_DEBUG14 = 238, /*!< Debug function 14 */ + FUNC_DEBUG15 = 239, /*!< Debug function 15 */ + FUNC_DEBUG16 = 240, /*!< Debug function 16 */ + FUNC_DEBUG17 = 241, /*!< Debug function 17 */ + FUNC_DEBUG18 = 242, /*!< Debug function 18 */ + FUNC_DEBUG19 = 243, /*!< Debug function 19 */ + FUNC_DEBUG20 = 244, /*!< Debug function 20 */ + FUNC_DEBUG21 = 245, /*!< Debug function 21 */ + FUNC_DEBUG22 = 246, /*!< Debug function 22 */ + FUNC_DEBUG23 = 247, /*!< Debug function 23 */ + FUNC_DEBUG24 = 248, /*!< Debug function 24 */ + FUNC_DEBUG25 = 249, /*!< Debug function 25 */ + FUNC_DEBUG26 = 250, /*!< Debug function 26 */ + FUNC_DEBUG27 = 251, /*!< Debug function 27 */ + FUNC_DEBUG28 = 252, /*!< Debug function 28 */ + FUNC_DEBUG29 = 253, /*!< Debug function 29 */ + FUNC_DEBUG30 = 254, /*!< Debug function 30 */ + FUNC_DEBUG31 = 255, /*!< Debug function 31 */ + FUNC_MAX = 256, /*!< Function numbers */ +} fpioa_function_t; +/* clang-format on */ + +/** + * @brief FPIOA pull settings + * + * @note FPIOA pull settings description + * + * | PU | PD | Description | + * |-----|-----|-----------------------------------| + * | 0 | 0 | No Pull | + * | 0 | 1 | Pull Down | + * | 1 | 0 | Pull Up | + * | 1 | 1 | Undefined | + * + */ + +/* clang-format off */ +typedef enum _fpioa_pull +{ + FPIOA_PULL_NONE, /*!< No Pull */ + FPIOA_PULL_DOWN, /*!< Pull Down */ + FPIOA_PULL_UP, /*!< Pull Up */ + FPIOA_PULL_MAX /*!< Count of pull settings */ +} fpioa_pull_t; +/* clang-format on */ + +/** + * @brief FPIOA driving settings + * + * @note FPIOA driving settings description + * There are 16 kinds of driving settings + * + * @note Low Level Output Current + * + * |DS[3:0] |Min(mA)|Typ(mA)|Max(mA)| + * |--------|-------|-------|-------| + * |0000 |3.2 |5.4 |8.3 | + * |0001 |4.7 |8.0 |12.3 | + * |0010 |6.3 |10.7 |16.4 | + * |0011 |7.8 |13.2 |20.2 | + * |0100 |9.4 |15.9 |24.2 | + * |0101 |10.9 |18.4 |28.1 | + * |0110 |12.4 |20.9 |31.8 | + * |0111 |13.9 |23.4 |35.5 | + * + * @note High Level Output Current + * + * |DS[3:0] |Min(mA)|Typ(mA)|Max(mA)| + * |--------|-------|-------|-------| + * |0000 |5.0 |7.6 |11.2 | + * |0001 |7.5 |11.4 |16.8 | + * |0010 |10.0 |15.2 |22.3 | + * |0011 |12.4 |18.9 |27.8 | + * |0100 |14.9 |22.6 |33.3 | + * |0101 |17.4 |26.3 |38.7 | + * |0110 |19.8 |30.0 |44.1 | + * |0111 |22.3 |33.7 |49.5 | + * + */ + +/* clang-format off */ +typedef enum _fpioa_driving +{ + FPIOA_DRIVING_0, /*!< 0000 */ + FPIOA_DRIVING_1, /*!< 0001 */ + FPIOA_DRIVING_2, /*!< 0010 */ + FPIOA_DRIVING_3, /*!< 0011 */ + FPIOA_DRIVING_4, /*!< 0100 */ + FPIOA_DRIVING_5, /*!< 0101 */ + FPIOA_DRIVING_6, /*!< 0110 */ + FPIOA_DRIVING_7, /*!< 0111 */ + FPIOA_DRIVING_8, /*!< 1000 */ + FPIOA_DRIVING_9, /*!< 1001 */ + FPIOA_DRIVING_10, /*!< 1010 */ + FPIOA_DRIVING_11, /*!< 1011 */ + FPIOA_DRIVING_12, /*!< 1100 */ + FPIOA_DRIVING_13, /*!< 1101 */ + FPIOA_DRIVING_14, /*!< 1110 */ + FPIOA_DRIVING_15, /*!< 1111 */ + FPIOA_DRIVING_MAX /*!< Count of driving settings */ +} fpioa_driving_t; +/* clang-format on */ + +/** + * @brief FPIOA IO + * + * FPIOA IO is the specific pin of the chip package. Every IO + * has a 32bit width register that can independently implement + * schmitt trigger, invert input, invert output, strong pull + * up, driving selector, static input and static output. And more, + * it can implement any pin of any peripheral devices. + * + * @note FPIOA IO's register bits Layout + * + * | Bits | Name |Description | + * |-----------|----------|---------------------------------------------------| + * | 31 | PAD_DI | Read current IO's data input. | + * | 30:24 | NA | Reserved bits. | + * | 23 | ST | Schmitt trigger. | + * | 22 | DI_INV | Invert Data input. | + * | 21 | IE_INV | Invert the input enable signal. | + * | 20 | IE_EN | Input enable. It can disable or enable IO input. | + * | 19 | SL | Slew rate control enable. | + * | 18 | SPU | Strong pull up. | + * | 17 | PD | Pull select: 0 for pull down, 1 for pull up. | + * | 16 | PU | Pull enable. | + * | 15 | DO_INV | Invert the result of data output select (DO_SEL). | + * | 14 | DO_SEL | Data output select: 0 for DO, 1 for OE. | + * | 13 | OE_INV | Invert the output enable signal. | + * | 12 | OE_EN | Output enable.It can disable or enable IO output. | + * | 11:8 | DS | Driving selector. | + * | 7:0 | CH_SEL | Channel select from 256 input. | + * + */ +typedef struct _fpioa_io_config +{ + uint32_t ch_sel : 8; + /*!< Channel select from 256 input. */ + uint32_t ds : 4; + /*!< Driving selector. */ + uint32_t oe_en : 1; + /*!< Static output enable, will AND with OE_INV. */ + uint32_t oe_inv : 1; + /*!< Invert output enable. */ + uint32_t do_sel : 1; + /*!< Data output select: 0 for DO, 1 for OE. */ + uint32_t do_inv : 1; + /*!< Invert the result of data output select (DO_SEL). */ + uint32_t pu : 1; + /*!< Pull up enable. 0 for nothing, 1 for pull up. */ + uint32_t pd : 1; + /*!< Pull down enable. 0 for nothing, 1 for pull down. */ + uint32_t resv0 : 1; + /*!< Reserved bits. */ + uint32_t sl : 1; + /*!< Slew rate control enable. */ + uint32_t ie_en : 1; + /*!< Static input enable, will AND with IE_INV. */ + uint32_t ie_inv : 1; + /*!< Invert input enable. */ + uint32_t di_inv : 1; + /*!< Invert Data input. */ + uint32_t st : 1; + /*!< Schmitt trigger. */ + uint32_t resv1 : 7; + /*!< Reserved bits. */ + uint32_t pad_di : 1; + /*!< Read current IO's data input. */ +} __attribute__((packed, aligned(4))) fpioa_io_config_t; + +/** + * @brief FPIOA tie setting + * + * FPIOA Object have 48 IO pin object and 256 bit input tie bits. + * All SPI arbitration signal will tie high by default. + * + * @note FPIOA function tie bits RAM Layout + * + * | Address | Name |Description | + * |-----------|------------------|----------------------------------| + * | 0x000 | TIE_EN[31:0] | Input tie enable bits [31:0] | + * | 0x004 | TIE_EN[63:32] | Input tie enable bits [63:32] | + * | 0x008 | TIE_EN[95:64] | Input tie enable bits [95:64] | + * | 0x00C | TIE_EN[127:96] | Input tie enable bits [127:96] | + * | 0x010 | TIE_EN[159:128] | Input tie enable bits [159:128] | + * | 0x014 | TIE_EN[191:160] | Input tie enable bits [191:160] | + * | 0x018 | TIE_EN[223:192] | Input tie enable bits [223:192] | + * | 0x01C | TIE_EN[255:224] | Input tie enable bits [255:224] | + * | 0x020 | TIE_VAL[31:0] | Input tie value bits [31:0] | + * | 0x024 | TIE_VAL[63:32] | Input tie value bits [63:32] | + * | 0x028 | TIE_VAL[95:64] | Input tie value bits [95:64] | + * | 0x02C | TIE_VAL[127:96] | Input tie value bits [127:96] | + * | 0x030 | TIE_VAL[159:128] | Input tie value bits [159:128] | + * | 0x034 | TIE_VAL[191:160] | Input tie value bits [191:160] | + * | 0x038 | TIE_VAL[223:192] | Input tie value bits [223:192] | + * | 0x03C | TIE_VAL[255:224] | Input tie value bits [255:224] | + * + * @note Function which input tie high by default + * + * | Name |Description | + * |---------------|---------------------------------------| + * | SPI0_ARB | Arbitration function of SPI master 0 | + * | SPI1_ARB | Arbitration function of SPI master 1 | + * + * Tie high means the SPI Arbitration input is 1 + * + */ +typedef struct _fpioa_tie +{ + uint32_t en[FUNC_MAX / 32]; + /*!< FPIOA GPIO multiplexer tie enable array */ + uint32_t val[FUNC_MAX / 32]; + /*!< FPIOA GPIO multiplexer tie value array */ +} __attribute__((packed, aligned(4))) fpioa_tie_t; + +/** + * @brief FPIOA Object + * + * FPIOA Object have 48 IO pin object and 256 bit input tie bits. + * All SPI arbitration signal will tie high by default. + * + * @note FPIOA IO Pin RAM Layout + * + * | Address | Name |Description | + * |-----------|----------|--------------------------------| + * | 0x000 | PAD0 | FPIOA GPIO multiplexer io 0 | + * | 0x004 | PAD1 | FPIOA GPIO multiplexer io 1 | + * | 0x008 | PAD2 | FPIOA GPIO multiplexer io 2 | + * | 0x00C | PAD3 | FPIOA GPIO multiplexer io 3 | + * | 0x010 | PAD4 | FPIOA GPIO multiplexer io 4 | + * | 0x014 | PAD5 | FPIOA GPIO multiplexer io 5 | + * | 0x018 | PAD6 | FPIOA GPIO multiplexer io 6 | + * | 0x01C | PAD7 | FPIOA GPIO multiplexer io 7 | + * | 0x020 | PAD8 | FPIOA GPIO multiplexer io 8 | + * | 0x024 | PAD9 | FPIOA GPIO multiplexer io 9 | + * | 0x028 | PAD10 | FPIOA GPIO multiplexer io 10 | + * | 0x02C | PAD11 | FPIOA GPIO multiplexer io 11 | + * | 0x030 | PAD12 | FPIOA GPIO multiplexer io 12 | + * | 0x034 | PAD13 | FPIOA GPIO multiplexer io 13 | + * | 0x038 | PAD14 | FPIOA GPIO multiplexer io 14 | + * | 0x03C | PAD15 | FPIOA GPIO multiplexer io 15 | + * | 0x040 | PAD16 | FPIOA GPIO multiplexer io 16 | + * | 0x044 | PAD17 | FPIOA GPIO multiplexer io 17 | + * | 0x048 | PAD18 | FPIOA GPIO multiplexer io 18 | + * | 0x04C | PAD19 | FPIOA GPIO multiplexer io 19 | + * | 0x050 | PAD20 | FPIOA GPIO multiplexer io 20 | + * | 0x054 | PAD21 | FPIOA GPIO multiplexer io 21 | + * | 0x058 | PAD22 | FPIOA GPIO multiplexer io 22 | + * | 0x05C | PAD23 | FPIOA GPIO multiplexer io 23 | + * | 0x060 | PAD24 | FPIOA GPIO multiplexer io 24 | + * | 0x064 | PAD25 | FPIOA GPIO multiplexer io 25 | + * | 0x068 | PAD26 | FPIOA GPIO multiplexer io 26 | + * | 0x06C | PAD27 | FPIOA GPIO multiplexer io 27 | + * | 0x070 | PAD28 | FPIOA GPIO multiplexer io 28 | + * | 0x074 | PAD29 | FPIOA GPIO multiplexer io 29 | + * | 0x078 | PAD30 | FPIOA GPIO multiplexer io 30 | + * | 0x07C | PAD31 | FPIOA GPIO multiplexer io 31 | + * | 0x080 | PAD32 | FPIOA GPIO multiplexer io 32 | + * | 0x084 | PAD33 | FPIOA GPIO multiplexer io 33 | + * | 0x088 | PAD34 | FPIOA GPIO multiplexer io 34 | + * | 0x08C | PAD35 | FPIOA GPIO multiplexer io 35 | + * | 0x090 | PAD36 | FPIOA GPIO multiplexer io 36 | + * | 0x094 | PAD37 | FPIOA GPIO multiplexer io 37 | + * | 0x098 | PAD38 | FPIOA GPIO multiplexer io 38 | + * | 0x09C | PAD39 | FPIOA GPIO multiplexer io 39 | + * | 0x0A0 | PAD40 | FPIOA GPIO multiplexer io 40 | + * | 0x0A4 | PAD41 | FPIOA GPIO multiplexer io 41 | + * | 0x0A8 | PAD42 | FPIOA GPIO multiplexer io 42 | + * | 0x0AC | PAD43 | FPIOA GPIO multiplexer io 43 | + * | 0x0B0 | PAD44 | FPIOA GPIO multiplexer io 44 | + * | 0x0B4 | PAD45 | FPIOA GPIO multiplexer io 45 | + * | 0x0B8 | PAD46 | FPIOA GPIO multiplexer io 46 | + * | 0x0BC | PAD47 | FPIOA GPIO multiplexer io 47 | + * + */ +typedef struct _fpioa +{ + fpioa_io_config_t io[FPIOA_NUM_IO]; + /*!< FPIOA GPIO multiplexer io array */ + fpioa_tie_t tie; + /*!< FPIOA GPIO multiplexer tie */ +} __attribute__((packed, aligned(4))) fpioa_t; + +/** + * @brief FPIOA object instanse + */ +extern volatile fpioa_t *const fpioa; + +/** + * @brief Initialize FPIOA user custom default settings + * + * @note This function will set all FPIOA pad registers to user-defined + * values from kconfig + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_init(void); + +/** + * @brief Get IO configuration + * + * @param[in] number The IO number + * @param cfg Pointer to struct of IO configuration for specified IO + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_get_io(int number, fpioa_io_config_t *cfg); + +/** + * @brief Set IO configuration + * + * @param[in] number The IO number + * @param[in] cfg Pointer to struct of IO configuration for specified IO + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_io(int number, fpioa_io_config_t *cfg); + +/** + * @brief Set IO configuration with function number + * + * @note The default IO configuration which bind to function number will + * set automatically + * + * @param[in] number The IO number + * @param[in] function The function enum number + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_function_raw(int number, fpioa_function_t function); + +/** + * @brief Set only IO configuration with function number + * + * @note The default IO configuration which bind to function number will + * set automatically + * + * @param[in] number The IO number + * @param[in] function The function enum number + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_function(int number, fpioa_function_t function); + +/** + * @brief Set tie enable to function + * + * @param[in] function The function enum number + * @param[in] enable Tie enable to set, 1 is enable, 0 is disable + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_tie_enable(fpioa_function_t function, int enable); + +/** + * @brief Set tie value to function + * + * @param[in] function The function enum number + * @param[in] value Tie value to set, 1 is HIGH, 0 is LOW + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_tie_value(fpioa_function_t function, int value); + +/** + * @brief Set IO pull function + * + * @param[in] number The IO number + * @param[in] pull The pull enum number + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_io_pull(int number, fpioa_pull_t pull); + +/** + * @brief Get IO pull function + * + * @param[in] number The IO number + * + * @return result + * - -1 Fail + * - Other The pull enum number + */ +int fpioa_get_io_pull(int number); + +/** + * @brief Set IO driving + * + * @param[in] number The IO number + * @param[in] driving The driving enum number + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_io_driving(int number, fpioa_driving_t driving); + +/** + * @brief Get IO driving + * + * @param[in] number The IO number + * + * @return result + * - -1 Fail + * - Other The driving enum number + */ +int fpioa_get_io_driving(int number); + +/** + * @brief Get IO by function + * + * @param[in] function The function enum number + * + * @return result + * - -1 Fail + * - Other The IO number + */ +int fpioa_get_io_by_function(fpioa_function_t function); + +/** + * @brief Set IO slew rate control + * + * @param[in] number The IO number + * @param[in] sl_value Enable slew rate. 0: disable 1:enable + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_sl(int number, uint8_t sl_enable); + +/** + * @brief Set IO schmitt trigger + * + * @param[in] number The IO number + * @param[in] st_enable Enable schmitt trigger. 0: disable 1:enable + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_st(int number, uint8_t st_enable); + +/** + * @brief Set IO output invert enable + * + * @param[in] number The IO number + * @param[in] inv_enable Enable output invert. 0: disable 1:enable + * + * @return result + * - 0 Success + * - Other Fail + */ +int fpioa_set_oe_inv(int number, uint8_t inv_enable); + +#ifdef __cplusplus +} +#endif + +#endif /* _DRIVER_FPIOA_H */ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_clockconfig.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_clockconfig.c index 616348bf6..4e1836180 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_clockconfig.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_clockconfig.c @@ -128,8 +128,6 @@ void k210_clockconfig(void) { /* PLL0 selected */ g_cpu_clock = k210_get_pll0clk() / 2; - - syslog(LOG_NOTICE, "g_cpu clock = %d sel %#x\r\n", g_cpu_clock, clksel0); } else { @@ -142,12 +140,18 @@ void k210_clockconfig(void) void k210_sysctl_init(void) { -// sysctl_pll_set_freq(SYSCTL_PLL0, 800000000UL); -// sysctl_pll_set_freq(SYSCTL_PLL1, 400000000UL); -// sysctl_pll_set_freq(SYSCTL_PLL2, 45158400UL); + sysctl_pll_set_freq(SYSCTL_PLL0, 800000000UL); + sysctl_pll_set_freq(SYSCTL_PLL1, 400000000UL); + sysctl_pll_set_freq(SYSCTL_PLL2, 45158400UL); + sysctl_clock_set_threshold(SYSCTL_THRESHOLD_APB1, 2); -// sysctl_set_power_mode(SYSCTL_POWER_BANK0, SYSCTL_POWER_V18); -// sysctl_set_power_mode(SYSCTL_POWER_BANK1, SYSCTL_POWER_V18); -// sysctl_set_power_mode(SYSCTL_POWER_BANK2, SYSCTL_POWER_V18); + sysctl_set_power_mode(SYSCTL_POWER_BANK0, SYSCTL_POWER_V18); + sysctl_set_power_mode(SYSCTL_POWER_BANK1, SYSCTL_POWER_V18); + sysctl_set_power_mode(SYSCTL_POWER_BANK2, SYSCTL_POWER_V18); + + // for IO-27/28 + sysctl_set_power_mode(SYSCTL_POWER_BANK4, SYSCTL_POWER_V33); + // for IO-20~23 + sysctl_set_power_mode(SYSCTL_POWER_BANK3, SYSCTL_POWER_V33); } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_fpioa.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_fpioa.c index 267011ec3..0adcee8db 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_fpioa.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_fpioa.c @@ -47,55 +47,21 @@ int k210_fpioa_get_io_by_function(uint8_t function) { int index = 0; uint32_t RegValue = 0x0000; - uint32_t *fpioa = (uint32_t *)K210_FPIOA_BASE; + uint32_t *fpioa_base = (uint32_t *)K210_FPIOA_BASE; for (index = 0; index < K210_IO_NUMBER; index++) { - RegValue = getreg32(&fpioa[index]); + RegValue = getreg32(&fpioa_base[index]); if ((RegValue & 0xFF) == function) return index; } return -1; } -int fpioa_set_io_pull(int number, fpioa_pull_t pull) -{ - /* Check parameters */ - if (number < 0 || number >= K210_IO_NUMBER || pull >= FPIOA_PULL_MAX) - return -1; - - /* read register */ - uint32_t *fpioa = (uint32_t *)K210_FPIOA_BASE; - fpioa_io_config_t cfg = *(fpioa_io_config_t *)(&fpioa[number]); - uint32_t ioflags = 0x0000; - - switch (pull) - { - case FPIOA_PULL_NONE: - cfg.pu = 0; - cfg.pd = 0; - break; - case FPIOA_PULL_DOWN: - cfg.pu = 0; - cfg.pd = 1; - break; - case FPIOA_PULL_UP: - cfg.pu = 1; - cfg.pd = 0; - break; - default: - break; - } - - /* write register */ - ioflags = *(uint32_t*)(&cfg); - putreg32(ioflags, &fpioa[number]); - return 0; -} void k210_fpioa_config(uint32_t io, uint32_t ioflags) { - uint32_t *fpioa = (uint32_t *)K210_FPIOA_BASE; + uint32_t *fpioa_base = (uint32_t *)K210_FPIOA_BASE; DEBUGASSERT(io < K210_IO_NUMBER); - putreg32(ioflags, &fpioa[io]); + putreg32(ioflags, &fpioa_base[io]); } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_fpioa.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_fpioa.h index cc122c3b8..6c4a472ea 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_fpioa.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_fpioa.h @@ -22,7 +22,7 @@ * @file k210_fpioa.h * @brief nuttx source code * https://github.com/apache/incubator-nuttx.git -* @version 10.3.0 +* @version 10.3.0 * @author AIIT XUOS Lab * @date 2022-03-23 */ @@ -35,6 +35,7 @@ ****************************************************************************/ #include +#include "fpioa.h" /**************************************************************************** * Pre-processor Definitions @@ -44,48 +45,263 @@ #define K210_GPIOHS_MAX_PINNO 32 #define K210_GPIO_MAX_PINNO 8 -#define K210_IO_FUNC_UARTHS_RX 18 /* UART High speed Receiver */ -#define K210_IO_FUNC_UARTHS_TX 19 /* UART High speed Transmitter */ -#define K210_IO_FUNC_GPIOHS0 24 /* GPIO High speed 0 */ -#define K210_IO_FUNC_GPIOHS1 25 /* GPIO High speed 1 */ -#define K210_IO_FUNC_GPIOHS2 26 /* GPIO High speed 2 */ -#define K210_IO_FUNC_GPIOHS3 27 /* GPIO High speed 3 */ -#define K210_IO_FUNC_GPIOHS4 28 /* GPIO High speed 4 */ -#define K210_IO_FUNC_GPIOHS5 29 /* GPIO High speed 5 */ -#define K210_IO_FUNC_GPIOHS6 30 /* GPIO High speed 6 */ -#define K210_IO_FUNC_GPIOHS7 31 /* GPIO High speed 7 */ -#define K210_IO_FUNC_GPIOHS8 32 /* GPIO High speed 8 */ -#define K210_IO_FUNC_GPIOHS9 33 /* GPIO High speed 9 */ -#define K210_IO_FUNC_GPIOHS10 34 /* GPIO High speed 10 */ -#define K210_IO_FUNC_GPIOHS11 35 /* GPIO High speed 11 */ -#define K210_IO_FUNC_GPIOHS12 36 /* GPIO High speed 12 */ -#define K210_IO_FUNC_GPIOHS13 37 /* GPIO High speed 13 */ -#define K210_IO_FUNC_GPIOHS14 38 /* GPIO High speed 14 */ -#define K210_IO_FUNC_GPIOHS15 39 /* GPIO High speed 15 */ -#define K210_IO_FUNC_GPIOHS16 40 /* GPIO High speed 16 */ -#define K210_IO_FUNC_GPIOHS17 41 /* GPIO High speed 17 */ -#define K210_IO_FUNC_GPIOHS18 42 /* GPIO High speed 18 */ -#define K210_IO_FUNC_GPIOHS19 43 /* GPIO High speed 19 */ -#define K210_IO_FUNC_GPIOHS20 44 /* GPIO High speed 20 */ -#define K210_IO_FUNC_GPIOHS21 45 /* GPIO High speed 21 */ -#define K210_IO_FUNC_GPIOHS22 46 /* GPIO High speed 22 */ -#define K210_IO_FUNC_GPIOHS23 47 /* GPIO High speed 23 */ -#define K210_IO_FUNC_GPIOHS24 48 /* GPIO High speed 24 */ -#define K210_IO_FUNC_GPIOHS25 49 /* GPIO High speed 25 */ -#define K210_IO_FUNC_GPIOHS26 50 /* GPIO High speed 26 */ -#define K210_IO_FUNC_GPIOHS27 51 /* GPIO High speed 27 */ -#define K210_IO_FUNC_GPIOHS28 52 /* GPIO High speed 28 */ -#define K210_IO_FUNC_GPIOHS29 53 /* GPIO High speed 29 */ -#define K210_IO_FUNC_GPIOHS30 54 /* GPIO High speed 30 */ -#define K210_IO_FUNC_GPIOHS31 55 /* GPIO High speed 31 */ -#define K210_IO_FUNC_GPIO0 56 /* GPIO pin 0 */ -#define K210_IO_FUNC_GPIO1 57 /* GPIO pin 1 */ -#define K210_IO_FUNC_GPIO2 58 /* GPIO pin 2 */ -#define K210_IO_FUNC_GPIO3 59 /* GPIO pin 3 */ -#define K210_IO_FUNC_GPIO4 60 /* GPIO pin 4 */ -#define K210_IO_FUNC_GPIO5 61 /* GPIO pin 5 */ -#define K210_IO_FUNC_GPIO6 62 /* GPIO pin 6 */ -#define K210_IO_FUNC_GPIO7 63 /* GPIO pin 7 */ +#define K210_IO_FUNC_JTAG_TCLK 0 /* JTAG Test Clock */ +#define K210_IO_FUNC_JTAG_TDI 1 /* JTAG Test Data In */ +#define K210_IO_FUNC_JTAG_TMS 2 /* JTAG Test Mode Select */ +#define K210_IO_FUNC_JTAG_TDO 3 /* JTAG Test Data Out */ +#define K210_IO_FUNC_SPI0_D0 4 /* SPI0 Data 0 */ +#define K210_IO_FUNC_SPI0_D1 5 /* SPI0 Data 1 */ +#define K210_IO_FUNC_SPI0_D2 6 /* SPI0 Data 2 */ +#define K210_IO_FUNC_SPI0_D3 7 /* SPI0 Data 3 */ +#define K210_IO_FUNC_SPI0_D4 8 /* SPI0 Data 4 */ +#define K210_IO_FUNC_SPI0_D5 9 /* SPI0 Data 5 */ +#define K210_IO_FUNC_SPI0_D6 10 /* SPI0 Data 6 */ +#define K210_IO_FUNC_SPI0_D7 11 /* SPI0 Data 7 */ +#define K210_IO_FUNC_SPI0_SS0 12 /* SPI0 Chip Select 0 */ +#define K210_IO_FUNC_SPI0_SS1 13 /* SPI0 Chip Select 1 */ +#define K210_IO_FUNC_SPI0_SS2 14 /* SPI0 Chip Select 2 */ +#define K210_IO_FUNC_SPI0_SS3 15 /* SPI0 Chip Select 3 */ +#define K210_IO_FUNC_SPI0_ARB 16 /* SPI0 Arbitration */ +#define K210_IO_FUNC_SPI0_SCLK 17 /* SPI0 Serial Clock */ +#define K210_IO_FUNC_UARTHS_RX 18 /* UART High speed Receiver */ +#define K210_IO_FUNC_UARTHS_TX 19 /* UART High speed Transmitter */ +#define K210_IO_FUNC_RESV6 20 /* Reserved function */ +#define K210_IO_FUNC_RESV7 21 /* Reserved function */ +#define K210_IO_FUNC_CLK_SPI1 22 /* Clock SPI1 */ +#define K210_IO_FUNC_CLK_I2C1 23 /* Clock I2C1 */ +#define K210_IO_FUNC_GPIOHS0 24 /* GPIO High speed 0 */ +#define K210_IO_FUNC_GPIOHS1 25 /* GPIO High speed 1 */ +#define K210_IO_FUNC_GPIOHS2 26 /* GPIO High speed 2 */ +#define K210_IO_FUNC_GPIOHS3 27 /* GPIO High speed 3 */ +#define K210_IO_FUNC_GPIOHS4 28 /* GPIO High speed 4 */ +#define K210_IO_FUNC_GPIOHS5 29 /* GPIO High speed 5 */ +#define K210_IO_FUNC_GPIOHS6 30 /* GPIO High speed 6 */ +#define K210_IO_FUNC_GPIOHS7 31 /* GPIO High speed 7 */ +#define K210_IO_FUNC_GPIOHS8 32 /* GPIO High speed 8 */ +#define K210_IO_FUNC_GPIOHS9 33 /* GPIO High speed 9 */ +#define K210_IO_FUNC_GPIOHS10 34 /* GPIO High speed 10 */ +#define K210_IO_FUNC_GPIOHS11 35 /* GPIO High speed 11 */ +#define K210_IO_FUNC_GPIOHS12 36 /* GPIO High speed 12 */ +#define K210_IO_FUNC_GPIOHS13 37 /* GPIO High speed 13 */ +#define K210_IO_FUNC_GPIOHS14 38 /* GPIO High speed 14 */ +#define K210_IO_FUNC_GPIOHS15 39 /* GPIO High speed 15 */ +#define K210_IO_FUNC_GPIOHS16 40 /* GPIO High speed 16 */ +#define K210_IO_FUNC_GPIOHS17 41 /* GPIO High speed 17 */ +#define K210_IO_FUNC_GPIOHS18 42 /* GPIO High speed 18 */ +#define K210_IO_FUNC_GPIOHS19 43 /* GPIO High speed 19 */ +#define K210_IO_FUNC_GPIOHS20 44 /* GPIO High speed 20 */ +#define K210_IO_FUNC_GPIOHS21 45 /* GPIO High speed 21 */ +#define K210_IO_FUNC_GPIOHS22 46 /* GPIO High speed 22 */ +#define K210_IO_FUNC_GPIOHS23 47 /* GPIO High speed 23 */ +#define K210_IO_FUNC_GPIOHS24 48 /* GPIO High speed 24 */ +#define K210_IO_FUNC_GPIOHS25 49 /* GPIO High speed 25 */ +#define K210_IO_FUNC_GPIOHS26 50 /* GPIO High speed 26 */ +#define K210_IO_FUNC_GPIOHS27 51 /* GPIO High speed 27 */ +#define K210_IO_FUNC_GPIOHS28 52 /* GPIO High speed 28 */ +#define K210_IO_FUNC_GPIOHS29 53 /* GPIO High speed 29 */ +#define K210_IO_FUNC_GPIOHS30 54 /* GPIO High speed 30 */ +#define K210_IO_FUNC_GPIOHS31 55 /* GPIO High speed 31 */ +#define K210_IO_FUNC_GPIO0 56 /* GPIO pin 0 */ +#define K210_IO_FUNC_GPIO1 57 /* GPIO pin 1 */ +#define K210_IO_FUNC_GPIO2 58 /* GPIO pin 2 */ +#define K210_IO_FUNC_GPIO3 59 /* GPIO pin 3 */ +#define K210_IO_FUNC_GPIO4 60 /* GPIO pin 4 */ +#define K210_IO_FUNC_GPIO5 61 /* GPIO pin 5 */ +#define K210_IO_FUNC_GPIO6 62 /* GPIO pin 6 */ +#define K210_IO_FUNC_GPIO7 63 /* GPIO pin 7 */ +#define K210_IO_FUNC_UART1_RX 64 /* UART1 Receiver */ +#define K210_IO_FUNC_UART1_TX 65 /* UART1 Transmitter */ +#define K210_IO_FUNC_UART2_RX 66 /* UART2 Receiver */ +#define K210_IO_FUNC_UART2_TX 67 /* UART2 Transmitter */ +#define K210_IO_FUNC_UART3_RX 68 /* UART3 Receiver */ +#define K210_IO_FUNC_UART3_TX 69 /* UART3 Transmitter */ +#define K210_IO_FUNC_SPI1_D0 70 /* SPI1 Data 0 */ +#define K210_IO_FUNC_SPI1_D1 71 /* SPI1 Data 1 */ +#define K210_IO_FUNC_SPI1_D2 72 /* SPI1 Data 2 */ +#define K210_IO_FUNC_SPI1_D3 73 /* SPI1 Data 3 */ +#define K210_IO_FUNC_SPI1_D4 74 /* SPI1 Data 4 */ +#define K210_IO_FUNC_SPI1_D5 75 /* SPI1 Data 5 */ +#define K210_IO_FUNC_SPI1_D6 76 /* SPI1 Data 6 */ +#define K210_IO_FUNC_SPI1_D7 77 /* SPI1 Data 7 */ +#define K210_IO_FUNC_SPI1_SS0 78 /* SPI1 Chip Select 0 */ +#define K210_IO_FUNC_SPI1_SS1 79 /* SPI1 Chip Select 1 */ +#define K210_IO_FUNC_SPI1_SS2 80 /* SPI1 Chip Select 2 */ +#define K210_IO_FUNC_SPI1_SS3 81 /* SPI1 Chip Select 3 */ +#define K210_IO_FUNC_SPI1_ARB 82 /* SPI1 Arbitration */ +#define K210_IO_FUNC_SPI1_SCLK 83 /* SPI1 Serial Clock */ +#define K210_IO_FUNC_SPI_SLAVE_D0 84 /* SPI Slave Data 0 */ +#define K210_IO_FUNC_SPI_SLAVE_SS 85 /* SPI Slave Select */ +#define K210_IO_FUNC_SPI_SLAVE_SCLK 86 /* SPI Slave Serial Clock */ +#define K210_IO_FUNC_I2S0_MCLK 87 /* I2S0 Master Clock */ +#define K210_IO_FUNC_I2S0_SCLK 88 /* I2S0 Serial Clock(BCLK) */ +#define K210_IO_FUNC_I2S0_WS 89 /* I2S0 Word Select(LRCLK) */ +#define K210_IO_FUNC_I2S0_IN_D0 90 /* I2S0 Serial Data Input 0 */ +#define K210_IO_FUNC_I2S0_IN_D1 91 /* I2S0 Serial Data Input 1 */ +#define K210_IO_FUNC_I2S0_IN_D2 92 /* I2S0 Serial Data Input 2 */ +#define K210_IO_FUNC_I2S0_IN_D3 93 /* I2S0 Serial Data Input 3 */ +#define K210_IO_FUNC_I2S0_OUT_D0 94 /* I2S0 Serial Data Output 0 */ +#define K210_IO_FUNC_I2S0_OUT_D1 95 /* I2S0 Serial Data Output 1 */ +#define K210_IO_FUNC_I2S0_OUT_D2 96 /* I2S0 Serial Data Output 2 */ +#define K210_IO_FUNC_I2S0_OUT_D3 97 /* I2S0 Serial Data Output 3 */ +#define K210_IO_FUNC_I2S1_MCLK 98 /* I2S1 Master Clock */ +#define K210_IO_FUNC_I2S1_SCLK 99 /* I2S1 Serial Clock(BCLK) */ +#define K210_IO_FUNC_I2S1_WS 100 /* I2S1 Word Select(LRCLK) */ +#define K210_IO_FUNC_I2S1_IN_D0 101 /* I2S1 Serial Data Input 0 */ +#define K210_IO_FUNC_I2S1_IN_D1 102 /* I2S1 Serial Data Input 1 */ +#define K210_IO_FUNC_I2S1_IN_D2 103 /* I2S1 Serial Data Input 2 */ +#define K210_IO_FUNC_I2S1_IN_D3 104 /* I2S1 Serial Data Input 3 */ +#define K210_IO_FUNC_I2S1_OUT_D0 105 /* I2S1 Serial Data Output 0 */ +#define K210_IO_FUNC_I2S1_OUT_D1 106 /* I2S1 Serial Data Output 1 */ +#define K210_IO_FUNC_I2S1_OUT_D2 107 /* I2S1 Serial Data Output 2 */ +#define K210_IO_FUNC_I2S1_OUT_D3 108 /* I2S1 Serial Data Output 3 */ +#define K210_IO_FUNC_I2S2_MCLK 109 /* I2S2 Master Clock */ +#define K210_IO_FUNC_I2S2_SCLK 110 /* I2S2 Serial Clock(BCLK) */ +#define K210_IO_FUNC_I2S2_WS 111 /* I2S2 Word Select(LRCLK) */ +#define K210_IO_FUNC_I2S2_IN_D0 112 /* I2S2 Serial Data Input 0 */ +#define K210_IO_FUNC_I2S2_IN_D1 113 /* I2S2 Serial Data Input 1 */ +#define K210_IO_FUNC_I2S2_IN_D2 114 /* I2S2 Serial Data Input 2 */ +#define K210_IO_FUNC_I2S2_IN_D3 115 /* I2S2 Serial Data Input 3 */ +#define K210_IO_FUNC_I2S2_OUT_D0 116 /* I2S2 Serial Data Output 0 */ +#define K210_IO_FUNC_I2S2_OUT_D1 117 /* I2S2 Serial Data Output 1 */ +#define K210_IO_FUNC_I2S2_OUT_D2 118 /* I2S2 Serial Data Output 2 */ +#define K210_IO_FUNC_I2S2_OUT_D3 119 /* I2S2 Serial Data Output 3 */ +#define K210_IO_FUNC_RESV0 120 /* Reserved function */ +#define K210_IO_FUNC_RESV1 121 /* Reserved function */ +#define K210_IO_FUNC_RESV2 122 /* Reserved function */ +#define K210_IO_FUNC_RESV3 123 /* Reserved function */ +#define K210_IO_FUNC_RESV4 124 /* Reserved function */ +#define K210_IO_FUNC_RESV5 125 /* Reserved function */ +#define K210_IO_FUNC_I2C0_SCLK 126 /* I2C0 Serial Clock */ +#define K210_IO_FUNC_I2C0_SDA 127 /* I2C0 Serial Data */ +#define K210_IO_FUNC_I2C1_SCLK 128 /* I2C1 Serial Clock */ +#define K210_IO_FUNC_I2C1_SDA 129 /* I2C1 Serial Data */ +#define K210_IO_FUNC_I2C2_SCLK 130 /* I2C2 Serial Clock */ +#define K210_IO_FUNC_I2C2_SDA 131 /* I2C2 Serial Data */ +#define K210_IO_FUNC_CMOS_XCLK 132 /* DVP System Clock */ +#define K210_IO_FUNC_CMOS_RST 133 /* DVP System Reset */ +#define K210_IO_FUNC_CMOS_PWDN 134 /* DVP Power Down Mode */ +#define K210_IO_FUNC_CMOS_VSYNC 135 /* DVP Vertical Sync */ +#define K210_IO_FUNC_CMOS_HREF 136 /* DVP Horizontal Reference output */ +#define K210_IO_FUNC_CMOS_PCLK 137 /* Pixel Clock */ +#define K210_IO_FUNC_CMOS_D0 138 /* Data Bit 0 */ +#define K210_IO_FUNC_CMOS_D1 139 /* Data Bit 1 */ +#define K210_IO_FUNC_CMOS_D2 140 /* Data Bit 2 */ +#define K210_IO_FUNC_CMOS_D3 141 /* Data Bit 3 */ +#define K210_IO_FUNC_CMOS_D4 142 /* Data Bit 4 */ +#define K210_IO_FUNC_CMOS_D5 143 /* Data Bit 5 */ +#define K210_IO_FUNC_CMOS_D6 144 /* Data Bit 6 */ +#define K210_IO_FUNC_CMOS_D7 145 /* Data Bit 7 */ +#define K210_IO_FUNC_SCCB_SCLK 146 /* SCCB Serial Clock */ +#define K210_IO_FUNC_SCCB_SDA 147 /* SCCB Serial Data */ +#define K210_IO_FUNC_UART1_CTS 148 /* UART1 Clear To Send */ +#define K210_IO_FUNC_UART1_DSR 149 /* UART1 Data Set Ready */ +#define K210_IO_FUNC_UART1_DCD 150 /* UART1 Data Carrier Detect */ +#define K210_IO_FUNC_UART1_RI 151 /* UART1 Ring Indicator */ +#define K210_IO_FUNC_UART1_SIR_IN 152 /* UART1 Serial Infrared Input */ +#define K210_IO_FUNC_UART1_DTR 153 /* UART1 Data Terminal Ready */ +#define K210_IO_FUNC_UART1_RTS 154 /* UART1 Request To Send */ +#define K210_IO_FUNC_UART1_OUT2 155 /* UART1 User-designated Output 2 */ +#define K210_IO_FUNC_UART1_OUT1 156 /* UART1 User-designated Output 1 */ +#define K210_IO_FUNC_UART1_SIR_OUT 157 /* UART1 Serial Infrared Output */ +#define K210_IO_FUNC_UART1_BAUD 158 /* UART1 Transmit Clock Output */ +#define K210_IO_FUNC_UART1_RE 159 /* UART1 Receiver Output Enable */ +#define K210_IO_FUNC_UART1_DE 160 /* UART1 Driver Output Enable */ +#define K210_IO_FUNC_UART1_RS485_EN 161 /* UART1 RS485 Enable */ +#define K210_IO_FUNC_UART2_CTS 162 /* UART2 Clear To Send */ +#define K210_IO_FUNC_UART2_DSR 163 /* UART2 Data Set Ready */ +#define K210_IO_FUNC_UART2_DCD 164 /* UART2 Data Carrier Detect */ +#define K210_IO_FUNC_UART2_RI 165 /* UART2 Ring Indicator */ +#define K210_IO_FUNC_UART2_SIR_IN 166 /* UART2 Serial Infrared Input */ +#define K210_IO_FUNC_UART2_DTR 167 /* UART2 Data Terminal Ready */ +#define K210_IO_FUNC_UART2_RTS 168 /* UART2 Request To Send */ +#define K210_IO_FUNC_UART2_OUT2 169 /* UART2 User-designated Output 2 */ +#define K210_IO_FUNC_UART2_OUT1 170 /* UART2 User-designated Output 1 */ +#define K210_IO_FUNC_UART2_SIR_OUT 171 /* UART2 Serial Infrared Output */ +#define K210_IO_FUNC_UART2_BAUD 172 /* UART2 Transmit Clock Output */ +#define K210_IO_FUNC_UART2_RE 173 /* UART2 Receiver Output Enable */ +#define K210_IO_FUNC_UART2_DE 174 /* UART2 Driver Output Enable */ +#define K210_IO_FUNC_UART2_RS485_EN 175 /* UART2 RS485 Enable */ +#define K210_IO_FUNC_UART3_CTS 176 /* UART3 Clear To Send */ +#define K210_IO_FUNC_UART3_DSR 177 /* UART3 Data Set Ready */ +#define K210_IO_FUNC_UART3_DCD 178 /* UART3 Data Carrier Detect */ +#define K210_IO_FUNC_UART3_RI 179 /* UART3 Ring Indicator */ +#define K210_IO_FUNC_UART3_SIR_IN 180 /* UART3 Serial Infrared Input */ +#define K210_IO_FUNC_UART3_DTR 181 /* UART3 Data Terminal Ready */ +#define K210_IO_FUNC_UART3_RTS 182 /* UART3 Request To Send */ +#define K210_IO_FUNC_UART3_OUT2 183 /* UART3 User-designated Output 2 */ +#define K210_IO_FUNC_UART3_OUT1 184 /* UART3 User-designated Output 1 */ +#define K210_IO_FUNC_UART3_SIR_OUT 185 /* UART3 Serial Infrared Output */ +#define K210_IO_FUNC_UART3_BAUD 186 /* UART3 Transmit Clock Output */ +#define K210_IO_FUNC_UART3_RE 187 /* UART3 Receiver Output Enable */ +#define K210_IO_FUNC_UART3_DE 188 /* UART3 Driver Output Enable */ +#define K210_IO_FUNC_UART3_RS485_EN 189 /* UART3 RS485 Enable */ +#define K210_IO_FUNC_TIMER0_TOGGLE1 190 /* TIMER0 Toggle Output 1 */ +#define K210_IO_FUNC_TIMER0_TOGGLE2 191 /* TIMER0 Toggle Output 2 */ +#define K210_IO_FUNC_TIMER0_TOGGLE3 192 /* TIMER0 Toggle Output 3 */ +#define K210_IO_FUNC_TIMER0_TOGGLE4 193 /* TIMER0 Toggle Output 4 */ +#define K210_IO_FUNC_TIMER1_TOGGLE1 194 /* TIMER1 Toggle Output 1 */ +#define K210_IO_FUNC_TIMER1_TOGGLE2 195 /* TIMER1 Toggle Output 2 */ +#define K210_IO_FUNC_TIMER1_TOGGLE3 196 /* TIMER1 Toggle Output 3 */ +#define K210_IO_FUNC_TIMER1_TOGGLE4 197 /* TIMER1 Toggle Output 4 */ +#define K210_IO_FUNC_TIMER2_TOGGLE1 198 /* TIMER2 Toggle Output 1 */ +#define K210_IO_FUNC_TIMER2_TOGGLE2 199 /* TIMER2 Toggle Output 2 */ +#define K210_IO_FUNC_TIMER2_TOGGLE3 200 /* TIMER2 Toggle Output 3 */ +#define K210_IO_FUNC_TIMER2_TOGGLE4 201 /* TIMER2 Toggle Output 4 */ +#define K210_IO_FUNC_CLK_SPI2 202 /* Clock SPI2 */ +#define K210_IO_FUNC_CLK_I2C2 203 /* Clock I2C2 */ +#define K210_IO_FUNC_INTERNAL0 204 /* Internal function signal 0 */ +#define K210_IO_FUNC_INTERNAL1 205 /* Internal function signal 1 */ +#define K210_IO_FUNC_INTERNAL2 206 /* Internal function signal 2 */ +#define K210_IO_FUNC_INTERNAL3 207 /* Internal function signal 3 */ +#define K210_IO_FUNC_INTERNAL4 208 /* Internal function signal 4 */ +#define K210_IO_FUNC_INTERNAL5 209 /* Internal function signal 5 */ +#define K210_IO_FUNC_INTERNAL6 210 /* Internal function signal 6 */ +#define K210_IO_FUNC_INTERNAL7 211 /* Internal function signal 7 */ +#define K210_IO_FUNC_INTERNAL8 212 /* Internal function signal 8 */ +#define K210_IO_FUNC_INTERNAL9 213 /* Internal function signal 9 */ +#define K210_IO_FUNC_INTERNAL10 214 /* Internal function signal 10 */ +#define K210_IO_FUNC_INTERNAL11 215 /* Internal function signal 11 */ +#define K210_IO_FUNC_INTERNAL12 216 /* Internal function signal 12 */ +#define K210_IO_FUNC_INTERNAL13 217 /* Internal function signal 13 */ +#define K210_IO_FUNC_INTERNAL14 218 /* Internal function signal 14 */ +#define K210_IO_FUNC_INTERNAL15 219 /* Internal function signal 15 */ +#define K210_IO_FUNC_INTERNAL16 220 /* Internal function signal 16 */ +#define K210_IO_FUNC_INTERNAL17 221 /* Internal function signal 17 */ +#define K210_IO_FUNC_CONSTANT 222 /* Constant function */ +#define K210_IO_FUNC_INTERNAL18 223 /* Internal function signal 18 */ +#define K210_IO_FUNC_DEBUG0 224 /* Debug function 0 */ +#define K210_IO_FUNC_DEBUG1 225 /* Debug function 1 */ +#define K210_IO_FUNC_DEBUG2 226 /* Debug function 2 */ +#define K210_IO_FUNC_DEBUG3 227 /* Debug function 3 */ +#define K210_IO_FUNC_DEBUG4 228 /* Debug function 4 */ +#define K210_IO_FUNC_DEBUG5 229 /* Debug function 5 */ +#define K210_IO_FUNC_DEBUG6 230 /* Debug function 6 */ +#define K210_IO_FUNC_DEBUG7 231 /* Debug function 7 */ +#define K210_IO_FUNC_DEBUG8 232 /* Debug function 8 */ +#define K210_IO_FUNC_DEBUG9 233 /* Debug function 9 */ +#define K210_IO_FUNC_DEBUG10 234 /* Debug function 10 */ +#define K210_IO_FUNC_DEBUG11 235 /* Debug function 11 */ +#define K210_IO_FUNC_DEBUG12 236 /* Debug function 12 */ +#define K210_IO_FUNC_DEBUG13 237 /* Debug function 13 */ +#define K210_IO_FUNC_DEBUG14 238 /* Debug function 14 */ +#define K210_IO_FUNC_DEBUG15 239 /* Debug function 15 */ +#define K210_IO_FUNC_DEBUG16 240 /* Debug function 16 */ +#define K210_IO_FUNC_DEBUG17 241 /* Debug function 17 */ +#define K210_IO_FUNC_DEBUG18 242 /* Debug function 18 */ +#define K210_IO_FUNC_DEBUG19 243 /* Debug function 19 */ +#define K210_IO_FUNC_DEBUG20 244 /* Debug function 20 */ +#define K210_IO_FUNC_DEBUG21 245 /* Debug function 21 */ +#define K210_IO_FUNC_DEBUG22 246 /* Debug function 22 */ +#define K210_IO_FUNC_DEBUG23 247 /* Debug function 23 */ +#define K210_IO_FUNC_DEBUG24 248 /* Debug function 24 */ +#define K210_IO_FUNC_DEBUG25 249 /* Debug function 25 */ +#define K210_IO_FUNC_DEBUG26 250 /* Debug function 26 */ +#define K210_IO_FUNC_DEBUG27 251 /* Debug function 27 */ +#define K210_IO_FUNC_DEBUG28 252 /* Debug function 28 */ +#define K210_IO_FUNC_DEBUG29 253 /* Debug function 29 */ +#define K210_IO_FUNC_DEBUG30 254 /* Debug function 30 */ +#define K210_IO_FUNC_DEBUG31 255 /* Debug function 31 */ +#define K210_IO_FUNC_MAX 256 /* Function numbers */ #define K210_IO_DS(x) (x << 8) /* Driving Selector */ @@ -102,34 +318,6 @@ #define K210_IOFLAG_GPIOHS (K210_IO_DS(0xf) | K210_IO_OUTPUT_ENABLE | \ K210_IO_INPUT_ENABLE | K210_IO_ST) -typedef struct _fpioa_io_config -{ - uint32_t ch_sel : 8; /* Channel select from 256 input. */ - uint32_t ds : 4; /* Driving selector. */ - uint32_t oe_en : 1; /* Static output enable, will AND with OE_INV. */ - uint32_t oe_inv : 1; /* Invert output enable. */ - uint32_t do_sel : 1; /* Data output select: 0 for DO, 1 for OE. */ - uint32_t do_inv : 1; /* Invert the result of data output select (DO_SEL). */ - uint32_t pu : 1; /* Pull up enable. 0 for nothing, 1 for pull up. */ - uint32_t pd : 1; /* Pull down enable. 0 for nothing, 1 for pull down. */ - uint32_t resv0 : 1; /* Reserved bits. */ - uint32_t sl : 1; /* Slew rate control enable. */ - uint32_t ie_en : 1; /* Static input enable, will AND with IE_INV. */ - uint32_t ie_inv : 1; /* Invert input enable. */ - uint32_t di_inv : 1; /* Invert Data input. */ - uint32_t st : 1; /* Schmitt trigger. */ - uint32_t resv1 : 7; /* Reserved bits. */ - uint32_t pad_di : 1; /* Read current IO's data input. */ -} __attribute__((packed, aligned(4))) fpioa_io_config_t; - -typedef enum _fpioa_pull -{ - FPIOA_PULL_NONE, /* No Pull */ - FPIOA_PULL_DOWN, /* Pull Down */ - FPIOA_PULL_UP, /* Pull Up */ - FPIOA_PULL_MAX /* Count of pull settings */ -} fpioa_pull_t; - /**************************************************************************** * Public Functions Prototypes diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_serial.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_serial.c new file mode 100644 index 000000000..c5371ebf2 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_serial.c @@ -0,0 +1,733 @@ +/**************************************************************************** + * arch/risc-v/src/k210/k210_serial.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "riscv_internal.h" +#include "k210_config.h" +#include "chip.h" +#include "k210.h" +#include "k210_uart_16550.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* If we are not using the serial driver for the console, then we still must + * provide some minimal implementation of up_putc. + */ + +#ifdef USE_SERIALDRIVER + +/* Which UART with be tty0/console and which tty1? The console will always + * be ttyS0. If there is no console then will use the lowest numbered UART. + */ + +#ifdef HAVE_SERIAL_CONSOLE +# if defined(CONFIG_UART0_SERIAL_CONSOLE) +# define CONSOLE_DEV g_uart0port /* UART0 is console */ +# define TTYS0_DEV g_uart0port /* UART0 is ttyS0 */ +# undef TTYS1_DEV /* No ttyS1 */ +# define SERIAL_CONSOLE 1 +# else +# error "I'm confused... Do we have a serial console or not?" +# endif +#else +# undef CONSOLE_DEV /* No console */ +# undef CONFIG_UART0_SERIAL_CONSOLE +# if defined(CONFIG_K210_UART0) +# define TTYS0_DEV g_uart0port /* UART0 is ttyS0 */ +# undef TTYS1_DEV /* No ttyS1 */ +# define SERIAL_CONSOLE 1 +# else +# undef TTYS0_DEV +# undef TTYS1_DEV +# endif +#endif + +/* Common initialization logic will not not know that the all of the UARTs + * have been disabled. So, as a result, we may still have to provide + * stub implementations of riscv_earlyserialinit(), riscv_serialinit(), and + * up_putc(). + */ + +#ifdef HAVE_UART_DEVICE + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct up_dev_s +{ + uintptr_t uartbase; /* Base address of UART registers */ + uint32_t baud; /* Configured baud */ + uint8_t irq; /* IRQ associated with this UART */ + uint8_t im; /* Interrupt mask state */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Low-level helpers */ + +static uint32_t up_serialin(struct up_dev_s *priv, int offset); +static void up_serialout(struct up_dev_s *priv, int offset, uint32_t value); +static void up_restoreuartint(struct up_dev_s *priv, uint8_t im); +static void up_disableuartint(struct up_dev_s *priv, uint8_t *im); + +/* Serial driver methods */ + +static int up_setup(struct uart_dev_s *dev); +static void up_shutdown(struct uart_dev_s *dev); +static int up_attach(struct uart_dev_s *dev); +static void up_detach(struct uart_dev_s *dev); +static int up_interrupt(int irq, void *context, void *arg); +static int up_ioctl(struct file *filep, int cmd, unsigned long arg); +static int up_receive(struct uart_dev_s *dev, unsigned int *status); +static void up_rxint(struct uart_dev_s *dev, bool enable); +static bool up_rxavailable(struct uart_dev_s *dev); +static void up_send(struct uart_dev_s *dev, int ch); +static void up_txint(struct uart_dev_s *dev, bool enable); +static bool up_txready(struct uart_dev_s *dev); +static bool up_txempty(struct uart_dev_s *dev); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct uart_ops_s g_uart_ops = +{ + .setup = up_setup, + .shutdown = up_shutdown, + .attach = up_attach, + .detach = up_detach, + .ioctl = up_ioctl, + .receive = up_receive, + .rxint = up_rxint, + .rxavailable = up_rxavailable, +#ifdef CONFIG_SERIAL_IFLOWCONTROL + .rxflowcontrol = NULL, +#endif + .send = up_send, + .txint = up_txint, + .txready = up_txready, + .txempty = up_txempty, +}; + +/* I/O buffers */ + +#ifdef CONFIG_K210_UART0 +static char g_uart0rxbuffer[CONFIG_UART0_RXBUFSIZE]; +static char g_uart0txbuffer[CONFIG_UART0_TXBUFSIZE]; +static uint32_t g_rxdata; +#endif + +#ifdef CONFIG_K210_UART0 +static struct up_dev_s g_uart0priv = +{ + .uartbase = K210_UART0_BASE, + .baud = CONFIG_UART0_BAUD, + .irq = K210_IRQ_UART0, +}; + +static uart_dev_t g_uart0port = +{ +#if SERIAL_CONSOLE == 1 + .isconsole = 1, +#endif + .recv = + { + .size = CONFIG_UART0_RXBUFSIZE, + .buffer = g_uart0rxbuffer, + }, + .xmit = + { + .size = CONFIG_UART0_TXBUFSIZE, + .buffer = g_uart0txbuffer, + }, + .ops = &g_uart_ops, + .priv = &g_uart0priv, +}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_serialin + ****************************************************************************/ + +static uint32_t up_serialin(struct up_dev_s *priv, int offset) +{ + return getreg32(priv->uartbase + offset); +} + +/**************************************************************************** + * Name: up_serialout + ****************************************************************************/ + +static void up_serialout(struct up_dev_s *priv, int offset, uint32_t value) +{ + putreg32(value, priv->uartbase + offset); +} + +/**************************************************************************** + * Name: up_restoreuartint + ****************************************************************************/ + +static void up_restoreuartint(struct up_dev_s *priv, uint8_t im) +{ + irqstate_t flags = enter_critical_section(); + + priv->im = im; + up_serialout(priv, UART_IE_OFFSET, im); + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: up_disableuartint + ****************************************************************************/ + +static void up_disableuartint(struct up_dev_s *priv, uint8_t *im) +{ + irqstate_t flags = enter_critical_section(); + + /* Return the current interrupt mask value */ + + if (im) + { + *im = priv->im; + } + + /* Disable all interrupts */ + + priv->im = 0; + up_serialout(priv, UART_IE_OFFSET, 0); + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: up_setup + * + * Description: + * Configure the UART baud, bits, parity, etc. This method is called the + * first time that the serial port is opened. + * + ****************************************************************************/ + +static int up_setup(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + +#if 0 /* TODO: Setup divisor */ +#endif + + /* Enable RX */ + + up_serialout(priv, UART_RXCTL_OFFSET, 1); + + /* Set TX watermark level to 1 and enable TX */ + + up_serialout(priv, UART_TXCTL_OFFSET, 1 << 16 | 1); + + return OK; +} + +/**************************************************************************** + * Name: up_shutdown + * + * Description: + * Disable the UART. This method is called when the serial + * port is closed + * + ****************************************************************************/ + +static void up_shutdown(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* Disable interrupts */ + + up_disableuartint(priv, NULL); +} + +/**************************************************************************** + * Name: up_attach + * + * Description: + * Configure the UART to operation in interrupt driven mode. This method is + * called when the serial port is opened. Normally, this is just after the + * the setup() method is called, however, the serial console may operate in + * a non-interrupt driven mode during the boot phase. + * + * RX and TX interrupts are not enabled by the attach method (unless the + * hardware supports multiple levels of interrupt enabling). The RX and TX + * interrupts are not enabled until the txint() and rxint() are called. + * + ****************************************************************************/ + +static int up_attach(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + int ret; + + /* Initialize interrupt generation on the peripheral */ + + up_serialout(priv, UART_IE_OFFSET, UART_IE_TXWM | UART_IE_RXWM); + + ret = irq_attach(priv->irq, up_interrupt, dev); + + if (ret == OK) + { + /* Enable the interrupt (RX and TX interrupts are still disabled + * in the UART + */ + + up_enable_irq(priv->irq); + } + + return ret; +} + +/**************************************************************************** + * Name: up_detach + * + * Description: + * Detach UART interrupts. This method is called when the serial port is + * closed normally just before the shutdown method is called. The exception + * is the serial console which is never shutdown. + * + ****************************************************************************/ + +static void up_detach(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* Disable interrupts */ + + up_disable_irq(priv->irq); + + /* Detach from the interrupt */ + + irq_detach(priv->irq); +} + +/**************************************************************************** + * Name: up_interrupt + * + * Description: + * This is the UART interrupt handler. It will be invoked when an + * interrupt received on the 'irq' It should call uart_transmitchars or + * uart_receivechar to perform the appropriate data transfers. The + * interrupt handling logic must be able to map the 'irq' number into the + * appropriate uart_dev_s structure in order to call these functions. + * + ****************************************************************************/ + +static int up_interrupt(int irq, void *context, void *arg) +{ + struct uart_dev_s *dev = (struct uart_dev_s *)arg; + struct up_dev_s *priv; + uint32_t status; + int passes; + + DEBUGASSERT(dev != NULL && dev->priv != NULL); + priv = (struct up_dev_s *)dev->priv; + + /* Loop until there are no characters to be transferred or, + * until we have been looping for a long time. + */ + + for (passes = 0; passes < 256; passes++) + { + /* Retrieve interrupt pending status */ + + status = up_serialin(priv, UART_IP_OFFSET); + + if (status == 0) + { + break; + } + + if (status & UART_IP_RXWM) + { + /* Process incoming bytes */ + + uart_recvchars(dev); + } + + if (status & UART_IP_TXWM) + { + /* Process outgoing bytes */ + + uart_xmitchars(dev); + } + } + + return OK; +} + +/**************************************************************************** + * Name: up_ioctl + * + * Description: + * All ioctl calls will be routed through this method + * + ****************************************************************************/ + +static int up_ioctl(struct file *filep, int cmd, unsigned long arg) +{ + return -ENOTTY; +} + +/**************************************************************************** + * Name: up_receive + * + * Description: + * Called (usually) from the interrupt level to receive one + * character from the UART. Error bits associated with the + * receipt are provided in the return 'status'. + * + ****************************************************************************/ + +static int up_receive(struct uart_dev_s *dev, unsigned int *status) +{ + /* Return status information */ + + if (status) + { + *status = 0; /* We are not yet tracking serial errors */ + } + + /* Return cached data */ + + return g_rxdata; +} + +/**************************************************************************** + * Name: up_rxint + * + * Description: + * Call to enable or disable RX interrupts + * + ****************************************************************************/ + +static void up_rxint(struct uart_dev_s *dev, bool enable) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + irqstate_t flags = enter_critical_section(); + + if (enable) + { +#ifndef CONFIG_SUPPRESS_SERIAL_INTS + priv->im |= UART_IE_RXWM; +#endif + } + else + { + priv->im &= ~UART_IE_RXWM; + } + + up_serialout(priv, UART_IE_OFFSET, priv->im); + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: up_rxavailable + * + * Description: + * Return true if the receive register is not empty + * + ****************************************************************************/ + +static bool up_rxavailable(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* Return true is data is available in the receive data buffer */ + + uint32_t rxdata = up_serialin(priv, UART_RXDATA_OFFSET); + + /* NOTE: In K210, actual data is also retrieved */ + + g_rxdata = rxdata & 0xff; + + return (rxdata & UART_RX_EMPTY) == 0; +} + +/**************************************************************************** + * Name: up_send + * + * Description: + * This method will send one byte on the UART. + * + ****************************************************************************/ + +static void up_send(struct uart_dev_s *dev, int ch) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + up_serialout(priv, UART_TXDATA_OFFSET, (uint32_t)ch); +} + +/**************************************************************************** + * Name: up_txint + * + * Description: + * Call to enable or disable TX interrupts + * + ****************************************************************************/ + +static void up_txint(struct uart_dev_s *dev, bool enable) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + irqstate_t flags; + + flags = enter_critical_section(); + if (enable) + { + /* Enable the TX interrupt */ + +#ifndef CONFIG_SUPPRESS_SERIAL_INTS + priv->im |= UART_IE_TXWM; + up_serialout(priv, UART_IE_OFFSET, priv->im); + + /* Fake a TX interrupt here by just calling uart_xmitchars() with + * interrupts disabled (note this may recurse). + */ + + uart_xmitchars(dev); +#endif + } + else + { + /* Disable the TX interrupt */ + + priv->im &= ~UART_IE_TXWM; + up_serialout(priv, UART_IE_OFFSET, priv->im); + } + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: up_txready + * + * Description: + * Return true if the tranmsit data register is not full + * + ****************************************************************************/ + +static bool up_txready(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* Return TRUE if the TX FIFO is not full */ + + return (up_serialin(priv, UART_TXDATA_OFFSET) & UART_TX_FULL) == 0; +} + +/**************************************************************************** + * Name: up_txempty + * + * Description: + * Return true if the tranmsit data register is empty + * + ****************************************************************************/ + +static bool up_txempty(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* Return TRUE if the TX wartermak is pending */ + + return (up_serialin(priv, UART_IP_OFFSET) & UART_IP_TXWM) == 1; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef USE_EARLYSERIALINIT + +/**************************************************************************** + * Name: riscv_earlyserialinit + * + * Description: + * Performs the low level UART initialization early in debug so that the + * serial console will be available during bootup. This must be called + * before riscv_serialinit. NOTE: This function depends on GPIO pin + * configuration performed in up_consoleinit() and main clock + * initialization performed in up_clkinitialize(). + * + ****************************************************************************/ + +void riscv_earlyserialinit(void) +{ + /* Disable interrupts from all UARTS. The console is enabled in + * k210_consoleinit(). + */ + + up_disableuartint(TTYS0_DEV.priv, NULL); +#ifdef TTYS1_DEV + up_disableuartint(TTYS1_DEV.priv, NULL); +#endif + + /* Configuration whichever one is the console */ + +#ifdef HAVE_SERIAL_CONSOLE + CONSOLE_DEV.isconsole = true; + up_setup(&CONSOLE_DEV); +#endif +} +#endif + +/**************************************************************************** + * Name: riscv_serialinit + * + * Description: + * Register serial console and serial ports. This assumes + * that riscv_earlyserialinit was called previously. + * + ****************************************************************************/ + +void riscv_serialinit(void) +{ + /* Register the console */ + +#ifdef HAVE_SERIAL_CONSOLE + uart_register("/dev/console", &CONSOLE_DEV); +#endif + + /* Register all UARTs */ + uart_register("/dev/ttyS0", &TTYS0_DEV); + +#ifdef CONFIG_K210_16550_UART + /* Register UART1-UART3 */ + k210_uart_16550_register(); +#endif +} + +/**************************************************************************** + * Name: up_putc + * + * Description: + * Provide priority, low-level access to support OS debug writes + * + ****************************************************************************/ + +int up_putc(int ch) +{ +#ifdef HAVE_SERIAL_CONSOLE + struct up_dev_s *priv = (struct up_dev_s *)CONSOLE_DEV.priv; + uint8_t imr; + + up_disableuartint(priv, &imr); + + /* Check for LF */ + + if (ch == '\n') + { + /* Add CR */ + + riscv_lowputc('\r'); + } + + riscv_lowputc(ch); + up_restoreuartint(priv, imr); +#endif + return ch; +} + +/**************************************************************************** + * Name: riscv_earlyserialinit, riscv_serialinit, and up_putc + * + * Description: + * stubs that may be needed. These stubs would be used if all UARTs are + * disabled. In that case, the logic in common/up_initialize() is not + * smart enough to know that there are not UARTs and will still expect + * these interfaces to be provided. + * + ****************************************************************************/ + +#else /* HAVE_UART_DEVICE */ +void riscv_earlyserialinit(void) +{ +} + +void riscv_serialinit(void) +{ +} + +int up_putc(int ch) +{ + return ch; +} + +#endif /* HAVE_UART_DEVICE */ +#else /* USE_SERIALDRIVER */ + +/**************************************************************************** + * Name: up_putc + * + * Description: + * Provide priority, low-level access to support OS debug writes + * + ****************************************************************************/ + +int up_putc(int ch) +{ +#ifdef HAVE_SERIAL_CONSOLE + /* Check for LF */ + + if (ch == '\n') + { + /* Add CR */ + + riscv_lowputc('\r'); + } + + riscv_lowputc(ch); +#endif + return ch; +} + +#endif /* USE_SERIALDRIVER */ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.c new file mode 100644 index 000000000..0f9267408 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.c @@ -0,0 +1,1002 @@ +/**************************************************************************** + * drivers/serial/uart_16550.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/* Serial driver for 16550 UART */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include "k210_uart_16550.h" + +#ifdef CONFIG_SERIAL_TERMIOS +# include +#endif + +#ifdef CONFIG_K210_16550_UART + + +/**************************************************************************** + * Pre-processor definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int k210_16550_setup(FAR struct uart_dev_s *dev); +static void k210_16550_shutdown(FAR struct uart_dev_s *dev); +static int k210_16550_attach(FAR struct uart_dev_s *dev); +static void k210_16550_detach(FAR struct uart_dev_s *dev); +static int k210_16550_interrupt(int irq, FAR void *context, FAR void *arg); +static int k210_16550_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +static int k210_16550_receive(FAR struct uart_dev_s *dev, unsigned int *status); +static void k210_16550_rxint(FAR struct uart_dev_s *dev, bool enable); +static bool k210_16550_rxavailable(FAR struct uart_dev_s *dev); +#ifdef CONFIG_SERIAL_IFLOWCONTROL +static bool k210_16550_rxflowcontrol(struct uart_dev_s *dev, + unsigned int nbuffered, bool upper); +#endif +#ifdef CONFIG_SERIAL_TXDMA +static void k210_16550_dmasend(FAR struct uart_dev_s *dev); +static void k210_16550_dmatxavail(FAR struct uart_dev_s *dev); +#endif +#ifdef CONFIG_SERIAL_RXDMA +static void k210_16550_dmareceive(FAR struct uart_dev_s *dev); +static void k210_16550_dmarxfree(FAR struct uart_dev_s *dev); +#endif +static void k210_16550_send(FAR struct uart_dev_s *dev, int ch); +static void k210_16550_txint(FAR struct uart_dev_s *dev, bool enable); +static bool k210_16550_txready(FAR struct uart_dev_s *dev); +static bool k210_16550_txempty(FAR struct uart_dev_s *dev); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct uart_ops_s g_uart_ops = +{ + .setup = k210_16550_setup, + .shutdown = k210_16550_shutdown, + .attach = k210_16550_attach, + .detach = k210_16550_detach, + .ioctl = k210_16550_ioctl, + .receive = k210_16550_receive, + .rxint = k210_16550_rxint, + .rxavailable = k210_16550_rxavailable, +#ifdef CONFIG_SERIAL_IFLOWCONTROL + .rxflowcontrol = k210_16550_rxflowcontrol, +#endif +#ifdef CONFIG_SERIAL_TXDMA + .dmasend = k210_16550_dmasend, +#endif +#ifdef CONFIG_SERIAL_RXDMA + .dmareceive = k210_16550_dmareceive, + .dmarxfree = k210_16550_dmarxfree, +#endif +#ifdef CONFIG_SERIAL_TXDMA + .dmatxavail = k210_16550_dmatxavail, +#endif + .send = k210_16550_send, + .txint = k210_16550_txint, + .txready = k210_16550_txready, + .txempty = k210_16550_txempty, +}; + +/* I/O buffers */ + +#ifdef CONFIG_K210_16550_UART1 +static char g_uart1rxbuffer[CONFIG_K210_16550_UART1_RXBUFSIZE]; +static char g_uart1txbuffer[CONFIG_K210_16550_UART1_TXBUFSIZE]; +#endif +#ifdef CONFIG_K210_16550_UART2 +static char g_uart2rxbuffer[CONFIG_K210_16550_UART2_RXBUFSIZE]; +static char g_uart2txbuffer[CONFIG_K210_16550_UART2_TXBUFSIZE]; +#endif +#ifdef CONFIG_K210_16550_UART3 +static char g_uart3rxbuffer[CONFIG_K210_16550_UART3_RXBUFSIZE]; +static char g_uart3txbuffer[CONFIG_K210_16550_UART3_TXBUFSIZE]; +#endif + +/* This describes the state of the 16550 uart1 port. */ + +#ifdef CONFIG_K210_16550_UART1 +static struct k210_16550_s g_uart1priv = +{ + .uartbase = CONFIG_K210_16550_UART1_BASE, +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + .baud = CONFIG_K210_16550_UART1_BAUD, + .uartclk = CONFIG_K210_16550_UART1_CLOCK, +#endif + .irq = CONFIG_K210_16550_UART1_IRQ, +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + .parity = CONFIG_K210_16550_UART1_PARITY, + .bits = CONFIG_K210_16550_UART1_BITS, + .stopbits2 = CONFIG_K210_16550_UART1_2STOP, +#if defined(CONFIG_K210_16550_UART1_IFLOWCONTROL) || defined(CONFIG_K210_16550_UART1_OFLOWCONTROL) + .flow = true, +#endif +#endif +}; + +static uart_dev_t g_uart1port = +{ + .recv = + { + .size = CONFIG_K210_16550_UART1_RXBUFSIZE, + .buffer = g_uart1rxbuffer, + }, + .xmit = + { + .size = CONFIG_K210_16550_UART1_TXBUFSIZE, + .buffer = g_uart1txbuffer, + }, + .ops = &g_uart_ops, + .priv = &g_uart1priv, +}; +#endif + +/* This describes the state of the 16550 uart2 port. */ + +#ifdef CONFIG_K210_16550_UART2 +static struct k210_16550_s g_uart2priv = +{ + .uartbase = CONFIG_K210_16550_UART2_BASE, +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + .baud = CONFIG_K210_16550_UART2_BAUD, + .uartclk = CONFIG_K210_16550_UART2_CLOCK, +#endif + .irq = CONFIG_K210_16550_UART2_IRQ, +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + .parity = CONFIG_K210_16550_UART2_PARITY, + .bits = CONFIG_K210_16550_UART2_BITS, + .stopbits2 = CONFIG_K210_16550_UART2_2STOP, +#if defined(CONFIG_K210_16550_UART2_IFLOWCONTROL) || defined(CONFIG_K210_16550_UART2_OFLOWCONTROL) + .flow = true, +#endif +#endif +}; + +static uart_dev_t g_uart2port = +{ + .recv = + { + .size = CONFIG_K210_16550_UART2_RXBUFSIZE, + .buffer = g_uart2rxbuffer, + }, + .xmit = + { + .size = CONFIG_K210_16550_UART2_TXBUFSIZE, + .buffer = g_uart2txbuffer, + }, + .ops = &g_uart_ops, + .priv = &g_uart2priv, +}; + +#endif + +/* This describes the state of the 16550 uart1 port. */ + +#ifdef CONFIG_K210_16550_UART3 +static struct k210_16550_s g_uart3priv = +{ + .uartbase = CONFIG_K210_16550_UART3_BASE, +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + .baud = CONFIG_K210_16550_UART3_BAUD, + .uartclk = CONFIG_K210_16550_UART3_CLOCK, +#endif + .irq = CONFIG_K210_16550_UART3_IRQ, +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + .parity = CONFIG_K210_16550_UART3_PARITY, + .bits = CONFIG_K210_16550_UART3_BITS, + .stopbits2 = CONFIG_K210_16550_UART3_2STOP, +#if defined(CONFIG_K210_16550_UART3_IFLOWCONTROL) || defined(CONFIG_K210_16550_UART3_OFLOWCONTROL) + .flow = true, +#endif +#endif +}; + +static uart_dev_t g_uart3port = +{ + .recv = + { + .size = CONFIG_K210_16550_UART3_RXBUFSIZE, + .buffer = g_uart3rxbuffer, + }, + .xmit = + { + .size = CONFIG_K210_16550_UART3_TXBUFSIZE, + .buffer = g_uart3txbuffer, + }, + .ops = &g_uart_ops, + .priv = &g_uart3priv, +}; + +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: k210_16550_serialin + ****************************************************************************/ + +static inline uart_datawidth_t k210_16550_serialin(FAR struct k210_16550_s *priv, + int offset) +{ +#ifdef CONFIG_SERIAL_UART_ARCH_MMIO + return *((FAR volatile uart_datawidth_t *)(priv->uartbase + offset)); +#else + return uart_getreg(priv->uartbase, offset); +#endif +} + +/**************************************************************************** + * Name: k210_16550_serialout + ****************************************************************************/ + +static inline void k210_16550_serialout(FAR struct k210_16550_s *priv, int offset, + uart_datawidth_t value) +{ +#ifdef CONFIG_SERIAL_UART_ARCH_MMIO + *((FAR volatile uart_datawidth_t *)(priv->uartbase + offset)) = value; +#else + uart_putreg(priv->uartbase, offset, value); +#endif +} + +/**************************************************************************** + * Name: k210_16550_disableuartint + ****************************************************************************/ + +static inline void k210_16550_disableuartint(FAR struct k210_16550_s *priv, + FAR uart_datawidth_t *ier) +{ + if (ier) + { + *ier = priv->ier & UART_IER_ALLIE; + } + + priv->ier &= ~UART_IER_ALLIE; + k210_16550_serialout(priv, UART_IER_OFFSET, priv->ier); +} + +/**************************************************************************** + * Name: k210_16550_restoreuartint + ****************************************************************************/ + +static inline void k210_16550_restoreuartint(FAR struct k210_16550_s *priv, + uint32_t ier) +{ + priv->ier |= ier & UART_IER_ALLIE; + k210_16550_serialout(priv, UART_IER_OFFSET, priv->ier); +} + +/**************************************************************************** + * Name: k210_16550_enablebreaks + ****************************************************************************/ + +static inline void k210_16550_enablebreaks(FAR struct k210_16550_s *priv, + bool enable) +{ + uint32_t lcr = k210_16550_serialin(priv, UART_LCR_OFFSET); + + if (enable) + { + lcr |= UART_LCR_BRK; + } + else + { + lcr &= ~UART_LCR_BRK; + } + + k210_16550_serialout(priv, UART_LCR_OFFSET, lcr); +} + +/**************************************************************************** + * Name: k210_16550_divisor + * + * Description: + * Select a divider to produce the BAUD from the UART_CLK. + * + * BAUD = UART_CLK / (16 * DL), or + * DIV = UART_CLK / BAUD / 16 + * + * Ignoring the fractional divider for now. + * + ****************************************************************************/ + +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG +static inline uint32_t k210_16550_divisor(FAR struct k210_16550_s *priv) +{ + return (priv->uartclk / (uint32_t)priv->baud); +// return (priv->uartclk + (priv->baud << 3)) / (priv->baud << 4); +} +#endif + +/**************************************************************************** + * Name: k210_16550_setup + * + * Description: + * Configure the UART baud, bits, parity, fifos, etc. This + * method is called the first time that the serial port is + * opened. + * + ****************************************************************************/ + +static int k210_16550_setup(FAR struct uart_dev_s *dev) +{ +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + uint16_t div; + uint8_t dlh, dll, dlf; + uint32_t lcr; +#if defined(CONFIG_SERIAL_IFLOWCONTROL) || defined(CONFIG_SERIAL_OFLOWCONTROL) + uint32_t mcr; +#endif + + /* Clear fifos */ + + k210_16550_serialout(priv, UART_FCR_OFFSET, + (UART_FCR_RXRST | UART_FCR_TXRST)); + + /* Set trigger */ + + k210_16550_serialout(priv, UART_FCR_OFFSET, + (UART_FCR_FIFOEN | UART_FCR_RXTRIGGER_8)); + + /* Set up the IER */ + + priv->ier = k210_16550_serialin(priv, UART_IER_OFFSET); + + /* Set up the LCR */ + + lcr = 0; + switch (priv->bits) + { + case 5 : + lcr |= UART_LCR_WLS_5BIT; + break; + + case 6 : + lcr |= UART_LCR_WLS_6BIT; + break; + + case 7 : + lcr |= UART_LCR_WLS_7BIT; + break; + + default: + case 8 : + lcr |= UART_LCR_WLS_8BIT; + break; + } + + if (priv->stopbits2) + { + lcr |= UART_LCR_STB; + } + + if (priv->parity == 1) + { + lcr |= UART_LCR_PEN; + } + else if (priv->parity == 2) + { + lcr |= (UART_LCR_PEN | UART_LCR_EPS); + } + + /* Enter DLAB=1 */ + + k210_16550_serialout(priv, UART_LCR_OFFSET, (lcr | UART_LCR_DLAB)); + + /* Set the BAUD divisor */ + + div = k210_16550_divisor(priv); + dlh = div >> 12; + dll = (div - (dlh << 12)) / 16; + dlf = div - (dlh << 12) - dll * 16; + + k210_16550_serialout(priv, UART_DLM_OFFSET, dlh); + k210_16550_serialout(priv, UART_DLL_OFFSET, dll); + k210_16550_serialout(priv, UART_DLF_OFFSET, dlf); + + /* Clear DLAB */ + + k210_16550_serialout(priv, UART_LCR_OFFSET, lcr); + + /* Configure the FIFOs */ + + k210_16550_serialout(priv, UART_FCR_OFFSET, + (UART_FCR_RXTRIGGER_8 | UART_FCR_TXRST | UART_FCR_RXRST | + UART_FCR_FIFOEN)); + + /* Set up the auto flow control */ + +#if defined(CONFIG_SERIAL_IFLOWCONTROL) || defined(CONFIG_SERIAL_OFLOWCONTROL) + mcr = k210_16550_serialin(priv, UART_MCR_OFFSET); + if (priv->flow) + { + mcr |= UART_MCR_AFCE; + } + else + { + mcr &= ~UART_MCR_AFCE; + } + + mcr |= UART_MCR_RTS; + + k210_16550_serialout(priv, UART_MCR_OFFSET, mcr); + + k210_16550_serialout(priv, UART_SRT_OFFSET, 0x0); + +#endif /* defined(CONFIG_SERIAL_IFLOWCONTROL) || defined(CONFIG_SERIAL_OFLOWCONTROL) */ + +#endif + return OK; +} + +/**************************************************************************** + * Name: k210_16550_shutdown + * + * Description: + * Disable the UART. This method is called when the serial + * port is closed + * + ****************************************************************************/ + +static void k210_16550_shutdown(struct uart_dev_s *dev) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + k210_16550_disableuartint(priv, NULL); +} + +/**************************************************************************** + * Name: k210_16550_attach + * + * Description: + * Configure the UART to operation in interrupt driven mode. This method + * is called when the serial port is opened. Normally, this is just after + * the setup() method is called, however, the serial console may operate in + * a non-interrupt driven mode during the boot phase. + * + * RX and TX interrupts are not enabled when by the attach method (unless + * the hardware supports multiple levels of interrupt enabling). The RX + * and TX interrupts are not enabled until the txint() and rxint() methods + * are called. + * + ****************************************************************************/ + +static int k210_16550_attach(struct uart_dev_s *dev) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + int ret; + + /* Attach and enable the IRQ */ + + ret = irq_attach(priv->irq, k210_16550_interrupt, dev); +#ifndef CONFIG_ARCH_NOINTC + if (ret == OK) + { + /* Enable the interrupt (RX and TX interrupts are still disabled + * in the UART + */ + + up_enable_irq(priv->irq); + } +#endif + + return ret; +} + +/**************************************************************************** + * Name: k210_16550_detach + * + * Description: + * Detach UART interrupts. This method is called when the serial port is + * closed normally just before the shutdown method is called. + * The exception is the serial console which is never shutdown. + * + ****************************************************************************/ + +static void k210_16550_detach(FAR struct uart_dev_s *dev) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + + up_disable_irq(priv->irq); + irq_detach(priv->irq); +} + +/**************************************************************************** + * Name: k210_16550_interrupt + * + * Description: + * This is the UART interrupt handler. It will be invoked when an + * interrupt received on the 'irq' It should call uart_transmitchars or + * uart_receivechar to perform the appropriate data transfers. The + * interrupt handling logic must be able to map the 'irq' number into the + * appropriate k210_16550_s structure in order to call these functions. + * + ****************************************************************************/ + +static int k210_16550_interrupt(int irq, FAR void *context, FAR void *arg) +{ + FAR struct uart_dev_s *dev = (struct uart_dev_s *)arg; + FAR struct k210_16550_s *priv; + uint32_t status; + int passes; + uint8_t v_int_status; + + DEBUGASSERT(dev != NULL && dev->priv != NULL); + priv = (FAR struct k210_16550_s *)dev->priv; + + /* Loop until there are no characters to be transferred or, + * until we have been looping for a long time. + */ + + for (passes = 0; passes < 256; passes++) + { + /* Get the current UART status and check for loop + * termination conditions + */ + + status = k210_16550_serialin(priv, UART_IIR_OFFSET); + + if (status == 0) + { + break; + } + v_int_status = status & 0xF; + + /* The UART_IIR_INTSTATUS bit should be zero if there are pending + * interrupts + */ + if(v_int_status == UART_INTERRUPT_SEND) + { + uart_xmitchars(dev); + break; + } + + else if (v_int_status == UART_INTERRUPT_RECEIVE || v_int_status == UART_INTERRUPT_CHARACTER_TIMEOUT) + { + uart_recvchars(dev); + break; + } + } + + return OK; +} + +/**************************************************************************** + * Name: k210_16550_ioctl + * + * Description: + * All ioctl calls will be routed through this method + * + ****************************************************************************/ + +static int k210_16550_ioctl(struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct uart_dev_s *dev = inode->i_private; + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + int ret; + +#ifdef CONFIG_SERIAL_UART_ARCH_IOCTL + ret = uart_ioctl(filep, cmd, arg); + + if (ret != -ENOTTY) + { + return ret; + } + +#else + ret = OK; +#endif + + switch (cmd) + { +#ifdef CONFIG_SERIAL_TIOCSERGSTRUCT + case TIOCSERGSTRUCT: + { + FAR struct k210_16550_s *user = (FAR struct k210_16550_s *)arg; + if (!user) + { + ret = -EINVAL; + } + else + { + memcpy(user, dev, sizeof(struct k210_16550_s)); + } + } + break; +#endif + + case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */ + { + irqstate_t flags = enter_critical_section(); + k210_16550_enablebreaks(priv, true); + leave_critical_section(flags); + } + break; + + case TIOCCBRK: /* BSD compatibility: Turn break off, unconditionally */ + { + irqstate_t flags; + flags = enter_critical_section(); + k210_16550_enablebreaks(priv, false); + leave_critical_section(flags); + } + break; + +#if defined(CONFIG_SERIAL_TERMIOS) && !defined(CONFIG_K210_16550_SUPRESS_CONFIG) + case TCGETS: + { + FAR struct termios *termiosp = (FAR struct termios *)arg; + irqstate_t flags; + + if (!termiosp) + { + ret = -EINVAL; + break; + } + + flags = enter_critical_section(); + + cfsetispeed(termiosp, priv->baud); + termiosp->c_cflag = ((priv->parity != 0) ? PARENB : 0) | + ((priv->parity == 1) ? PARODD : 0); + termiosp->c_cflag |= (priv->stopbits2) ? CSTOPB : 0; +#if defined(CONFIG_SERIAL_IFLOWCONTROL) || defined(CONFIG_SERIAL_OFLOWCONTROL) + termiosp->c_cflag |= priv->flow ? CRTSCTS : 0; +#endif + + switch (priv->bits) + { + case 5: + termiosp->c_cflag |= CS5; + break; + + case 6: + termiosp->c_cflag |= CS6; + break; + + case 7: + termiosp->c_cflag |= CS7; + break; + + case 8: + default: + termiosp->c_cflag |= CS8; + break; + } + + leave_critical_section(flags); + } + break; + + case TCSETS: + { + FAR struct termios *termiosp = (FAR struct termios *)arg; + irqstate_t flags; + + if (!termiosp) + { + ret = -EINVAL; + break; + } + + flags = enter_critical_section(); + + switch (termiosp->c_cflag & CSIZE) + { + case CS5: + priv->bits = 5; + break; + + case CS6: + priv->bits = 6; + break; + + case CS7: + priv->bits = 7; + break; + + case CS8: + default: + priv->bits = 8; + break; + } + + if ((termiosp->c_cflag & PARENB) != 0) + { + priv->parity = (termiosp->c_cflag & PARODD) ? 1 : 2; + } + else + { + priv->parity = 0; + } + + priv->baud = cfgetispeed(termiosp); + priv->stopbits2 = (termiosp->c_cflag & CSTOPB) != 0; +#if defined(CONFIG_SERIAL_IFLOWCONTROL) || defined(CONFIG_SERIAL_OFLOWCONTROL) + priv->flow = (termiosp->c_cflag & CRTSCTS) != 0; +#endif + + k210_16550_setup(dev); + leave_critical_section(flags); + } + break; +#endif + + default: + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Name: k210_16550_receive + * + * Description: + * Called (usually) from the interrupt level to receive one + * character from the UART. Error bits associated with the + * receipt are provided in the return 'status'. + * + ****************************************************************************/ + +static int k210_16550_receive(struct uart_dev_s *dev, unsigned int *status) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + uint32_t rbr = 0; + *status = k210_16550_serialin(priv, UART_LSR_OFFSET); + rbr = k210_16550_serialin(priv, UART_RBR_OFFSET); + return rbr; +} + +/**************************************************************************** + * Name: k210_16550_rxint + * + * Description: + * Call to enable or disable RX interrupts + * + ****************************************************************************/ + +static void k210_16550_rxint(struct uart_dev_s *dev, bool enable) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + + if (enable) + { + priv->ier |= UART_IER_ERBFI; + } + else + { + priv->ier &= ~UART_IER_ERBFI; + } + + k210_16550_serialout(priv, UART_IER_OFFSET, priv->ier); +} + +/**************************************************************************** + * Name: k210_16550_rxavailable + * + * Description: + * Return true if the receive fifo is not empty + * + ****************************************************************************/ + +static bool k210_16550_rxavailable(struct uart_dev_s *dev) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + return ((k210_16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_DR) != 0); +} + +/**************************************************************************** + * Name: k210_16550_dma* + * + * Description: + * Stubbed out DMA-related methods + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_IFLOWCONTROL +static bool k210_16550_rxflowcontrol(struct uart_dev_s *dev, + unsigned int nbuffered, bool upper) +{ +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + + if (priv->flow) + { + /* Disable Rx interrupt to prevent more data being from + * peripheral if the RX buffer is near full. When hardware + * RTS is enabled, this will prevent more data from coming + * in. Otherwise, enable Rx interrupt to make sure that more + * input is received. + */ + + k210_16550_rxint(dev, !upper); + return true; + } +#endif + + return false; +} +#endif + +/**************************************************************************** + * Name: k210_16550_dma* + * + * Description: + * Stub functions used when serial DMA is enabled. + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_TXDMA +static void k210_16550_dmasend(FAR struct uart_dev_s *dev) +{ +} +#endif + +#ifdef CONFIG_SERIAL_RXDMA +static void k210_16550_dmareceive(FAR struct uart_dev_s *dev) +{ +} + +static void k210_16550_dmarxfree(FAR struct uart_dev_s *dev) +{ +} +#endif + +#ifdef CONFIG_SERIAL_TXDMA +static void k210_16550_dmatxavail(FAR struct uart_dev_s *dev) +{ +} +#endif + +/**************************************************************************** + * Name: k210_16550_send + * + * Description: + * This method will send one byte on the UART + * + ****************************************************************************/ + +static void k210_16550_send(struct uart_dev_s *dev, int ch) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + k210_16550_serialout(priv, UART_THR_OFFSET, (uart_datawidth_t)ch); +} + +/**************************************************************************** + * Name: k210_16550_txint + * + * Description: + * Call to enable or disable TX interrupts + * + ****************************************************************************/ + +static void k210_16550_txint(struct uart_dev_s *dev, bool enable) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + irqstate_t flags; + + flags = enter_critical_section(); + if (enable) + { + priv->ier |= UART_IER_ETBEI; + k210_16550_serialout(priv, UART_IER_OFFSET, priv->ier); + + /* Fake a TX interrupt here by just calling uart_xmitchars() with + * interrupts disabled (note this may recurse). + */ + + uart_xmitchars(dev); + } + else + { + priv->ier &= ~UART_IER_ETBEI; + k210_16550_serialout(priv, UART_IER_OFFSET, priv->ier); + } + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: k210_16550_txready + * + * Description: + * Return true if the tranmsit fifo is not full + * + ****************************************************************************/ + +static bool k210_16550_txready(struct uart_dev_s *dev) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + return (((k210_16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_THRE) != 0)); +} + +/**************************************************************************** + * Name: k210_16550_txempty + * + * Description: + * Return true if the transmit fifo is empty + * + ****************************************************************************/ + +static bool k210_16550_txempty(struct uart_dev_s *dev) +{ + FAR struct k210_16550_s *priv = (FAR struct k210_16550_s *)dev->priv; + return ((k210_16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_TEMT) != 0); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: k210_uart_16550_register + * + * Description: + * Register serial console and serial ports. This assumes that + * up_earlyserialinit was called previously. + * + ****************************************************************************/ + +void k210_uart_16550_register(void) +{ +#if defined(CONFIG_K210_16550_UART1) + k210_16550_setup(&g_uart1port); + uart_register("/dev/ttyS1", &g_uart1port); +#endif +#if defined(CONFIG_K210_16550_UART2) + k210_16550_setup(&g_uart2port); + uart_register("/dev/ttyS2", &g_uart2port); +#endif +#if defined(CONFIG_K210_16550_UART3) + k210_16550_setup(&g_uart3port); + uart_register("/dev/ttyS3", &g_uart3port); +#endif +} + +#endif /* CONFIG_K210_16550_UART */ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.h new file mode 100644 index 000000000..0cc6c2bd2 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.h @@ -0,0 +1,340 @@ +/**************************************************************************** + * include/nuttx/serial/uart_16550.h + * Serial driver for 16550 UART + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SERIAL_UART_K210_16550_H +#define __INCLUDE_NUTTX_SERIAL_UART_K210_16550_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_K210_16550_UART + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* CONFIGURATION ************************************************************/ + +/* Are any UARTs enabled? */ + +#undef HAVE_UART +#if defined(CONFIG_K210_16550_UART1) || defined(CONFIG_K210_16550_UART2) || defined(CONFIG_K210_16550_UART3) +# define HAVE_UART 1 +#endif + +/* We need to be told the address increment between registers and the + * register bit width. + */ + +#ifndef CONFIG_K210_16550_REGINCR +# error "CONFIG_K210_16550_REGINCR not defined" +#endif + +#if CONFIG_K210_16550_REGINCR != 1 && CONFIG_K210_16550_REGINCR != 2 && CONFIG_K210_16550_REGINCR != 4 +# error "CONFIG_K210_16550_REGINCR not supported" +#endif + +#ifndef CONFIG_K210_16550_REGWIDTH +# error "CONFIG_K210_16550_REGWIDTH not defined" +#endif + +#if CONFIG_K210_16550_REGWIDTH != 8 && CONFIG_K210_16550_REGWIDTH != 16 && CONFIG_K210_16550_REGWIDTH != 32 +# error "CONFIG_K210_16550_REGWIDTH not supported" +#endif + +#ifndef CONFIG_K210_16550_ADDRWIDTH +# error "CONFIG_K210_16550_ADDRWIDTH not defined" +#endif + +#if CONFIG_K210_16550_ADDRWIDTH != 0 && CONFIG_K210_16550_ADDRWIDTH != 8 && \ + CONFIG_K210_16550_ADDRWIDTH != 16 && CONFIG_K210_16550_ADDRWIDTH != 32 && \ + CONFIG_K210_16550_ADDRWIDTH != 64 +# error "CONFIG_K210_16550_ADDRWIDTH not supported" +#endif + +/* If a UART is enabled, then its base address, clock, and IRQ + * must also be provided + */ + +#ifdef CONFIG_K210_16550_UART1 +# ifndef CONFIG_K210_16550_UART1_BASE +# error "CONFIG_K210_16550_UART1_BASE not provided" +# undef CONFIG_K210_16550_UART1 +# endif +# ifndef CONFIG_K210_16550_UART1_CLOCK +# error "CONFIG_K210_16550_UART1_CLOCK not provided" +# undef CONFIG_K210_16550_UART1 +# endif +# ifndef CONFIG_K210_16550_UART1_IRQ +# error "CONFIG_K210_16550_UART1_IRQ not provided" +# undef CONFIG_K210_16550_UART1 +# endif +#endif + +#ifdef CONFIG_K210_16550_UART2 +# ifndef CONFIG_K210_16550_UART2_BASE +# error "CONFIG_K210_16550_UART2_BASE not provided" +# undef CONFIG_K210_16550_UART2 +# endif +# ifndef CONFIG_K210_16550_UART2_CLOCK +# error "CONFIG_K210_16550_UART2_CLOCK not provided" +# undef CONFIG_K210_16550_UART2 +# endif +# ifndef CONFIG_K210_16550_UART2_IRQ +# error "CONFIG_K210_16550_UART2_IRQ not provided" +# undef CONFIG_K210_16550_UART2 +# endif +#endif + +#ifdef CONFIG_K210_16550_UART3 +# ifndef CONFIG_K210_16550_UART3_BASE +# error "CONFIG_K210_16550_UART3_BASE not provided" +# undef CONFIG_K210_16550_UART3 +# endif +# ifndef CONFIG_K210_16550_UART3_CLOCK +# error "CONFIG_K210_16550_UART3_CLOCK not provided" +# undef CONFIG_K210_16550_UART3 +# endif +# ifndef CONFIG_K210_16550_UART3_IRQ +# error "CONFIG_K210_16550_UART3_IRQ not provided" +# undef CONFIG_K210_16550_UART3 +# endif +#endif + +/* Is there a serial console? There should be at most one defined. + * It could be on any UARTn, n=0,1,2,3 + */ + +/* Register offsets *********************************************************/ + +#define UART_RBR_INCR 0 /* (DLAB =0) Receiver Buffer Register */ +#define UART_THR_INCR 0 /* (DLAB =0) Transmit Holding Register */ +#define UART_DLL_INCR 0 /* (DLAB =1) Divisor Latch LSB */ +#define UART_DLM_INCR 1 /* (DLAB =1) Divisor Latch MSB */ +#define UART_IER_INCR 1 /* (DLAB =0) Interrupt Enable Register */ +#define UART_IIR_INCR 2 /* Interrupt ID Register */ +#define UART_FCR_INCR 2 /* FIFO Control Register */ +#define UART_LCR_INCR 3 /* Line Control Register */ +#define UART_MCR_INCR 4 /* Modem Control Register */ +#define UART_LSR_INCR 5 /* Line Status Register */ +#define UART_MSR_INCR 6 /* Modem Status Register */ +#define UART_SCR_INCR 7 /* Scratch Pad Register */ +#define UART_SRT_INCR 39 /* Receive Fifo Trigger Register*/ +#define UART_DLF_INCR 48 /* Divisor factor Register*/ +#define UART_CPR_INCR 61 /* Component Register */ + +#define UART_RBR_OFFSET (CONFIG_K210_16550_REGINCR*UART_RBR_INCR) +#define UART_THR_OFFSET (CONFIG_K210_16550_REGINCR*UART_THR_INCR) +#define UART_DLL_OFFSET (CONFIG_K210_16550_REGINCR*UART_DLL_INCR) +#define UART_DLM_OFFSET (CONFIG_K210_16550_REGINCR*UART_DLM_INCR) +#define UART_IER_OFFSET (CONFIG_K210_16550_REGINCR*UART_IER_INCR) +#define UART_IIR_OFFSET (CONFIG_K210_16550_REGINCR*UART_IIR_INCR) +#define UART_FCR_OFFSET (CONFIG_K210_16550_REGINCR*UART_FCR_INCR) +#define UART_LCR_OFFSET (CONFIG_K210_16550_REGINCR*UART_LCR_INCR) +#define UART_MCR_OFFSET (CONFIG_K210_16550_REGINCR*UART_MCR_INCR) +#define UART_LSR_OFFSET (CONFIG_K210_16550_REGINCR*UART_LSR_INCR) +#define UART_MSR_OFFSET (CONFIG_K210_16550_REGINCR*UART_MSR_INCR) +#define UART_SCR_OFFSET (CONFIG_K210_16550_REGINCR*UART_SCR_INCR) +#define UART_SRT_OFFSET (CONFIG_K210_16550_REGINCR*UART_SRT_INCR) +#define UART_DLF_OFFSET (CONFIG_K210_16550_REGINCR*UART_DLF_INCR) +#define UART_CPR_OFFSET (CONFIG_K210_16550_REGINCR*UART_CPR_INCR) + +/* Register bit definitions *************************************************/ + +/* RBR (DLAB =0) Receiver Buffer Register */ + +#define UART_RBR_MASK (0xff) /* Bits 0-7: Oldest received byte in RX FIFO */ + /* Bits 8-31: Reserved */ + +/* THR (DLAB =0) Transmit Holding Register */ + +#define UART_THR_MASK (0xff) /* Bits 0-7: Adds byte to TX FIFO */ + /* Bits 8-31: Reserved */ + +/* DLL (DLAB =1) Divisor Latch LSB */ + +#define UART_DLL_MASK (0xff) /* Bits 0-7: DLL */ + /* Bits 8-31: Reserved */ + +/* DLM (DLAB =1) Divisor Latch MSB */ + +#define UART_DLM_MASK (0xff) /* Bits 0-7: DLM */ + /* Bits 8-31: Reserved */ + +/* IER (DLAB =0) Interrupt Enable Register */ + +#define UART_IER_ERBFI (1 << 0) /* Bit 0: Enable received data available interrupt */ +#define UART_IER_ETBEI (1 << 1) /* Bit 1: Enable THR empty interrupt */ +#define UART_IER_ELSI (1 << 2) /* Bit 2: Enable receiver line status interrupt */ +#define UART_IER_EDSSI (1 << 3) /* Bit 3: Enable MODEM status interrupt */ + /* Bits 4-7: Reserved */ +#define UART_IER_ALLIE (0x0f) + +/* IIR Interrupt ID Register */ + +#define UART_IIR_INTSTATUS (1 << 0) /* Bit 0: Interrupt status (active low) */ +#define UART_IIR_INTID_SHIFT (1) /* Bits 1-3: Interrupt identification */ +#define UART_IIR_INTID_MASK (7 << UART_IIR_INTID_SHIFT) +# define UART_IIR_INTID_MSI (0 << UART_IIR_INTID_SHIFT) /* Modem Status */ +# define UART_IIR_INTID_THRE (1 << UART_IIR_INTID_SHIFT) /* THR Empty Interrupt */ +# define UART_IIR_INTID_RDA (2 << UART_IIR_INTID_SHIFT) /* Receive Data Available (RDA) */ +# define UART_IIR_INTID_RLS (3 << UART_IIR_INTID_SHIFT) /* Receiver Line Status (RLS) */ +# define UART_IIR_INTID_CTI (6 << UART_IIR_INTID_SHIFT) /* Character Time-out Indicator (CTI) */ + + /* Bits 4-5: Reserved */ +#define UART_IIR_FIFOEN_SHIFT (6) /* Bits 6-7: RCVR FIFO interrupt */ +#define UART_IIR_FIFOEN_MASK (3 << UART_IIR_FIFOEN_SHIFT) + +/* FCR FIFO Control Register */ + +#define UART_FCR_FIFOEN (1 << 0) /* Bit 0: Enable FIFOs */ +#define UART_FCR_RXRST (1 << 1) /* Bit 1: RX FIFO Reset */ +#define UART_FCR_TXRST (1 << 2) /* Bit 2: TX FIFO Reset */ +#define UART_FCR_DMAMODE (1 << 3) /* Bit 3: DMA Mode Select */ + /* Bits 4-5: Reserved */ +#define UART_FCR_RXTRIGGER_SHIFT (6) /* Bits 6-7: RX Trigger Level */ +#define UART_FCR_RXTRIGGER_MASK (3 << UART_FCR_RXTRIGGER_SHIFT) +# define UART_FCR_RXTRIGGER_1 (0 << UART_FCR_RXTRIGGER_SHIFT) /* Trigger level 0 (1 character) */ +# define UART_FCR_RXTRIGGER_4 (1 << UART_FCR_RXTRIGGER_SHIFT) /* Trigger level 1 (4 characters) */ +# define UART_FCR_RXTRIGGER_8 (2 << UART_FCR_RXTRIGGER_SHIFT) /* Trigger level 2 (8 characters) */ +# define UART_FCR_RXTRIGGER_14 (3 << UART_FCR_RXTRIGGER_SHIFT) /* Trigger level 3 (14 characters) */ + +/* LCR Line Control Register */ + +#define UART_LCR_WLS_SHIFT (0) /* Bit 0-1: Word Length Select */ +#define UART_LCR_WLS_MASK (3 << UART_LCR_WLS_SHIFT) +# define UART_LCR_WLS_5BIT (0 << UART_LCR_WLS_SHIFT) +# define UART_LCR_WLS_6BIT (1 << UART_LCR_WLS_SHIFT) +# define UART_LCR_WLS_7BIT (2 << UART_LCR_WLS_SHIFT) +# define UART_LCR_WLS_8BIT (3 << UART_LCR_WLS_SHIFT) +#define UART_LCR_STB (1 << 2) /* Bit 2: Number of Stop Bits */ +#define UART_LCR_PEN (1 << 3) /* Bit 3: Parity Enable */ +#define UART_LCR_EPS (1 << 4) /* Bit 4: Even Parity Select */ +#define UART_LCR_STICKY (1 << 5) /* Bit 5: Stick Parity */ +#define UART_LCR_BRK (1 << 6) /* Bit 6: Break Control */ +#define UART_LCR_DLAB (1 << 7) /* Bit 7: Divisor Latch Access Bit (DLAB) */ + +/* MCR Modem Control Register */ + +#define UART_MCR_DTR (1 << 0) /* Bit 0: DTR Control Source for DTR output */ +#define UART_MCR_RTS (1 << 1) /* Bit 1: Control Source for RTS output */ +#define UART_MCR_OUT1 (1 << 2) /* Bit 2: Auxiliary user-defined output 1 */ +#define UART_MCR_OUT2 (1 << 3) /* Bit 3: Auxiliary user-defined output 2 */ +#define UART_MCR_LPBK (1 << 4) /* Bit 4: Loopback Mode Select */ +#define UART_MCR_AFCE (1 << 5) /* Bit 5: Auto Flow Control Enable */ + /* Bit 6-7: Reserved */ + +/* LSR Line Status Register */ + +#define UART_LSR_DR (1 << 0) /* Bit 0: Data Ready */ +#define UART_LSR_OE (1 << 1) /* Bit 1: Overrun Error */ +#define UART_LSR_PE (1 << 2) /* Bit 2: Parity Error */ +#define UART_LSR_FE (1 << 3) /* Bit 3: Framing Error */ +#define UART_LSR_BI (1 << 4) /* Bit 4: Break Interrupt */ +#define UART_LSR_THRE (1 << 5) /* Bit 5: Transmitter Holding Register Empty */ +#define UART_LSR_TEMT (1 << 6) /* Bit 6: Transmitter Empty */ +#define UART_LSR_RXFE (1 << 7) /* Bit 7: Error in RX FIFO (RXFE) */ + +#define UART_INTERRUPT_SEND 0x02U +#define UART_INTERRUPT_RECEIVE 0x04U +#define UART_INTERRUPT_CHARACTER_TIMEOUT 0x0CU + +/* SCR Scratch Pad Register */ + +#define UART_SCR_MASK (0xff) /* Bits 0-7: SCR data */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#if CONFIG_K210_16550_REGWIDTH == 8 +typedef uint8_t uart_datawidth_t; +#elif CONFIG_K210_16550_REGWIDTH == 16 +typedef uint16_t uart_datawidth_t; +#elif CONFIG_K210_16550_REGWIDTH == 32 +typedef uint32_t uart_datawidth_t; +#endif + +#if CONFIG_K210_16550_ADDRWIDTH == 0 +typedef uintptr_t uart_addrwidth_t; +#elif CONFIG_K210_16550_ADDRWIDTH == 8 +typedef uint8_t uart_addrwidth_t; +#elif CONFIG_K210_16550_ADDRWIDTH == 16 +typedef uint16_t uart_addrwidth_t; +#elif CONFIG_K210_16550_ADDRWIDTH == 32 +typedef uint32_t uart_addrwidth_t; +#elif CONFIG_K210_16550_ADDRWIDTH == 64 +typedef uint64_t uart_addrwidth_t; +#endif + +struct k210_16550_s +{ + uart_addrwidth_t uartbase; /* Base address of UART registers */ +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + uint32_t baud; /* Configured baud */ + uint32_t uartclk; /* UART clock frequency */ +#endif + uart_datawidth_t ier; /* Saved IER value */ + uint8_t irq; /* IRQ associated with this UART */ +#ifndef CONFIG_K210_16550_SUPRESS_CONFIG + uint8_t parity; /* 0=none, 1=odd, 2=even */ + uint8_t bits; /* Number of bits (7 or 8) */ + int stopbits2; /* true: Configure with 2 stop bits instead of 1 */ +#if defined(CONFIG_SERIAL_IFLOWCONTROL) || defined(CONFIG_SERIAL_OFLOWCONTROL) + bool flow; /* flow control (RTS/CTS) enabled */ +#endif +#endif +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions Definitions + ****************************************************************************/ + +/**************************************************************************** + * Name: uart_getreg(), uart_putreg(), uart_ioctl() + * + * Description: + * These functions must be provided by the processor-specific code in order + * to correctly access 16550 registers + * uart_ioctl() is optional to provide custom IOCTLs + * + ****************************************************************************/ + +#ifndef CONFIG_SERIAL_UART_ARCH_MMIO +uart_datawidth_t uart_getreg(uart_addrwidth_t base, unsigned int offset); +void uart_putreg(uart_addrwidth_t base, + unsigned int offset, + uart_datawidth_t value); +#endif + +struct file; /* Forward reference */ +int uart_ioctl(struct file *filep, int cmd, unsigned long arg); + +void k210_uart_16550_register(void); +#endif /* CONFIG_K210_16550_UART */ +#endif /* __INCLUDE_NUTTX_SERIAL_UART_16550_H */ From 3fa418120c4b3e8cbd8c3448a508712d49538065 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Wed, 28 Sep 2022 09:51:01 +0800 Subject: [PATCH 06/30] support Adapter4G for xidatong-riscv64 on nuttx support mulan on nuttx --- .../xidatong-riscv64/configs/4gnsh/defconfig | 77 +++++ .../nuttx/arch/risc-v/src/k210/encoding.h | 35 +- .../nuttx/arch/risc-v/src/k210/fpioa.c | 35 +- .../nuttx/arch/risc-v/src/k210/fpioa.h | 325 ++---------------- .../arch/risc-v/src/k210/k210_clockconfig.c | 9 + .../arch/risc-v/src/k210/k210_memorymap.h | 9 + .../nuttx/arch/risc-v/src/k210/k210_serial.c | 9 + .../nuttx/arch/risc-v/src/k210/k210_sysctl.c | 35 +- .../nuttx/arch/risc-v/src/k210/k210_sysctl.h | 35 +- .../arch/risc-v/src/k210/k210_systemreset.c | 2 +- .../arch/risc-v/src/k210/k210_uart_16550.c | 38 +- .../arch/risc-v/src/k210/k210_uart_16550.h | 39 +-- 12 files changed, 265 insertions(+), 383 deletions(-) create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/4gnsh/defconfig diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/4gnsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/4gnsh/defconfig new file mode 100644 index 000000000..88480a614 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/4gnsh/defconfig @@ -0,0 +1,77 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_DISABLE_LOSMART is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ADD_NUTTX_FETURES=y +CONFIG_ARCH="risc-v" +CONFIG_ARCH_BOARD="xidatong-riscv64" +CONFIG_ARCH_BOARD_XIDATONG_RISCV64=y +CONFIG_ARCH_CHIP="k210" +CONFIG_ARCH_CHIP_K210=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BINFMT_DISABLE=y +CONFIG_BOARD_LOOPSPERMSEC=46000 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_IFUPDOWN=y +CONFIG_NSH_DISABLE_MKDIR=y +CONFIG_NSH_DISABLE_RM=y +CONFIG_NSH_DISABLE_RMDIR=y +CONFIG_NSH_DISABLE_UMOUNT=y +CONFIG_NSH_READLINE=y +CONFIG_NSH_STRERROR=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=2097152 +CONFIG_RAM_START=0x80400000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=100 +CONFIG_READLINE_CMD_HISTORY_LINELEN=120 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=28 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2019 +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=20 +CONFIG_TESTING_GETPRIME=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SCHED_HPWORK=y +CONFIG_DEV_GPIO=y +CONFIG_BOARDCTL_RESET=y +CONFIG_K210_16550_UART=y +CONFIG_K210_16550_UART2=y +CONFIG_K210_16550_UART2_BASE=0x50220000 +CONFIG_K210_16550_UART2_CLOCK=195000000 +CONFIG_K210_16550_UART2_IRQ=39 +CONFIG_K210_16550_UART2_BAUD=115200 +CONFIG_K210_16550_UART2_PARITY=0 +CONFIG_K210_16550_UART2_BITS=8 +CONFIG_K210_16550_UART2_2STOP=0 +CONFIG_K210_16550_UART2_RXBUFSIZE=128 +CONFIG_K210_16550_UART2_TXBUFSIZE=128 +CONFIG_SUPPORT_CONNECTION_FRAMEWORK=y +CONFIG_CONNECTION_FRAMEWORK_DEBUG=y +CONFIG_CONNECTION_ADAPTER_4G=y +CONFIG_ADAPTER_EC200T=y +CONFIG_ADAPTER_4G_EC200T="ec200t" +CONFIG_ADAPTER_EC200T_DRIVER="/dev/ttyS2" diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/encoding.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/encoding.h index 980e36f4c..a9a5e0353 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/encoding.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/encoding.h @@ -1,17 +1,32 @@ -/* Copyright 2018 Canaan Inc. +/**************************************************************************** + * arch/risc-v/src/k210/encoding.h * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/** +* @file encoding.h +* @brief nuttx source code +* https://github.com/apache/incubator-nuttx.git +* @version 10.3.0 +* @author AIIT XUOS Lab +* @date 2022-09-28 +*/ + #ifndef RISCV_CSR_ENCODING_H #define RISCV_CSR_ENCODING_H diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.c index 093ae74ec..67a93b161 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.c @@ -1,17 +1,32 @@ -/* Copyright 2018 Canaan Inc. +/**************************************************************************** + * arch/risc-v/src/k210/fpioa.c * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/** +* @file fpioa.c +* @brief nuttx source code +* https://github.com/apache/incubator-nuttx.git +* @version 10.3.0 +* @author AIIT XUOS Lab +* @date 2022-09-28 +*/ + #include #include #include "fpioa.h" diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.h index 15e86eaea..5b465556e 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/fpioa.h @@ -1,322 +1,43 @@ -/* Copyright 2018 Canaan Inc. +/**************************************************************************** + * arch/risc-v/src/k210/fpioa.h * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /** - * @file - * @brief Field Programmable GPIO Array (FPIOA) - * - * The FPIOA peripheral supports the following features: - * - * - 48 IO with 256 functions - * - * - Schmitt trigger - * - * - Invert input and output - * - * - Pull up and pull down - * - * - Driving selector - * - * - Static input and output - * - */ +* @file fpioa.h +* @brief nuttx source code +* https://github.com/apache/incubator-nuttx.git +* @version 10.3.0 +* @author AIIT XUOS Lab +* @date 2022-09-28 +*/ #ifndef _DRIVER_FPIOA_H #define _DRIVER_FPIOA_H #include -//#include "platform.h" #ifdef __cplusplus extern "C" { #endif -/* clang-format off */ -/* Pad number settings */ #define FPIOA_NUM_IO (48) -/* clang-format on */ -/** - * @brief FPIOA IO functions - * - * @note FPIOA pin function table - * - * | Function | Name | Description | - * |-----------|------------------|-----------------------------------| - * | 0 | JTAG_TCLK | JTAG Test Clock | - * | 1 | JTAG_TDI | JTAG Test Data In | - * | 2 | JTAG_TMS | JTAG Test Mode Select | - * | 3 | JTAG_TDO | JTAG Test Data Out | - * | 4 | SPI0_D0 | SPI0 Data 0 | - * | 5 | SPI0_D1 | SPI0 Data 1 | - * | 6 | SPI0_D2 | SPI0 Data 2 | - * | 7 | SPI0_D3 | SPI0 Data 3 | - * | 8 | SPI0_D4 | SPI0 Data 4 | - * | 9 | SPI0_D5 | SPI0 Data 5 | - * | 10 | SPI0_D6 | SPI0 Data 6 | - * | 11 | SPI0_D7 | SPI0 Data 7 | - * | 12 | SPI0_SS0 | SPI0 Chip Select 0 | - * | 13 | SPI0_SS1 | SPI0 Chip Select 1 | - * | 14 | SPI0_SS2 | SPI0 Chip Select 2 | - * | 15 | SPI0_SS3 | SPI0 Chip Select 3 | - * | 16 | SPI0_ARB | SPI0 Arbitration | - * | 17 | SPI0_SCLK | SPI0 Serial Clock | - * | 18 | UARTHS_RX | UART High speed Receiver | - * | 19 | UARTHS_TX | UART High speed Transmitter | - * | 20 | RESV6 | Reserved function | - * | 21 | RESV7 | Reserved function | - * | 22 | CLK_SPI1 | Clock SPI1 | - * | 23 | CLK_I2C1 | Clock I2C1 | - * | 24 | GPIOHS0 | GPIO High speed 0 | - * | 25 | GPIOHS1 | GPIO High speed 1 | - * | 26 | GPIOHS2 | GPIO High speed 2 | - * | 27 | GPIOHS3 | GPIO High speed 3 | - * | 28 | GPIOHS4 | GPIO High speed 4 | - * | 29 | GPIOHS5 | GPIO High speed 5 | - * | 30 | GPIOHS6 | GPIO High speed 6 | - * | 31 | GPIOHS7 | GPIO High speed 7 | - * | 32 | GPIOHS8 | GPIO High speed 8 | - * | 33 | GPIOHS9 | GPIO High speed 9 | - * | 34 | GPIOHS10 | GPIO High speed 10 | - * | 35 | GPIOHS11 | GPIO High speed 11 | - * | 36 | GPIOHS12 | GPIO High speed 12 | - * | 37 | GPIOHS13 | GPIO High speed 13 | - * | 38 | GPIOHS14 | GPIO High speed 14 | - * | 39 | GPIOHS15 | GPIO High speed 15 | - * | 40 | GPIOHS16 | GPIO High speed 16 | - * | 41 | GPIOHS17 | GPIO High speed 17 | - * | 42 | GPIOHS18 | GPIO High speed 18 | - * | 43 | GPIOHS19 | GPIO High speed 19 | - * | 44 | GPIOHS20 | GPIO High speed 20 | - * | 45 | GPIOHS21 | GPIO High speed 21 | - * | 46 | GPIOHS22 | GPIO High speed 22 | - * | 47 | GPIOHS23 | GPIO High speed 23 | - * | 48 | GPIOHS24 | GPIO High speed 24 | - * | 49 | GPIOHS25 | GPIO High speed 25 | - * | 50 | GPIOHS26 | GPIO High speed 26 | - * | 51 | GPIOHS27 | GPIO High speed 27 | - * | 52 | GPIOHS28 | GPIO High speed 28 | - * | 53 | GPIOHS29 | GPIO High speed 29 | - * | 54 | GPIOHS30 | GPIO High speed 30 | - * | 55 | GPIOHS31 | GPIO High speed 31 | - * | 56 | GPIO0 | GPIO pin 0 | - * | 57 | GPIO1 | GPIO pin 1 | - * | 58 | GPIO2 | GPIO pin 2 | - * | 59 | GPIO3 | GPIO pin 3 | - * | 60 | GPIO4 | GPIO pin 4 | - * | 61 | GPIO5 | GPIO pin 5 | - * | 62 | GPIO6 | GPIO pin 6 | - * | 63 | GPIO7 | GPIO pin 7 | - * | 64 | UART1_RX | UART1 Receiver | - * | 65 | UART1_TX | UART1 Transmitter | - * | 66 | UART2_RX | UART2 Receiver | - * | 67 | UART2_TX | UART2 Transmitter | - * | 68 | UART3_RX | UART3 Receiver | - * | 69 | UART3_TX | UART3 Transmitter | - * | 70 | SPI1_D0 | SPI1 Data 0 | - * | 71 | SPI1_D1 | SPI1 Data 1 | - * | 72 | SPI1_D2 | SPI1 Data 2 | - * | 73 | SPI1_D3 | SPI1 Data 3 | - * | 74 | SPI1_D4 | SPI1 Data 4 | - * | 75 | SPI1_D5 | SPI1 Data 5 | - * | 76 | SPI1_D6 | SPI1 Data 6 | - * | 77 | SPI1_D7 | SPI1 Data 7 | - * | 78 | SPI1_SS0 | SPI1 Chip Select 0 | - * | 79 | SPI1_SS1 | SPI1 Chip Select 1 | - * | 80 | SPI1_SS2 | SPI1 Chip Select 2 | - * | 81 | SPI1_SS3 | SPI1 Chip Select 3 | - * | 82 | SPI1_ARB | SPI1 Arbitration | - * | 83 | SPI1_SCLK | SPI1 Serial Clock | - * | 84 | SPI_SLAVE_D0 | SPI Slave Data 0 | - * | 85 | SPI_SLAVE_SS | SPI Slave Select | - * | 86 | SPI_SLAVE_SCLK | SPI Slave Serial Clock | - * | 87 | I2S0_MCLK | I2S0 Master Clock | - * | 88 | I2S0_SCLK | I2S0 Serial Clock(BCLK) | - * | 89 | I2S0_WS | I2S0 Word Select(LRCLK) | - * | 90 | I2S0_IN_D0 | I2S0 Serial Data Input 0 | - * | 91 | I2S0_IN_D1 | I2S0 Serial Data Input 1 | - * | 92 | I2S0_IN_D2 | I2S0 Serial Data Input 2 | - * | 93 | I2S0_IN_D3 | I2S0 Serial Data Input 3 | - * | 94 | I2S0_OUT_D0 | I2S0 Serial Data Output 0 | - * | 95 | I2S0_OUT_D1 | I2S0 Serial Data Output 1 | - * | 96 | I2S0_OUT_D2 | I2S0 Serial Data Output 2 | - * | 97 | I2S0_OUT_D3 | I2S0 Serial Data Output 3 | - * | 98 | I2S1_MCLK | I2S1 Master Clock | - * | 99 | I2S1_SCLK | I2S1 Serial Clock(BCLK) | - * | 100 | I2S1_WS | I2S1 Word Select(LRCLK) | - * | 101 | I2S1_IN_D0 | I2S1 Serial Data Input 0 | - * | 102 | I2S1_IN_D1 | I2S1 Serial Data Input 1 | - * | 103 | I2S1_IN_D2 | I2S1 Serial Data Input 2 | - * | 104 | I2S1_IN_D3 | I2S1 Serial Data Input 3 | - * | 105 | I2S1_OUT_D0 | I2S1 Serial Data Output 0 | - * | 106 | I2S1_OUT_D1 | I2S1 Serial Data Output 1 | - * | 107 | I2S1_OUT_D2 | I2S1 Serial Data Output 2 | - * | 108 | I2S1_OUT_D3 | I2S1 Serial Data Output 3 | - * | 109 | I2S2_MCLK | I2S2 Master Clock | - * | 110 | I2S2_SCLK | I2S2 Serial Clock(BCLK) | - * | 111 | I2S2_WS | I2S2 Word Select(LRCLK) | - * | 112 | I2S2_IN_D0 | I2S2 Serial Data Input 0 | - * | 113 | I2S2_IN_D1 | I2S2 Serial Data Input 1 | - * | 114 | I2S2_IN_D2 | I2S2 Serial Data Input 2 | - * | 115 | I2S2_IN_D3 | I2S2 Serial Data Input 3 | - * | 116 | I2S2_OUT_D0 | I2S2 Serial Data Output 0 | - * | 117 | I2S2_OUT_D1 | I2S2 Serial Data Output 1 | - * | 118 | I2S2_OUT_D2 | I2S2 Serial Data Output 2 | - * | 119 | I2S2_OUT_D3 | I2S2 Serial Data Output 3 | - * | 120 | RESV0 | Reserved function | - * | 121 | RESV1 | Reserved function | - * | 122 | RESV2 | Reserved function | - * | 123 | RESV3 | Reserved function | - * | 124 | RESV4 | Reserved function | - * | 125 | RESV5 | Reserved function | - * | 126 | I2C0_SCLK | I2C0 Serial Clock | - * | 127 | I2C0_SDA | I2C0 Serial Data | - * | 128 | I2C1_SCLK | I2C1 Serial Clock | - * | 129 | I2C1_SDA | I2C1 Serial Data | - * | 130 | I2C2_SCLK | I2C2 Serial Clock | - * | 131 | I2C2_SDA | I2C2 Serial Data | - * | 132 | CMOS_XCLK | DVP System Clock | - * | 133 | CMOS_RST | DVP System Reset | - * | 134 | CMOS_PWDN | DVP Power Down Mode | - * | 135 | CMOS_VSYNC | DVP Vertical Sync | - * | 136 | CMOS_HREF | DVP Horizontal Reference output | - * | 137 | CMOS_PCLK | Pixel Clock | - * | 138 | CMOS_D0 | Data Bit 0 | - * | 139 | CMOS_D1 | Data Bit 1 | - * | 140 | CMOS_D2 | Data Bit 2 | - * | 141 | CMOS_D3 | Data Bit 3 | - * | 142 | CMOS_D4 | Data Bit 4 | - * | 143 | CMOS_D5 | Data Bit 5 | - * | 144 | CMOS_D6 | Data Bit 6 | - * | 145 | CMOS_D7 | Data Bit 7 | - * | 146 | SCCB_SCLK | SCCB Serial Clock | - * | 147 | SCCB_SDA | SCCB Serial Data | - * | 148 | UART1_CTS | UART1 Clear To Send | - * | 149 | UART1_DSR | UART1 Data Set Ready | - * | 150 | UART1_DCD | UART1 Data Carrier Detect | - * | 151 | UART1_RI | UART1 Ring Indicator | - * | 152 | UART1_SIR_IN | UART1 Serial Infrared Input | - * | 153 | UART1_DTR | UART1 Data Terminal Ready | - * | 154 | UART1_RTS | UART1 Request To Send | - * | 155 | UART1_OUT2 | UART1 User-designated Output 2 | - * | 156 | UART1_OUT1 | UART1 User-designated Output 1 | - * | 157 | UART1_SIR_OUT | UART1 Serial Infrared Output | - * | 158 | UART1_BAUD | UART1 Transmit Clock Output | - * | 159 | UART1_RE | UART1 Receiver Output Enable | - * | 160 | UART1_DE | UART1 Driver Output Enable | - * | 161 | UART1_RS485_EN | UART1 RS485 Enable | - * | 162 | UART2_CTS | UART2 Clear To Send | - * | 163 | UART2_DSR | UART2 Data Set Ready | - * | 164 | UART2_DCD | UART2 Data Carrier Detect | - * | 165 | UART2_RI | UART2 Ring Indicator | - * | 166 | UART2_SIR_IN | UART2 Serial Infrared Input | - * | 167 | UART2_DTR | UART2 Data Terminal Ready | - * | 168 | UART2_RTS | UART2 Request To Send | - * | 169 | UART2_OUT2 | UART2 User-designated Output 2 | - * | 170 | UART2_OUT1 | UART2 User-designated Output 1 | - * | 171 | UART2_SIR_OUT | UART2 Serial Infrared Output | - * | 172 | UART2_BAUD | UART2 Transmit Clock Output | - * | 173 | UART2_RE | UART2 Receiver Output Enable | - * | 174 | UART2_DE | UART2 Driver Output Enable | - * | 175 | UART2_RS485_EN | UART2 RS485 Enable | - * | 176 | UART3_CTS | UART3 Clear To Send | - * | 177 | UART3_DSR | UART3 Data Set Ready | - * | 178 | UART3_DCD | UART3 Data Carrier Detect | - * | 179 | UART3_RI | UART3 Ring Indicator | - * | 180 | UART3_SIR_IN | UART3 Serial Infrared Input | - * | 181 | UART3_DTR | UART3 Data Terminal Ready | - * | 182 | UART3_RTS | UART3 Request To Send | - * | 183 | UART3_OUT2 | UART3 User-designated Output 2 | - * | 184 | UART3_OUT1 | UART3 User-designated Output 1 | - * | 185 | UART3_SIR_OUT | UART3 Serial Infrared Output | - * | 186 | UART3_BAUD | UART3 Transmit Clock Output | - * | 187 | UART3_RE | UART3 Receiver Output Enable | - * | 188 | UART3_DE | UART3 Driver Output Enable | - * | 189 | UART3_RS485_EN | UART3 RS485 Enable | - * | 190 | TIMER0_TOGGLE1 | TIMER0 Toggle Output 1 | - * | 191 | TIMER0_TOGGLE2 | TIMER0 Toggle Output 2 | - * | 192 | TIMER0_TOGGLE3 | TIMER0 Toggle Output 3 | - * | 193 | TIMER0_TOGGLE4 | TIMER0 Toggle Output 4 | - * | 194 | TIMER1_TOGGLE1 | TIMER1 Toggle Output 1 | - * | 195 | TIMER1_TOGGLE2 | TIMER1 Toggle Output 2 | - * | 196 | TIMER1_TOGGLE3 | TIMER1 Toggle Output 3 | - * | 197 | TIMER1_TOGGLE4 | TIMER1 Toggle Output 4 | - * | 198 | TIMER2_TOGGLE1 | TIMER2 Toggle Output 1 | - * | 199 | TIMER2_TOGGLE2 | TIMER2 Toggle Output 2 | - * | 200 | TIMER2_TOGGLE3 | TIMER2 Toggle Output 3 | - * | 201 | TIMER2_TOGGLE4 | TIMER2 Toggle Output 4 | - * | 202 | CLK_SPI2 | Clock SPI2 | - * | 203 | CLK_I2C2 | Clock I2C2 | - * | 204 | INTERNAL0 | Internal function signal 0 | - * | 205 | INTERNAL1 | Internal function signal 1 | - * | 206 | INTERNAL2 | Internal function signal 2 | - * | 207 | INTERNAL3 | Internal function signal 3 | - * | 208 | INTERNAL4 | Internal function signal 4 | - * | 209 | INTERNAL5 | Internal function signal 5 | - * | 210 | INTERNAL6 | Internal function signal 6 | - * | 211 | INTERNAL7 | Internal function signal 7 | - * | 212 | INTERNAL8 | Internal function signal 8 | - * | 213 | INTERNAL9 | Internal function signal 9 | - * | 214 | INTERNAL10 | Internal function signal 10 | - * | 215 | INTERNAL11 | Internal function signal 11 | - * | 216 | INTERNAL12 | Internal function signal 12 | - * | 217 | INTERNAL13 | Internal function signal 13 | - * | 218 | INTERNAL14 | Internal function signal 14 | - * | 219 | INTERNAL15 | Internal function signal 15 | - * | 220 | INTERNAL16 | Internal function signal 16 | - * | 221 | INTERNAL17 | Internal function signal 17 | - * | 222 | CONSTANT | Constant function | - * | 223 | INTERNAL18 | Internal function signal 18 | - * | 224 | DEBUG0 | Debug function 0 | - * | 225 | DEBUG1 | Debug function 1 | - * | 226 | DEBUG2 | Debug function 2 | - * | 227 | DEBUG3 | Debug function 3 | - * | 228 | DEBUG4 | Debug function 4 | - * | 229 | DEBUG5 | Debug function 5 | - * | 230 | DEBUG6 | Debug function 6 | - * | 231 | DEBUG7 | Debug function 7 | - * | 232 | DEBUG8 | Debug function 8 | - * | 233 | DEBUG9 | Debug function 9 | - * | 234 | DEBUG10 | Debug function 10 | - * | 235 | DEBUG11 | Debug function 11 | - * | 236 | DEBUG12 | Debug function 12 | - * | 237 | DEBUG13 | Debug function 13 | - * | 238 | DEBUG14 | Debug function 14 | - * | 239 | DEBUG15 | Debug function 15 | - * | 240 | DEBUG16 | Debug function 16 | - * | 241 | DEBUG17 | Debug function 17 | - * | 242 | DEBUG18 | Debug function 18 | - * | 243 | DEBUG19 | Debug function 19 | - * | 244 | DEBUG20 | Debug function 20 | - * | 245 | DEBUG21 | Debug function 21 | - * | 246 | DEBUG22 | Debug function 22 | - * | 247 | DEBUG23 | Debug function 23 | - * | 248 | DEBUG24 | Debug function 24 | - * | 249 | DEBUG25 | Debug function 25 | - * | 250 | DEBUG26 | Debug function 26 | - * | 251 | DEBUG27 | Debug function 27 | - * | 252 | DEBUG28 | Debug function 28 | - * | 253 | DEBUG29 | Debug function 29 | - * | 254 | DEBUG30 | Debug function 30 | - * | 255 | DEBUG31 | Debug function 31 | - * - * Any IO of FPIOA have 256 functions, it is a IO-function matrix. - * All IO have default reset function, after reset, re-configure - * IO function is required. - */ - -/* clang-format off */ typedef enum _fpioa_function { FUNC_JTAG_TCLK = 0, /*!< JTAG Test Clock */ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_clockconfig.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_clockconfig.c index 4e1836180..cf900b832 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_clockconfig.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_clockconfig.c @@ -18,6 +18,15 @@ * ****************************************************************************/ +/** +* @file k210_clockconfig.c +* @brief nuttx source code +* https://github.com/apache/incubator-nuttx.git +* @version 10.3.0 +* @author AIIT XUOS Lab +* @date 2022-09-28 +*/ + /**************************************************************************** * Included Files ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_memorymap.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_memorymap.h index 11f3b0634..1ef7d0ea5 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_memorymap.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_memorymap.h @@ -18,6 +18,15 @@ * ****************************************************************************/ +/** +* @file k210_memorymap.h +* @brief nuttx source code +* https://github.com/apache/incubator-nuttx.git +* @version 10.3.0 +* @author AIIT XUOS Lab +* @date 2022-09-28 +*/ + #ifndef __ARCH_RISCV_SRC_K210_K210_MEMORYMAP_H #define __ARCH_RISCV_SRC_K210_K210_MEMORYMAP_H diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_serial.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_serial.c index c5371ebf2..d35ba2d02 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_serial.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_serial.c @@ -18,6 +18,15 @@ * ****************************************************************************/ +/** +* @file k210_serial.c +* @brief nuttx source code +* https://github.com/apache/incubator-nuttx.git +* @version 10.3.0 +* @author AIIT XUOS Lab +* @date 2022-09-28 +*/ + /**************************************************************************** * Included Files ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_sysctl.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_sysctl.c index 509b35c0e..39b5d8e42 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_sysctl.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_sysctl.c @@ -1,17 +1,32 @@ -/* Copyright 2018 Canaan Inc. +/**************************************************************************** + * arch/risc-v/src/k210/k210_sysctl.c * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/** +* @file k210_sysctl.c +* @brief nuttx source code +* https://github.com/apache/incubator-nuttx.git +* @version 10.3.0 +* @author AIIT XUOS Lab +* @date 2022-09-28 +*/ + #include #include #include diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_sysctl.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_sysctl.h index 625a3f3e3..fc4a2bbc6 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_sysctl.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_sysctl.h @@ -1,17 +1,32 @@ -/* Copyright 2018 Canaan Inc. +/**************************************************************************** + * arch/risc-v/src/k210/k210_sysctl.h * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/** +* @file k210_sysctl.h +* @brief nuttx source code +* https://github.com/apache/incubator-nuttx.git +* @version 10.3.0 +* @author AIIT XUOS Lab +* @date 2022-09-28 +*/ + #ifndef _DRIVER_SYSCTL_H #define _DRIVER_SYSCTL_H diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_systemreset.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_systemreset.c index ce7fe7fe1..d98e995ed 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_systemreset.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_systemreset.c @@ -12,7 +12,7 @@ /** * @file k210_systemreset.c - * @briefk210_systemreset.c support reboot + * @brief k210 support reboot * @version 1.0 * @author AIIT XUOS Lab * @date 2022.06.27 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.c index 0f9267408..c52c7cde9 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.c @@ -1,24 +1,22 @@ -/**************************************************************************** - * drivers/serial/uart_16550.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ -/* Serial driver for 16550 UART */ +/** + * @file k210_uart_16550.c + * @brief k210 uart1-uart3 support + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.09.28 + */ /**************************************************************************** * Included Files diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.h index 0cc6c2bd2..dbf2f4cbf 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_uart_16550.h @@ -1,23 +1,22 @@ -/**************************************************************************** - * include/nuttx/serial/uart_16550.h - * Serial driver for 16550 UART - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file k210_uart_16550.h + * @brief k210 uart1-uart3 support + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.09.28 + */ #ifndef __INCLUDE_NUTTX_SERIAL_UART_K210_16550_H #define __INCLUDE_NUTTX_SERIAL_UART_K210_16550_H From 51f346e935230620305420e81df290e7c7fa2a8b Mon Sep 17 00:00:00 2001 From: wlyu Date: Wed, 28 Sep 2022 10:21:11 +0800 Subject: [PATCH 07/30] fixed udp tcp failed to receive and send bug on nuttx --- .../socket_demo/lwip_tcp_socket_demo.c | 93 +++++++++++-------- .../socket_demo/lwip_udp_socket_demo.c | 93 +++++++++++-------- .../xidatong-arm32/configs/netnsh/defconfig | 3 + 3 files changed, 109 insertions(+), 80 deletions(-) diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c index ec31187a9..2675b0964 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c @@ -43,21 +43,47 @@ char tcp_socket_ip[] = {192, 168, 250, 252}; #define lw_error printf #define LWIP_DEMO_TIMES 3 - -/** Create u32_t value from bytes */ -#define LWIP_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \ - ((uint32_t)((b) & 0xff) << 16) | \ - ((uint32_t)((c) & 0xff) << 8) | \ - (uint32_t)((d) & 0xff)) - -#define PP_HTONL(x) ((uint32_t)(x)) -#define LWIP_TARGET_PORT 6000 +#define LWIP_TARGET_PORT 4840 #endif uint16_t tcp_socket_port = LWIP_TARGET_PORT; +char tcp_ip_str[128] = {0}; /******************************************************************************/ +void tcp_set_ip(char *ip_str) +{ + int ip1, ip2, ip3, ip4, port = 0; + + if(ip_str == NULL) + { + return; + } + + if(sscanf(ip_str, "%d.%d.%d.%d:%d", &ip1, &ip2, &ip3, &ip4, &port)) + { + printf("config ip %s port %d\n", ip_str, port); + strcpy(tcp_ip_str, ip_str); + tcp_socket_ip[0] = ip1; + tcp_socket_ip[1] = ip2; + tcp_socket_ip[2] = ip3; + tcp_socket_ip[3] = ip4; + if(port) + tcp_socket_port = port; + return; + } + + if(sscanf(ip_str, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4)) + { + printf("config ip %s\n", ip_str); + tcp_socket_ip[0] = ip1; + tcp_socket_ip[1] = ip2; + tcp_socket_ip[2] = ip3; + tcp_socket_ip[3] = ip4; + strcpy(tcp_ip_str, ip_str); + } +} + static void TCPSocketRecvTask(void *arg) { int fd = -1, clientfd; @@ -97,7 +123,7 @@ static void TCPSocketRecvTask(void *arg) } lw_print("tcp bind success, start to receive.\n"); - lw_notice("\n\nLocal Port:%d\n\n", tcp_socket_port); + lw_notice("\nLocal Port:%d\n", tcp_socket_port); // setup socket fd as listening mode if (listen(fd, 5) != 0 ) @@ -115,7 +141,8 @@ static void TCPSocketRecvTask(void *arg) while(1) { memset(recv_buf, 0, TCP_DEMO_BUF_SIZE); - recv_len = recvfrom(clientfd, recv_buf, TCP_DEMO_BUF_SIZE, 0, (struct sockaddr *)&tcp_addr, &addr_len); + recv_len = recvfrom(clientfd, recv_buf, TCP_DEMO_BUF_SIZE, 0, + (struct sockaddr *)&tcp_addr, &addr_len); if(recv_len > 0) { lw_notice("Receive from : %s\n", inet_ntoa(tcp_addr.sin_addr)); @@ -137,10 +164,7 @@ void TCPSocketRecvTest(int argc, char *argv[]) if(argc >= 2) { lw_print("lw: [%s] target ip %s\n", __func__, argv[1]); - if(sscanf(argv[1], "%d.%d.%d.%d:%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3], &tcp_socket_port) == EOK) - { - sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]); - } + tcp_set_ip(argv[1]); } lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip); @@ -151,11 +175,11 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | TCPSocketRecv, TCPSocketRecvTest, TCP recv echo); #endif - static void TCPSocketSendTask(void *arg) { int cnt = LWIP_DEMO_TIMES; int fd = -1; + int ret; char send_msg[128]; lw_print("%s start\n", __func__); @@ -171,23 +195,25 @@ static void TCPSocketSendTask(void *arg) struct sockaddr_in tcp_sock; tcp_sock.sin_family = AF_INET; tcp_sock.sin_port = htons(tcp_socket_port); - tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_socket_ip[0], tcp_socket_ip[1], tcp_socket_ip[2], tcp_socket_ip[3])); + tcp_sock.sin_addr.s_addr = inet_addr(tcp_ip_str); + memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero)); - if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr))) + ret = connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr)); + if (ret) { - lw_print("Unable to connect\n"); + lw_print("Unable to connect %s = %d\n", tcp_ip_str, ret); close(fd); return; } - lw_notice("\n\nTarget Port:%d\n\n", tcp_socket_port); + lw_print("TCP connect %s:%d success, start to send.\n", tcp_ip_str, tcp_socket_port); while (cnt --) { lw_print("Lwip client is running.\n"); snprintf(send_msg, sizeof(send_msg), "TCP test package times %d\r\n", cnt); - sendto(fd, send_msg, strlen(send_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr)); + send(fd, send_msg, strlen(send_msg), 0); lw_notice("Send tcp msg: %s ", send_msg); PrivTaskDelay(1000); } @@ -196,47 +222,34 @@ static void TCPSocketSendTask(void *arg) return; } - #ifdef ADD_XIZI_FETURES void TCPSocketSendTest(int argc, char *argv[]) { if(argc >= 2) { lw_print("lw: [%s] target ip %s\n", __func__, argv[1]); - if(sscanf(argv[1], "%d.%d.%d.%d:%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3], &tcp_socket_port) == EOK) - { - sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]); - } + tcp_set_ip(argv[1]); } lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip); sys_thread_new("TCP Socket Send", TCPSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); } -SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3), TCPSocketSend, TCPSocketSendTest, TCP send demo); #endif #ifdef ADD_NUTTX_FETURES - -void tcp_set_ip(char *ip_str) -{ - char ip[4] = {0}; - if(sscanf(ip_str, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])) - { - printf("config ip %s\n", ip_str); - memcpy(tcp_socket_ip, ip, 4); - } -} - -void tcp_recv_demo(void) +void tcp_recv_demo(char *ip_str) { + tcp_set_ip(ip_str); TCPSocketRecvTask(NULL); } -void tcp_send_demo(void) +void tcp_send_demo(char *ip_str) { + tcp_set_ip(ip_str); TCPSocketSendTask(NULL); } #endif diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c index 0b0211cab..ef2c06d53 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c @@ -31,36 +31,60 @@ #include #define LWIP_DEMO_TIMES 3 -#define LWIP_LOCAL_PORT 6000 +#define LWIP_LOCAL_PORT 4840 #define lw_error printf #define lw_notice printf #define lw_print printf - -/** Create u32_t value from bytes */ -#define LWIP_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \ - ((uint32_t)((b) & 0xff) << 16) | \ - ((uint32_t)((c) & 0xff) << 8) | \ - (uint32_t)((d) & 0xff)) - -#define PP_HTONL(x) ((uint32_t)(x)) - #endif #define UDP_BUF_SIZE 65536 char udp_socket_ip[] = {192, 168, 250, 252}; +char udp_ip_str[128] = {0}; uint16_t udp_socket_port = LWIP_LOCAL_PORT; /*****************************************************************************/ +void udp_set_ip(char *ip_str) +{ + int ip1, ip2, ip3, ip4, port = 0; + + if(ip_str == NULL) + { + return; + } + + if(sscanf(ip_str, "%d.%d.%d.%d:%d", &ip1, &ip2, &ip3, &ip4, &port)) + { + printf("config ip %s port %d\n", ip_str, port); + strcpy(udp_ip_str, ip_str); + udp_socket_ip[0] = ip1; + udp_socket_ip[1] = ip2; + udp_socket_ip[2] = ip3; + udp_socket_ip[3] = ip4; + if(port) + udp_socket_port = port; + return; + } + + if(sscanf(ip_str, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4)) + { + printf("config ip %s\n", ip_str); + udp_socket_ip[0] = ip1; + udp_socket_ip[1] = ip2; + udp_socket_ip[2] = ip3; + udp_socket_ip[3] = ip4; + strcpy(udp_ip_str, ip_str); + } +} + static void UdpSocketRecvTask(void *arg) { int fd = -1; char *recv_buf; struct sockaddr_in udp_addr, server_addr; int recv_len; - socklen_t addr_len; while(1) { @@ -98,13 +122,13 @@ static void UdpSocketRecvTask(void *arg) while(1) { memset(recv_buf, 0, UDP_BUF_SIZE); - recv_len = recvfrom(fd, recv_buf, UDP_BUF_SIZE, 0, (struct sockaddr *)&server_addr, &addr_len); + recv_len = recv(fd, recv_buf, UDP_BUF_SIZE, 0); if(recv_len > 0) { lw_notice("Receive from : %s\n", inet_ntoa(server_addr.sin_addr)); lw_notice("Receive data : %s\n\n", recv_buf); } - sendto(fd, recv_buf, recv_len, 0, (struct sockaddr*)&server_addr, addr_len); + send(fd, recv_buf, recv_len, 0); } close(fd); @@ -118,14 +142,12 @@ void UdpSocketRecvTest(int argc, char *argv[]) if(argc >= 2) { lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]); - if(sscanf(argv[1], "%d.%d.%d.%d:%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3], &udp_socket_port) == EOK) - { - sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]); - } + udp_set_ip(argv[1]); } lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip); - sys_thread_new("UdpSocketRecvTask", UdpSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); + sys_thread_new("UdpSocketRecvTask", UdpSocketRecvTask, NULL, + LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); } SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3), @@ -150,7 +172,7 @@ static void UdpSocketSendTask(void *arg) struct sockaddr_in udp_sock; udp_sock.sin_family = AF_INET; udp_sock.sin_port = htons(udp_socket_port); - udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_socket_ip[0], udp_socket_ip[1], udp_socket_ip[2], udp_socket_ip[3])); + udp_sock.sin_addr.s_addr = inet_addr(udp_ip_str); memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero)); if(connect(fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr))) @@ -160,13 +182,14 @@ static void UdpSocketSendTask(void *arg) return; } - lw_print("UDP connect success, start to send.\n"); - lw_notice("\n\nTarget Port:%d\n\n", udp_sock.sin_port); + lw_print("UDP connect %s:%d success, start to send.\n", + udp_ip_str, + udp_socket_port); - while (cnt --) + while(cnt --) { snprintf(send_str, sizeof(send_str), "UDP test package times %d\r\n", cnt); - sendto(fd, send_str, strlen(send_str), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr)); + send(fd, send_str, strlen(send_str), 0); lw_notice("Send UDP msg: %s ", send_str); PrivTaskDelay(1000); } @@ -181,14 +204,12 @@ void UdpSocketSendTest(int argc, char *argv[]) if(argc >= 2) { lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]); - if(sscanf(argv[1], "%d.%d.%d.%d:%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3], &udp_socket_port) == EOK) - { - sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]); - } + udp_set_ip(argv[1]); } lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip); - sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); + sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, + sLWIP_DEMO_TASK_PRIO); } SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3), @@ -196,23 +217,15 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | #endif #ifdef ADD_NUTTX_FETURES -void udp_set_ip(char *ip_str) -{ - char ip[4] = {0}; - if(sscanf(ip_str, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])) - { - printf("config ip %s\n", ip_str); - memcpy(udp_socket_ip, ip, 4); - } -} - -void udp_recv_demo(void) +void udp_recv_demo(char *ip_str) { + udp_set_ip(ip_str); UdpSocketRecvTask(NULL); } -void udp_send_demo(void) +void udp_send_demo(char *ip_str) { + udp_set_ip(ip_str); UdpSocketSendTask(NULL); } #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/netnsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/netnsh/defconfig index 9c4f04b90..a218aecc8 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/netnsh/defconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/netnsh/defconfig @@ -23,6 +23,7 @@ CONFIG_BOARD_LOOPSPERMSEC=104926 CONFIG_BUILTIN=y CONFIG_CLOCK_MONOTONIC=y CONFIG_ETH0_PHY_LAN8720=y +CONFIG_FS_PROCFS=y CONFIG_IMXRT_ENET_PHYINIT=y CONFIG_IMXRT_GPIO_IRQ=y CONFIG_IMXRT_GPIO3_0_15_IRQ=y @@ -77,3 +78,5 @@ CONFIG_NSH_ROMFSETC=y CONFIG_NSH_ARCHROMFS=y CONFIG_BOARDCTL_RESET=y CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_APPLICATION_CONNECTION=y +CONFIG_SOCKET_DEMO=y From 32b54cee33cbd2deb99c5913e3e0c4a9d4271189 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Wed, 28 Sep 2022 14:32:14 +0800 Subject: [PATCH 08/30] add GPIO_WIFI_EN register and change PrivSerialIoctl --- .../transform_layer/nuttx/transform.c | 20 +++++++++++++++++++ .../xidatong-riscv64/include/board.h | 2 +- .../xidatong-riscv64/src/k210_gpio.c | 8 ++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/APP_Framework/Framework/transform_layer/nuttx/transform.c b/APP_Framework/Framework/transform_layer/nuttx/transform.c index 878aa0f93..35e3a599d 100644 --- a/APP_Framework/Framework/transform_layer/nuttx/transform.c +++ b/APP_Framework/Framework/transform_layer/nuttx/transform.c @@ -139,10 +139,30 @@ static int PrivSerialIoctl(int fd, int cmd, void *args) { struct SerialDataCfg *serial_cfg = (struct SerialDataCfg *)args; unsigned long serial_baud_rate = (unsigned long)serial_cfg->serial_baud_rate; + struct termios term; + + /* Extended serial port */ if(serial_cfg->is_ext_uart == 1) { return ioctl(fd, OPE_INT, serial_baud_rate); } + + /* Standard serial port,only the baud rate is set */ + else if(serial_cfg->is_ext_uart == 0) + { + if(ioctl(fd, TCGETS, (unsigned long)&term) < 0) + { + return -1; + } + if ((cfsetispeed(&term, serial_baud_rate) < 0) ||(cfsetospeed(&term, serial_baud_rate) < 0)) + { + return -1; + } + if(ioctl(fd, TCSETS, (unsigned long)&term) < 0) + { + return -1; + } + } return 0; } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h index 03564ace5..5677e9855 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h @@ -57,7 +57,7 @@ /* GPIO pins used by the GPIO Subsystem */ -#define BOARD_NGPIOOUT 3 /* Amount of GPIO Output pins */ +#define BOARD_NGPIOOUT 4 /* Amount of GPIO Output pins */ #define BOARD_NGPIOINT 0 /* Amount of GPIO Input */ /**************************************************************************** diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_gpio.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_gpio.c index 12c88622b..a54b3714d 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_gpio.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_gpio.c @@ -51,10 +51,12 @@ #define GPIO_E220_M0 44 #define GPIO_E220_M1 45 #define GPIO_E18_MODE 46 +#define GPIO_WIFI_EN 8 #define FPIOA_E220_M0 1 #define FPIOA_E220_M1 2 #define FPIOA_E18_MODE 3 +#define FPIOA_WIFI_EN 4 /**************************************************************************** * Private Types @@ -94,14 +96,16 @@ static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] = { GPIO_E220_M0, GPIO_E220_M1, - GPIO_E18_MODE + GPIO_E18_MODE, + GPIO_WIFI_EN }; static const uint32_t g_fpioa[BOARD_NGPIOOUT] = { FPIOA_E220_M0, FPIOA_E220_M1, - FPIOA_E18_MODE + FPIOA_E18_MODE, + FPIOA_WIFI_EN }; static struct k210gpio_dev_s g_gpout[BOARD_NGPIOOUT]; From 48250b7285be618bdf685dc5b802adf8945d319f Mon Sep 17 00:00:00 2001 From: wlyu Date: Wed, 28 Sep 2022 15:19:01 +0800 Subject: [PATCH 09/30] optimize socket demo on nuttx --- .../socket_demo/lwip_tcp_socket_demo.c | 49 ++++++++----------- .../socket_demo/lwip_udp_socket_demo.c | 37 ++++++-------- .../xidatong-arm32/configs/netnsh/defconfig | 4 +- .../apps/nshlib/nsh_Applicationscmd.c | 26 +++------- 4 files changed, 44 insertions(+), 72 deletions(-) diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c index 59865940e..56b24ddb6 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c @@ -50,7 +50,7 @@ uint16_t tcp_socket_port = LWIP_TARGET_PORT; char tcp_ip_str[128] = {0}; /******************************************************************************/ -void tcp_set_ip(char *ip_str) +void TcpSocketConfigParam(char *ip_str) { int ip1, ip2, ip3, ip4, port = 0; @@ -83,7 +83,7 @@ void tcp_set_ip(char *ip_str) } } -static void TCPSocketRecvTask(void *arg) +static void TcpSocketRecvTask(void *arg) { int fd = -1, clientfd; int recv_len; @@ -155,24 +155,26 @@ static void TCPSocketRecvTask(void *arg) free(recv_buf); } -#ifdef ADD_XIZI_FETURES -void TCPSocketRecvTest(int argc, char *argv[]) +void TcpSocketRecvTest(int argc, char *argv[]) { - int result = 0; - if(argc >= 2) { lw_print("lw: [%s] target ip %s\n", __func__, argv[1]); - tcp_set_ip(argv[1]); + TcpSocketConfigParam(argv[1]); } +#ifdef ADD_XIZI_FETURES lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip); - sys_thread_new("TCPSocketRecvTask", TCPSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); -} -PRIV_SHELL_CMD_FUNCTION(TCPSocketRecvTest, a tcp receive sample, PRIV_SHELL_CMD_MAIN_ATTR); + sys_thread_new("TcpSocketRecvTask", TcpSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); #endif -static void TCPSocketSendTask(void *arg) +#ifdef ADD_NUTTX_FETURES + TcpSocketRecvTask(NULL); +#endif +} +PRIV_SHELL_CMD_FUNCTION(TcpSocketRecvTest, a tcp receive sample, PRIV_SHELL_CMD_MAIN_ATTR); + +static void TcpSocketSendTask(void *arg) { int cnt = LWIP_DEMO_TIMES; int fd = -1; @@ -219,32 +221,21 @@ static void TCPSocketSendTask(void *arg) return; } -#ifdef ADD_XIZI_FETURES -void TCPSocketSendTest(int argc, char *argv[]) +void TcpSocketSendTest(int argc, char *argv[]) { if(argc >= 2) { lw_print("lw: [%s] target ip %s\n", __func__, argv[1]); - tcp_set_ip(argv[1]); + TcpSocketConfigParam(argv[1]); } +#ifdef ADD_XIZI_FETURES lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip); - sys_thread_new("TCP Socket Send", TCPSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); -} -PRIV_SHELL_CMD_FUNCTION(TCPSocketSendTest, a tcp send sample, PRIV_SHELL_CMD_MAIN_ATTR); + sys_thread_new("Tcp Socket Send", TcpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); #endif - #ifdef ADD_NUTTX_FETURES -void tcp_recv_demo(char *ip_str) -{ - tcp_set_ip(ip_str); - TCPSocketRecvTask(NULL); -} - -void tcp_send_demo(char *ip_str) -{ - tcp_set_ip(ip_str); - TCPSocketSendTask(NULL); -} + TcpSocketSendTask(NULL); #endif +} +PRIV_SHELL_CMD_FUNCTION(TcpSocketSendTest, a tcp send sample, PRIV_SHELL_CMD_MAIN_ATTR); diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c index e502e45c9..62465d4bc 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c @@ -45,7 +45,7 @@ char udp_ip_str[128] = {0}; uint16_t udp_socket_port = LWIP_LOCAL_PORT; /*****************************************************************************/ -void udp_set_ip(char *ip_str) +void UdpSocketConfigParam(char *ip_str) { int ip1, ip2, ip3, ip4, port = 0; @@ -115,7 +115,7 @@ static void UdpSocketRecvTask(void *arg) continue; } - lw_notice("UDP bind sucess, start to receive.\n"); + lw_notice("UDP bind success, start to receive.\n"); lw_notice("\n\nLocal Port:%d\n\n", udp_socket_port); while(1) @@ -135,21 +135,24 @@ static void UdpSocketRecvTask(void *arg) } } -#ifdef ADD_XIZI_FETURES void UdpSocketRecvTest(int argc, char *argv[]) { if(argc >= 2) { lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]); - udp_set_ip(argv[1]); + UdpSocketConfigParam(argv[1]); } +#ifdef ADD_XIZI_FETURES lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip); sys_thread_new("UdpSocketRecvTask", UdpSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); +#endif +#ifdef ADD_NUTTX_FETURES + UdpSocketRecvTask(NULL); +#endif } PRIV_SHELL_CMD_FUNCTION(UdpSocketRecvTest, a udp receive sample, PRIV_SHELL_CMD_MAIN_ATTR); -#endif static void UdpSocketSendTask(void *arg) { @@ -195,32 +198,22 @@ static void UdpSocketSendTask(void *arg) return; } -#ifdef ADD_XIZI_FETURES void UdpSocketSendTest(int argc, char *argv[]) { if(argc >= 2) { lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]); - udp_set_ip(argv[1]); + UdpSocketConfigParam(argv[1]); } +#ifdef ADD_XIZI_FETURES lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip); sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, - sLWIP_DEMO_TASK_PRIO); + LWIP_DEMO_TASK_PRIO); +#endif +#ifdef ADD_NUTTX_FETURES + UdpSocketSendTask(NULL); +#endif } PRIV_SHELL_CMD_FUNCTION(UdpSocketSendTest, a udp send sample, PRIV_SHELL_CMD_MAIN_ATTR); -#endif -#ifdef ADD_NUTTX_FETURES -void udp_recv_demo(char *ip_str) -{ - udp_set_ip(ip_str); - UdpSocketRecvTask(NULL); -} - -void udp_send_demo(char *ip_str) -{ - udp_set_ip(ip_str); - UdpSocketSendTask(NULL); -} -#endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/netnsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/netnsh/defconfig index a218aecc8..18e37d804 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/netnsh/defconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/netnsh/defconfig @@ -73,9 +73,7 @@ CONFIG_READLINE_CMD_HISTORY=y CONFIG_READLINE_CMD_HISTORY_LEN=100 CONFIG_READLINE_CMD_HISTORY_LINELEN=120 CONFIG_READLINE_TABCOMPLETION=y -CONFIG_FS_ROMFS=y -CONFIG_NSH_ROMFSETC=y -CONFIG_NSH_ARCHROMFS=y + CONFIG_BOARDCTL_RESET=y CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_APPLICATION_CONNECTION=y diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index c6096f2e6..42c3f47db 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -81,45 +81,35 @@ int cmd_Extsram(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: socket test ****************************************************************************/ #if defined(CONFIG_SOCKET_DEMO) && !defined(CONFIG_NSH_DISABLE_SOCKET_DEMO) -extern void udp_set_ip(char *ip_str); -extern int udp_recv_demo(void); +void UdpSocketRecvTest(int argc, char *argv[]); int cmd_Udprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, UDP receive!\n"); - if(argc == 2) - udp_set_ip(argv[1]); - udp_recv_demo(); + UdpSocketRecvTest(argc, argv); return OK; } -extern int udp_send_demo(void); +void UdpSocketSendTest(int argc, char *argv[]); int cmd_Udpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, UDP send!\n"); - if(argc == 2) - udp_set_ip(argv[1]); - udp_send_demo(); + UdpSocketSendTest(argc, argv); return OK; } -extern void tcp_set_ip(char *ip_str); -extern int tcp_recv_demo(void); +void TcpSocketRecvTest(int argc, char *argv[]); int cmd_Tcprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, TCP receive!\n"); - if(argc == 2) - tcp_set_ip(argv[1]); - tcp_recv_demo(); + TcpSocketRecvTest(argc, argv); return OK; } -extern int tcp_send_demo(void); +void TcpSocketSendTest(int argc, char *argv[]); int cmd_Tcpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, TCP send!\n"); - if(argc == 2) - tcp_set_ip(argv[1]); - tcp_send_demo(); + TcpSocketSendTest(argc, argv); return OK; } #endif From ecba6148cb2f8c437f8b69bf5aab62e457a2922a Mon Sep 17 00:00:00 2001 From: wlyu Date: Wed, 28 Sep 2022 19:45:32 +0800 Subject: [PATCH 10/30] fixed the bug of wifi test on nuttx and remove warning --- .../Framework/connection/adapter_agent.c | 45 ++++++++++--------- .../Framework/connection/wifi/adapter_wifi.c | 6 +-- .../Framework/connection/wifi/adapter_wifi.h | 4 +- .../connection/wifi/esp07s_wifi/esp07s_wifi.c | 4 +- .../xidatong-arm32/configs/wifinsh/defconfig | 4 +- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/APP_Framework/Framework/connection/adapter_agent.c b/APP_Framework/Framework/connection/adapter_agent.c index af9948cd8..db52a67c3 100755 --- a/APP_Framework/Framework/connection/adapter_agent.c +++ b/APP_Framework/Framework/connection/adapter_agent.c @@ -139,9 +139,9 @@ int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const abstime.tv_sec = timeout_s; - PrivMutexObtain(&agent->lock); + PrivMutexObtain(&agent->lock); agent->receive_mode = AT_MODE; - + memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; @@ -154,8 +154,8 @@ int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const const char *cmd = NULL; agent->reply = reply; - PrivMutexAbandon(&agent->lock); - + PrivMutexAbandon(&agent->lock); + if(agent->reply != NULL) { PrivMutexObtain(&agent->lock); reply->reply_len = 0; @@ -230,7 +230,7 @@ char *GetReplyText(ATReplyType reply) } int AtSetReplyLrEnd(ATAgentType agent, char enable) -{ +{ if (!agent) { return -1; } @@ -241,7 +241,7 @@ int AtSetReplyLrEnd(ATAgentType agent, char enable) } int AtSetReplyEndChar(ATAgentType agent, char last_ch, char end_ch) -{ +{ if (!agent) { return -1; } @@ -253,7 +253,7 @@ int AtSetReplyEndChar(ATAgentType agent, char last_ch, char end_ch) } int AtSetReplyCharNum(ATAgentType agent, unsigned int num) -{ +{ if (!agent) { return -1; } @@ -292,18 +292,18 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s) abstime.tv_sec = timeout_s; if(buffer_len > ENTM_RECV_MAX){ printf("read length more then max length[%d] Bytes",ENTM_RECV_MAX); - return -1; + return -1; } - PrivMutexObtain(&agent->lock); + PrivMutexObtain(&agent->lock); agent->receive_mode = ENTM_MODE; agent->read_len = buffer_len; - PrivMutexAbandon(&agent->lock); + PrivMutexAbandon(&agent->lock); //PrivTaskDelay(1000); if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) { printf("wait sem[%d] timeout\n",agent->entm_rx_notice); return -1; } - PrivMutexObtain(&agent->lock); + PrivMutexObtain(&agent->lock); printf("EntmRecv once len %d.\n", agent->entm_recv_len); @@ -312,7 +312,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s) memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX); agent->entm_recv_len = 0; agent->read_len = 0; - PrivMutexAbandon(&agent->lock); + PrivMutexAbandon(&agent->lock); return buffer_len; } @@ -323,7 +323,7 @@ static int GetCompleteATReply(ATAgentType agent) char ch = 0, last_ch = 0; bool is_full = false; - PrivMutexObtain(&agent->lock); + PrivMutexObtain(&agent->lock); memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; @@ -331,7 +331,7 @@ static int GetCompleteATReply(ATAgentType agent) memset(agent->entm_recv_buf, 0x00, 256); agent->entm_recv_len = 0; - PrivMutexAbandon(&agent->lock); + PrivMutexAbandon(&agent->lock); while (1) { PrivRead(agent->fd, &ch, 1); @@ -359,7 +359,7 @@ static int GetCompleteATReply(ATAgentType agent) } else { printf("entm_recv_buf is_full ...\n"); } - } + } else if (agent->receive_mode == AT_MODE) { if (read_len < agent->maintain_max) { if(ch != 0) { ///< if the char is null then do not save it to the buff @@ -367,13 +367,14 @@ static int GetCompleteATReply(ATAgentType agent) read_len++; agent->maintain_len = read_len; } - + } else { - printf("maintain_len is_full ...\n"); + printf("maintain_len is_full %d ...\n", read_len); is_full = true; } - if (((ch == '\n') && (last_ch == '\r') && (agent->reply_lr_end)) || + if (((ch == '\n') && (agent->reply_lr_end)) || + ((ch == '\n') && (last_ch == '\r') && (agent->reply_lr_end)) || ((ch == agent->reply_end_char) && (agent->reply_end_char) && (last_ch == agent->reply_end_last_char) && (agent->reply_end_last_char)) || ((read_len == agent->reply_char_num) && (agent->reply_char_num))) { @@ -384,7 +385,7 @@ static int GetCompleteATReply(ATAgentType agent) PrivMutexAbandon(&agent->lock); return -1; } - + printf("GetCompleteATReply done\n"); agent->receive_mode = DEFAULT_MODE; PrivMutexAbandon(&agent->lock); @@ -418,7 +419,7 @@ int DeleteATAgent(ATAgentType agent) if(agent->at_handler > 0){ PrivTaskDelete(agent->at_handler, 0); } - + if (agent->fd > 0) { printf("close agent fd = %d\n",agent->fd); PrivClose(agent->fd); @@ -464,7 +465,7 @@ static void *ATAgentReceiveProcess(void *param) while (1) { if (GetCompleteATReply(agent) > 0) { - PrivMutexObtain(&agent->lock); + PrivMutexObtain(&agent->lock); if (agent->reply != NULL) { ATReplyType reply = agent->reply; @@ -550,7 +551,7 @@ int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max) if (GetATAgent(agent_name) != NULL) { return result; } - + while (i < AT_AGENT_MAX && at_agent_table[i].fd > 0) { i++; } diff --git a/APP_Framework/Framework/connection/wifi/adapter_wifi.c b/APP_Framework/Framework/connection/wifi/adapter_wifi.c index b9e1abdfb..c5d5b47af 100644 --- a/APP_Framework/Framework/connection/wifi/adapter_wifi.c +++ b/APP_Framework/Framework/connection/wifi/adapter_wifi.c @@ -99,8 +99,8 @@ int AdapterWifiInit(void) /******************wifi TEST*********************/ int AdapterWifiTest(void) { - char cmd[64]; - int baud_rate = BAUD_RATE_57600; +// char cmd[64]; +// int baud_rate = BAUD_RATE_57600; struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); @@ -338,7 +338,7 @@ void AdapterWifiGetParam(int argc, char *argv[]) } -int AdapterWifiTest(int argc, char *argv[]) +int AdapterWifiTestWithParam(int argc, char *argv[]) { int i, ret; diff --git a/APP_Framework/Framework/connection/wifi/adapter_wifi.h b/APP_Framework/Framework/connection/wifi/adapter_wifi.h index 25c6709a7..042dcc092 100644 --- a/APP_Framework/Framework/connection/wifi/adapter_wifi.h +++ b/APP_Framework/Framework/connection/wifi/adapter_wifi.h @@ -31,8 +31,8 @@ struct WifiParam { - uint8_t wifi_ssid[128]; - uint8_t wifi_pwd[128]; + char wifi_ssid[128]; + char wifi_pwd[128]; }; diff --git a/APP_Framework/Framework/connection/wifi/esp07s_wifi/esp07s_wifi.c b/APP_Framework/Framework/connection/wifi/esp07s_wifi/esp07s_wifi.c index 4eba52263..20558699e 100755 --- a/APP_Framework/Framework/connection/wifi/esp07s_wifi/esp07s_wifi.c +++ b/APP_Framework/Framework/connection/wifi/esp07s_wifi/esp07s_wifi.c @@ -238,7 +238,7 @@ static int Esp07sWifiSetUp(struct Adapter *adapter) result = GetReplyText(reply); if (!result) { - printf("%s %n get reply failed.\n",__func__,__LINE__); + printf("%s %d get reply failed.\n",__func__,__LINE__); ret = -1; goto __exit; } @@ -355,7 +355,7 @@ static int Esp07sWifiNetstat(struct Adapter *adapter) result = GetReplyText(reply); if (!result) { - printf("%s %n get reply failed.\n",__func__,__LINE__); + printf("%s %d get reply failed.\n",__func__,__LINE__); ret = -1; goto __exit; } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/wifinsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/wifinsh/defconfig index 6fe18f3ff..2d1625113 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/wifinsh/defconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/configs/wifinsh/defconfig @@ -47,15 +47,17 @@ CONFIG_SYSTEM_NSH=y CONFIG_DEV_GPIO=y CONFIG_READLINE_CMD_HISTORY=y CONFIG_READLINE_CMD_HISTORY_LEN=100 + CONFIG_READLINE_CMD_HISTORY_LINELEN=120 CONFIG_READLINE_TABCOMPLETION=y CONFIG_FS_ROMFS=y CONFIG_NSH_ROMFSETC=y CONFIG_NSH_ARCHROMFS=y CONFIG_BOARDCTL_RESET=y -CONFIG_CONNECTION_FRAMEWORK_DEBUG=y CONFIG_CONNECTION_ADAPTER_WIFI=y CONFIG_ADAPTER_ESP07S_WIFI=y CONFIG_ADAPTER_WIFI_ESP07S="esp07s_wifi" CONFIG_ADAPTER_ESP07S_DRIVER="/dev/ttyS2" CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_SUPPORT_CONNECTION_FRAMEWORK=y + From 7dc887e516e64119c1f8e74f7238add6cbab50bf Mon Sep 17 00:00:00 2001 From: wlyu Date: Wed, 28 Sep 2022 20:07:54 +0800 Subject: [PATCH 11/30] fixed the bug of compilation following adapter zigbee change --- .../apps/nshlib/nsh_Applicationscmd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 42c3f47db..faff3ef98 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -330,35 +330,35 @@ int cmd_WindSpeedQsFs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) ****************************************************************************/ #if defined(CONFIG_CONNECTION_ADAPTER_ZIGBEE) && !defined(CONFIG_NSH_DISABLE_OPENZIGBEE) -extern int openzigbee(void); +extern int OpenZigbee(void); int cmd_openzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, world!\n"); FrameworkInit(); - openzigbee(); + OpenZigbee(); return OK; } #endif #if defined(CONFIG_CONNECTION_ADAPTER_ZIGBEE) && !defined(CONFIG_NSH_DISABLE_SENDZIGBEE) -extern int sendzigbee(int argc, char *argv[]); +extern int SendZigbee(int argc, char *argv[]); int cmd_sendzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, world!\n"); FrameworkInit(); - sendzigbee(argc,argv); + SendZigbee(argc,argv); return OK; } #endif #if defined(CONFIG_CONNECTION_ADAPTER_ZIGBEE) && !defined(CONFIG_NSH_DISABLE_RECVZIGBEE) -extern int recvzigbee(void); +extern int RecvZigbee(void); int cmd_recvzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, world!\n"); FrameworkInit(); - recvzigbee(); + RecvZigbee(); return OK; } #endif From 9fcd539f1bf1eeaf4ec3a74837408ac746aeff9c Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 10 Oct 2022 09:26:36 +0800 Subject: [PATCH 12/30] add ch376 for xidatong-riscv64 --- .../aiit_board/xidatong-riscv64/src/Makefile | 2 +- .../xidatong-riscv64/src/ch376inc.h | 926 +++++++++++++++++ .../xidatong-riscv64/src/k210_ch376.c | 978 ++++++++++++++++++ .../xidatong-riscv64/src/k210_ch376.h | 118 +++ 4 files changed, 2023 insertions(+), 1 deletion(-) create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376inc.h create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.h diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile index d6fa521c7..3258528d7 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile @@ -20,7 +20,7 @@ include $(TOPDIR)/Make.defs -CSRCS = k210_bringup.c k210_boot.c +CSRCS = k210_bringup.c k210_boot.c k210_ch376.c ifeq ($(CONFIG_BOARDCTL_RESET),y) CSRCS += k210_reset.c diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376inc.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376inc.h new file mode 100644 index 000000000..63d757a73 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376inc.h @@ -0,0 +1,926 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file ch376inc.h + * @brief xidatong-riscv64 ch376inc.h + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.10.10 + */ + +#ifndef __CH376INC_H__ +#define __CH376INC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************************************************************* */ +/* 甯哥敤绫诲瀷鍜屽父閲忓畾涔 */ + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif +#ifndef NULL +#define NULL 0 +#endif + +#ifndef UINT8 +typedef unsigned char UINT8; +#endif +#ifndef UINT16 +typedef unsigned short UINT16; +#endif +#ifndef UINT32 +typedef unsigned long UINT32; +#endif +#ifndef PUINT8 +typedef unsigned char *PUINT8; +#endif +#ifndef PUINT16 +typedef unsigned short *PUINT16; +#endif +#ifndef PUINT32 +typedef unsigned long *PUINT32; +#endif +#ifndef UINT8V +typedef unsigned char volatile UINT8V; +#endif +#ifndef PUINT8V +typedef unsigned char volatile *PUINT8V; +#endif + +/* ********************************************************************************************************************* */ +/* 纭欢鐗规 */ + +#define CH376_DAT_BLOCK_LEN 0x40 /* USB鍗曚釜鏁版嵁鍖, 鏁版嵁鍧楃殑鏈澶ч暱搴, 榛樿缂撳啿鍖虹殑闀垮害 */ + +/* ********************************************************************************************************************* */ +/* 鍛戒护浠g爜 */ +/* 閮ㄥ垎鍛戒护鍏煎CH375鑺墖, 浣嗘槸杈撳叆鏁版嵁鎴栬呰緭鍑烘暟鎹殑鍙兘灞閮ㄤ笉鍚) */ +/* 涓涓懡浠ゆ搷浣滈『搴忓寘鍚: + 涓涓懡浠ょ爜(瀵逛簬涓插彛鏂瑰紡,鍛戒护鐮佷箣鍓嶈繕闇瑕佷袱涓悓姝ョ爜), + 鑻ュ共涓緭鍏ユ暟鎹(鍙互鏄0涓), + 浜х敓涓柇閫氱煡 鎴栬 鑻ュ共涓緭鍑烘暟鎹(鍙互鏄0涓), 浜岄変竴, 鏈変腑鏂氱煡鍒欎竴瀹氭病鏈夎緭鍑烘暟鎹, 鏈夎緭鍑烘暟鎹垯涓瀹氫笉浜х敓涓柇 + 浠匔MD01_WR_REQ_DATA鍛戒护渚嬪, 椤哄簭鍖呭惈: 涓涓懡浠ょ爜, 涓涓緭鍑烘暟鎹, 鑻ュ共涓緭鍏ユ暟鎹 + 鍛戒护鐮佽捣鍚嶈鍒: CMDxy_NAME + 鍏朵腑鐨剎鍜寉閮芥槸鏁板瓧, x璇存槑鏈灏戣緭鍏ユ暟鎹釜鏁(瀛楄妭鏁), y璇存槑鏈灏戣緭鍑烘暟鎹釜鏁(瀛楄妭鏁), y濡傛灉鏄疕鍒欒鏄庝骇鐢熶腑鏂氱煡, + 鏈変簺鍛戒护鑳藉瀹炵幇0鍒板涓瓧鑺傜殑鏁版嵁鍧楄鍐, 鏁版嵁鍧楁湰韬殑瀛楄妭鏁版湭鍖呭惈鍦ㄤ笂杩皒鎴杫涔嬪唴 */ +/* 鏈枃浠堕粯璁や細鍚屾椂鎻愪緵涓嶤H375鑺墖鍛戒护鐮佸吋瀹圭殑鍛戒护鐮佹牸寮忥紙鍗冲幓鎺墄鍜寉涔嬪悗), 濡傛灉涓嶉渶瑕, 閭d箞鍙互瀹氫箟_NO_CH375_COMPATIBLE_绂佹 */ + +/* ********************************************************************************************************************* */ +/* 涓昏鍛戒护(鎵嬪唽涓), 甯哥敤 */ + +#define CMD01_GET_IC_VER 0x01 /* 鑾峰彇鑺墖鍙婂浐浠剁増鏈 */ +/* 杈撳嚭: 鐗堟湰鍙( 浣7涓0, 浣6涓1, 浣5~浣0涓虹増鏈彿 ) */ +/* CH376杩斿洖鐗堟湰鍙风殑鍊间负041H鍗崇増鏈彿涓01H */ + +#define CMD21_SET_BAUDRATE 0x02 /* 涓插彛鏂瑰紡: 璁剧疆涓插彛閫氳娉㈢壒鐜(涓婄數鎴栬呭浣嶅悗鐨勯粯璁ゆ尝鐗圭巼涓9600bps,鐢盌4/D5/D6寮曡剼閫夋嫨) */ +/* 杈撳叆: 娉㈢壒鐜囧垎棰戠郴鏁, 娉㈢壒鐜囧垎棰戝父鏁 */ +/* 杈撳嚭: 鎿嶄綔鐘舵( CMD_RET_SUCCESS鎴朇MD_RET_ABORT, 鍏跺畠鍊艰鏄庢搷浣滄湭瀹屾垚 ) */ + +#define CMD00_ENTER_SLEEP 0x03 /* 杩涘叆鐫$湢鐘舵 */ + +#define CMD00_RESET_ALL 0x05 /* 鎵ц纭欢澶嶄綅 */ + +#define CMD11_CHECK_EXIST 0x06 /* 娴嬭瘯閫氳鎺ュ彛鍜屽伐浣滅姸鎬 */ +/* 杈撳叆: 浠绘剰鏁版嵁 */ +/* 杈撳嚭: 杈撳叆鏁版嵁鐨勬寜浣嶅彇鍙 */ + +#define CMD20_CHK_SUSPEND 0x0B /* 璁惧鏂瑰紡: 璁剧疆妫鏌SB鎬荤嚎鎸傝捣鐘舵佺殑鏂瑰紡 */ +/* 杈撳叆: 鏁版嵁10H, 妫鏌ユ柟寮 */ +/* 00H=涓嶆鏌SB鎸傝捣, 04H=浠50mS涓洪棿闅旀鏌SB鎸傝捣, 05H=浠10mS涓洪棿闅旀鏌SB鎸傝捣 */ + +#define CMD20_SET_SDO_INT 0x0B /* SPI鎺ュ彛鏂瑰紡: 璁剧疆SPI鐨凷DO寮曡剼鐨勪腑鏂柟寮 */ +/* 杈撳叆: 鏁版嵁16H, 涓柇鏂瑰紡 */ +/* 10H=绂佹SDO寮曡剼鐢ㄤ簬涓柇杈撳嚭,鍦⊿CS鐗囬夋棤鏁堟椂涓夋佽緭鍑虹姝, 90H=SDO寮曡剼鍦⊿CS鐗囬夋棤鏁堟椂鍏煎仛涓柇璇锋眰杈撳嚭 */ + +#define CMD14_GET_FILE_SIZE 0x0C /* 涓绘満鏂囦欢妯″紡: 鑾峰彇褰撳墠鏂囦欢闀垮害 */ +/* 杈撳叆: 鏁版嵁68H */ +/* 杈撳嚭: 褰撳墠鏂囦欢闀垮害(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + +#define CMD50_SET_FILE_SIZE 0x0D /* 涓绘満鏂囦欢妯″紡: 璁剧疆褰撳墠鏂囦欢闀垮害 */ +/* 杈撳叆: 鏁版嵁68H, 褰撳墠鏂囦欢闀垮害(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + +#define CMD11_SET_USB_MODE 0x15 /* 璁剧疆USB宸ヤ綔妯″紡 */ +/* 杈撳叆: 妯″紡浠g爜 */ +/* 00H=鏈惎鐢ㄧ殑璁惧鏂瑰紡, 01H=宸插惎鐢ㄧ殑璁惧鏂瑰紡骞朵笖浣跨敤澶栭儴鍥轰欢妯″紡(涓插彛涓嶆敮鎸), 02H=宸插惎鐢ㄧ殑璁惧鏂瑰紡骞朵笖浣跨敤鍐呯疆鍥轰欢妯″紡 */ +/* 03H=SD鍗′富鏈烘ā寮/鏈惎鐢ㄧ殑涓绘満妯″紡,鐢ㄤ簬绠$悊鍜屽瓨鍙朣D鍗′腑鐨勬枃浠 */ +/* 04H=鏈惎鐢ㄧ殑涓绘満鏂瑰紡, 05H=宸插惎鐢ㄧ殑涓绘満鏂瑰紡, 06H=宸插惎鐢ㄧ殑涓绘満鏂瑰紡骞朵笖鑷姩浜х敓SOF鍖, 07H=宸插惎鐢ㄧ殑涓绘満鏂瑰紡骞朵笖澶嶄綅USB鎬荤嚎 */ +/* 杈撳嚭: 鎿嶄綔鐘舵( CMD_RET_SUCCESS鎴朇MD_RET_ABORT, 鍏跺畠鍊艰鏄庢搷浣滄湭瀹屾垚 ) */ + +#define CMD01_GET_STATUS 0x22 /* 鑾峰彇涓柇鐘舵佸苟鍙栨秷涓柇璇锋眰 */ +/* 杈撳嚭: 涓柇鐘舵 */ + +#define CMD00_UNLOCK_USB 0x23 /* 璁惧鏂瑰紡: 閲婃斁褰撳墠USB缂撳啿鍖 */ + +#define CMD01_RD_USB_DATA0 0x27 /* 浠庡綋鍓峌SB涓柇鐨勭鐐圭紦鍐插尯鎴栬呬富鏈虹鐐圭殑鎺ユ敹缂撳啿鍖鸿鍙栨暟鎹潡 */ +/* 杈撳嚭: 闀垮害, 鏁版嵁娴 */ + +#define CMD01_RD_USB_DATA 0x28 /* 璁惧鏂瑰紡: 浠庡綋鍓峌SB涓柇鐨勭鐐圭紦鍐插尯璇诲彇鏁版嵁鍧, 骞堕噴鏀剧紦鍐插尯, 鐩稿綋浜 CMD01_RD_USB_DATA0 + CMD00_UNLOCK_USB */ +/* 杈撳嚭: 闀垮害, 鏁版嵁娴 */ + +#define CMD10_WR_USB_DATA7 0x2B /* 璁惧鏂瑰紡: 鍚慤SB绔偣2鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ +/* 杈撳叆: 闀垮害, 鏁版嵁娴 */ + +#define CMD10_WR_HOST_DATA 0x2C /* 鍚慤SB涓绘満绔偣鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ +/* 杈撳叆: 闀垮害, 鏁版嵁娴 */ + +#define CMD01_WR_REQ_DATA 0x2D /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡 */ +/* 杈撳嚭: 闀垮害 */ +/* 杈撳叆: 鏁版嵁娴 */ + +#define CMD20_WR_OFS_DATA 0x2E /* 鍚戝唴閮ㄧ紦鍐插尯鎸囧畾鍋忕Щ鍦板潃鍐欏叆鏁版嵁鍧 */ +/* 杈撳叆: 鍋忕Щ, 闀垮害, 鏁版嵁娴 */ + +#define CMD10_SET_FILE_NAME 0x2F /* 涓绘満鏂囦欢妯″紡: 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ +/* 杈撳叆: 浠0缁撴潫鐨勫瓧绗︿覆(鍚粨鏉熺0鍦ㄥ唴闀垮害涓嶈秴杩14涓瓧绗) */ + +/* ********************************************************************************************************************* */ +/* 涓昏鍛戒护(鎵嬪唽涓), 甯哥敤, 浠ヤ笅鍛戒护鎬绘槸鍦ㄦ搷浣滅粨鏉熸椂浜х敓涓柇閫氱煡, 骞朵笖鎬绘槸娌℃湁杈撳嚭鏁版嵁 */ + +#define CMD0H_DISK_CONNECT 0x30 /* 涓绘満鏂囦欢妯″紡/涓嶆敮鎸丼D鍗: 妫鏌ョ鐩樻槸鍚﹁繛鎺 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_MOUNT 0x31 /* 涓绘満鏂囦欢妯″紡: 鍒濆鍖栫鐩樺苟娴嬭瘯纾佺洏鏄惁灏辩华 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_FILE_OPEN 0x32 /* 涓绘満鏂囦欢妯″紡: 鎵撳紑鏂囦欢鎴栬呯洰褰(鏂囦欢澶),鎴栬呮灇涓炬枃浠跺拰鐩綍(鏂囦欢澶) */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_FILE_ENUM_GO 0x33 /* 涓绘満鏂囦欢妯″紡: 缁х画鏋氫妇鏂囦欢鍜岀洰褰(鏂囦欢澶) */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_FILE_CREATE 0x34 /* 涓绘満鏂囦欢妯″紡: 鏂板缓鏂囦欢,濡傛灉鏂囦欢宸茬粡瀛樺湪閭d箞鍏堝垹闄 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_FILE_ERASE 0x35 /* 涓绘満鏂囦欢妯″紡: 鍒犻櫎鏂囦欢,濡傛灉宸茬粡鎵撳紑鍒欑洿鎺ュ垹闄,鍚﹀垯瀵逛簬鏂囦欢浼氬厛鎵撳紑鍐嶅垹闄,瀛愮洰褰曞繀椤诲厛鎵撳紑 */ +/* 杈撳嚭涓柇 */ + +#define CMD1H_FILE_CLOSE 0x36 /* 涓绘満鏂囦欢妯″紡: 鍏抽棴褰撳墠宸茬粡鎵撳紑鐨勬枃浠舵垨鑰呯洰褰(鏂囦欢澶) */ +/* 杈撳叆: 鏄惁鍏佽鏇存柊鏂囦欢闀垮害 */ +/* 00H=绂佹鏇存柊闀垮害, 01H=鍏佽鏇存柊闀垮害 */ +/* 杈撳嚭涓柇 */ + +#define CMD1H_DIR_INFO_READ 0x37 /* 涓绘満鏂囦欢妯″紡: 璇诲彇鏂囦欢鐨勭洰褰曚俊鎭 */ +/* 杈撳叆: 鎸囧畾闇瑕佽鍙栫殑鐩綍淇℃伅缁撴瀯鍦ㄦ墖鍖哄唴鐨勭储寮曞彿 */ +/* 绱㈠紩鍙疯寖鍥翠负00H~0FH, 绱㈠紩鍙0FFH鍒欎负褰撳墠宸茬粡鎵撳紑鐨勬枃浠 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DIR_INFO_SAVE 0x38 /* 涓绘満鏂囦欢妯″紡: 淇濆瓨鏂囦欢鐨勭洰褰曚俊鎭 */ +/* 杈撳嚭涓柇 */ + +#define CMD4H_BYTE_LOCATE 0x39 /* 涓绘満鏂囦欢妯″紡: 浠ュ瓧鑺備负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ +/* 杈撳叆: 鍋忕Щ瀛楄妭鏁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +/* 杈撳嚭涓柇 */ + +#define CMD2H_BYTE_READ 0x3A /* 涓绘満鏂囦欢妯″紡: 浠ュ瓧鑺備负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ +/* 杈撳叆: 璇锋眰璇诲彇鐨勫瓧鑺傛暟(鎬婚暱搴16浣,浣庡瓧鑺傚湪鍓) */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_BYTE_RD_GO 0x3B /* 涓绘満鏂囦欢妯″紡: 缁х画瀛楄妭璇 */ +/* 杈撳嚭涓柇 */ + +#define CMD2H_BYTE_WRITE 0x3C /* 涓绘満鏂囦欢妯″紡: 浠ュ瓧鑺備负鍗曚綅鍚戝綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ +/* 杈撳叆: 璇锋眰鍐欏叆鐨勫瓧鑺傛暟(鎬婚暱搴16浣,浣庡瓧鑺傚湪鍓) */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_BYTE_WR_GO 0x3D /* 涓绘満鏂囦欢妯″紡: 缁х画瀛楄妭鍐 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_CAPACITY 0x3E /* 涓绘満鏂囦欢妯″紡: 鏌ヨ纾佺洏鐗╃悊瀹归噺 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_QUERY 0x3F /* 涓绘満鏂囦欢妯″紡: 鏌ヨ纾佺洏绌洪棿淇℃伅 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DIR_CREATE 0x40 /* 涓绘満鏂囦欢妯″紡: 鏂板缓鐩綍(鏂囦欢澶)骞舵墦寮,濡傛灉鐩綍宸茬粡瀛樺湪閭d箞鐩存帴鎵撳紑 */ +/* 杈撳嚭涓柇 */ + +#define CMD4H_SEC_LOCATE 0x4A /* 涓绘満鏂囦欢妯″紡: 浠ユ墖鍖轰负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ +/* 杈撳叆: 鍋忕Щ鎵囧尯鏁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +/* 杈撳嚭涓柇 */ + +#define CMD1H_SEC_READ 0x4B /* 涓绘満鏂囦欢妯″紡/涓嶆敮鎸丼D鍗: 浠ユ墖鍖轰负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ +/* 杈撳叆: 璇锋眰璇诲彇鐨勬墖鍖烘暟 */ +/* 杈撳嚭涓柇 */ + +#define CMD1H_SEC_WRITE 0x4C /* 涓绘満鏂囦欢妯″紡/涓嶆敮鎸丼D鍗: 浠ユ墖鍖轰负鍗曚綅鍦ㄥ綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ +/* 杈撳叆: 璇锋眰鍐欏叆鐨勬墖鍖烘暟 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_BOC_CMD 0x50 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 瀵筓SB瀛樺偍鍣ㄦ墽琛孊ulkOnly浼犺緭鍗忚鐨勫懡浠 */ +/* 杈撳嚭涓柇 */ + +#define CMD5H_DISK_READ 0x54 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 浠嶶SB瀛樺偍鍣ㄨ鐗╃悊鎵囧尯 */ +/* 杈撳叆: LBA鐗╃悊鎵囧尯鍦板潃(鎬婚暱搴32浣, 浣庡瓧鑺傚湪鍓), 鎵囧尯鏁(01H~FFH) */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_RD_GO 0x55 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 缁х画鎵цUSB瀛樺偍鍣ㄧ殑鐗╃悊鎵囧尯璇绘搷浣 */ +/* 杈撳嚭涓柇 */ + +#define CMD5H_DISK_WRITE 0x56 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鍚慤SB瀛樺偍鍣ㄥ啓鐗╃悊鎵囧尯 */ +/* 杈撳叆: LBA鐗╃悊鎵囧尯鍦板潃(鎬婚暱搴32浣, 浣庡瓧鑺傚湪鍓), 鎵囧尯鏁(01H~FFH) */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_WR_GO 0x57 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 缁х画鎵цUSB瀛樺偍鍣ㄧ殑鐗╃悊鎵囧尯鍐欐搷浣 */ +/* 杈撳嚭涓柇 */ + +/* ********************************************************************************************************************* */ +/* 杈呭姪鍛戒护(鎵嬪唽浜), 涓嶅お甯哥敤鎴栬呮槸涓轰簡涓嶤H375鍜孋H372鍏煎 */ + +#define CMD10_SET_USB_SPEED 0x04 /* 璁剧疆USB鎬荤嚎閫熷害, 鍦ㄦ瘡娆MD11_SET_USB_MODE璁剧疆USB宸ヤ綔妯″紡鏃朵細鑷姩鎭㈠鍒12Mbps鍏ㄩ */ +/* 杈撳叆: 鎬荤嚎閫熷害浠g爜 */ +/* 00H=12Mbps鍏ㄩ烣ullSpeed锛堥粯璁ゅ硷級, 01H=1.5Mbps锛堜粎淇敼棰戠巼锛, 02H=1.5Mbps浣庨烲owSpeed */ + +#define CMD11_GET_DEV_RATE 0x0A /* 涓绘満鏂瑰紡: 鑾峰彇褰撳墠杩炴帴鐨刄SB璁惧鐨勬暟鎹熺巼绫诲瀷 */ +/* 杈撳叆: 鏁版嵁07H */ +/* 杈撳嚭: 鏁版嵁閫熺巼绫诲瀷 */ +/* 浣4涓1鍒欐槸1.5Mbps浣庨烾SB璁惧, 鍚﹀垯鏄12Mbps鍏ㄩ烾SB璁惧 */ + +#define CMD11_GET_TOGGLE 0x0A /* 鑾峰彇OUT浜嬪姟鐨勫悓姝ョ姸鎬 */ +/* 杈撳叆: 鏁版嵁1AH */ +/* 杈撳嚭: 鍚屾鐘舵 */ +/* 浣4涓1鍒橭UT浜嬪姟鍚屾, 鍚﹀垯OUT浜嬪姟涓嶅悓姝 */ + +#define CMD11_READ_VAR8 0x0A /* 璇诲彇鎸囧畾鐨8浣嶆枃浠剁郴缁熷彉閲 */ +/* 杈撳叆: 鍙橀噺鍦板潃 */ +/* 杈撳嚭: 鏁版嵁 */ + +/*#define CMD11_GET_MAX_LUN = CMD11_READ_VAR8( VAR_UDISK_LUN )*/ /* 涓绘満鏂瑰紡: 鑾峰彇USB瀛樺偍鍣ㄦ渶澶у拰褰撳墠閫昏緫鍗曞厓鍙 */ + +#define CMD20_SET_RETRY 0x0B /* 涓绘満鏂瑰紡: 璁剧疆USB浜嬪姟鎿嶄綔鐨勯噸璇曟鏁 */ +/* 杈撳叆: 鏁版嵁25H, 閲嶈瘯娆℃暟 */ +/* 浣7涓0鍒欐敹鍒癗AK鏃朵笉閲嶈瘯, 浣7涓1浣6涓0鍒欐敹鍒癗AK鏃舵棤闄愰噸璇, 浣7涓1浣6涓1鍒欐敹鍒癗AK鏃舵渶澶氶噸璇3绉, 浣5~浣0涓鸿秴鏃跺悗鐨勯噸璇曟鏁 */ + +#define CMD20_WRITE_VAR8 0x0B /* 璁剧疆鎸囧畾鐨8浣嶆枃浠剁郴缁熷彉閲 */ +/* 杈撳叆: 鍙橀噺鍦板潃, 鏁版嵁 */ + +/*#define CMD20_SET_DISK_LUN = CMD20_WRITE_VAR8( VAR_UDISK_LUN )*/ /* 涓绘満鏂瑰紡: 璁剧疆USB瀛樺偍鍣ㄧ殑褰撳墠閫昏緫鍗曞厓鍙 */ + +#define CMD14_READ_VAR32 0x0C /* 璇诲彇鎸囧畾鐨32浣嶆枃浠剁郴缁熷彉閲 */ +/* 杈撳叆: 鍙橀噺鍦板潃 */ +/* 杈撳嚭: 鏁版嵁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + +#define CMD50_WRITE_VAR32 0x0D /* 璁剧疆鎸囧畾鐨32浣嶆枃浠剁郴缁熷彉閲 */ +/* 杈撳叆: 鍙橀噺鍦板潃, 鏁版嵁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + +#define CMD01_DELAY_100US 0x0F /* 寤舵椂100uS(涓插彛涓嶆敮鎸) */ +/* 杈撳嚭: 寤舵椂鏈熼棿杈撳嚭0,寤舵椂缁撴潫杈撳嚭闈0 */ + +#define CMD40_SET_USB_ID 0x12 /* 璁惧鏂瑰紡: 璁剧疆USB鍘傚晢VID鍜屼骇鍝丳ID */ +/* 杈撳叆: 鍘傚晢ID浣庡瓧鑺, 鍘傚晢ID楂樺瓧鑺, 浜у搧ID浣庡瓧鑺, 浜у搧ID楂樺瓧鑺 */ + +#define CMD10_SET_USB_ADDR 0x13 /* 璁剧疆USB鍦板潃 */ +/* 杈撳叆: 鍦板潃鍊 */ + +#define CMD01_TEST_CONNECT 0x16 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 妫鏌SB璁惧杩炴帴鐘舵 */ +/* 杈撳嚭: 鐘舵( USB_INT_CONNECT鎴朥SB_INT_DISCONNECT鎴朥SB_INT_USB_READY, 鍏跺畠鍊艰鏄庢搷浣滄湭瀹屾垚 ) */ + +#define CMD00_ABORT_NAK 0x17 /* 涓绘満鏂瑰紡: 鏀惧純褰撳墠NAK鐨勯噸璇 */ + +#define CMD10_SET_ENDP2 0x18 /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 璁剧疆USB绔偣0鐨勬帴鏀跺櫒 */ +/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ +/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ +/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000-灏辩华ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ + +#define CMD10_SET_ENDP3 0x19 /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 璁剧疆USB绔偣0鐨勫彂閫佸櫒 */ +/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ +/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ +/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000~1000-灏辩华ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ + +#define CMD10_SET_ENDP4 0x1A /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 璁剧疆USB绔偣1鐨勬帴鏀跺櫒 */ +/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ +/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ +/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000-灏辩华ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ + +#define CMD10_SET_ENDP5 0x1B /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 璁剧疆USB绔偣1鐨勫彂閫佸櫒 */ +/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ +/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ +/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000~1000-灏辩华ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ + +#define CMD10_SET_ENDP6 0x1C /* 璁剧疆USB绔偣2/涓绘満绔偣鐨勬帴鏀跺櫒 */ +/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ +/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ +/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000-灏辩华ACK, 1101-灏辩华浣嗕笉杩斿洖ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ + +#define CMD10_SET_ENDP7 0x1D /* 璁剧疆USB绔偣2/涓绘満绔偣鐨勫彂閫佸櫒 */ +/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ +/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ +/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000-灏辩华ACK, 1101-灏辩华浣嗘棤椤诲簲绛, 1110-姝e繖NAK, 1111-閿欒STALL */ + +#define CMD00_DIRTY_BUFFER 0x25 /* 涓绘満鏂囦欢妯″紡: 娓呴櫎鍐呴儴鐨勭鐩樺拰鏂囦欢缂撳啿鍖 */ + +#define CMD10_WR_USB_DATA3 0x29 /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 鍚慤SB绔偣0鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ +/* 杈撳叆: 闀垮害, 鏁版嵁娴 */ + +#define CMD10_WR_USB_DATA5 0x2A /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 鍚慤SB绔偣1鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ +/* 杈撳叆: 闀垮害, 鏁版嵁娴 */ + +/* ********************************************************************************************************************* */ +/* 杈呭姪鍛戒护(鎵嬪唽浜), 涓嶅お甯哥敤鎴栬呮槸涓轰簡涓嶤H375鍜孋H372鍏煎, 浠ヤ笅鍛戒护鎬绘槸鍦ㄦ搷浣滅粨鏉熸椂浜х敓涓柇閫氱煡, 骞朵笖鎬绘槸娌℃湁杈撳嚭鏁版嵁 */ + +#define CMD1H_CLR_STALL 0x41 /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-娓呴櫎绔偣閿欒 */ +/* 杈撳叆: 绔偣鍙 */ +/* 杈撳嚭涓柇 */ + +#define CMD1H_SET_ADDRESS 0x45 /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-璁剧疆USB鍦板潃 */ +/* 杈撳叆: 鍦板潃鍊 */ +/* 杈撳嚭涓柇 */ + +#define CMD1H_GET_DESCR 0x46 /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-鑾峰彇鎻忚堪绗 */ +/* 杈撳叆: 鎻忚堪绗︾被鍨 */ +/* 杈撳嚭涓柇 */ + +#define CMD1H_SET_CONFIG 0x49 /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-璁剧疆USB閰嶇疆 */ +/* 杈撳叆: 閰嶇疆鍊 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_AUTO_SETUP 0x4D /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鑷姩閰嶇疆USB璁惧 */ +/* 杈撳嚭涓柇 */ + +#define CMD2H_ISSUE_TKN_X 0x4E /* 涓绘満鏂瑰紡: 鍙戝嚭鍚屾浠ょ墝, 鎵ц浜嬪姟, 璇ュ懡浠ゅ彲浠f浛 CMD10_SET_ENDP6/CMD10_SET_ENDP7 + CMD1H_ISSUE_TOKEN */ +/* 杈撳叆: 鍚屾鏍囧織, 浜嬪姟灞炴 */ +/* 鍚屾鏍囧織鐨勪綅7涓轰富鏈虹鐐笽N鐨勫悓姝ヨЕ鍙戜綅, 浣6涓轰富鏈虹鐐筄UT鐨勫悓姝ヨЕ鍙戜綅, 浣5~浣0蹇呴』涓0 */ +/* 浜嬪姟灞炴х殑浣4浣嶆槸浠ょ墝, 楂4浣嶆槸绔偣鍙 */ +/* 杈撳嚭涓柇 */ + +#define CMD1H_ISSUE_TOKEN 0x4F /* 涓绘満鏂瑰紡: 鍙戝嚭浠ょ墝, 鎵ц浜嬪姟, 寤鸿鐢–MD2H_ISSUE_TKN_X鍛戒护 */ +/* 杈撳叆: 浜嬪姟灞炴 */ +/* 浣4浣嶆槸浠ょ墝, 楂4浣嶆槸绔偣鍙 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_INIT 0x51 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鍒濆鍖朥SB瀛樺偍鍣 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_RESET 0x52 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鎺у埗浼犺緭-澶嶄綅USB瀛樺偍鍣 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_SIZE 0x53 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鑾峰彇USB瀛樺偍鍣ㄧ殑瀹归噺 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_INQUIRY 0x58 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鏌ヨUSB瀛樺偍鍣ㄧ壒鎬 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_READY 0x59 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 妫鏌SB瀛樺偍鍣ㄥ氨缁 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_R_SENSE 0x5A /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_RD_DISK_SEC 0x5B /* 涓绘満鏂囦欢妯″紡: 浠庣鐩樿鍙栦竴涓墖鍖虹殑鏁版嵁鍒板唴閮ㄧ紦鍐插尯 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_WR_DISK_SEC 0x5C /* 涓绘満鏂囦欢妯″紡: 灏嗗唴閮ㄧ紦鍐插尯鐨勪竴涓墖鍖虹殑鏁版嵁鍐欏叆纾佺洏 */ +/* 杈撳嚭涓柇 */ + +#define CMD0H_DISK_MAX_LUN 0x5D /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-鑾峰彇USB瀛樺偍鍣ㄦ渶澶ч昏緫鍗曞厓鍙 */ +/* 杈撳嚭涓柇 */ + +/* ********************************************************************************************************************* */ +/* 浠ヤ笅瀹氫箟鍙槸涓轰簡鍏煎CH375鐨処NCLUDE鏂囦欢涓殑鍛戒护鍚嶇О鏍煎紡 */ + +#ifndef _NO_CH375_COMPATIBLE_ +#define CMD_GET_IC_VER CMD01_GET_IC_VER +#define CMD_SET_BAUDRATE CMD21_SET_BAUDRATE +#define CMD_ENTER_SLEEP CMD00_ENTER_SLEEP +#define CMD_RESET_ALL CMD00_RESET_ALL +#define CMD_CHECK_EXIST CMD11_CHECK_EXIST +#define CMD_CHK_SUSPEND CMD20_CHK_SUSPEND +#define CMD_SET_SDO_INT CMD20_SET_SDO_INT +#define CMD_GET_FILE_SIZE CMD14_GET_FILE_SIZE +#define CMD_SET_FILE_SIZE CMD50_SET_FILE_SIZE +#define CMD_SET_USB_MODE CMD11_SET_USB_MODE +#define CMD_GET_STATUS CMD01_GET_STATUS +#define CMD_UNLOCK_USB CMD00_UNLOCK_USB +#define CMD_RD_USB_DATA0 CMD01_RD_USB_DATA0 +#define CMD_RD_USB_DATA CMD01_RD_USB_DATA +#define CMD_WR_USB_DATA7 CMD10_WR_USB_DATA7 +#define CMD_WR_HOST_DATA CMD10_WR_HOST_DATA +#define CMD_WR_REQ_DATA CMD01_WR_REQ_DATA +#define CMD_WR_OFS_DATA CMD20_WR_OFS_DATA +#define CMD_SET_FILE_NAME CMD10_SET_FILE_NAME +#define CMD_DISK_CONNECT CMD0H_DISK_CONNECT +#define CMD_DISK_MOUNT CMD0H_DISK_MOUNT +#define CMD_FILE_OPEN CMD0H_FILE_OPEN +#define CMD_FILE_ENUM_GO CMD0H_FILE_ENUM_GO +#define CMD_FILE_CREATE CMD0H_FILE_CREATE +#define CMD_FILE_ERASE CMD0H_FILE_ERASE +#define CMD_FILE_CLOSE CMD1H_FILE_CLOSE +#define CMD_DIR_INFO_READ CMD1H_DIR_INFO_READ +#define CMD_DIR_INFO_SAVE CMD0H_DIR_INFO_SAVE +#define CMD_BYTE_LOCATE CMD4H_BYTE_LOCATE +#define CMD_BYTE_READ CMD2H_BYTE_READ +#define CMD_BYTE_RD_GO CMD0H_BYTE_RD_GO +#define CMD_BYTE_WRITE CMD2H_BYTE_WRITE +#define CMD_BYTE_WR_GO CMD0H_BYTE_WR_GO +#define CMD_DISK_CAPACITY CMD0H_DISK_CAPACITY +#define CMD_DISK_QUERY CMD0H_DISK_QUERY +#define CMD_DIR_CREATE CMD0H_DIR_CREATE +#define CMD_SEC_LOCATE CMD4H_SEC_LOCATE +#define CMD_SEC_READ CMD1H_SEC_READ +#define CMD_SEC_WRITE CMD1H_SEC_WRITE +#define CMD_DISK_BOC_CMD CMD0H_DISK_BOC_CMD +#define CMD_DISK_READ CMD5H_DISK_READ +#define CMD_DISK_RD_GO CMD0H_DISK_RD_GO +#define CMD_DISK_WRITE CMD5H_DISK_WRITE +#define CMD_DISK_WR_GO CMD0H_DISK_WR_GO +#define CMD_SET_USB_SPEED CMD10_SET_USB_SPEED +#define CMD_GET_DEV_RATE CMD11_GET_DEV_RATE +#define CMD_GET_TOGGLE CMD11_GET_TOGGLE +#define CMD_READ_VAR8 CMD11_READ_VAR8 +#define CMD_SET_RETRY CMD20_SET_RETRY +#define CMD_WRITE_VAR8 CMD20_WRITE_VAR8 +#define CMD_READ_VAR32 CMD14_READ_VAR32 +#define CMD_WRITE_VAR32 CMD50_WRITE_VAR32 +#define CMD_DELAY_100US CMD01_DELAY_100US +#define CMD_SET_USB_ID CMD40_SET_USB_ID +#define CMD_SET_USB_ADDR CMD10_SET_USB_ADDR +#define CMD_TEST_CONNECT CMD01_TEST_CONNECT +#define CMD_ABORT_NAK CMD00_ABORT_NAK +#define CMD_SET_ENDP2 CMD10_SET_ENDP2 +#define CMD_SET_ENDP3 CMD10_SET_ENDP3 +#define CMD_SET_ENDP4 CMD10_SET_ENDP4 +#define CMD_SET_ENDP5 CMD10_SET_ENDP5 +#define CMD_SET_ENDP6 CMD10_SET_ENDP6 +#define CMD_SET_ENDP7 CMD10_SET_ENDP7 +#define CMD_DIRTY_BUFFER CMD00_DIRTY_BUFFER +#define CMD_WR_USB_DATA3 CMD10_WR_USB_DATA3 +#define CMD_WR_USB_DATA5 CMD10_WR_USB_DATA5 +#define CMD_CLR_STALL CMD1H_CLR_STALL +#define CMD_SET_ADDRESS CMD1H_SET_ADDRESS +#define CMD_GET_DESCR CMD1H_GET_DESCR +#define CMD_SET_CONFIG CMD1H_SET_CONFIG +#define CMD_AUTO_SETUP CMD0H_AUTO_SETUP +#define CMD_ISSUE_TKN_X CMD2H_ISSUE_TKN_X +#define CMD_ISSUE_TOKEN CMD1H_ISSUE_TOKEN +#define CMD_DISK_INIT CMD0H_DISK_INIT +#define CMD_DISK_RESET CMD0H_DISK_RESET +#define CMD_DISK_SIZE CMD0H_DISK_SIZE +#define CMD_DISK_INQUIRY CMD0H_DISK_INQUIRY +#define CMD_DISK_READY CMD0H_DISK_READY +#define CMD_DISK_R_SENSE CMD0H_DISK_R_SENSE +#define CMD_RD_DISK_SEC CMD0H_RD_DISK_SEC +#define CMD_WR_DISK_SEC CMD0H_WR_DISK_SEC +#define CMD_DISK_MAX_LUN CMD0H_DISK_MAX_LUN +#endif + +/* ********************************************************************************************************************* */ +/* 骞跺彛鏂瑰紡, 鐘舵佺鍙(璇诲懡浠ょ鍙)鐨勪綅瀹氫箟 */ +#ifndef PARA_STATE_INTB +#define PARA_STATE_INTB 0x80 /* 骞跺彛鏂瑰紡鐘舵佺鍙g殑浣7: 涓柇鏍囧織,浣庢湁鏁 */ +#define PARA_STATE_BUSY 0x10 /* 骞跺彛鏂瑰紡鐘舵佺鍙g殑浣4: 蹇欐爣蹇,楂樻湁鏁 */ +#endif + +/* ********************************************************************************************************************* */ +/* 涓插彛鏂瑰紡, 鎿嶄綔鍛戒护鍓嶇殑寮曞鍚屾鐮 */ +#ifndef SER_CMD_TIMEOUT +#define SER_CMD_TIMEOUT 32 /* 涓插彛鍛戒护瓒呮椂鏃堕棿, 鍗曚綅涓簃S, 鍚屾鐮佷箣闂村強鍚屾鐮佷笌鍛戒护鐮佷箣闂寸殑闂撮殧搴旇灏介噺鐭, 瓒呮椂鍚庣殑澶勭悊鏂瑰紡涓轰涪寮 */ +#define SER_SYNC_CODE1 0x57 /* 鍚姩鎿嶄綔鐨勭1涓覆鍙e悓姝ョ爜 */ +#define SER_SYNC_CODE2 0xAB /* 鍚姩鎿嶄綔鐨勭2涓覆鍙e悓姝ョ爜 */ +#endif + +/* ********************************************************************************************************************* */ +/* 鎿嶄綔鐘舵 */ + +#ifndef CMD_RET_SUCCESS +#define CMD_RET_SUCCESS 0x51 /* 鍛戒护鎿嶄綔鎴愬姛 */ +#define CMD_RET_ABORT 0x5F /* 鍛戒护鎿嶄綔澶辫触 */ +#endif + +/* ********************************************************************************************************************* */ +/* USB涓柇鐘舵 */ + +#ifndef USB_INT_EP0_SETUP + +/* 浠ヤ笅鐘舵佷唬鐮佷负鐗规畩浜嬩欢涓柇, 濡傛灉閫氳繃CMD20_CHK_SUSPEND鍚敤USB鎬荤嚎鎸傝捣妫鏌, 閭d箞蹇呴』澶勭悊USB鎬荤嚎鎸傝捣鍜岀潯鐪犲敜閱掔殑涓柇鐘舵 */ +#define USB_INT_USB_SUSPEND 0x05 /* USB鎬荤嚎鎸傝捣浜嬩欢 */ +#define USB_INT_WAKE_UP 0x06 /* 浠庣潯鐪犱腑琚敜閱掍簨浠 */ + +/* 浠ヤ笅鐘舵佷唬鐮0XH鐢ㄤ簬USB璁惧鏂瑰紡 */ +/* 鍐呯疆鍥轰欢妯″紡涓嬪彧闇瑕佸鐞: USB_INT_EP1_OUT, USB_INT_EP1_IN, USB_INT_EP2_OUT, USB_INT_EP2_IN */ +/* 浣7-浣4涓0000 */ +/* 浣3-浣2鎸囩ず褰撳墠浜嬪姟, 00=OUT, 10=IN, 11=SETUP */ +/* 浣1-浣0鎸囩ず褰撳墠绔偣, 00=绔偣0, 01=绔偣1, 10=绔偣2, 11=USB鎬荤嚎澶嶄綅 */ +#define USB_INT_EP0_SETUP 0x0C /* USB绔偣0鐨凷ETUP */ +#define USB_INT_EP0_OUT 0x00 /* USB绔偣0鐨凮UT */ +#define USB_INT_EP0_IN 0x08 /* USB绔偣0鐨処N */ +#define USB_INT_EP1_OUT 0x01 /* USB绔偣1鐨凮UT */ +#define USB_INT_EP1_IN 0x09 /* USB绔偣1鐨処N */ +#define USB_INT_EP2_OUT 0x02 /* USB绔偣2鐨凮UT */ +#define USB_INT_EP2_IN 0x0A /* USB绔偣2鐨処N */ +/* USB_INT_BUS_RESET 0x0000XX11B */ /* USB鎬荤嚎澶嶄綅 */ +#define USB_INT_BUS_RESET1 0x03 /* USB鎬荤嚎澶嶄綅 */ +#define USB_INT_BUS_RESET2 0x07 /* USB鎬荤嚎澶嶄綅 */ +#define USB_INT_BUS_RESET3 0x0B /* USB鎬荤嚎澶嶄綅 */ +#define USB_INT_BUS_RESET4 0x0F /* USB鎬荤嚎澶嶄綅 */ + +#endif + +/* 浠ヤ笅鐘舵佷唬鐮2XH-3XH鐢ㄤ簬USB涓绘満鏂瑰紡鐨勯氳澶辫触浠g爜 */ +/* 浣7-浣6涓00 */ +/* 浣5涓1 */ +/* 浣4鎸囩ず褰撳墠鎺ユ敹鐨勬暟鎹寘鏄惁鍚屾 */ +/* 浣3-浣0鎸囩ず瀵艰嚧閫氳澶辫触鏃禪SB璁惧鐨勫簲绛: 0010=ACK, 1010=NAK, 1110=STALL, 0011=DATA0, 1011=DATA1, XX00=瓒呮椂 */ +/* USB_INT_RET_ACK 0x001X0010B */ /* 閿欒:瀵逛簬IN浜嬪姟杩斿洖ACK */ +/* USB_INT_RET_NAK 0x001X1010B */ /* 閿欒:杩斿洖NAK */ +/* USB_INT_RET_STALL 0x001X1110B */ /* 閿欒:杩斿洖STALL */ +/* USB_INT_RET_DATA0 0x001X0011B */ /* 閿欒:瀵逛簬OUT/SETUP浜嬪姟杩斿洖DATA0 */ +/* USB_INT_RET_DATA1 0x001X1011B */ /* 閿欒:瀵逛簬OUT/SETUP浜嬪姟杩斿洖DATA1 */ +/* USB_INT_RET_TOUT 0x001XXX00B */ /* 閿欒:杩斿洖瓒呮椂 */ +/* USB_INT_RET_TOGX 0x0010X011B */ /* 閿欒:瀵逛簬IN浜嬪姟杩斿洖鏁版嵁涓嶅悓姝 */ +/* USB_INT_RET_PID 0x001XXXXXB */ /* 閿欒:鏈畾涔 */ + +/* 浠ヤ笅鐘舵佷唬鐮1XH鐢ㄤ簬USB涓绘満鏂瑰紡鐨勬搷浣滅姸鎬佷唬鐮 */ +#ifndef USB_INT_SUCCESS +#define USB_INT_SUCCESS 0x14 /* USB浜嬪姟鎴栬呬紶杈撴搷浣滄垚鍔 */ +#define USB_INT_CONNECT 0x15 /* 妫娴嬪埌USB璁惧杩炴帴浜嬩欢, 鍙兘鏄柊杩炴帴鎴栬呮柇寮鍚庨噸鏂拌繛鎺 */ +#define USB_INT_DISCONNECT 0x16 /* 妫娴嬪埌USB璁惧鏂紑浜嬩欢 */ +#define USB_INT_BUF_OVER 0x17 /* USB浼犺緭鐨勬暟鎹湁璇垨鑰呮暟鎹お澶氱紦鍐插尯婧㈠嚭 */ +#define USB_INT_USB_READY 0x18 /* USB璁惧宸茬粡琚垵濮嬪寲(宸茬粡鍒嗛厤USB鍦板潃) */ +#define USB_INT_DISK_READ 0x1D /* USB瀛樺偍鍣ㄨ姹傛暟鎹鍑 */ +#define USB_INT_DISK_WRITE 0x1E /* USB瀛樺偍鍣ㄨ姹傛暟鎹啓鍏 */ +#define USB_INT_DISK_ERR 0x1F /* USB瀛樺偍鍣ㄦ搷浣滃け璐 */ +#endif + +/* 浠ヤ笅鐘舵佷唬鐮佺敤浜庝富鏈烘枃浠舵ā寮忎笅鐨勬枃浠剁郴缁熼敊璇爜 */ +#ifndef ERR_DISK_DISCON +#define ERR_DISK_DISCON 0x82 /* 纾佺洏灏氭湭杩炴帴,鍙兘纾佺洏宸茬粡鏂紑 */ +#define ERR_LARGE_SECTOR 0x84 /* 纾佺洏鐨勬墖鍖哄お澶,鍙敮鎸佹瘡鎵囧尯512瀛楄妭 */ +#define ERR_TYPE_ERROR 0x92 /* 纾佺洏鍒嗗尯绫诲瀷涓嶆敮鎸,鍙敮鎸丗AT12/FAT16/BigDOS/FAT32,闇瑕佺敱纾佺洏绠$悊宸ュ叿閲嶆柊鍒嗗尯 */ +#define ERR_BPB_ERROR 0xA1 /* 纾佺洏灏氭湭鏍煎紡鍖,鎴栬呭弬鏁伴敊璇,闇瑕佺敱WINDOWS閲囩敤榛樿鍙傛暟閲嶆柊鏍煎紡鍖 */ +#define ERR_DISK_FULL 0xB1 /* 纾佺洏鏂囦欢澶弧,鍓╀綑绌洪棿澶皯鎴栬呭凡缁忔病鏈,闇瑕佺鐩樻暣鐞 */ +#define ERR_FDT_OVER 0xB2 /* 鐩綍(鏂囦欢澶)鍐呮枃浠跺お澶,娌℃湁绌洪棽鐨勭洰褰曢」,FAT12/FAT16鏍圭洰褰曚笅鐨勬枃浠舵暟搴旇灏戜簬512涓,闇瑕佺鐩樻暣鐞 */ +#define ERR_FILE_CLOSE 0xB4 /* 鏂囦欢宸茬粡鍏抽棴,濡傛灉闇瑕佷娇鐢,搴旇閲嶆柊鎵撳紑鏂囦欢 */ +#define ERR_OPEN_DIR 0x41 /* 鎸囧畾璺緞鐨勭洰褰(鏂囦欢澶)琚墦寮 */ +#define ERR_MISS_FILE 0x42 /* 鎸囧畾璺緞鐨勬枃浠舵病鏈夋壘鍒,鍙兘鏄枃浠跺悕绉伴敊璇 */ +#define ERR_FOUND_NAME 0x43 /* 鎼滅储鍒扮浉鍖归厤鐨勬枃浠跺悕,鎴栬呮槸瑕佹眰鎵撳紑鐩綍(鏂囦欢澶)鑰屽疄闄呯粨鏋滃嵈鎵撳紑浜嗘枃浠 */ +/* 浠ヤ笅鏂囦欢绯荤粺閿欒鐮佺敤浜庢枃浠剁郴缁熷瓙绋嬪簭 */ +#define ERR_MISS_DIR 0xB3 /* 鎸囧畾璺緞鐨勬煇涓瓙鐩綍(鏂囦欢澶)娌℃湁鎵惧埌,鍙兘鏄洰褰曞悕绉伴敊璇 */ +#define ERR_LONG_BUF_OVER 0x48 /* 闀挎枃浠剁紦鍐插尯婧㈠嚭 */ +#define ERR_LONG_NAME_ERR 0x49 /* 鐭枃浠跺悕娌℃湁瀵瑰簲鐨勯暱鏂囦欢鍚嶆垨鑰呴暱鏂囦欢鍚嶉敊璇 */ +#define ERR_NAME_EXIST 0x4A /* 鍚屽悕鐨勭煭鏂囦欢宸茬粡瀛樺湪,寤鸿閲嶆柊鐢熸垚鍙﹀涓涓煭鏂囦欢鍚 */ +#endif + +/* ********************************************************************************************************************* */ +/* 浠ヤ笅鐘舵佷唬鐮佺敤浜庝富鏈烘枃浠舵ā寮忎笅鐨勭鐩樺強鏂囦欢鐘舵, VAR_DISK_STATUS */ +#ifndef DEF_DISK_UNKNOWN +#define DEF_DISK_UNKNOWN 0x00 /* 灏氭湭鍒濆鍖,鏈煡鐘舵 */ +#define DEF_DISK_DISCONN 0x01 /* 纾佺洏娌℃湁杩炴帴鎴栬呭凡缁忔柇寮 */ +#define DEF_DISK_CONNECT 0x02 /* 纾佺洏宸茬粡杩炴帴,浣嗘槸灏氭湭鍒濆鍖栨垨鑰呮棤娉曡瘑鍒纾佺洏 */ +#define DEF_DISK_MOUNTED 0x03 /* 纾佺洏宸茬粡鍒濆鍖栨垚鍔,浣嗘槸灏氭湭鍒嗘瀽鏂囦欢绯荤粺鎴栬呮枃浠剁郴缁熶笉鏀寔 */ +#define DEF_DISK_READY 0x10 /* 宸茬粡鍒嗘瀽纾佺洏鐨勬枃浠剁郴缁熷苟涓旇兘澶熸敮鎸 */ +#define DEF_DISK_OPEN_ROOT 0x12 /* 宸茬粡鎵撳紑鏍圭洰褰,浣跨敤鍚庡繀椤诲叧闂,娉ㄦ剰FAT12/FAT16鏍圭洰褰曟槸鍥哄畾闀垮害 */ +#define DEF_DISK_OPEN_DIR 0x13 /* 宸茬粡鎵撳紑瀛愮洰褰(鏂囦欢澶) */ +#define DEF_DISK_OPEN_FILE 0x14 /* 宸茬粡鎵撳紑鏂囦欢 */ +#endif + +/* ********************************************************************************************************************* */ +/* 鏂囦欢绯荤粺甯哥敤瀹氫箟 */ + +#ifndef DEF_SECTOR_SIZE +#define DEF_SECTOR_SIZE 512 /* U鐩樻垨鑰匰D鍗¢粯璁ょ殑鐗╃悊鎵囧尯鐨勫ぇ灏 */ +#endif + +#ifndef DEF_WILDCARD_CHAR +#define DEF_WILDCARD_CHAR 0x2A /* 璺緞鍚嶇殑閫氶厤绗 '*' */ +#define DEF_SEPAR_CHAR1 0x5C /* 璺緞鍚嶇殑鍒嗛殧绗 '\' */ +#define DEF_SEPAR_CHAR2 0x2F /* 璺緞鍚嶇殑鍒嗛殧绗 '/' */ +#define DEF_FILE_YEAR 2004 /* 榛樿鏂囦欢鏃ユ湡: 2004骞 */ +#define DEF_FILE_MONTH 1 /* 榛樿鏂囦欢鏃ユ湡: 1鏈 */ +#define DEF_FILE_DATE 1 /* 榛樿鏂囦欢鏃ユ湡: 1鏃 */ +#endif + +#ifndef ATTR_DIRECTORY + +/* FAT鏁版嵁鍖轰腑鏂囦欢鐩綍淇℃伅 */ +typedef struct _FAT_DIR_INFO { + UINT8 DIR_Name[11]; /* 00H,鏂囦欢鍚,鍏11瀛楄妭,涓嶈冻澶勫~绌烘牸 */ + UINT8 DIR_Attr; /* 0BH,鏂囦欢灞炴,鍙傝冨悗闈㈢殑璇存槑 */ + UINT8 DIR_NTRes; /* 0CH */ + UINT8 DIR_CrtTimeTenth; /* 0DH,鏂囦欢鍒涘缓鐨勬椂闂,浠0.1绉掑崟浣嶈鏁 */ + UINT16 DIR_CrtTime; /* 0EH,鏂囦欢鍒涘缓鐨勬椂闂 */ + UINT16 DIR_CrtDate; /* 10H,鏂囦欢鍒涘缓鐨勬棩鏈 */ + UINT16 DIR_LstAccDate; /* 12H,鏈杩戜竴娆″瓨鍙栨搷浣滅殑鏃ユ湡 */ + UINT16 DIR_FstClusHI; /* 14H */ + UINT16 DIR_WrtTime; /* 16H,鏂囦欢淇敼鏃堕棿,鍙傝冨墠闈㈢殑瀹廙AKE_FILE_TIME */ + UINT16 DIR_WrtDate; /* 18H,鏂囦欢淇敼鏃ユ湡,鍙傝冨墠闈㈢殑瀹廙AKE_FILE_DATE */ + UINT16 DIR_FstClusLO; /* 1AH */ + UINT32 DIR_FileSize; /* 1CH,鏂囦欢闀垮害 */ +} FAT_DIR_INFO, *P_FAT_DIR_INFO; /* 20H */ + +/* 鏂囦欢灞炴 */ +#define ATTR_READ_ONLY 0x01 /* 鏂囦欢涓哄彧璇诲睘鎬 */ +#define ATTR_HIDDEN 0x02 /* 鏂囦欢涓洪殣鍚睘鎬 */ +#define ATTR_SYSTEM 0x04 /* 鏂囦欢涓虹郴缁熷睘鎬 */ +#define ATTR_VOLUME_ID 0x08 /* 鍗锋爣 */ +#define ATTR_DIRECTORY 0x10 /* 瀛愮洰褰(鏂囦欢澶) */ +#define ATTR_ARCHIVE 0x20 /* 鏂囦欢涓哄瓨妗e睘鎬 */ +#define ATTR_LONG_NAME ( ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID ) /* 闀挎枃浠跺悕灞炴 */ +#define ATTR_LONG_NAME_MASK ( ATTR_LONG_NAME | ATTR_DIRECTORY | ATTR_ARCHIVE ) +/* 鏂囦欢灞炴 UINT8 */ +/* bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 */ +/* 鍙 闅 绯 鍗 鐩 瀛 鏈畾涔 */ +/* 璇 钘 缁 鏍 褰 妗 */ +/* 鏂囦欢鏃堕棿 UINT16 */ +/* Time = (Hour<<11) + (Minute<<5) + (Second>>1) */ +#define MAKE_FILE_TIME( h, m, s ) ( (h<<11) + (m<<5) + (s>>1) ) /* 鐢熸垚鎸囧畾鏃跺垎绉掔殑鏂囦欢鏃堕棿鏁版嵁 */ +/* 鏂囦欢鏃ユ湡 UINT16 */ +/* Date = ((Year-1980)<<9) + (Month<<5) + Day */ +#define MAKE_FILE_DATE( y, m, d ) ( ((y-1980)<<9) + (m<<5) + d ) /* 鐢熸垚鎸囧畾骞存湀鏃ョ殑鏂囦欢鏃ユ湡鏁版嵁 */ + +#define LONE_NAME_MAX_CHAR (255*2) /* 闀挎枃浠跺悕鏈澶氬瓧绗︽暟/瀛楄妭鏁 */ +#define LONG_NAME_PER_DIR (13*2) /* 闀挎枃浠跺悕鍦ㄦ瘡涓枃浠剁洰褰曚俊鎭粨鏋勪腑鐨勫瓧绗︽暟/瀛楄妭鏁 */ + +#endif + +/* ********************************************************************************************************************* */ +/* SCSI鍛戒护鍜屾暟鎹緭鍏ヨ緭鍑虹粨鏋 */ + +#ifndef SPC_CMD_INQUIRY + +/* SCSI鍛戒护鐮 */ +#define SPC_CMD_INQUIRY 0x12 +#define SPC_CMD_READ_CAPACITY 0x25 +#define SPC_CMD_READ10 0x28 +#define SPC_CMD_WRITE10 0x2A +#define SPC_CMD_TEST_READY 0x00 +#define SPC_CMD_REQUEST_SENSE 0x03 +#define SPC_CMD_MODESENSE6 0x1A +#define SPC_CMD_MODESENSE10 0x5A +#define SPC_CMD_START_STOP 0x1B + +/* BulkOnly鍗忚鐨勫懡浠ゅ潡 */ +typedef struct _BULK_ONLY_CBW { + UINT32 CBW_Sig; + UINT32 CBW_Tag; + UINT8 CBW_DataLen0; /* 08H,杈撳叆: 鏁版嵁浼犺緭闀垮害,瀵逛簬杈撳叆鏁版嵁鍏舵湁鏁堝兼槸0鍒48,瀵逛簬杈撳嚭鏁版嵁鍏舵湁鏁堝间负0鍒33 */ + UINT8 CBW_DataLen1; + UINT16 CBW_DataLen2; + UINT8 CBW_Flag; /* 0CH,杈撳叆: 浼犺緭鏂瑰悜绛夋爣蹇,浣7涓1鍒欒緭鍏ユ暟鎹,浣嶄负0鍒欒緭鍑烘暟鎹垨鑰呮病鏈夋暟鎹 */ + UINT8 CBW_LUN; + UINT8 CBW_CB_Len; /* 0EH,杈撳叆: 鍛戒护鍧楃殑闀垮害,鏈夋晥鍊兼槸1鍒16 */ + UINT8 CBW_CB_Buf[16]; /* 0FH,杈撳叆: 鍛戒护鍧,璇ョ紦鍐插尯鏈澶氫负16涓瓧鑺 */ +} BULK_ONLY_CBW, *P_BULK_ONLY_CBW; /* BulkOnly鍗忚鐨勫懡浠ゅ潡, 杈撳叆CBW缁撴瀯 */ + +/* INQUIRY鍛戒护鐨勮繑鍥炴暟鎹 */ +typedef struct _INQUIRY_DATA { + UINT8 DeviceType; /* 00H, 璁惧绫诲瀷 */ + UINT8 RemovableMedia; /* 01H, 浣7涓1璇存槑鏄Щ鍔ㄥ瓨鍌 */ + UINT8 Versions; /* 02H, 鍗忚鐗堟湰 */ + UINT8 DataFormatAndEtc; /* 03H, 鎸囧畾杩斿洖鏁版嵁鏍煎紡 */ + UINT8 AdditionalLength; /* 04H, 鍚庣画鏁版嵁鐨勯暱搴 */ + UINT8 Reserved1; + UINT8 Reserved2; + UINT8 MiscFlag; /* 07H, 涓浜涙帶鍒舵爣蹇 */ + UINT8 VendorIdStr[8]; /* 08H, 鍘傚晢淇℃伅 */ + UINT8 ProductIdStr[16]; /* 10H, 浜у搧淇℃伅 */ + UINT8 ProductRevStr[4]; /* 20H, 浜у搧鐗堟湰 */ +} INQUIRY_DATA, *P_INQUIRY_DATA; /* 24H */ + +/* REQUEST SENSE鍛戒护鐨勮繑鍥炴暟鎹 */ +typedef struct _SENSE_DATA { + UINT8 ErrorCode; /* 00H, 閿欒浠g爜鍙婃湁鏁堜綅 */ + UINT8 SegmentNumber; + UINT8 SenseKeyAndEtc; /* 02H, 涓婚敭鐮 */ + UINT8 Information0; + UINT8 Information1; + UINT8 Information2; + UINT8 Information3; + UINT8 AdditSenseLen; /* 07H, 鍚庣画鏁版嵁鐨勯暱搴 */ + UINT8 CmdSpecInfo[4]; + UINT8 AdditSenseCode; /* 0CH, 闄勫姞閿爜 */ + UINT8 AddSenCodeQual; /* 0DH, 璇︾粏鐨勯檮鍔犻敭鐮 */ + UINT8 FieldReplaUnit; + UINT8 SenseKeySpec[3]; +} SENSE_DATA, *P_SENSE_DATA; /* 12H */ + +#endif + +/* ********************************************************************************************************************* */ +/* 涓绘満鏂囦欢妯″紡涓嬬殑鏁版嵁杈撳叆鍜岃緭鍑虹粨鏋 */ + +#ifndef MAX_FILE_NAME_LEN + +#define MAX_FILE_NAME_LEN (13+1) /* 鏂囦欢鍚嶆渶澶ч暱搴,鏈澶ч暱搴︽槸1涓牴鐩綍绗+8涓富鏂囦欢鍚+1涓皬鏁扮偣+3涓被鍨嬪悕+缁撴潫绗=14 */ + +/* 鍛戒护鐨勮緭鍏ユ暟鎹拰杈撳嚭鏁版嵁 */ +typedef union _CH376_CMD_DATA { + struct { + UINT8 mBuffer[ MAX_FILE_NAME_LEN ]; + } Default; + + INQUIRY_DATA DiskMountInq; /* 杩斿洖: INQUIRY鍛戒护鐨勮繑鍥炴暟鎹 */ + /* CMD0H_DISK_MOUNT: 鍒濆鍖栫鐩樺苟娴嬭瘯纾佺洏鏄惁灏辩华,棣栨鎵ц鏃 */ + + FAT_DIR_INFO OpenDirInfo; /* 杩斿洖: 鏋氫妇鍒扮殑鏂囦欢鐩綍淇℃伅 */ + /* CMD0H_FILE_OPEN: 鏋氫妇鏂囦欢鍜岀洰褰(鏂囦欢澶) */ + + FAT_DIR_INFO EnumDirInfo; /* 杩斿洖: 鏋氫妇鍒扮殑鏂囦欢鐩綍淇℃伅 */ + /* CMD0H_FILE_ENUM_GO: 缁х画鏋氫妇鏂囦欢鍜岀洰褰(鏂囦欢澶) */ + + struct { + UINT8 mUpdateFileSz; /* 杈撳叆鍙傛暟: 鏄惁鍏佽鏇存柊鏂囦欢闀垮害, 0鍒欑姝㈡洿鏂伴暱搴 */ + } FileCLose; /* CMD1H_FILE_CLOSE: 鍏抽棴褰撳墠宸茬粡鎵撳紑鐨勬枃浠 */ + + struct { + UINT8 mDirInfoIndex; /* 杈撳叆鍙傛暟: 鎸囧畾闇瑕佽鍙栫殑鐩綍淇℃伅缁撴瀯鍦ㄦ墖鍖哄唴鐨勭储寮曞彿, 0FFH鍒欎负褰撳墠宸茬粡鎵撳紑鐨勬枃浠 */ + } DirInfoRead; /* CMD1H_DIR_INFO_READ: 璇诲彇鏂囦欢鐨勭洰褰曚俊鎭 */ + + union { + UINT32 mByteOffset; /* 杈撳叆鍙傛暟: 鍋忕Щ瀛楄妭鏁,浠ュ瓧鑺備负鍗曚綅鐨勫亸绉婚噺(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + UINT32 mSectorLba; /* 杩斿洖: 褰撳墠鏂囦欢鎸囬拡瀵瑰簲鐨勭粷瀵圭嚎鎬ф墖鍖哄彿,0FFFFFFFFH鍒欏凡鍒版枃浠跺熬(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + } ByteLocate; /* CMD4H_BYTE_LOCATE: 浠ュ瓧鑺備负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ + + struct { + UINT16 mByteCount; /* 杈撳叆鍙傛暟: 璇锋眰璇诲彇鐨勫瓧鑺傛暟(鎬婚暱搴16浣,浣庡瓧鑺傚湪鍓) */ + } ByteRead; /* CMD2H_BYTE_READ: 浠ュ瓧鑺備负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ + + struct { + UINT16 mByteCount; /* 杈撳叆鍙傛暟: 璇锋眰鍐欏叆鐨勫瓧鑺傛暟(鎬婚暱搴16浣,浣庡瓧鑺傚湪鍓) */ + } ByteWrite; /* CMD2H_BYTE_WRITE: 浠ュ瓧鑺備负鍗曚綅鍚戝綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ + + union { + UINT32 mSectorOffset; /* 杈撳叆鍙傛暟: 鍋忕Щ鎵囧尯鏁,浠ユ墖鍖轰负鍗曚綅鐨勫亸绉婚噺(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + UINT32 mSectorLba; /* 杩斿洖: 褰撳墠鏂囦欢鎸囬拡瀵瑰簲鐨勭粷瀵圭嚎鎬ф墖鍖哄彿,0FFFFFFFFH鍒欏凡鍒版枃浠跺熬(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + } SectorLocate; /* CMD4H_SEC_LOCATE: 浠ユ墖鍖轰负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ + + struct { + UINT8 mSectorCount; /* 杈撳叆鍙傛暟: 璇锋眰璇诲彇鐨勬墖鍖烘暟 */ + /* 杩斿洖: 鍏佽璇诲彇鐨勬墖鍖烘暟 */ + UINT8 mReserved1; + UINT8 mReserved2; + UINT8 mReserved3; + UINT32 mStartSector; /* 杩斿洖: 鍏佽璇诲彇鐨勬墖鍖哄潡鐨勮捣濮嬬粷瀵圭嚎鎬ф墖鍖哄彿(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + } SectorRead; /* CMD1H_SEC_READ: 浠ユ墖鍖轰负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ + + struct { + UINT8 mSectorCount; /* 杈撳叆鍙傛暟: 璇锋眰鍐欏叆鐨勬墖鍖烘暟 */ + /* 杩斿洖: 鍏佽鍐欏叆鐨勬墖鍖烘暟 */ + UINT8 mReserved1; + UINT8 mReserved2; + UINT8 mReserved3; + UINT32 mStartSector; /* 杩斿洖: 鍏佽鍐欏叆鐨勬墖鍖哄潡鐨勮捣濮嬬粷瀵圭嚎鎬ф墖鍖哄彿(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + } SectorWrite; /* CMD1H_SEC_WRITE: 浠ユ墖鍖轰负鍗曚綅鍦ㄥ綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ + + struct { + UINT32 mDiskSizeSec; /* 杩斿洖: 鏁翠釜鐗╃悊纾佺洏鐨勬绘墖鍖烘暟(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + } DiskCapacity; /* CMD0H_DISK_CAPACITY: 鏌ヨ纾佺洏鐗╃悊瀹归噺 */ + + struct { + UINT32 mTotalSector; /* 杩斿洖: 褰撳墠閫昏緫鐩樼殑鎬绘墖鍖烘暟(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + UINT32 mFreeSector; /* 杩斿洖: 褰撳墠閫昏緫鐩樼殑鍓╀綑鎵囧尯鏁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + UINT8 mDiskFat; /* 杩斿洖: 褰撳墠閫昏緫鐩樼殑FAT绫诲瀷,1-FAT12,2-FAT16,3-FAT32 */ + } DiskQuery; /* CMD_DiskQuery, 鏌ヨ纾佺洏淇℃伅 */ + + BULK_ONLY_CBW DiskBocCbw; /* 杈撳叆鍙傛暟: CBW鍛戒护缁撴瀯 */ + /* CMD0H_DISK_BOC_CMD: 瀵筓SB瀛樺偍鍣ㄦ墽琛孊ulkOnly浼犺緭鍗忚鐨勫懡浠 */ + + struct { + UINT8 mMaxLogicUnit; /* 杩斿洖: USB瀛樺偍鍣ㄧ殑鏈澶ч昏緫鍗曞厓鍙 */ + } DiskMaxLun; /* CMD0H_DISK_MAX_LUN: 鎺у埗浼犺緭-鑾峰彇USB瀛樺偍鍣ㄦ渶澶ч昏緫鍗曞厓鍙 */ + + INQUIRY_DATA DiskInitInq; /* 杩斿洖: INQUIRY鍛戒护鐨勮繑鍥炴暟鎹 */ + /* CMD0H_DISK_INIT: 鍒濆鍖朥SB瀛樺偍鍣 */ + + INQUIRY_DATA DiskInqData; /* 杩斿洖: INQUIRY鍛戒护鐨勮繑鍥炴暟鎹 */ + /* CMD0H_DISK_INQUIRY: 鏌ヨUSB瀛樺偍鍣ㄧ壒鎬 */ + + SENSE_DATA ReqSenseData; /* 杩斿洖: REQUEST SENSE鍛戒护鐨勮繑鍥炴暟鎹 */ + /* CMD0H_DISK_R_SENSE: 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ + + struct { + UINT32 mDiskSizeSec; /* 杩斿洖: 鏁翠釜鐗╃悊纾佺洏鐨勬绘墖鍖烘暟(鎬婚暱搴32浣,楂樺瓧鑺傚湪鍓) */ + } DiskSize; /* CMD0H_DISK_SIZE: 鑾峰彇USB瀛樺偍鍣ㄧ殑瀹归噺 */ + + struct { + UINT32 mStartSector; /* 杈撳叆鍙傛暟: LBA鎵囧尯鍦板潃(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + UINT8 mSectorCount; /* 杈撳叆鍙傛暟: 璇锋眰璇诲彇鐨勬墖鍖烘暟 */ + } DiskRead; /* CMD5H_DISK_READ: 浠嶶SB瀛樺偍鍣ㄨ鏁版嵁鍧(浠ユ墖鍖轰负鍗曚綅) */ + + struct { + UINT32 mStartSector; /* 杈撳叆鍙傛暟: LBA鎵囧尯鍦板潃(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + UINT8 mSectorCount; /* 杈撳叆鍙傛暟: 璇锋眰鍐欏叆鐨勬墖鍖烘暟 */ + } DiskWrite; /* CMD5H_DISK_WRITE: 鍚慤SB瀛樺偍鍣ㄥ啓鏁版嵁鍧(浠ユ墖鍖轰负鍗曚綅) */ +} CH376_CMD_DATA, *P_CH376_CMD_DATA; + +#endif + +/* ********************************************************************************************************************* */ +/* 涓绘満鏂囦欢妯″紡涓嬬殑鏂囦欢绯荤粺鍙橀噺鐨勫湴鍧 */ + +#ifndef VAR_FILE_SIZE + +/* 8浣/鍗曞瓧鑺傚彉閲 */ +#define VAR_SYS_BASE_INFO 0x20 /* 褰撳墠绯荤粺鐨勫熀鏈俊鎭 */ +/* 浣6鐢ㄤ簬鎸囩ずUSB瀛樺偍璁惧鐨勫瓙绫诲埆SubClass-Code, 浣6涓0鍒欒鏄庡瓙绫诲埆涓6, 浣6涓1鍒欒鏄庡瓙绫诲埆鏄潪6鐨勫叾瀹冨 */ +/* 浣5鐢ㄤ簬鎸囩ずUSB璁惧鏂瑰紡涓嬬殑USB閰嶇疆鐘舵佸拰USB涓绘満鏂瑰紡涓嬬殑USB璁惧杩炴帴鐘舵 */ +/* USB璁惧鏂瑰紡涓, 浣5涓1鍒橴SB閰嶇疆瀹屾垚, 浣5浣0鍒欏皻鏈厤缃 */ +/* USB涓绘満鏂瑰紡涓, 浣5涓1鍒橴SB绔彛瀛樺湪USB璁惧, 浣5浣0鍒橴SB绔彛娌℃湁USB璁惧 */ +/* 浣4鐢ㄤ簬鎸囩ずUSB璁惧鏂瑰紡涓嬬殑缂撳啿鍖洪攣瀹氱姸鎬, 浣4涓1鍒欒鏄嶶SB缂撳啿鍖哄浜庨攣瀹氱姸鎬, 浣6涓1鍒欒鏄庡凡缁忛噴鏀 */ +/* 鍏跺畠浣, 淇濈暀,璇峰嬁淇敼 */ +#define VAR_RETRY_TIMES 0x25 /* USB浜嬪姟鎿嶄綔鐨勯噸璇曟鏁 */ +/* 浣7涓0鍒欐敹鍒癗AK鏃朵笉閲嶈瘯, 浣7涓1浣6涓0鍒欐敹鍒癗AK鏃舵棤闄愰噸璇(鍙互鐢–MD_ABORT_NAK鍛戒护鏀惧純閲嶈瘯), 浣7涓1浣6涓1鍒欐敹鍒癗AK鏃舵渶澶氶噸璇3绉 */ +/* 浣5~浣0涓鸿秴鏃跺悗鐨勯噸璇曟鏁 */ +#define VAR_FILE_BIT_FLAG 0x26 /* 涓绘満鏂囦欢妯″紡涓嬬殑浣嶆爣蹇 */ +/* 浣1鍜屼綅0, 閫昏緫鐩樼殑FAT鏂囦欢绯荤粺鏍囧織, 00-FAT12, 01-FAT16, 10-FAT32, 11-闈炴硶 */ +/* 浣2, 褰撳墠缂撳啿鍖轰腑鐨凢AT琛ㄦ暟鎹槸鍚﹁淇敼鏍囧織, 0-鏈慨鏀, 1-宸蹭慨鏀 */ +/* 浣3, 鏂囦欢闀垮害闇瑕佷慨鏀规爣蹇, 褰撳墠鏂囦欢琚拷鍔犳暟鎹, 0-鏈拷鍔犳棤闇淇敼, 1-宸茶拷鍔犻渶瑕佷慨鏀 */ +/* 鍏跺畠浣, 淇濈暀,璇峰嬁淇敼 */ +#define VAR_DISK_STATUS 0x2B /* 涓绘満鏂囦欢妯″紡涓嬬殑纾佺洏鍙婃枃浠剁姸鎬 */ +#define VAR_SD_BIT_FLAG 0x30 /* 涓绘満鏂囦欢妯″紡涓婼D鍗$殑浣嶆爣蹇 */ +/* 浣0, SD鍗$増鏈, 0-鍙敮鎸丼D绗竴鐗,1-鏀寔SD绗簩鐗 */ +/* 浣1, 鑷姩璇嗗埆, 0-SD鍗, 1-MMC鍗 */ +/* 浣2, 鑷姩璇嗗埆, 0-鏍囧噯瀹归噺SD鍗, 1-澶у閲廠D鍗(HC-SD) */ +/* 浣4, ACMD41鍛戒护瓒呮椂 */ +/* 浣5, CMD1鍛戒护瓒呮椂 */ +/* 浣6, CMD58鍛戒护瓒呮椂 */ +/* 鍏跺畠浣, 淇濈暀,璇峰嬁淇敼 */ +#define VAR_UDISK_TOGGLE 0x31 /* USB瀛樺偍璁惧鐨凚ULK-IN/BULK-OUT绔偣鐨勫悓姝ユ爣蹇 */ +/* 浣7, Bulk-In绔偣鐨勫悓姝ユ爣蹇 */ +/* 浣6, Bulk-In绔偣鐨勫悓姝ユ爣蹇 */ +/* 浣5~浣0, 蹇呴』涓0 */ +#define VAR_UDISK_LUN 0x34 /* USB瀛樺偍璁惧鐨勯昏緫鍗曞厓鍙 */ +/* 浣7~浣4, USB瀛樺偍璁惧鐨勫綋鍓嶉昏緫鍗曞厓鍙,CH376鍒濆鍖朥SB瀛樺偍璁惧鍚,榛樿鏄闂0#閫昏緫鍗曞厓 */ +/* 浣3~浣0, USB瀛樺偍璁惧鐨勬渶澶ч昏緫鍗曞厓鍙,鍔1鍚庣瓑浜庨昏緫鍗曞厓鏁 */ +#define VAR_SEC_PER_CLUS 0x38 /* 閫昏緫鐩樼殑姣忕皣鎵囧尯鏁 */ +#define VAR_FILE_DIR_INDEX 0x3B /* 褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄦ墖鍖哄唴鐨勭储寮曞彿 */ +#define VAR_CLUS_SEC_OFS 0x3C /* 褰撳墠鏂囦欢鎸囬拡鍦ㄧ皣鍐呯殑鎵囧尯鍋忕Щ,涓0xFF鍒欐寚鍚戞枃浠舵湯灏,绨囩粨鏉 */ + +/* 32浣/4瀛楄妭鍙橀噺 */ +#define VAR_DISK_ROOT 0x44 /* 瀵逛簬FAT16鐩樹负鏍圭洰褰曞崰鐢ㄦ墖鍖烘暟,瀵逛簬FAT32鐩樹负鏍圭洰褰曡捣濮嬬皣鍙(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_DSK_TOTAL_CLUS 0x48 /* 閫昏緫鐩樼殑鎬荤皣鏁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_DSK_START_LBA 0x4C /* 閫昏緫鐩樼殑璧峰缁濆鎵囧尯鍙稬BA(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_DSK_DAT_START 0x50 /* 閫昏緫鐩樼殑鏁版嵁鍖哄煙鐨勮捣濮婰BA(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_LBA_BUFFER 0x54 /* 褰撳墠纾佺洏鏁版嵁缂撳啿鍖虹殑鏁版嵁瀵瑰簲鐨凩BA(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_LBA_CURRENT 0x58 /* 褰撳墠璇诲啓鐨勭鐩樿捣濮婰BA鍦板潃(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_FAT_DIR_LBA 0x5C /* 褰撳墠鏂囦欢鐩綍淇℃伅鎵鍦ㄧ殑鎵囧尯LBA鍦板潃(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_START_CLUSTER 0x60 /* 褰撳墠鏂囦欢鎴栬呯洰褰(鏂囦欢澶)鐨勮捣濮嬬皣鍙(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_CURRENT_CLUST 0x64 /* 褰撳墠鏂囦欢鐨勫綋鍓嶇皣鍙(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_FILE_SIZE 0x68 /* 褰撳墠鏂囦欢鐨勯暱搴(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_CURRENT_OFFSET 0x6C /* 褰撳墠鏂囦欢鎸囬拡,褰撳墠璇诲啓浣嶇疆鐨勫瓧鑺傚亸绉(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ + +#endif + +/* ********************************************************************************************************************* */ +/* 甯哥敤USB瀹氫箟 */ + +/* USB鐨勫寘鏍囪瘑PID, 涓绘満鏂瑰紡鍙兘鐢ㄥ埌 */ +#ifndef DEF_USB_PID_SETUP +#define DEF_USB_PID_NULL 0x00 /* 淇濈暀PID, 鏈畾涔 */ +#define DEF_USB_PID_SOF 0x05 +#define DEF_USB_PID_SETUP 0x0D +#define DEF_USB_PID_IN 0x09 +#define DEF_USB_PID_OUT 0x01 +#define DEF_USB_PID_ACK 0x02 +#define DEF_USB_PID_NAK 0x0A +#define DEF_USB_PID_STALL 0x0E +#define DEF_USB_PID_DATA0 0x03 +#define DEF_USB_PID_DATA1 0x0B +#define DEF_USB_PID_PRE 0x0C +#endif + +/* USB璇锋眰绫诲瀷, 澶栫疆鍥轰欢妯″紡鍙兘鐢ㄥ埌 */ +#ifndef DEF_USB_REQ_TYPE +#define DEF_USB_REQ_READ 0x80 /* 鎺у埗璇绘搷浣 */ +#define DEF_USB_REQ_WRITE 0x00 /* 鎺у埗鍐欐搷浣 */ +#define DEF_USB_REQ_TYPE 0x60 /* 鎺у埗璇锋眰绫诲瀷 */ +#define DEF_USB_REQ_STAND 0x00 /* 鏍囧噯璇锋眰 */ +#define DEF_USB_REQ_CLASS 0x20 /* 璁惧绫昏姹 */ +#define DEF_USB_REQ_VENDOR 0x40 /* 鍘傚晢璇锋眰 */ +#define DEF_USB_REQ_RESERVE 0x60 /* 淇濈暀璇锋眰 */ +#endif + +/* USB鏍囧噯璁惧璇锋眰, RequestType鐨勪綅6浣5=00(Standard), 澶栫疆鍥轰欢妯″紡鍙兘鐢ㄥ埌 */ +#ifndef DEF_USB_GET_DESCR +#define DEF_USB_CLR_FEATURE 0x01 +#define DEF_USB_SET_FEATURE 0x03 +#define DEF_USB_GET_STATUS 0x00 +#define DEF_USB_SET_ADDRESS 0x05 +#define DEF_USB_GET_DESCR 0x06 +#define DEF_USB_SET_DESCR 0x07 +#define DEF_USB_GET_CONFIG 0x08 +#define DEF_USB_SET_CONFIG 0x09 +#define DEF_USB_GET_INTERF 0x0A +#define DEF_USB_SET_INTERF 0x0B +#define DEF_USB_SYNC_FRAME 0x0C +#endif + +/* ********************************************************************************************************************* */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c new file mode 100644 index 000000000..75be34c2c --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c @@ -0,0 +1,978 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file k210_ch376.c + * @brief xidatong-riscv64 k210_ch376.c + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.10.10 + */ + +/* CH376鑺墖 鏂囦欢绯荤粺灞 V1.3 */ +/* 鎻愪緵鏂囦欢绯荤粺甯哥敤瀛愮▼搴,鎻愪緵鍛戒护鎵撳寘 */ +/* 涓嶄娇鐢ㄧ殑瀛愮▼搴忓彲浠ユ敞閲婃帀,浠庤岃妭绾﹀崟鐗囨満鐨勭▼搴廟OM绌洪棿鍜屾暟鎹甊AM绌洪棿 */ +/* 杩欓噷鐨勫瓙绋嬪簭鏄氳繃鎷彿涓殑鍙橀噺浼犻掑弬鏁,濡傛灉鍙傛暟杈冨,涓轰簡鑺傜害RAM,涔熷彲浠ュ弬鑰僀H375瀛愮▼搴忓簱鏀规垚閫氳繃鍚屼竴鍏ㄥ眬鍙橀噺/鑱斿悎缁撴瀯CH376_CMD_DATA浼犻 */ + +/* name 鍙傛暟鏄寚鐭枃浠跺悕, 鍙互鍖呮嫭鏍圭洰褰曠, 浣嗕笉鍚湁璺緞鍒嗛殧绗, 鎬婚暱搴︿笉瓒呰繃1+8+1+3+1瀛楄妭 */ +/* PathName 鍙傛暟鏄寚鍏ㄨ矾寰勭殑鐭枃浠跺悕, 鍖呮嫭鏍圭洰褰曠銆佸绾у瓙鐩綍鍙婅矾寰勫垎闅旂銆佹枃浠跺悕/鐩綍鍚 */ +/* LongName 鍙傛暟鏄寚闀挎枃浠跺悕, 浠NICODE灏忕椤哄簭缂栫爜, 浠ヤ袱涓0瀛楄妭缁撴潫, 浣跨敤闀挎枃浠跺悕瀛愮▼搴忓繀椤诲厛瀹氫箟鍏ㄥ眬缂撳啿鍖篏lobalBuf, 闀垮害涓嶅皬浜64瀛楄妭, 鍙互涓庡叾瀹冨瓙绋嬪簭鍏辩敤 */ + +/* 瀹氫箟 NO_DEFAULT_CH376_INT 鐢ㄤ簬绂佹榛樿鐨刉ait376Interrupt瀛愮▼搴,绂佹鍚,搴旂敤绋嬪簭蹇呴』鑷瀹氫箟涓涓悓鍚嶅瓙绋嬪簭 */ +/* 瀹氫箟 DEF_INT_TIMEOUT 鐢ㄤ簬璁剧疆榛樿鐨刉ait376Interrupt瀛愮▼搴忎腑鐨勭瓑寰呬腑鏂殑瓒呮椂鏃堕棿/寰幆璁℃暟鍊, 0鍒欎笉妫鏌ヨ秴鏃惰屼竴鐩寸瓑寰 */ +/* 瀹氫箟 EN_DIR_CREATE 鐢ㄤ簬鎻愪緵鏂板缓澶氱骇瀛愮洰褰曠殑瀛愮▼搴,榛樿鏄笉鎻愪緵 */ +/* 瀹氫箟 EN_DISK_QUERY 鐢ㄤ簬鎻愪緵纾佺洏瀹归噺鏌ヨ鍜屽墿浣欑┖闂存煡璇㈢殑瀛愮▼搴,榛樿鏄笉鎻愪緵 */ +/* 瀹氫箟 EN_SECTOR_ACCESS 鐢ㄤ簬鎻愪緵浠ユ墖鍖轰负鍗曚綅璇诲啓鏂囦欢鐨勫瓙绋嬪簭,榛樿鏄笉鎻愪緵 */ +/* 瀹氫箟 EN_LONG_NAME 鐢ㄤ簬鎻愪緵鏀寔闀挎枃浠跺悕鐨勫瓙绋嬪簭,榛樿鏄笉鎻愪緵 */ +/* 瀹氫箟 DEF_IC_V43_U 鐢ㄤ簬鍘绘帀鏀寔浣庣増鏈殑绋嬪簭浠g爜,浠呮敮鎸乂4.3鍙婁互涓婄増鏈殑CH376鑺墖,榛樿鏄敮鎸佷綆鐗堟湰 */ + +#if 0 +#define DEF_IC_V43_U 1 /* 鎺ㄨ崘瀹氫箟 DEF_IC_V43_U 浠ヤ紭鍖栦唬鐮 */ +#endif + +#include "k210_ch376.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ +static int fd; + +/* 涓插彛鏂瑰紡鏈敤鍒 */ +void xEndCH376Cmd(void) +{ +} + +void xWriteCH376Cmd( UINT8 cmd ) { /* 鍚慍H376鐨勫懡浠ょ鍙e啓鍏ュ懡浠,鍛ㄦ湡涓嶅皬浜2uS,濡傛灉鍗曠墖鏈鸿緝蹇垯寤舵椂 */ + UINT8 temp[3]; + temp[0] = 0x57; + temp[1] = 0xab; + temp[2] = cmd; + up_udelay(5); + write(fd, temp, 3); +} + +//鍐欐暟鎹 +void xWriteCH376Data( UINT8 dat ) { /* 鍚慍H376鐨勬暟鎹鍙e啓鍏ユ暟鎹,鍛ㄦ湡涓嶅皬浜1uS,濡傛灉鍗曠墖鏈鸿緝蹇垯寤舵椂 */ + UINT8 tmp = dat; + write(fd, &tmp, 1); + up_udelay(2); +} + +//璇绘暟鎹 +UINT8 xReadCH376Data(void) { + UINT32 i; + UINT8 data; + int res; + for(i=0;i<500000;i++) + { + res = read(fd, &data, 1); + if(res == 1) + { + return ((UINT8)data); + } + up_udelay(1); + } + return ERR_USB_UNKNOWN; +} + +UINT8 CH376ReadBlock( PUINT8 buf ) /* 浠庡綋鍓嶄富鏈虹鐐圭殑鎺ユ敹缂撳啿鍖鸿鍙栨暟鎹潡,杩斿洖闀垮害 */ +{ + UINT8 s, l; + xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); + s = l = xReadCH376Data( ); /* 闀垮害 */ + if ( l ) { + do { + *buf = xReadCH376Data( ); + buf ++; + } while ( -- l ); + } + xEndCH376Cmd( ); + return( s ); +} + +/* 鏌ヨCH376涓柇(INT#浣庣數骞) */ +UINT8 Query376Interrupt( void ) +{ + //浜х敓涓柇鐨勫悓鏃讹紝涓插彛浼氭敹鍒颁竴涓暟鎹紝鐩存帴璇诲嚭鏉ヤ涪鎺 + if(xReadCH376Data() == ERR_USB_UNKNOWN) return FALSE ; + else return TRUE ; +} + +/* CH376鍒濆鍖栦唬鐮 */ +UINT8 mInitCH376Host( void ) /* 鍒濆鍖朇H376 */ +{ + UINT8 res; + up_mdelay(50); /* 涓婄數鍚庤嚦灏戝欢鏃50ms鎿嶄綔 */ + fd = open("/dev/ttyS3", O_RDWR); + up_mdelay(600); + xWriteCH376Cmd( CMD11_CHECK_EXIST ); /* 娴嬭瘯鍗曠墖鏈轰笌CH376涔嬮棿鐨勯氳鎺ュ彛 */ + xWriteCH376Data( 0x65 ); + res = xReadCH376Data( ); + xEndCH376Cmd( ); + if ( res != 0x9A ) return( ERR_USB_UNKNOWN ); /* 閫氳鎺ュ彛涓嶆甯,鍙兘鍘熷洜鏈:鎺ュ彛杩炴帴寮傚父,鍏跺畠璁惧褰卞搷(鐗囬変笉鍞竴),涓插彛娉㈢壒鐜,涓鐩村湪澶嶄綅,鏅舵尟涓嶅伐浣 */ + + xWriteCH376Cmd( CMD11_SET_USB_MODE ); /* 璁惧USB宸ヤ綔妯″紡 */ + xWriteCH376Data( 0x06 ); + up_udelay( 20 ); + res = xReadCH376Data( ); + xEndCH376Cmd( ); + if ( res == CMD_RET_SUCCESS ) return( USB_INT_SUCCESS ); + else return( ERR_USB_UNKNOWN ); /* 璁剧疆妯″紡閿欒 */ + +} + +UINT8 CH376WriteReqBlock( PUINT8 buf ) /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡,杩斿洖闀垮害 */ +{ + UINT8 s, l; + xWriteCH376Cmd( CMD01_WR_REQ_DATA ); + s = l = xReadCH376Data( ); /* 闀垮害 */ + if ( l ) { + do { + xWriteCH376Data( *buf ); + buf ++; + } while ( -- l ); + } + xEndCH376Cmd( ); + return( s ); +} + +void CH376WriteHostBlock( PUINT8 buf, UINT8 len ) /* 鍚慤SB涓绘満绔偣鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ +{ + xWriteCH376Cmd( CMD10_WR_HOST_DATA ); + xWriteCH376Data( len ); /* 闀垮害 */ + if ( len ) { + do { + xWriteCH376Data( *buf ); + buf ++; + } while ( -- len ); + } + xEndCH376Cmd( ); +} + +void CH376WriteOfsBlock( PUINT8 buf, UINT8 ofs, UINT8 len ) /* 鍚戝唴閮ㄧ紦鍐插尯鎸囧畾鍋忕Щ鍦板潃鍐欏叆鏁版嵁鍧 */ +{ + xWriteCH376Cmd( CMD20_WR_OFS_DATA ); + xWriteCH376Data( ofs ); /* 鍋忕Щ鍦板潃 */ + xWriteCH376Data( len ); /* 闀垮害 */ + if ( len ) { + do { + xWriteCH376Data( *buf ); + buf ++; + } while ( -- len ); + } + xEndCH376Cmd( ); +} + +void CH376SetFileName( PUINT8 name ) /* 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ +{ + UINT8 c; +#ifndef DEF_IC_V43_U + UINT8 s; + xWriteCH376Cmd( CMD01_GET_IC_VER ); + if ( xReadCH376Data( ) < 0x43 ) { + if ( CH376ReadVar8( VAR_DISK_STATUS ) < DEF_DISK_READY ) { + xWriteCH376Cmd( CMD10_SET_FILE_NAME ); + xWriteCH376Data( 0 ); + s = CH376SendCmdWaitInt( CMD0H_FILE_OPEN ); + if ( s == USB_INT_SUCCESS ) { + s = CH376ReadVar8( 0xCF ); + if ( s ) { + CH376WriteVar32( 0x4C, CH376ReadVar32( 0x4C ) + ( (UINT16)s << 8 ) ); + CH376WriteVar32( 0x50, CH376ReadVar32( 0x50 ) + ( (UINT16)s << 8 ) ); + CH376WriteVar32( 0x70, 0 ); + } + } + } + } +#endif + xWriteCH376Cmd( CMD10_SET_FILE_NAME ); + c = *name; + xWriteCH376Data( c ); + while ( c ) { + name ++; + c = *name; + if ( c == DEF_SEPAR_CHAR1 || c == DEF_SEPAR_CHAR2 ) c = 0; /* 寮鸿灏嗘枃浠跺悕鎴 */ + xWriteCH376Data( c ); + } + xEndCH376Cmd( ); +} + +UINT32 CH376Read32bitDat( void ) /* 浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ +{ + UINT8 c0, c1, c2, c3; + c0 = xReadCH376Data( ); + c1 = xReadCH376Data( ); + c2 = xReadCH376Data( ); + c3 = xReadCH376Data( ); + xEndCH376Cmd( ); + return( c0 | (UINT16)c1 << 8 | (UINT32)c2 << 16 | (UINT32)c3 << 24 ); +} + +UINT8 CH376ReadVar8( UINT8 var ) /* 璇籆H376鑺墖鍐呴儴鐨8浣嶅彉閲 */ +{ + UINT8 c0; + xWriteCH376Cmd( CMD11_READ_VAR8 ); + xWriteCH376Data( var ); + c0 = xReadCH376Data( ); + xEndCH376Cmd( ); + return( c0 ); +} + +void CH376WriteVar8( UINT8 var, UINT8 dat ) /* 鍐機H376鑺墖鍐呴儴鐨8浣嶅彉閲 */ +{ + xWriteCH376Cmd( CMD20_WRITE_VAR8 ); + xWriteCH376Data( var ); + xWriteCH376Data( dat ); + xEndCH376Cmd( ); +} + +UINT32 CH376ReadVar32( UINT8 var ) /* 璇籆H376鑺墖鍐呴儴鐨32浣嶅彉閲 */ +{ + xWriteCH376Cmd( CMD14_READ_VAR32 ); + xWriteCH376Data( var ); + return( CH376Read32bitDat( ) ); /* 浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ +} + +void CH376WriteVar32( UINT8 var, UINT32 dat ) /* 鍐機H376鑺墖鍐呴儴鐨32浣嶅彉閲 */ +{ + xWriteCH376Cmd( CMD50_WRITE_VAR32 ); + xWriteCH376Data( var ); + xWriteCH376Data( (UINT8)dat ); + xWriteCH376Data( (UINT8)( (UINT16)dat >> 8 ) ); + xWriteCH376Data( (UINT8)( dat >> 16 ) ); + xWriteCH376Data( (UINT8)( dat >> 24 ) ); + xEndCH376Cmd( ); +} + +void CH376EndDirInfo( void ) /* 鍦ㄨ皟鐢–H376DirInfoRead鑾峰彇FAT_DIR_INFO缁撴瀯涔嬪悗搴旇閫氱煡CH376缁撴潫 */ +{ + CH376WriteVar8( 0x0D, 0x00 ); +} + +UINT32 CH376GetFileSize( void ) /* 璇诲彇褰撳墠鏂囦欢闀垮害 */ +{ + return( CH376ReadVar32( VAR_FILE_SIZE ) ); +} + +UINT8 CH376GetDiskStatus( void ) /* 鑾峰彇纾佺洏鍜屾枃浠剁郴缁熺殑宸ヤ綔鐘舵 */ +{ + return( CH376ReadVar8( VAR_DISK_STATUS ) ); +} + +UINT8 CH376GetIntStatus( void ) /* 鑾峰彇涓柇鐘舵佸苟鍙栨秷涓柇璇锋眰 */ +{ + UINT8 s; + xWriteCH376Cmd( CMD01_GET_STATUS ); + s = xReadCH376Data( ); + xEndCH376Cmd( ); + return( s ); +} + +#ifndef NO_DEFAULT_CH376_INT +UINT8 Wait376Interrupt( void ) /* 绛夊緟CH376涓柇(INT#浣庣數骞)锛岃繑鍥炰腑鏂姸鎬佺爜, 瓒呮椂鍒欒繑鍥濫RR_USB_UNKNOWN */ +{ +#ifdef DEF_INT_TIMEOUT +#if DEF_INT_TIMEOUT < 1 + while ( Query376Interrupt( ) == FALSE ); /* 涓鐩寸瓑涓柇 */ + return( CH376GetIntStatus( ) ); /* 妫娴嬪埌涓柇 */ +#else + UINT32 i; + for ( i = 0; i < DEF_INT_TIMEOUT; i ++ ) { /* 璁℃暟闃叉瓒呮椂 */ + if ( Query376Interrupt( ) ) return( CH376GetIntStatus( ) ); /* 妫娴嬪埌涓柇 */ +/* 鍦ㄧ瓑寰匔H376涓柇鐨勮繃绋嬩腑,鍙互鍋氫簺闇瑕佸強鏃跺鐞嗙殑鍏跺畠浜嬫儏 */ + } + return( ERR_USB_UNKNOWN ); /* 涓嶅簲璇ュ彂鐢熺殑鎯呭喌 */ +#endif +#else + UINT32 i; + for ( i = 0; i < 5000000; i ++ ) { /* 璁℃暟闃叉瓒呮椂,榛樿鐨勮秴鏃舵椂闂,涓庡崟鐗囨満涓婚鏈夊叧 */ + if ( Query376Interrupt( ) ) return( CH376GetIntStatus( ) ); /* 妫娴嬪埌涓柇 */ +/* 鍦ㄧ瓑寰匔H376涓柇鐨勮繃绋嬩腑,鍙互鍋氫簺闇瑕佸強鏃跺鐞嗙殑鍏跺畠浜嬫儏 */ + } + return( ERR_USB_UNKNOWN ); /* 涓嶅簲璇ュ彂鐢熺殑鎯呭喌 */ +#endif +} +#endif + +UINT8 CH376SendCmdWaitInt( UINT8 mCmd ) /* 鍙戝嚭鍛戒护鐮佸悗,绛夊緟涓柇 */ +{ + xWriteCH376Cmd( mCmd ); + xEndCH376Cmd( ); + return( Wait376Interrupt( ) ); +} + +UINT8 CH376SendCmdDatWaitInt( UINT8 mCmd, UINT8 mDat ) /* 鍙戝嚭鍛戒护鐮佸拰涓瀛楄妭鏁版嵁鍚,绛夊緟涓柇 */ +{ + xWriteCH376Cmd( mCmd ); + xWriteCH376Data( mDat ); + xEndCH376Cmd( ); + return( Wait376Interrupt( ) ); +} + +UINT8 CH376DiskReqSense( void ) /* 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ +{ + UINT8 s; + up_mdelay( 5 ); + s = CH376SendCmdWaitInt( CMD0H_DISK_R_SENSE ); + up_mdelay( 5 ); + return( s ); +} + +UINT8 CH376DiskConnect( void ) /* 妫鏌鐩樻槸鍚﹁繛鎺,涓嶆敮鎸丼D鍗 */ +{ + if ( Query376Interrupt( ) ) CH376GetIntStatus( ); /* 妫娴嬪埌涓柇 */ + return( CH376SendCmdWaitInt( CMD0H_DISK_CONNECT ) ); +} + +UINT8 CH376DiskMount( void ) /* 鍒濆鍖栫鐩樺苟娴嬭瘯纾佺洏鏄惁灏辩华 */ +{ + return( CH376SendCmdWaitInt( CMD0H_DISK_MOUNT ) ); +} + +UINT8 CH376FileOpen( PUINT8 name ) /* 鍦ㄦ牴鐩綍鎴栬呭綋鍓嶇洰褰曚笅鎵撳紑鏂囦欢鎴栬呯洰褰(鏂囦欢澶) */ +{ + CH376SetFileName( name ); /* 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ +#ifndef DEF_IC_V43_U + if ( name[0] == DEF_SEPAR_CHAR1 || name[0] == DEF_SEPAR_CHAR2 ) CH376WriteVar32( VAR_CURRENT_CLUST, 0 ); +#endif + return( CH376SendCmdWaitInt( CMD0H_FILE_OPEN ) ); +} + +UINT8 CH376FileCreate( PUINT8 name ) /* 鍦ㄦ牴鐩綍鎴栬呭綋鍓嶇洰褰曚笅鏂板缓鏂囦欢,濡傛灉鏂囦欢宸茬粡瀛樺湪閭d箞鍏堝垹闄 */ +{ + if ( name ) CH376SetFileName( name ); /* 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ + return( CH376SendCmdWaitInt( CMD0H_FILE_CREATE ) ); +} + +UINT8 CH376DirCreate( PUINT8 name ) /* 鍦ㄦ牴鐩綍涓嬫柊寤虹洰褰(鏂囦欢澶)骞舵墦寮,濡傛灉鐩綍宸茬粡瀛樺湪閭d箞鐩存帴鎵撳紑 */ +{ + CH376SetFileName( name ); /* 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ +#ifndef DEF_IC_V43_U + if ( name[0] == DEF_SEPAR_CHAR1 || name[0] == DEF_SEPAR_CHAR2 ) CH376WriteVar32( VAR_CURRENT_CLUST, 0 ); +#endif + return( CH376SendCmdWaitInt( CMD0H_DIR_CREATE ) ); +} + +UINT8 CH376SeparatePath( PUINT8 path ) /* 浠庤矾寰勪腑鍒嗙鍑烘渶鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰(鏂囦欢澶)鍚,杩斿洖鏈鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰曞悕鐨勫瓧鑺傚亸绉 */ +{ + PUINT8 pName; + for ( pName = path; *pName != 0; ++ pName ); /* 鍒版枃浠跺悕瀛楃涓茬粨鏉熶綅缃 */ + while ( *pName != DEF_SEPAR_CHAR1 && *pName != DEF_SEPAR_CHAR2 && pName != path ) pName --; /* 鎼滅储鍊掓暟绗竴涓矾寰勫垎闅旂 */ + if ( pName != path ) pName ++; /* 鎵惧埌浜嗚矾寰勫垎闅旂,鍒欎慨鏀规寚鍚戠洰鏍囨枃浠剁殑鏈鍚庝竴绾ф枃浠跺悕,璺宠繃鍓嶉潰鐨勫绾х洰褰曞悕鍙婅矾寰勫垎闅旂 */ + return( pName - path ); +} + +UINT8 CH376FileOpenDir( PUINT8 PathName, UINT8 StopName ) /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢鎴栬呯洰褰曠殑涓婄骇鐩綍,鏀寔澶氱骇鐩綍璺緞,鏀寔璺緞鍒嗛殧绗,璺緞闀垮害涓嶈秴杩255涓瓧绗 */ +/* StopName 鎸囧悜鏈鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰曞悕 */ +{ + UINT8 i, s; + s = 0; + i = 1; /* 璺宠繃鏈夊彲鑳界殑鏍圭洰褰曠 */ + while ( 1 ) { + while ( PathName[i] != DEF_SEPAR_CHAR1 && PathName[i] != DEF_SEPAR_CHAR2 && PathName[i] != 0 ) ++ i; /* 鎼滅储涓嬩竴涓矾寰勫垎闅旂鎴栬呰矾寰勭粨鏉熺 */ + if ( PathName[i] ) i ++; /* 鎵惧埌浜嗚矾寰勫垎闅旂,淇敼鎸囧悜鐩爣鏂囦欢鐨勬渶鍚庝竴绾ф枃浠跺悕 */ + else i = 0; /* 璺緞缁撴潫 */ + s = CH376FileOpen( &PathName[s] ); /* 鎵撳紑鏂囦欢鎴栬呯洰褰 */ + if ( i && i != StopName ) { /* 璺緞灏氭湭缁撴潫 */ + if ( s != ERR_OPEN_DIR ) { /* 鍥犱负鏄愮骇鎵撳紑,灏氭湭鍒拌矾寰勭粨鏉,鎵浠,濡傛灉涓嶆槸鎴愬姛鎵撳紑浜嗙洰褰,閭d箞璇存槑鏈夐棶棰 */ + if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); /* 涓棿璺緞蹇呴』鏄洰褰曞悕,濡傛灉鏄枃浠跺悕鍒欏嚭閿 */ + else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); /* 涓棿璺緞鐨勬煇涓瓙鐩綍娌℃湁鎵惧埌,鍙兘鏄洰褰曞悕绉伴敊璇 */ + else return( s ); /* 鎿嶄綔鍑洪敊 */ + } + s = i; /* 浠庝笅涓绾х洰褰曞紑濮嬬户缁 */ + } + else return( s ); /* 璺緞缁撴潫,USB_INT_SUCCESS涓烘垚鍔熸墦寮鏂囦欢,ERR_OPEN_DIR涓烘垚鍔熸墦寮鐩綍(鏂囦欢澶),鍏跺畠涓烘搷浣滃嚭閿 */ + } +} + +UINT8 CH376FileOpenPath( PUINT8 PathName ) /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢鎴栬呯洰褰(鏂囦欢澶),鏀寔澶氱骇鐩綍璺緞,鏀寔璺緞鍒嗛殧绗,璺緞闀垮害涓嶈秴杩255涓瓧绗 */ +{ + return( CH376FileOpenDir( PathName, 0xFF ) ); +} + +UINT8 CH376FileCreatePath( PUINT8 PathName ) /* 鏂板缓澶氱骇鐩綍涓嬬殑鏂囦欢,鏀寔澶氱骇鐩綍璺緞,鏀寔璺緞鍒嗛殧绗,璺緞闀垮害涓嶈秴杩255涓瓧绗 */ +{ + UINT8 s; + UINT8 Name; + Name = CH376SeparatePath( PathName ); /* 浠庤矾寰勪腑鍒嗙鍑烘渶鍚庝竴绾ф枃浠跺悕,杩斿洖鏈鍚庝竴绾ф枃浠跺悕鐨勫亸绉 */ + if ( Name ) { /* 鏄绾х洰褰 */ + s = CH376FileOpenDir( PathName, Name ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏈鍚庝竴绾х洰褰,鍗虫墦寮鏂板缓鏂囦欢鐨勪笂绾х洰褰 */ + if ( s != ERR_OPEN_DIR ) { /* 鍥犱负鏄墦寮涓婄骇鐩綍,鎵浠,濡傛灉涓嶆槸鎴愬姛鎵撳紑浜嗙洰褰,閭d箞璇存槑鏈夐棶棰 */ + if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); /* 涓棿璺緞蹇呴』鏄洰褰曞悕,濡傛灉鏄枃浠跺悕鍒欏嚭閿 */ + else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); /* 涓棿璺緞鐨勬煇涓瓙鐩綍娌℃湁鎵惧埌,鍙兘鏄洰褰曞悕绉伴敊璇 */ + else return( s ); /* 鎿嶄綔鍑洪敊 */ + } + } + return( CH376FileCreate( &PathName[Name] ) ); /* 鍦ㄦ牴鐩綍鎴栬呭綋鍓嶇洰褰曚笅鏂板缓鏂囦欢 */ +} + +#ifdef EN_DIR_CREATE +UINT8 CH376DirCreatePath( PUINT8 PathName ) /* 鏂板缓澶氱骇鐩綍涓嬬殑鐩綍(鏂囦欢澶)骞舵墦寮,鏀寔澶氱骇鐩綍璺緞,鏀寔璺緞鍒嗛殧绗,璺緞闀垮害涓嶈秴杩255涓瓧绗 */ +{ + UINT8 s; + UINT8 Name; + UINT8 ClustBuf[4]; + Name = CH376SeparatePath( PathName ); /* 浠庤矾寰勪腑鍒嗙鍑烘渶鍚庝竴绾х洰褰曞悕,杩斿洖鏈鍚庝竴绾ф枃浠跺悕鐨勫亸绉 */ + if ( Name ) { /* 鏄绾х洰褰 */ + s = CH376FileOpenDir( PathName, Name ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏈鍚庝竴绾х洰褰,鍗虫墦寮鏂板缓鐩綍鐨勪笂绾х洰褰 */ + if ( s != ERR_OPEN_DIR ) { /* 鍥犱负鏄墦寮涓婄骇鐩綍,鎵浠,濡傛灉涓嶆槸鎴愬姛鎵撳紑浜嗙洰褰,閭d箞璇存槑鏈夐棶棰 */ + if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); /* 涓棿璺緞蹇呴』鏄洰褰曞悕,濡傛灉鏄枃浠跺悕鍒欏嚭閿 */ + else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); /* 涓棿璺緞鐨勬煇涓瓙鐩綍娌℃湁鎵惧埌,鍙兘鏄洰褰曞悕绉伴敊璇 */ + else return( s ); /* 鎿嶄綔鍑洪敊 */ + } + xWriteCH376Cmd( CMD14_READ_VAR32 ); + xWriteCH376Data( VAR_START_CLUSTER ); /* 涓婄骇鐩綍鐨勮捣濮嬬皣鍙 */ + for ( s = 0; s != 4; s ++ ) ClustBuf[ s ] = xReadCH376Data( ); + xEndCH376Cmd( ); + s = CH376DirCreate( &PathName[Name] ); /* 鍦ㄥ綋鍓嶇洰褰曚笅鏂板缓鐩綍 */ + if ( s != USB_INT_SUCCESS ) return( s ); + CH376WriteVar32( VAR_FILE_SIZE, sizeof(FAT_DIR_INFO) * 2 ); + s = CH376ByteLocate( sizeof(FAT_DIR_INFO) + STRUCT_OFFSET( FAT_DIR_INFO, DIR_FstClusHI ) ); /* 绉诲姩鏂囦欢鎸囬拡 */ + if ( s != USB_INT_SUCCESS ) return( s ); + s = CH376ByteWrite( &ClustBuf[2], 2, NULL ); /* 鍐欏叆涓婄骇鐩綍鐨勮捣濮嬬皣鍙风殑楂16浣 */ + if ( s != USB_INT_SUCCESS ) return( s ); + s = CH376ByteLocate( sizeof(FAT_DIR_INFO) + STRUCT_OFFSET( FAT_DIR_INFO, DIR_FstClusLO ) ); /* 绉诲姩鏂囦欢鎸囬拡 */ + if ( s != USB_INT_SUCCESS ) return( s ); + s = CH376ByteWrite( ClustBuf, 2, NULL ); /* 鍐欏叆涓婄骇鐩綍鐨勮捣濮嬬皣鍙风殑浣16浣 */ + if ( s != USB_INT_SUCCESS ) return( s ); + s = CH376ByteLocate( 0 ); /* 绉诲姩鏂囦欢鎸囬拡,鎭㈠鍒扮洰褰曞ご浣嶇疆 */ + if ( s != USB_INT_SUCCESS ) return( s ); + CH376WriteVar32( VAR_FILE_SIZE, 0 ); + return( s ); + } + else { /* 涓嶆槸澶氱骇鐩綍 */ + if ( PathName[0] == DEF_SEPAR_CHAR1 || PathName[0] == DEF_SEPAR_CHAR2 ) return( CH376DirCreate( PathName ) ); /* 鍦ㄦ牴鐩綍涓嬫柊寤虹洰褰 */ + else return( ERR_MISS_DIR ); /* 蹇呴』鎻愪緵瀹屾暣璺緞鎵嶈兘瀹炵幇鍦ㄥ綋鍓嶇洰褰曚笅鏂板缓鐩綍 */ + } +} +#endif + +UINT8 CH376FileErase( PUINT8 PathName ) /* 鍒犻櫎鏂囦欢,濡傛灉宸茬粡鎵撳紑鍒欑洿鎺ュ垹闄,鍚﹀垯瀵逛簬鏂囦欢浼氬厛鎵撳紑鍐嶅垹闄,鏀寔澶氱骇鐩綍璺緞 */ +{ + UINT8 s; + if ( PathName ) { /* 鏂囦欢灏氭湭鎵撳紑 */ + for ( s = 1; PathName[s] != DEF_SEPAR_CHAR1 && PathName[s] != DEF_SEPAR_CHAR2 && PathName[s] != 0; ++ s ); /* 鎼滅储涓嬩竴涓矾寰勫垎闅旂鎴栬呰矾寰勭粨鏉熺 */ + if ( PathName[s] ) { /* 鏈夎矾寰勫垎闅旂,鏄绾х洰褰曚笅鐨勬枃浠舵垨鑰呯洰褰 */ + s = CH376FileOpenPath( PathName ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢鎴栬呯洰褰 */ + if ( s != USB_INT_SUCCESS && s != ERR_OPEN_DIR ) return( s ); /* 鎿嶄綔鍑洪敊 */ + } + else CH376SetFileName( PathName ); /* 娌℃湁璺緞鍒嗛殧绗,鏄牴鐩綍鎴栬呭綋鍓嶇洰褰曚笅鐨勬枃浠舵垨鑰呯洰褰,璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ + } + return( CH376SendCmdWaitInt( CMD0H_FILE_ERASE ) ); +} + +UINT8 CH376FileClose( UINT8 UpdateSz ) /* 鍏抽棴褰撳墠宸茬粡鎵撳紑鐨勬枃浠舵垨鑰呯洰褰(鏂囦欢澶) */ +{ + return( CH376SendCmdDatWaitInt( CMD1H_FILE_CLOSE, UpdateSz ) ); +} + +UINT8 CH376DirInfoRead( void ) /* 璇诲彇褰撳墠鏂囦欢鐨勭洰褰曚俊鎭 */ +{ + return( CH376SendCmdDatWaitInt( CMD1H_DIR_INFO_READ, 0xFF ) ); +} + +UINT8 CH376DirInfoSave( void ) /* 淇濆瓨鏂囦欢鐨勭洰褰曚俊鎭 */ +{ + return( CH376SendCmdWaitInt( CMD0H_DIR_INFO_SAVE ) ); +} + +UINT8 CH376ByteLocate( UINT32 offset ) /* 浠ュ瓧鑺備负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ +{ + xWriteCH376Cmd( CMD4H_BYTE_LOCATE ); + xWriteCH376Data( (UINT8)offset ); + xWriteCH376Data( (UINT8)((UINT16)offset>>8) ); + xWriteCH376Data( (UINT8)(offset>>16) ); + xWriteCH376Data( (UINT8)(offset>>24) ); + xEndCH376Cmd( ); + return( Wait376Interrupt( ) ); +} + +UINT8 CH376ByteRead( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) /* 浠ュ瓧鑺備负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ +{ + UINT8 s; + xWriteCH376Cmd( CMD2H_BYTE_READ ); + xWriteCH376Data( (UINT8)ReqCount ); + xWriteCH376Data( (UINT8)(ReqCount>>8) ); + xEndCH376Cmd( ); + if ( RealCount ) *RealCount = 0; + while ( 1 ) { + s = Wait376Interrupt( ); + if ( s == USB_INT_DISK_READ ) { + s = CH376ReadBlock( buf ); /* 浠庡綋鍓嶄富鏈虹鐐圭殑鎺ユ敹缂撳啿鍖鸿鍙栨暟鎹潡,杩斿洖闀垮害 */ + xWriteCH376Cmd( CMD0H_BYTE_RD_GO ); + xEndCH376Cmd( ); + buf += s; + if ( RealCount ) *RealCount += s; + } + else return( s ); /* 閿欒 */ + } +} + +UINT8 CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) /* 浠ュ瓧鑺備负鍗曚綅鍚戝綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ +{ + UINT8 s; + xWriteCH376Cmd( CMD2H_BYTE_WRITE ); + xWriteCH376Data( (UINT8)ReqCount ); + xWriteCH376Data( (UINT8)(ReqCount>>8) ); + xEndCH376Cmd( ); + if ( RealCount ) *RealCount = 0; + while ( 1 ) { + s = Wait376Interrupt( ); + if ( s == USB_INT_DISK_WRITE ) { + s = CH376WriteReqBlock( buf ); /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡,杩斿洖闀垮害 */ + xWriteCH376Cmd( CMD0H_BYTE_WR_GO ); + xEndCH376Cmd( ); + buf += s; + if ( RealCount ) *RealCount += s; + } + else return( s ); /* 閿欒 */ + } +} + +#ifdef EN_DISK_QUERY + +UINT8 CH376DiskCapacity( PUINT32 DiskCap ) /* 鏌ヨ纾佺洏鐗╃悊瀹归噺,鎵囧尯鏁 */ +{ + UINT8 s; + s = CH376SendCmdWaitInt( CMD0H_DISK_CAPACITY ); + if ( s == USB_INT_SUCCESS ) { /* 鍙傝僀H376INC.H鏂囦欢涓瑿H376_CMD_DATA缁撴瀯鐨凞iskCapacity */ + xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); + xReadCH376Data( ); /* 闀垮害鎬绘槸sizeof(CH376_CMD_DATA.DiskCapacity) */ + *DiskCap = CH376Read32bitDat( ); /* CH376_CMD_DATA.DiskCapacity.mDiskSizeSec,浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ + } + else *DiskCap = 0; + return( s ); +} + +UINT8 CH376DiskQuery( PUINT32 DiskFre ) /* 鏌ヨ纾佺洏鍓╀綑绌洪棿淇℃伅,鎵囧尯鏁 */ +{ + UINT8 s; + UINT8 c0, c1, c2, c3; +#ifndef DEF_IC_V43_U + xWriteCH376Cmd( CMD01_GET_IC_VER ); + if ( xReadCH376Data( ) < 0x43 ) { + if ( CH376ReadVar8( VAR_DISK_STATUS ) >= DEF_DISK_READY ) CH376WriteVar8( VAR_DISK_STATUS, DEF_DISK_MOUNTED ); + } +#endif + s = CH376SendCmdWaitInt( CMD0H_DISK_QUERY ); + if ( s == USB_INT_SUCCESS ) { /* 鍙傝僀H376INC.H鏂囦欢涓瑿H376_CMD_DATA缁撴瀯鐨凞iskQuery */ + xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); + xReadCH376Data( ); /* 闀垮害鎬绘槸sizeof(CH376_CMD_DATA.DiskQuery) */ + xReadCH376Data( ); /* CH376_CMD_DATA.DiskQuery.mTotalSector */ + xReadCH376Data( ); + xReadCH376Data( ); + xReadCH376Data( ); + c0 = xReadCH376Data( ); /* CH376_CMD_DATA.DiskQuery.mFreeSector */ + c1 = xReadCH376Data( ); + c2 = xReadCH376Data( ); + c3 = xReadCH376Data( ); + *DiskFre = c0 | (UINT16)c1 << 8 | (UINT32)c2 << 16 | (UINT32)c3 << 24; + xReadCH376Data( ); /* CH376_CMD_DATA.DiskQuery.mDiskFat */ + xEndCH376Cmd( ); + } + else *DiskFre = 0; + return( s ); +} + +#endif + +UINT8 CH376SecLocate( UINT32 offset ) /* 浠ユ墖鍖轰负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ +{ + xWriteCH376Cmd( CMD4H_SEC_LOCATE ); + xWriteCH376Data( (UINT8)offset ); + xWriteCH376Data( (UINT8)((UINT16)offset>>8) ); + xWriteCH376Data( (UINT8)(offset>>16) ); + xWriteCH376Data( 0 ); /* 瓒呭嚭鏈澶ф枃浠跺昂瀵 */ + xEndCH376Cmd( ); + return( Wait376Interrupt( ) ); +} + +#ifdef EN_SECTOR_ACCESS + +UINT8 CH376DiskReadSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ) /* 浠嶶鐩樿鍙栧涓墖鍖虹殑鏁版嵁鍧楀埌缂撳啿鍖,涓嶆敮鎸丼D鍗 */ +/* iLbaStart 鏄噯澶囪鍙栫殑绾挎ц捣濮嬫墖鍖哄彿, iSectorCount 鏄噯澶囪鍙栫殑鎵囧尯鏁 */ +{ + UINT8 s, err; + UINT16 mBlockCount; + for ( err = 0; err != 3; ++ err ) { /* 鍑洪敊閲嶈瘯 */ + xWriteCH376Cmd( CMD5H_DISK_READ ); /* 浠嶶SB瀛樺偍鍣ㄨ鎵囧尯 */ + xWriteCH376Data( (UINT8)iLbaStart ); /* LBA鐨勬渶浣8浣 */ + xWriteCH376Data( (UINT8)( (UINT16)iLbaStart >> 8 ) ); + xWriteCH376Data( (UINT8)( iLbaStart >> 16 ) ); + xWriteCH376Data( (UINT8)( iLbaStart >> 24 ) ); /* LBA鐨勬渶楂8浣 */ + xWriteCH376Data( iSectorCount ); /* 鎵囧尯鏁 */ + xEndCH376Cmd( ); + for ( mBlockCount = iSectorCount * DEF_SECTOR_SIZE / CH376_DAT_BLOCK_LEN; mBlockCount != 0; -- mBlockCount ) { /* 鏁版嵁鍧楄鏁 */ + s = Wait376Interrupt( ); /* 绛夊緟涓柇骞惰幏鍙栫姸鎬 */ + if ( s == USB_INT_DISK_READ ) { /* USB瀛樺偍鍣ㄨ鏁版嵁鍧,璇锋眰鏁版嵁璇诲嚭 */ + s = CH376ReadBlock( buf ); /* 浠庡綋鍓嶄富鏈虹鐐圭殑鎺ユ敹缂撳啿鍖鸿鍙栨暟鎹潡,杩斿洖闀垮害 */ + xWriteCH376Cmd( CMD0H_DISK_RD_GO ); /* 缁х画鎵цUSB瀛樺偍鍣ㄧ殑璇绘搷浣 */ + xEndCH376Cmd( ); + buf += s; + } + else break; /* 杩斿洖閿欒鐘舵 */ + } + if ( mBlockCount == 0 ) { + s = Wait376Interrupt( ); /* 绛夊緟涓柇骞惰幏鍙栫姸鎬 */ + if ( s == USB_INT_SUCCESS ) return( USB_INT_SUCCESS ); /* 鎿嶄綔鎴愬姛 */ + } + if ( s == USB_INT_DISCONNECT ) return( s ); /* U鐩樿绉婚櫎 */ + CH376DiskReqSense( ); /* 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ + } + return( s ); /* 鎿嶄綔澶辫触 */ +} + +UINT8 CH376DiskWriteSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ) /* 灏嗙紦鍐插尯涓殑澶氫釜鎵囧尯鐨勬暟鎹潡鍐欏叆U鐩,涓嶆敮鎸丼D鍗 */ +/* iLbaStart 鏄啓鍏ョ殑绾胯捣濮嬫ф墖鍖哄彿, iSectorCount 鏄啓鍏ョ殑鎵囧尯鏁 */ +{ + UINT8 s, err; + UINT16 mBlockCount; + for ( err = 0; err != 3; ++ err ) { /* 鍑洪敊閲嶈瘯 */ + xWriteCH376Cmd( CMD5H_DISK_WRITE ); /* 鍚慤SB瀛樺偍鍣ㄥ啓鎵囧尯 */ + xWriteCH376Data( (UINT8)iLbaStart ); /* LBA鐨勬渶浣8浣 */ + xWriteCH376Data( (UINT8)( (UINT16)iLbaStart >> 8 ) ); + xWriteCH376Data( (UINT8)( iLbaStart >> 16 ) ); + xWriteCH376Data( (UINT8)( iLbaStart >> 24 ) ); /* LBA鐨勬渶楂8浣 */ + xWriteCH376Data( iSectorCount ); /* 鎵囧尯鏁 */ + xEndCH376Cmd( ); + for ( mBlockCount = iSectorCount * DEF_SECTOR_SIZE / CH376_DAT_BLOCK_LEN; mBlockCount != 0; -- mBlockCount ) { /* 鏁版嵁鍧楄鏁 */ + s = Wait376Interrupt( ); /* 绛夊緟涓柇骞惰幏鍙栫姸鎬 */ + if ( s == USB_INT_DISK_WRITE ) { /* USB瀛樺偍鍣ㄥ啓鏁版嵁鍧,璇锋眰鏁版嵁鍐欏叆 */ + CH376WriteHostBlock( buf, CH376_DAT_BLOCK_LEN ); /* 鍚慤SB涓绘満绔偣鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ + xWriteCH376Cmd( CMD0H_DISK_WR_GO ); /* 缁х画鎵цUSB瀛樺偍鍣ㄧ殑鍐欐搷浣 */ + xEndCH376Cmd( ); + buf += CH376_DAT_BLOCK_LEN; + } + else break; /* 杩斿洖閿欒鐘舵 */ + } + if ( mBlockCount == 0 ) { + s = Wait376Interrupt( ); /* 绛夊緟涓柇骞惰幏鍙栫姸鎬 */ + if ( s == USB_INT_SUCCESS ) return( USB_INT_SUCCESS ); /* 鎿嶄綔鎴愬姛 */ + } + if ( s == USB_INT_DISCONNECT ) return( s ); /* U鐩樿绉婚櫎 */ + CH376DiskReqSense( ); /* 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ + } + return( s ); /* 鎿嶄綔澶辫触 */ +} + +UINT8 CH376SecRead( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) /* 浠ユ墖鍖轰负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡,涓嶆敮鎸丼D鍗 */ +{ + UINT8 s; + UINT8 cnt; + UINT32 StaSec; +#ifndef DEF_IC_V43_U + UINT32 fsz, fofs; +#endif + if ( RealCount ) *RealCount = 0; + do { +#ifndef DEF_IC_V43_U + xWriteCH376Cmd( CMD01_GET_IC_VER ); + cnt = xReadCH376Data( ); + if ( cnt == 0x41 ) { + xWriteCH376Cmd( CMD14_READ_VAR32 ); + xWriteCH376Data( VAR_FILE_SIZE ); + xReadCH376Data( ); + fsz = xReadCH376Data( ); + fsz |= (UINT16)(xReadCH376Data( )) << 8; + cnt = xReadCH376Data( ); + fsz |= (UINT32)cnt << 16; + xWriteCH376Cmd( CMD14_READ_VAR32 ); + xWriteCH376Data( VAR_CURRENT_OFFSET ); + xReadCH376Data( ); + fofs = xReadCH376Data( ); + fofs |= (UINT16)(xReadCH376Data( )) << 8; + fofs |= (UINT32)(xReadCH376Data( )) << 16; + if ( fsz >= fofs + 510 ) CH376WriteVar8( VAR_FILE_SIZE + 3, 0xFF ); + else cnt = 0xFF; + } + else cnt = 0xFF; +#endif + xWriteCH376Cmd( CMD1H_SEC_READ ); + xWriteCH376Data( ReqCount ); + xEndCH376Cmd( ); + s = Wait376Interrupt( ); +#ifndef DEF_IC_V43_U + if ( cnt != 0xFF ) CH376WriteVar8( VAR_FILE_SIZE + 3, cnt ); +#endif + if ( s != USB_INT_SUCCESS ) return( s ); + xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); + xReadCH376Data( ); /* 闀垮害鎬绘槸sizeof(CH376_CMD_DATA.SectorRead) */ + cnt = xReadCH376Data( ); /* CH376_CMD_DATA.SectorRead.mSectorCount */ + xReadCH376Data( ); + xReadCH376Data( ); + xReadCH376Data( ); + StaSec = CH376Read32bitDat( ); /* CH376_CMD_DATA.SectorRead.mStartSector,浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ + if ( cnt == 0 ) break; + s = CH376DiskReadSec( buf, StaSec, cnt ); /* 浠嶶鐩樿鍙栧涓墖鍖虹殑鏁版嵁鍧楀埌缂撳啿鍖 */ + if ( s != USB_INT_SUCCESS ) return( s ); + buf += cnt * DEF_SECTOR_SIZE; + if ( RealCount ) *RealCount += cnt; + ReqCount -= cnt; + } while ( ReqCount ); + return( s ); +} + +UINT8 CH376SecWrite( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) /* 浠ユ墖鍖轰负鍗曚綅鍦ㄥ綋鍓嶄綅缃啓鍏ユ暟鎹潡,涓嶆敮鎸丼D鍗 */ +{ + UINT8 s; + UINT8 cnt; + UINT32 StaSec; + if ( RealCount ) *RealCount = 0; + do { + xWriteCH376Cmd( CMD1H_SEC_WRITE ); + xWriteCH376Data( ReqCount ); + xEndCH376Cmd( ); + s = Wait376Interrupt( ); + if ( s != USB_INT_SUCCESS ) return( s ); + xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); + xReadCH376Data( ); /* 闀垮害鎬绘槸sizeof(CH376_CMD_DATA.SectorWrite) */ + cnt = xReadCH376Data( ); /* CH376_CMD_DATA.SectorWrite.mSectorCount */ + xReadCH376Data( ); + xReadCH376Data( ); + xReadCH376Data( ); + StaSec = CH376Read32bitDat( ); /* CH376_CMD_DATA.SectorWrite.mStartSector,浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ + if ( cnt == 0 ) break; + s = CH376DiskWriteSec( buf, StaSec, cnt ); /* 灏嗙紦鍐插尯涓殑澶氫釜鎵囧尯鐨勬暟鎹潡鍐欏叆U鐩 */ + if ( s != USB_INT_SUCCESS ) return( s ); + buf += cnt * DEF_SECTOR_SIZE; + if ( RealCount ) *RealCount += cnt; + ReqCount -= cnt; + } while ( ReqCount ); + return( s ); +} + +#endif + +#ifdef EN_LONG_NAME + +UINT8 CH376LongNameWrite( PUINT8 buf, UINT16 ReqCount ) /* 闀挎枃浠跺悕涓撶敤鐨勫瓧鑺傚啓瀛愮▼搴 */ +{ + UINT8 s; +#ifndef DEF_IC_V43_U + UINT8 c; + c = CH376ReadVar8( VAR_DISK_STATUS ); + if ( c == DEF_DISK_OPEN_ROOT ) CH376WriteVar8( VAR_DISK_STATUS, DEF_DISK_OPEN_DIR ); +#endif + xWriteCH376Cmd( CMD2H_BYTE_WRITE ); + xWriteCH376Data( (UINT8)ReqCount ); + xWriteCH376Data( (UINT8)(ReqCount>>8) ); + xEndCH376Cmd( ); + while ( 1 ) { + s = Wait376Interrupt( ); + if ( s == USB_INT_DISK_WRITE ) { + if ( buf ) buf += CH376WriteReqBlock( buf ); /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡,杩斿洖闀垮害 */ + else { + xWriteCH376Cmd( CMD01_WR_REQ_DATA ); /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡 */ + s = xReadCH376Data( ); /* 闀垮害 */ + while ( s -- ) xWriteCH376Data( 0 ); /* 濉厖0 */ + } + xWriteCH376Cmd( CMD0H_BYTE_WR_GO ); + xEndCH376Cmd( ); + } +/* else if ( s == USB_INT_SUCCESS ) return( s );*/ /* 缁撴潫 */ + else { +#ifndef DEF_IC_V43_U + if ( c == DEF_DISK_OPEN_ROOT ) CH376WriteVar8( VAR_DISK_STATUS, c ); +#endif + return( s ); /* 閿欒 */ + } + } +} + +UINT8 CH376CheckNameSum( PUINT8 DirName ) /* 璁$畻闀挎枃浠跺悕鐨勭煭鏂囦欢鍚嶆楠屽拰,杈撳叆涓烘棤灏忔暟鐐瑰垎闅旂鐨勫浐瀹11瀛楄妭鏍煎紡 */ +{ + UINT8 NameLen; + UINT8 CheckSum; + CheckSum = 0; + for ( NameLen = 0; NameLen != 11; NameLen ++ ) CheckSum = ( CheckSum & 1 ? 0x80 : 0x00 ) + ( CheckSum >> 1 ) + *DirName++; + return( CheckSum ); +} + +UINT8 CH376LocateInUpDir( PUINT8 PathName ) /* 鍦ㄤ笂绾х洰褰(鏂囦欢澶)涓Щ鍔ㄦ枃浠舵寚閽堝埌褰撳墠鏂囦欢鐩綍淇℃伅鎵鍦ㄧ殑鎵囧尯 */ +/* 鍙﹀,椤轰究灏嗗綋鍓嶆枃浠剁洰褰曚俊鎭墍鍦ㄧ殑鎵囧尯鐨勫墠涓涓墖鍖虹殑LBA鍦板潃鍐欏叆CH376鍐呴儴VAR_FAT_DIR_LBA鍙橀噺(涓轰簡鏂逛究鏀堕泦闀挎枃浠跺悕鏃跺悜鍓嶆悳绱,鍚﹀垯瑕佸绉诲姩涓娆) */ +/* 浣跨敤浜嗗叏灞缂撳啿鍖篏lobalBuf鐨勫墠12涓瓧鑺 */ +{ + UINT8 s; + xWriteCH376Cmd( CMD14_READ_VAR32 ); + xWriteCH376Data( VAR_FAT_DIR_LBA ); /* 褰撳墠鏂囦欢鐩綍淇℃伅鎵鍦ㄧ殑鎵囧尯LBA鍦板潃 */ + for ( s = 4; s != 8; s ++ ) GlobalBuf[ s ] = xReadCH376Data( ); /* 涓存椂淇濆瓨浜庡叏灞缂撳啿鍖轰腑,鑺傜害RAM */ + xEndCH376Cmd( ); + s = CH376SeparatePath( PathName ); /* 浠庤矾寰勪腑鍒嗙鍑烘渶鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰曞悕,杩斿洖鏈鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰曞悕鐨勫亸绉 */ + if ( s ) s = CH376FileOpenDir( PathName, s ); /* 鏄绾х洰褰,鎵撳紑澶氱骇鐩綍涓嬬殑鏈鍚庝竴绾х洰褰,鍗虫墦寮鏂囦欢鐨勪笂绾х洰褰 */ + else s = CH376FileOpen( "/" ); /* 鏍圭洰褰曚笅鐨勬枃浠,鍒欐墦寮鏍圭洰褰 */ + if ( s != ERR_OPEN_DIR ) return( s ); + *(PUINT32)(&GlobalBuf[0]) = 0; /* 鐩綍鎵囧尯鍋忕Щ鎵囧尯鏁,淇濆瓨鍦ㄥ叏灞缂撳啿鍖轰腑,鑺傜害RAM */ + while ( 1 ) { /* 涓嶆柇绉诲姩鏂囦欢鎸囬拡,鐩村埌涓庡綋鍓嶆枃浠剁洰褰曚俊鎭墍鍦ㄧ殑鎵囧尯LBA鍦板潃鍖归厤 */ + s = CH376SecLocate( *(PUINT32)(&GlobalBuf[0]) ); /* 浠ユ墖鍖轰负鍗曚綅鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡 */ + if ( s != USB_INT_SUCCESS ) return( s ); + CH376ReadBlock( &GlobalBuf[8] ); /* 浠庡唴瀛樼紦鍐插尯璇诲彇CH376_CMD_DATA.SectorLocate.mSectorLba鏁版嵁鍧,杩斿洖闀垮害鎬绘槸sizeof(CH376_CMD_DATA.SectorLocate) */ + if ( *(PUINT32)(&GlobalBuf[8]) == *(PUINT32)(&GlobalBuf[4]) ) return( USB_INT_SUCCESS ); /* 宸插埌褰撳墠鏂囦欢鐩綍淇℃伅鎵囧尯 */ + xWriteCH376Cmd( CMD50_WRITE_VAR32 ); + xWriteCH376Data( VAR_FAT_DIR_LBA ); /* 寰楀埌鍓嶄竴涓墖鍖,璁剧疆涓烘柊鐨勬枃浠剁洰褰曚俊鎭墖鍖篖BA鍦板潃 */ + for ( s = 8; s != 12; s ++ ) xWriteCH376Data( GlobalBuf[ s ] ); + xEndCH376Cmd( ); + ++ *(PUINT32)(&GlobalBuf[0]); + } +} + +UINT8 CH376GetLongName( PUINT8 PathName, PUINT8 LongName ) /* 鐢辩煭鏂囦欢鍚嶆垨鑰呯洰褰(鏂囦欢澶)鍚嶈幏寰楃浉搴旂殑闀挎枃浠跺悕 */ +/* 闇瑕佽緭鍏ョ煭鏂囦欢鍚嶇殑瀹屾暣璺緞PathName,闇瑕佹彁渚涚紦鍐插尯鎺ユ敹闀挎枃浠跺悕LongName(浠NICODE灏忕缂栫爜,浠ュ弻0缁撴潫) */ +/* 浣跨敤浜嗗叏灞缂撳啿鍖篏lobalBuf鐨勫墠34涓瓧鑺,sizeof(GlobalBuf)>=sizeof(FAT_DIR_INFO)+2 */ +{ + UINT8 s; + UINT16 NameCount; /* 闀挎枃浠跺悕瀛楄妭璁℃暟 */ + s = CH376FileOpenPath( PathName ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢鎴栬呯洰褰 */ + if ( s != USB_INT_SUCCESS && s != ERR_OPEN_DIR ) return( s ); + s = CH376DirInfoRead( ); /* 璇诲彇褰撳墠鏂囦欢鐨勭洰褰曚俊鎭疐AT_DIR_INFO,灏嗙浉鍏虫暟鎹皟鍒板唴瀛樹腑 */ + if ( s != USB_INT_SUCCESS ) return( s ); + CH376ReadBlock( GlobalBuf ); /* 浠庡唴瀛樼紦鍐插尯璇诲彇FAT_DIR_INFO鏁版嵁鍧,杩斿洖闀垮害鎬绘槸sizeof(FAT_DIR_INFO) */ + CH376EndDirInfo( ); /* 鑾峰彇瀹孎AT_DIR_INFO缁撴瀯 */ + GlobalBuf[32] = CH376CheckNameSum( GlobalBuf ); /* 璁$畻闀挎枃浠跺悕鐨勭煭鏂囦欢鍚嶆楠屽拰,淇濆瓨鍦ㄥ叏灞缂撳啿鍖轰腑,鑺傜害RAM */ + GlobalBuf[33] = CH376ReadVar8( VAR_FILE_DIR_INDEX ); /* 褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄦ墖鍖哄唴鐨勭储寮曞彿,淇濆瓨鍦ㄥ叏灞缂撳啿鍖轰腑,鑺傜害RAM */ + NameCount = 0; + while ( 1 ) { + if ( GlobalBuf[33] == 0 ) { /* 褰撳墠鐨勬枃浠剁洰褰曚俊鎭墖鍖哄鐞嗙粨鏉,杞埌鍓嶄竴涓墖鍖 */ + s = CH376LocateInUpDir( PathName ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭墍鍦ㄧ殑鎵囧尯 */ + if ( s != USB_INT_SUCCESS ) break; + if ( CH376ReadVar32( VAR_CURRENT_OFFSET ) == 0 ) { /* 褰撳墠宸茬粡澶勪簬鐩綍鎵囧尯鐨勫紑濮,鏃犳硶鑾峰彇闀挎枃浠跺悕 */ + s = ERR_LONG_NAME_ERR; + break; + } + GlobalBuf[33] = DEF_SECTOR_SIZE / sizeof( FAT_DIR_INFO ); /* 鎸囧悜鍓嶄竴涓墖鍖虹殑鏈鍚庝竴涓枃浠剁洰褰曚俊鎭 */ + } + GlobalBuf[33] --; /* 浠庡悗鍚戝墠鎼滅储鏂囦欢鐩綍淇℃伅 */ + s = CH376SendCmdDatWaitInt( CMD1H_DIR_INFO_READ, GlobalBuf[33] ); /* 璇诲彇鎸囧畾鐨勭洰褰曚俊鎭疐AT_DIR_INFO,灏嗙浉鍏虫暟鎹皟鍒板唴瀛樹腑 */ + if ( s != USB_INT_SUCCESS ) break; + CH376ReadBlock( GlobalBuf ); /* 浠庡唴瀛樼紦鍐插尯璇诲彇FAT_DIR_INFO鏁版嵁鍧,杩斿洖闀垮害鎬绘槸sizeof(FAT_DIR_INFO) */ + CH376EndDirInfo( ); /* 鑾峰彇瀹孎AT_DIR_INFO缁撴瀯 */ + if ( ( GlobalBuf[11] & ATTR_LONG_NAME_MASK ) != ATTR_LONG_NAME || GlobalBuf[13] != GlobalBuf[32] ) { /* 绫诲瀷閿欒鎴栬呮牎楠屽拰閿欒 */ + s = ERR_LONG_NAME_ERR; + break; /* 娌℃湁鐩存帴杩斿洖鏄洜涓哄鏋滄槸鎵撳紑浜嗘牴鐩綍閭d箞蹇呴』瑕佸叧闂悗鎵嶈兘杩斿洖 */ + } + for ( s = 1; s < sizeof( FAT_DIR_INFO ); s += 2 ) { /* 鏀堕泦闀挎枃浠跺悕,闀挎枃浠跺悕鐨勫瓧绗﹀湪纾佺洏涓奤NICODE鐢ㄥ皬绔柟寮忓瓨鏀 */ + if ( s == 1 + 5 * 2 ) s = 14; /* 浠庨暱鏂囦欢鍚嶇殑绗竴缁1-5涓瓧绗﹁烦鍒扮浜岀粍6-11涓瓧绗 */ + else if ( s == 14 + 6 * 2 ) s = 28; /* 浠庨暱鏂囦欢鍚嶇殑绗簩缁6-11涓瓧绗﹁烦鍒扮涓夌粍12-13涓瓧绗 */ + LongName[ NameCount++ ] = GlobalBuf[ s ]; + LongName[ NameCount++ ] = GlobalBuf[ s + 1 ]; + if ( GlobalBuf[ s ] == 0 && GlobalBuf[ s + 1 ] == 0 ) break; /* 闀挎枃浠跺悕缁撴潫 */ + if ( NameCount >= LONG_NAME_BUF_LEN ) { /* 闀挎枃浠跺悕缂撳啿鍖烘孩鍑 */ + s = ERR_LONG_BUF_OVER; + goto CH376GetLongNameE; + } + } + if ( GlobalBuf[0] & 0x40 ) { /* 闀挎枃浠跺悕鐩綍淇℃伅鍧楃粨鏉 */ + if ( s >= sizeof( FAT_DIR_INFO ) ) *(PUINT16)( &LongName[ NameCount ] ) = 0x0000; /* 灏氭湭鏀堕泦鍒伴暱鏂囦欢鍚嶇殑缁撴潫绗,鍒欏己鍒剁粨鏉 */ + s = USB_INT_SUCCESS; /* 鎴愬姛瀹屾垚闀挎枃浠跺悕鏀堕泦瀹屾垚 */ + break; + } + } +CH376GetLongNameE: + CH376FileClose( FALSE ); /* 瀵逛簬鏍圭洰褰曞垯蹇呴』瑕佸叧闂 */ + return( s ); +} + +UINT8 CH376CreateLongName( PUINT8 PathName, PUINT8 LongName ) /* 鏂板缓鍏锋湁闀挎枃浠跺悕鐨勬枃浠,鍏抽棴鏂囦欢鍚庤繑鍥,LongName杈撳叆璺緞蹇呴』鍦≧AM涓 */ +/* 闇瑕佽緭鍏ョ煭鏂囦欢鍚嶇殑瀹屾暣璺緞PathName(璇蜂簨鍏堝弬鑰僃AT瑙勮寖鐢遍暱鏂囦欢鍚嶈嚜琛屼骇鐢),闇瑕佽緭鍏ヤ互UNICODE灏忕缂栫爜鐨勪互鍙0缁撴潫鐨勯暱鏂囦欢鍚峀ongName */ +/* 浣跨敤浜嗗叏灞缂撳啿鍖篏lobalBuf鐨勫墠64涓瓧鑺,sizeof(GlobalBuf)>=sizeof(FAT_DIR_INFO)*2 */ +{ + UINT8 s, i; + UINT8 DirBlockCnt; /* 闀挎枃浠跺悕鍗犵敤鏂囦欢鐩綍缁撴瀯鐨勪釜鏁 */ + UINT16 count; /* 涓存椂鍙橀噺,鐢ㄤ簬璁℃暟,鐢ㄤ簬瀛楄妭璇绘枃浠舵柟寮忎笅瀹為檯璇诲彇鐨勫瓧鑺傛暟 */ + UINT16 NameCount; /* 闀挎枃浠跺悕瀛楄妭璁℃暟 */ + UINT32 NewFileLoc; /* 褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄤ笂绾х洰褰曚腑鐨勮捣濮嬩綅缃,鍋忕Щ鍦板潃 */ + for ( count = 0; count < LONG_NAME_BUF_LEN; count += 2 ) if ( *(PUINT16)(&LongName[count]) == 0 ) break; /* 鍒扮粨鏉熶綅缃 */ + if ( count == 0 || count >= LONG_NAME_BUF_LEN || count > LONE_NAME_MAX_CHAR ) return( ERR_LONG_NAME_ERR ); /* 闀挎枃浠跺悕鏃犳晥 */ + DirBlockCnt = count / LONG_NAME_PER_DIR; /* 闀挎枃浠跺悕鍗犵敤鏂囦欢鐩綍缁撴瀯鐨勪釜鏁 */ + i = count - DirBlockCnt * LONG_NAME_PER_DIR; + if ( i ) { /* 鏈夐浂澶 */ + if ( ++ DirBlockCnt * LONG_NAME_PER_DIR > LONG_NAME_BUF_LEN ) return( ERR_LONG_BUF_OVER ); /* 缂撳啿鍖烘孩鍑 */ + count += 2; /* 鍔犱笂0缁撴潫绗﹀悗鐨勯暱搴 */ + i += 2; + if ( i < LONG_NAME_PER_DIR ) { /* 鏈鏈殑鏂囦欢鐩綍缁撴瀯涓嶆弧 */ + while ( i++ < LONG_NAME_PER_DIR ) LongName[count++] = 0xFF; /* 鎶婂墿浣欐暟鎹~涓0xFF */ + } + } + s = CH376FileOpenPath( PathName ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢 */ + if ( s == USB_INT_SUCCESS ) { /* 鐭枃浠跺悕瀛樺湪鍒欒繑鍥為敊璇 */ + s = ERR_NAME_EXIST; + goto CH376CreateLongNameE; + } + if ( s != ERR_MISS_FILE ) return( s ); + s = CH376FileCreatePath( PathName ); /* 鏂板缓澶氱骇鐩綍涓嬬殑鏂囦欢 */ + if ( s != USB_INT_SUCCESS ) return( s ); + i = CH376ReadVar8( VAR_FILE_DIR_INDEX ); /* 涓存椂鐢ㄤ簬淇濆瓨褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄦ墖鍖哄唴鐨勭储寮曞彿 */ + s = CH376LocateInUpDir( PathName ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭墍鍦ㄧ殑鎵囧尯 */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; /* 娌℃湁鐩存帴杩斿洖鏄洜涓哄鏋滄槸鎵撳紑浜嗘牴鐩綍閭d箞蹇呴』瑕佸叧闂悗鎵嶈兘杩斿洖 */ + NewFileLoc = CH376ReadVar32( VAR_CURRENT_OFFSET ) + i * sizeof(FAT_DIR_INFO); /* 璁$畻褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄤ笂绾х洰褰曚腑鐨勮捣濮嬩綅缃,鍋忕Щ鍦板潃 */ + s = CH376ByteLocate( NewFileLoc ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭殑浣嶇疆 */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + s = CH376ByteRead( &GlobalBuf[ sizeof(FAT_DIR_INFO) ], sizeof(FAT_DIR_INFO), NULL ); /* 浠ュ瓧鑺備负鍗曚綅璇诲彇鏁版嵁,鑾峰緱褰撳墠鏂囦欢鐨勭洰褰曚俊鎭疐AT_DIR_INFO */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + for ( i = DirBlockCnt; i != 0; -- i ) { /* 鎼滅储绌洪棽鐨勬枃浠剁洰褰曠粨鏋勭敤浜庡瓨鏀鹃暱鏂囦欢鍚 */ + s = CH376ByteRead( GlobalBuf, sizeof(FAT_DIR_INFO), &count ); /* 浠ュ瓧鑺備负鍗曚綅璇诲彇鏁版嵁,鑾峰緱涓嬩竴涓枃浠剁洰褰曚俊鎭疐AT_DIR_INFO */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + if ( count == 0 ) break; /* 鏃犳硶璇诲嚭鏁版嵁,涓婄骇鐩綍缁撴潫浜 */ + if ( GlobalBuf[0] && GlobalBuf[0] != 0xE5 ) { /* 鍚庨潰鏈夋鍦ㄤ娇鐢ㄧ殑鏂囦欢鐩綍缁撴瀯,鐢变簬闀挎枃浠跺悕蹇呴』杩炴帴瀛樻斁,鎵浠ョ┖闂翠笉澶,蹇呴』鏀惧純褰撳墠浣嶇疆骞跺悜鍚庤浆绉 */ + s = CH376ByteLocate( NewFileLoc ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭殑浣嶇疆 */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + GlobalBuf[ 0 ] = 0xE5; /* 鏂囦欢鍒犻櫎鏍囧織 */ + for ( s = 1; s != sizeof(FAT_DIR_INFO); s ++ ) GlobalBuf[ s ] = GlobalBuf[ sizeof(FAT_DIR_INFO) + s ]; + s = CH376LongNameWrite( GlobalBuf, sizeof(FAT_DIR_INFO) ); /* 鍐欏叆涓涓枃浠剁洰褰曠粨鏋,鐢ㄤ簬鍒犻櫎涔嬪墠鏂板缓鐨勬枃浠,瀹為檯涓婄◢鍚庝細灏嗕箣杞Щ鍒扮洰褰曠殑鏈鏈綅缃 */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + do { /* 鍚戝悗鎼滅储绌洪棽鐨勬枃浠剁洰褰曠粨鏋 */ + s = CH376ByteRead( GlobalBuf, sizeof(FAT_DIR_INFO), &count ); /* 浠ュ瓧鑺備负鍗曚綅璇诲彇鏁版嵁,鑾峰緱涓嬩竴涓枃浠剁洰褰曚俊鎭疐AT_DIR_INFO */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + } while ( count && GlobalBuf[0] ); /* 濡傛灉浠嶇劧鏄鍦ㄤ娇鐢ㄧ殑鏂囦欢鐩綍缁撴瀯鍒欑户缁悜鍚庢悳绱,鐩村埌涓婄骇鐩綍缁撴潫鎴栬呮湁灏氭湭浣跨敤杩囩殑鏂囦欢鐩綍缁撴瀯 */ + NewFileLoc = CH376ReadVar32( VAR_CURRENT_OFFSET ); /* 鐢ㄤ笂绾х洰褰曠殑褰撳墠鏂囦欢鎸囬拡浣滀负褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄤ笂绾х洰褰曚腑鐨勮捣濮嬩綅缃 */ + i = DirBlockCnt + 1; /* 闇瑕佺殑绌洪棽鐨勬枃浠剁洰褰曠粨鏋勭殑涓暟,鍖呮嫭鐭枃浠跺悕鏈韩涓涓拰闀挎枃浠跺悕 */ + if ( count == 0 ) break; /* 鏃犳硶璇诲嚭鏁版嵁,涓婄骇鐩綍缁撴潫浜 */ + NewFileLoc -= sizeof(FAT_DIR_INFO); /* 鍊掑洖鍒板垰鎵嶆悳绱㈠埌鐨勭┖闂茬殑鏂囦欢鐩綍缁撴瀯鐨勮捣濮嬩綅缃 */ + } + } + if ( i ) { /* 绌洪棽鐨勬枃浠剁洰褰曠粨鏋勪笉瓒充互瀛樻斁闀挎枃浠跺悕,鍘熷洜鏄笂绾х洰褰曠粨鏉熶簡,涓嬮潰澧炲姞涓婄骇鐩綍鐨勯暱搴 */ + s = CH376ReadVar8( VAR_SEC_PER_CLUS ); /* 姣忕皣鎵囧尯鏁 */ + if ( s == 128 ) { /* FAT12/FAT16鐨勬牴鐩綍,瀹归噺鏄浐瀹氱殑,鏃犳硶澧炲姞鏂囦欢鐩綍缁撴瀯 */ + s = ERR_FDT_OVER; /* FAT12/FAT16鏍圭洰褰曚笅鐨勬枃浠舵暟搴旇灏戜簬512涓,闇瑕佺鐩樻暣鐞 */ + goto CH376CreateLongNameE; + } + count = s * DEF_SECTOR_SIZE; /* 姣忕皣瀛楄妭鏁 */ + if ( count < i * sizeof(FAT_DIR_INFO) ) count <<= 1; /* 涓绨囦笉澶熷垯澧炲姞涓绨,杩欑鎯呭喌鍙細鍙戠敓浜庢瘡绨囦负512瀛楄妭鐨勬儏鍐典笅 */ + s = CH376LongNameWrite( NULL, count ); /* 浠ュ瓧鑺備负鍗曚綅鍚戝綋鍓嶄綅缃啓鍏ュ叏0鏁版嵁鍧,娓呯┖鏂板鍔犵殑鏂囦欢鐩綍绨 */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + } + s = CH376ByteLocate( NewFileLoc ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭殑浣嶇疆 */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + GlobalBuf[11] = ATTR_LONG_NAME; + GlobalBuf[12] = 0x00; + GlobalBuf[13] = CH376CheckNameSum( &GlobalBuf[ sizeof(FAT_DIR_INFO) ] ); /* 璁$畻闀挎枃浠跺悕鐨勭煭鏂囦欢鍚嶆楠屽拰 */ + GlobalBuf[26] = 0x00; + GlobalBuf[27] = 0x00; + for ( s = 0; DirBlockCnt != 0; ) { /* 闀挎枃浠跺悕鍗犵敤鐨勬枃浠剁洰褰曠粨鏋勮鏁 */ + GlobalBuf[0] = s ? DirBlockCnt : DirBlockCnt | 0x40; /* 棣栨瑕佺疆闀挎枃浠跺悕鍏ュ彛鏍囧織 */ + DirBlockCnt --; + NameCount = DirBlockCnt * LONG_NAME_PER_DIR; + for ( s = 1; s < sizeof( FAT_DIR_INFO ); s += 2 ) { /* 杈撳嚭闀挎枃浠跺悕,闀挎枃浠跺悕鐨勫瓧绗﹀湪纾佺洏涓奤NICODE鐢ㄥ皬绔柟寮忓瓨鏀 */ + if ( s == 1 + 5 * 2 ) s = 14; /* 浠庨暱鏂囦欢鍚嶇殑绗竴缁1-5涓瓧绗﹁烦鍒扮浜岀粍6-11涓瓧绗 */ + else if ( s == 14 + 6 * 2 ) s = 28; /* 浠庨暱鏂囦欢鍚嶇殑绗簩缁6-11涓瓧绗﹁烦鍒扮涓夌粍12-13涓瓧绗 */ + GlobalBuf[ s ] = LongName[ NameCount++ ]; + GlobalBuf[ s + 1 ] = LongName[ NameCount++ ]; + } + s = CH376LongNameWrite( GlobalBuf, sizeof(FAT_DIR_INFO) ); /* 浠ュ瓧鑺備负鍗曚綅鍐欏叆涓涓枃浠剁洰褰曠粨鏋,闀挎枃浠跺悕 */ + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + } + s = CH376LongNameWrite( &GlobalBuf[ sizeof(FAT_DIR_INFO) ], sizeof(FAT_DIR_INFO) ); /* 浠ュ瓧鑺備负鍗曚綅鍐欏叆涓涓枃浠剁洰褰曠粨鏋,杩欐槸杞Щ鏉ョ殑涔嬪墠鏂板缓鐨勬枃浠剁殑鐩綍淇℃伅 */ +CH376CreateLongNameE: + CH376FileClose( FALSE ); /* 瀵逛簬鏍圭洰褰曞垯蹇呴』瑕佸叧闂 */ + return( s ); +} + +#endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.h new file mode 100644 index 000000000..f87a8169a --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.h @@ -0,0 +1,118 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file k210_ch376.h + * @brief xidatong-riscv64 k210_ch376.h + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.10.10 + * */ + +#ifndef __CH376_FS_H__ +#define __CH376_FS_H__ + +#include "ch376inc.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "k210_uart_16550.h" + +#define ERR_USB_UNKNOWN 0xFA + +void xEndCH376Cmd( void ); +void xWriteCH376Cmd( UINT8 mCmd ); +void xWriteCH376Data( UINT8 mData ); +UINT8 xReadCH376Data( void ); +UINT8 Query376Interrupt( void ); +UINT8 mInitCH376Host( void ); + +#define STRUCT_OFFSET( s, m ) ( (UINT8)( & ((s *)0) -> m ) ) + +#ifdef EN_LONG_NAME +#ifndef LONG_NAME_BUF_LEN +#define LONG_NAME_BUF_LEN ( LONG_NAME_PER_DIR * 20 ) +#endif +#endif + +UINT8 CH376ReadBlock( PUINT8 buf ); +UINT8 CH376WriteReqBlock( PUINT8 buf ); + +void CH376WriteHostBlock( PUINT8 buf, UINT8 len ); +void CH376WriteOfsBlock( PUINT8 buf, UINT8 ofs, UINT8 len ); +void CH376SetFileName( PUINT8 name ); +UINT32 CH376Read32bitDat( void ); +UINT8 CH376ReadVar8( UINT8 var ); + +void CH376WriteVar8( UINT8 var, UINT8 dat ); +UINT32 CH376ReadVar32( UINT8 var ); +void CH376WriteVar32( UINT8 var, UINT32 dat ); +void CH376EndDirInfo( void ); +UINT32 CH376GetFileSize( void ); +UINT8 CH376GetDiskStatus( void ); +UINT8 CH376GetIntStatus( void ); + +#ifndef NO_DEFAULT_CH376_INT +UINT8 Wait376Interrupt( void ); +#endif + +UINT8 CH376SendCmdWaitInt( UINT8 mCmd ); +UINT8 CH376SendCmdDatWaitInt( UINT8 mCmd, UINT8 mDat ); +UINT8 CH376DiskReqSense( void ); +UINT8 CH376DiskConnect( void ); +UINT8 CH376DiskMount( void ); +UINT8 CH376FileOpen( PUINT8 name ); +UINT8 CH376FileCreate( PUINT8 name ); +UINT8 CH376DirCreate( PUINT8 name ); +UINT8 CH376SeparatePath( PUINT8 path ); +UINT8 CH376FileOpenDir( PUINT8 PathName, UINT8 StopName ); +UINT8 CH376FileOpenPath( PUINT8 PathName ); +UINT8 CH376FileCreatePath( PUINT8 PathName ); + +#ifdef EN_DIR_CREATE +UINT8 CH376DirCreatePath( PUINT8 PathName ); +UINT8 CH376FileErase( PUINT8 PathName ); +UINT8 CH376FileClose( UINT8 UpdateSz ); +UINT8 CH376DirInfoRead( void ); +UINT8 CH376DirInfoSave( void ); +UINT8 CH376ByteLocate( UINT32 offset ); +UINT8 CH376ByteRead( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ); +UINT8 CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ); +UINT8 CH376DiskCapacity( PUINT32 DiskCap ); +UINT8 CH376DiskQuery( PUINT32 DiskFre ); +UINT8 CH376SecLocate( UINT32 offset ); +UINT8 CH376DiskReadSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ); +UINT8 CH376DiskWriteSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ); +UINT8 CH376SecRead( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ); +UINT8 CH376SecWrite( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ); +#endif + +#ifdef EN_LONG_NAME +UINT8 CH376LongNameWrite( PUINT8 buf, UINT16 ReqCount ); +UINT8 CH376CheckNameSum( PUINT8 DirName ); +UINT8 CH376LocateInUpDir( PUINT8 PathName ); +UINT8 CH376GetLongName( PUINT8 PathName, PUINT8 LongName ); +UINT8 CH376CreateLongName( PUINT8 PathName, PUINT8 LongName ); +#endif + +#endif From 540c9a84d55cb16c6175dfb42bb1c07989cadd59 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 10 Oct 2022 16:23:42 +0800 Subject: [PATCH 13/30] add esp8285 wifi on nuttx for xidatong-riscv64 --- .../Framework/connection/wifi/Kconfig | 8 + .../Framework/connection/wifi/adapter_wifi.c | 20 + .../connection/wifi/esp8285_wifi/Kconfig | 10 + .../connection/wifi/esp8285_wifi/Make.defs | 6 + .../connection/wifi/esp8285_wifi/Makefile | 7 + .../wifi/esp8285_wifi/esp8285_wifi.c | 589 ++++++++++++++++++ .../app_match_nuttx/apps/nshlib/nsh.h | 2 +- .../apps/nshlib/nsh_Applicationscmd.c | 2 +- .../app_match_nuttx/apps/nshlib/nsh_command.c | 2 +- 9 files changed, 643 insertions(+), 3 deletions(-) create mode 100644 APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig create mode 100644 APP_Framework/Framework/connection/wifi/esp8285_wifi/Make.defs create mode 100644 APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile create mode 100644 APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c diff --git a/APP_Framework/Framework/connection/wifi/Kconfig b/APP_Framework/Framework/connection/wifi/Kconfig index 9afa7bf28..fcc6b31d2 100644 --- a/APP_Framework/Framework/connection/wifi/Kconfig +++ b/APP_Framework/Framework/connection/wifi/Kconfig @@ -8,6 +8,14 @@ if ADAPTER_HFA21_WIFI source "$APP_DIR/Framework/connection/wifi/hfa21_wifi/Kconfig" endif +config ADAPTER_ESP8285_WIFI + bool "Using wifi adapter device esp8285" + default n + +if ADAPTER_ESP8285_WIFI + source "$APP_DIR/Framework/connection/wifi/esp8285_wifi/Kconfig" +endif + config ADAPTER_ESP07S_WIFI bool "Using wifi adapter device esp07s" default n diff --git a/APP_Framework/Framework/connection/wifi/adapter_wifi.c b/APP_Framework/Framework/connection/wifi/adapter_wifi.c index a42942ac6..a6866f5d8 100644 --- a/APP_Framework/Framework/connection/wifi/adapter_wifi.c +++ b/APP_Framework/Framework/connection/wifi/adapter_wifi.c @@ -31,6 +31,10 @@ extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter); extern AdapterProductInfoType Esp07sWifiAttach(struct Adapter *adapter); #endif +#ifdef ADAPTER_ESP8285_WIFI +extern AdapterProductInfoType Esp8285WifiAttach(struct Adapter *adapter); +#endif + static int AdapterWifiRegister(struct Adapter *adapter) { int ret = 0; @@ -94,11 +98,27 @@ int AdapterWifiInit(void) adapter->info = product_info; adapter->done = product_info->model_done; +#endif + + +#ifdef ADAPTER_ESP8285_WIFI + AdapterProductInfoType product_info = Esp8285WifiAttach(adapter); + if (!product_info) { + printf("AdapterWifiInit ESP8285 attach error\n"); + PrivFree(adapter); + return -1; + } + + adapter->product_info_flag = 1; + adapter->info = product_info; + adapter->done = product_info->model_done; + #endif return ret; } + /******************wifi TEST*********************/ #ifdef ADD_XIZI_FETURES int AdapterWifiTest(void) diff --git a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig new file mode 100644 index 000000000..4b3b5b8d9 --- /dev/null +++ b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig @@ -0,0 +1,10 @@ +config ADAPTER_WIFI_ESP8285 + string "ESP8285 WIFI adapter name" + default "esp8285_wifi" + +if ADD_NUTTX_FETURES + config ADAPTER_ESP8285_DRIVER + string "ESP8285 device uart driver path" + default "/dev/ttyS2" +endif + diff --git a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Make.defs b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Make.defs new file mode 100644 index 000000000..2c5d833a3 --- /dev/null +++ b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Make.defs @@ -0,0 +1,6 @@ +############################################################################ +# APP_Framework/Framework/connection/wifi/esp8285/Make.defs +############################################################################ +ifneq ($(CONFIG_ADAPTER_ESP8285_WIFI),) +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/wifi/esp8285_wifi +endif diff --git a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile new file mode 100644 index 000000000..c1ee6bd29 --- /dev/null +++ b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile @@ -0,0 +1,7 @@ +include $(KERNEL_ROOT)/.config +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + CSRCS += esp8285_wifi.c + include $(APPDIR)/Application.mk + +endif diff --git a/APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c b/APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c new file mode 100644 index 000000000..07a050333 --- /dev/null +++ b/APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c @@ -0,0 +1,589 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file esp07_wifi.c + * @brief Implement the connection wifi adapter function, using ESP8285 device + * @version 1.1 + * @author AIIT XUOS Lab + * @date 2022.04.08 + */ + +#include +#include +#include "../adapter_wifi.h" +#include + +#define LEN_PARA_BUF 128 + +static int Esp8285WifiSetDown(struct Adapter *adapter_at); + +/** + * @description: check AT startup status + * @param at_agent - wifi device agent pointer + * @return success: EOK + */ +static int Esp8285WifiTestAtCmd(ATAgentType at_agent) +{ + int ret = 0; + + ret = AtCmdConfigAndCheck(at_agent, "ATE0\r\n", "OK"); ///< close echo function + if(ret < 0) { + printf("%s %d cmd[ATE0] config failed!\n",__func__,__LINE__); + ret = -1; + } + + PrivTaskDelay(2000); + ret = AtCmdConfigAndCheck(at_agent, "AT\r\n", "OK"); + if(ret < 0) { + printf("%s %d cmd[AT] config failed!\n",__func__,__LINE__); + ret = -1; + } + return ret; +} + +static int Esp8285UartOpen(struct Adapter *adapter) +{ + if (NULL == adapter) { + return -1; + } + + /* Open device in read-write mode */ + adapter->fd = PrivOpen(ADAPTER_ESP8285_DRIVER, O_RDWR); + if (adapter->fd < 0) { + printf("Esp8285WifiOpen get serial %s fd error\n", ADAPTER_ESP8285_DRIVER); + return -1; + } + /* set serial config, serial_baud_rate = 115200 */ + + struct SerialDataCfg cfg; + memset(&cfg, 0 ,sizeof(struct SerialDataCfg)); + + cfg.serial_baud_rate = BAUD_RATE_115200; + cfg.serial_data_bits = DATA_BITS_8; + cfg.serial_stop_bits = STOP_BITS_1; + cfg.serial_parity_mode = PARITY_NONE; + cfg.serial_bit_order = BIT_ORDER_LSB; + cfg.serial_invert_mode = NRZ_NORMAL; + cfg.serial_buffer_size = SERIAL_RB_BUFSZ; + cfg.is_ext_uart = 0; +#ifdef ADAPTER_ESP8285_DRIVER_EXT_PORT + cfg.is_ext_uart = 1; + cfg.ext_uart_no = ADAPTER_ESP8285_DRIVER_EXT_PORT; + cfg.port_configure = PORT_CFG_INIT; +#endif + + struct PrivIoctlCfg ioctl_cfg; + ioctl_cfg.ioctl_driver_type = SERIAL_TYPE; + ioctl_cfg.args = &cfg; + + PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg); + PrivTaskDelay(1000); + + printf("esp8285 uart config ready\n"); + return 0; +} + +/** + * @description: Open wifi + * @param adapter - wifi device pointer + * @return success: EOK, failure: ENOMEMORY + */ +static int Esp8285WifiOpen(struct Adapter *adapter) +{ + /*step1: open esp8285 serial port*/ + Esp8285UartOpen(adapter); + + /*step2: init AT agent*/ + if (!adapter->agent) { + char *agent_name = "wifi_uart_client"; + if (EOK != InitATAgent(agent_name, adapter->fd, 512)) { + printf("at agent init failed !\n"); + return -1; + } + ATAgentType at_agent = GetATAgent(agent_name); + + adapter->agent = at_agent; + } + + AtSetReplyEndChar(adapter->agent,'O','K'); + + ADAPTER_DEBUG("Esp8285Wifi open done\n"); + + return 0; +} + +/** + * @description: Close wifi + * @param adapter - wifi device pointer + * @return success: EOK + */ +static int Esp8285WifiClose(struct Adapter *adapter) +{ + Esp8285WifiSetDown(adapter); + PrivClose(adapter->fd); + return 0; +} + +/** + * @description: send data to adapter + * @param adapter - wifi device pointer + * @param data - data buffer + * @param data - data length + * @return success: EOK + */ +static int Esp8285WifiSend(struct Adapter *adapter, const void *data, size_t len) +{ + x_err_t result = EOK; + if (adapter->agent) { + EntmSend(adapter->agent, (const char *)data, len); + }else { + printf("Esp8285WifiSend can not find agent!\n"); + } + + return result; +} + +/** + * @description: receive data from adapter + * @param adapter - wifi device pointer + * @param data - data buffer + * @param data - data length + * @return success: EOK + */ +static int Esp8285WifiReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len) +{ + x_err_t result = EOK; + printf("esp8285 receive waiting ... \n"); + + if (adapter->agent) { + return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40); + } else { + printf("Esp8285WifiReceive can not find agent!\n"); + } + + return result; +} + +/** + * @description: connnect wifi to internet + * @param adapter - wifi device pointer + * @return success: EOK + */ +static int Esp8285WifiSetUp(struct Adapter *adapter) +{ + char cmd[LEN_PARA_BUF]; + int ret = 0; + char *result = NULL; + + struct WifiParam *param = (struct WifiParam *)adapter->adapter_param; + struct ATAgent *agent = adapter->agent; + + PrivTaskDelay(2000); + + if(Esp8285WifiTestAtCmd(agent) < 0) + { + printf("wifi at cmd startup failed.\n"); + return -1; + } + PrivTaskDelay(2000); + /* config as softAP+station mode */ + ret = AtCmdConfigAndCheck(agent, "AT+CWMODE=3\r\n", "OK"); + if(ret < 0) { + printf("%s %d cmd[AT+CWMODE=3] config failed!\n",__func__,__LINE__); + return -1; + } + PrivTaskDelay(2000); + /* connect the router */ + memset(cmd,0,sizeof(cmd)); + strncpy(cmd,"AT+CWJAP=",strlen("AT+CWJAP=")); + strncat(cmd,"\"",1); + strncat(cmd,param->wifi_ssid,strlen(param->wifi_ssid)); + + strncat(cmd,"\"",1); + strncat(cmd,",",1); + strncat(cmd,"\"",1); + strncat(cmd,param->wifi_pwd,strlen(param->wifi_pwd)); + + strncat(cmd,"\"",1); + strcat(cmd,"\r\n"); + + ret = AtCmdConfigAndCheck(agent, cmd, "OK"); + if(ret < 0) { + printf("%s %d cmd[%s] connect[%s] failed!\n",__func__,__LINE__,cmd,param->wifi_ssid); + return -1; + } + + /* check the wifi ip address */ + ATReplyType reply = CreateATReply(256); + if (NULL == reply) { + printf("%s %d at_create_resp failed!\n",__func__,__LINE__); + return -1; + } + ret = ATOrderSend(agent, REPLY_TIME_OUT, reply, "AT+CIFSR\r\n"); + if(ret < 0){ + printf("%s %d ATOrderSend AT+CIFSR failed.\n",__func__,__LINE__); + ret = -1; + goto __exit; + } + + result = GetReplyText(reply); + if (!result) { + printf("%s %n get reply failed.\n",__func__,__LINE__); + ret = -1; + goto __exit; + } + printf("[%s]\n", result); + +__exit: + DeleteATReply(reply); + + return ret; +} + +/** + * @description: disconnnect wifi from internet + * @param adapter - wifi device pointer + * @return success: EOK + */ +static int Esp8285WifiSetDown(struct Adapter *adapter) +{ + ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RESTORE\r\n"); + PrivTaskDelay(2000); + + return 0; +} + +/** + * @description: set wifi ip/gateway/netmask address(in sta mode) + * @param adapter - wifi device pointer + * @param ip - ip address + * @param gateway - gateway address + * @param netmask - netmask address + * @return success: EOK, failure: ENOMEMORY + */ +static int Esp8285WifiSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask) +{ + int ret = 0; + char cmd[LEN_PARA_BUF]; + + /* e.g. AT+CIPSTA_DEF="192.168.6.100","192.168.6.1","255.255.255.0" */ + memset(cmd,0,sizeof(cmd)); + strncpy(cmd,"AT+CIPAP_DEF=",strlen(" AT+CIPAP_DEF=")); + strncat(cmd,"\"",1); + strncat(cmd,ip,strlen(ip)); + strncat(cmd,"\"",1); + strncat(cmd,",",1); + strncat(cmd,"\"",1); + strncat(cmd,gateway,strlen(gateway)); + strncat(cmd,"\"",1); + strncat(cmd,",",1); + strncat(cmd,"\"",1); + strncat(cmd,netmask,strlen(netmask)); + strncat(cmd,"\"",1); + strcat(cmd,"\r\n"); + + ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK"); + if(ret < 0) { + printf("%s %d cmd[%s] config ip failed!\n",__func__,__LINE__,cmd); + return -1; + } + + return 0; +} + +/** + * @description: wifi ping function + * @param adapter - wifi device pointer + * @param destination - domain name or ip address + * @return success: EOK, failure: ENOMEMORY + */ +static int Esp8285WifiPing(struct Adapter *adapter, const char *destination) +{ + char cmd[LEN_PARA_BUF]; + int ret = 0; + + memset(cmd,0,sizeof(cmd)); + strncpy(cmd,"AT+PING=",strlen("AT+PING=")); + strncat(cmd,"\"",1); + strncat(cmd,destination,strlen(destination)); + strncat(cmd,"\"",1); + strcat(cmd,"\r\n"); + + ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK"); ///< config as softAP+station mode + if(ret < 0) { + printf("%s %d ping [%s] failed!\n",__func__,__LINE__,destination); + return -1; + } + + printf("ping [%s] ok\n", destination); + + return 0; +} + +/** + * @description: display wifi network configuration + * @param adapter - wifi device pointer + * @return success: EOK, failure: ENOMEMORY + */ +static int Esp8285WifiNetstat(struct Adapter *adapter) +{ + int ret = 0; + char *result = NULL; + + /* check the wifi ip address */ + ATReplyType reply = CreateATReply(256); + if (NULL == reply) { + printf("%s %d at_create_resp failed!\n",__func__,__LINE__); + return -1; + } + ret = ATOrderSend(adapter->agent, REPLY_TIME_OUT, reply, "AT+CIFSR\r\n"); + if(ret < 0){ + printf("%s %d ATOrderSend AT+CIFSR failed.\n",__func__,__LINE__); + ret = -1; + goto __exit; + } + + result = GetReplyText(reply); + if (!result) { + printf("%s %n get reply failed.\n",__func__,__LINE__); + ret = -1; + goto __exit; + } + printf("[%s]\n", result); + +__exit: + DeleteATReply(reply); + + return ret; +} + +/** + * @description: wifi connect function + * @param adapter - wifi device pointer + * @param net_role - net role, CLIENT or SERVER + * @param ip - ip address + * @param port - port num + * @param ip_type - ip type, IPV4 or IPV6 + * @return success: 0, failure: -1 + */ +static int Esp8285WifiConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type) +{ + int ret = EOK; + char cmd[LEN_PARA_BUF]; + struct ATAgent *agent = adapter->agent; + + memset(cmd,0,sizeof(cmd)); + if(adapter->socket.protocal == SOCKET_PROTOCOL_TCP && net_role == CLIENT) //esp8285 as tcp client to connect server + { + //e.g. AT+CIPSTART="TCP","192.168.3.116",8080 protocol, server IP and port + strncpy(cmd,"AT+CIPSTART=",strlen("AT+CIPSTART=")); + strncat(cmd,"\"",1); + strncat(cmd,"TCP",strlen("TCP")); + strncat(cmd,"\"",1); + strncat(cmd, ",", 1); + strncat(cmd,"\"",1); + strncat(cmd, ip, strlen(ip)); + strncat(cmd, "\"", 1); + strncat(cmd, ",", 1); + strncat(cmd, port, strlen(port)); + strcat(cmd,"\r\n"); + + ret = AtCmdConfigAndCheck(agent, cmd, "OK"); + if(ret < 0) { + printf("%s %d tcp connect [%s] failed!\n",__func__,__LINE__,ip); + return -1; + } + } + else if(adapter->socket.protocal == SOCKET_PROTOCOL_UDP) + { + //e.g. AT+CIPSTART="UDP","192.168.3.116",8080,2233,0 UDP protocol, server IP, port,local port,udp mode + strncpy(cmd,"AT+CIPSTART=",strlen("AT+CIPSTART=")); + strncat(cmd,"\"",1); + strncat(cmd,"UDP",strlen("UDP")); + strncat(cmd,"\"",1); + strncat(cmd, ",", 1); + strncat(cmd,"\"",1); + strncat(cmd, ip, strlen(ip)); + strncat(cmd, "\"", 1); + strncat(cmd, ",", 1); + strncat(cmd, port, strlen(port)); + strncat(cmd, ",", 1); + strncat(cmd, "2233", strlen("2233")); ///< local port + strncat(cmd, ",", 1); + strncat(cmd, "0", 1); ///< udp transparent transmission mode must be 0 + strcat(cmd,"\r\n"); + + ret = AtCmdConfigAndCheck(agent, cmd, "OK"); + if(ret < 0) { + printf("%s %d udp connect [%s] failed!\n",__func__,__LINE__,ip); + return -1; + } + } + + ret = AtCmdConfigAndCheck(agent, "AT+CIPMODE=1\r\n", "OK"); ///< config as transparent transmission + if(ret < 0) { + printf("%s %d cmd[%s] config as transparent transmission failed!\n",__func__,__LINE__,cmd); + return -1; + } + ATOrderSend(agent, REPLY_TIME_OUT, NULL, "AT+CIPSEND\r\n"); + + printf("[%s] connection config as transparent transmission\n",adapter->socket.protocal == SOCKET_PROTOCOL_UDP ? "udp" : "tcp"); + adapter->net_role = net_role; + + return 0; +} + +/** + * @description: wifi disconnect function + * @param adapter - wifi device pointer + * @return success: 0, failure: -1 + */ +static int Esp8285WifiDisconnect(struct Adapter *adapter) +{ + int ret = EOK; + char cmd[LEN_PARA_BUF]; + struct ATAgent *agent = adapter->agent; + memset(cmd,0,sizeof(cmd)); + + /* step1: stop transparent transmission mode */ + ATOrderSend(agent, REPLY_TIME_OUT, NULL, "+++\r\n"); + + /* step2: exit transparent transmission mode */ + ret = AtCmdConfigAndCheck(agent, "AT+CIPMODE=0\r\n", "OK"); + if(ret < 0) { + printf("%s %d cmd[AT+CIPMODE=0] exit failed!\n",__func__,__LINE__); + return -1; + } + + /* step3: disconnect */ + ret = AtCmdConfigAndCheck(agent, "AT+CIPCLOSE\r\n", "OK"); + if(ret < 0) { + printf("%s %d cmd [AT+CIPCLOSE] disconnect failed!\n",__func__,__LINE__); + return -1; + } + + return 0; +} + +static int Esp8285WifiIoctl(struct Adapter *adapter, int cmd, void *args) +{ + int32_t ret = 0; + char baud_str[LEN_PARA_BUF]; + struct SerialDataCfg cfg; + char at_cmd[LEN_PARA_BUF]; + uint32_t baud_rate = 0 ; + + switch (cmd) + { + case CONFIG_WIFI_RESET: /* reset wifi */ + ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RST\r\n"); + break; + case CONFIG_WIFI_RESTORE: /* resore wifi */ + ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RESTORE\r\n"); + break; + case CONFIG_WIFI_BAUDRATE: + /* step1: config mcu uart*/ + baud_rate = *((uint32_t *)args); + + memset(at_cmd, 0, sizeof(at_cmd)); + memset(baud_str, 0, sizeof(baud_str)); + memset(&cfg, 0 ,sizeof(struct SerialDataCfg)); + + cfg.serial_baud_rate = baud_rate; + cfg.serial_data_bits = DATA_BITS_8; + cfg.serial_stop_bits = STOP_BITS_1; + cfg.serial_parity_mode = PARITY_NONE; + cfg.serial_bit_order = BIT_ORDER_LSB; + cfg.serial_invert_mode = NRZ_NORMAL; + cfg.serial_buffer_size = SERIAL_RB_BUFSZ; + cfg.is_ext_uart = 0; +#ifdef ADAPTER_ESP8285_DRIVER_EXT_PORT + cfg.is_ext_uart = 1; + cfg.ext_uart_no = ADAPTER_ESP8285_DRIVER_EXT_PORT; + cfg.port_configure = PORT_CFG_INIT; +#endif + + struct PrivIoctlCfg ioctl_cfg; + ioctl_cfg.ioctl_driver_type = SERIAL_TYPE; + ioctl_cfg.args = &cfg; + + PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg); + + /* step2: config wifi uart*/ + itoa(baud_rate, baud_str, 10); + + strncpy(at_cmd, "AT+UART_DEF=", strlen("AT+UART_DEF=")); + strncat(at_cmd, baud_str, strlen(baud_str)); + strncat(at_cmd, ",", 1); + strncat(at_cmd, "8", 1); + strncat(at_cmd, ",", 1); + strncat(at_cmd, "1", 1); + strncat(at_cmd, ",", 1); + strncat(at_cmd, "0", 1); + strncat(at_cmd, ",", 1); + strncat(at_cmd, "3", 1); + strcat(at_cmd,"\r\n"); + + ret = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK"); + if(ret < 0) { + printf("%s %d cmd [%s] config uart failed!\n",__func__,__LINE__,at_cmd); + ret = -1; + } + + break; + default: + ret = -1; + break; + } + + return ret; +} + +static const struct IpProtocolDone esp8285_wifi_done = +{ + .open = Esp8285WifiOpen, + .close = Esp8285WifiClose, + .ioctl = Esp8285WifiIoctl, + .setup = Esp8285WifiSetUp, + .setdown = Esp8285WifiSetDown, + .setaddr = Esp8285WifiSetAddr, + .setdns = NULL, + .setdhcp = NULL, + .ping = Esp8285WifiPing, + .netstat = Esp8285WifiNetstat, + .connect = Esp8285WifiConnect, + .send = Esp8285WifiSend, + .recv = Esp8285WifiReceive, + .disconnect = Esp8285WifiDisconnect, +}; + +/** + * @description: Register wifi device esp8285 + * @return success: EOK, failure: ERROR + */ +AdapterProductInfoType Esp8285WifiAttach(struct Adapter *adapter) +{ + struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo)); + if (!product_info) + { + printf("Esp8285WifiAttach Attach malloc product_info error\n"); + PrivFree(product_info); + return NULL; + } + + strncpy(product_info->model_name, ADAPTER_WIFI_ESP8285, strlen(ADAPTER_WIFI_ESP8285)); + + product_info->model_done = (void *)&esp8285_wifi_done; + + return product_info; +} diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index df3e0f488..a54df4a9c 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1556,7 +1556,7 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, int cmd_AdapterBlueToothTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif -#if defined(CONFIG_ADAPTER_ESP07S_WIFI) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) +#if (defined(CONFIG_ADAPTER_ESP07S_WIFI) || defined(CONFIG_ADAPTER_ESP8285_WIFI)) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) int cmd_AdapterWifiTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index ef6d6b2be..65507a192 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -313,7 +313,7 @@ int cmd_recvzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif -#if defined(CONFIG_ADAPTER_ESP07S_WIFI) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) +#if (defined(CONFIG_ADAPTER_ESP07S_WIFI) || defined(CONFIG_ADAPTER_ESP8285_WIFI)) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) extern int AdapterWifiTest(int argc, char *argv[]); int cmd_AdapterWifiTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index 7f542859b..5dbd550c6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -701,7 +701,7 @@ static const struct cmdmap_s g_cmdmap[] = { "AdapterBlueToothTest", cmd_AdapterBlueToothTest, 1, 1, "[BlueTooth hc08 test.]" }, #endif -#if defined(CONFIG_ADAPTER_ESP07S_WIFI) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) +#if (defined(CONFIG_ADAPTER_ESP07S_WIFI) || defined(CONFIG_ADAPTER_ESP8285_WIFI)) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) { "wifitest", cmd_AdapterWifiTest, 1, 8, "[WIFI test.]" }, #endif From b65663af4c679f1ef9f66552fef813ed9fbdbbbd Mon Sep 17 00:00:00 2001 From: wlyu Date: Mon, 10 Oct 2022 20:21:53 +0800 Subject: [PATCH 14/30] change extrasram_test name with ExtramTest --- .../app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index faff3ef98..78373cdf6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -68,11 +68,11 @@ int cmd_Lcd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_Extsram ****************************************************************************/ #if defined(CONFIG_USER_TEST_SEMC) && !defined(CONFIG_NSH_DISABLE_USER_TEST_SEMC) -extern int extsram_test(void); +extern int ExtsramTest(void); int cmd_Extsram(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, extra sdram!\n"); - extsram_test(); + ExtsramTest(); return OK; } #endif From a1ddea8e5e7a50c2bfcfb7f12f3efbf3c91c9d34 Mon Sep 17 00:00:00 2001 From: wlyu Date: Mon, 10 Oct 2022 20:43:37 +0800 Subject: [PATCH 15/30] optimize extsram test output --- APP_Framework/Applications/app_test/test_extsram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/APP_Framework/Applications/app_test/test_extsram.c b/APP_Framework/Applications/app_test/test_extsram.c index 7467733cf..09b5316ce 100755 --- a/APP_Framework/Applications/app_test/test_extsram.c +++ b/APP_Framework/Applications/app_test/test_extsram.c @@ -53,7 +53,7 @@ int ExtsramTest(void) #endif /* write data */ - printf("Writing the %ld bytes data, waiting....", SRAM_SIZE); + printf("Writing the %ld bytes data, waiting....\n", SRAM_SIZE); start_time = PrivGetTickTime(); for (i = 0; i < SRAM_SIZE / data_width; i++) { @@ -91,7 +91,7 @@ int ExtsramTest(void) data = *(volatile uint32_t *)(SRAM_BANK_ADDR + i * data_width); if (data != 0x55555555) { - printf("SRAM test failed!"); + printf("SRAM test failed!\n"); break; } #endif From 0f1d2a4868c357c2af4b1a1eaf9fb10f90f01977 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 11 Oct 2022 21:16:40 +0800 Subject: [PATCH 16/30] add ch376 usb demo on xidatong-riscv64 --- .../aiit_board/xidatong-riscv64/Kconfig | 21 + .../aiit_board/xidatong-riscv64/src/Makefile | 6 +- .../xidatong-riscv64/src/ch376_demo.c | 68 + .../xidatong-riscv64/src/ch376inc.h | 1252 ++++++----------- .../xidatong-riscv64/src/k210_ch376.c | 1120 ++++++++------- .../xidatong-riscv64/src/k210_ch376.h | 130 +- .../app_match_nuttx/apps/nshlib/Kconfig | 4 + .../app_match_nuttx/apps/nshlib/nsh.h | 4 + .../apps/nshlib/nsh_Applicationscmd.c | 13 + .../app_match_nuttx/apps/nshlib/nsh_command.c | 4 + 10 files changed, 1193 insertions(+), 1429 deletions(-) create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376_demo.c diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig index 56405367b..90cfa7ee5 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig @@ -5,6 +5,27 @@ if ARCH_BOARD_XIDATONG_RISCV64 +menuconfig BSP_USING_CH376 + bool "Using ch376 device" + default n + select K210_16550_UART + select K210_16550_UART3 + +if BSP_USING_CH376 + +choice + prompt "select ch376 function." + default CH376_USB_FUNCTION + +config CH376_USB_FUNCTION + bool "select ch376 usb function" + +config CH376_SD_FUNCTION + bool "select ch376 sd function" +endchoice + +endif # BSP_USING_CH376 + menuconfig BSP_USING_CH438 bool "Using CH438 device" default n diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile index 3258528d7..90a9d8f65 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile @@ -20,7 +20,7 @@ include $(TOPDIR)/Make.defs -CSRCS = k210_bringup.c k210_boot.c k210_ch376.c +CSRCS = k210_bringup.c k210_boot.c ifeq ($(CONFIG_BOARDCTL_RESET),y) CSRCS += k210_reset.c @@ -46,4 +46,8 @@ ifeq ($(CONFIG_BSP_USING_CH438),y) CSRCS += k210_ch438.c ch438_demo.c endif +ifeq ($(CONFIG_BSP_USING_CH376),y) +CSRCS += k210_ch376.c ch376_demo.c +endif + include $(TOPDIR)/boards/Board.mk diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376_demo.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376_demo.c new file mode 100644 index 000000000..d4302842a --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376_demo.c @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file ch376_demo.c + * @brief xidatong-riscv64 ch376_demo.c + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.10.11 + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include "k210_ch376.h" + +uint8_t buf[64]; + +void CH376Demo(void) +{ + uint8_t s; + s = mInitCH376Host(); + printf ("ch376 init stat=0x%02x\n",(uint16_t)s); + + printf( "Wait Udisk/SD\n" ); + while ( CH376DiskConnect( ) != USB_INT_SUCCESS ) + { + up_mdelay( 100 ); + } + + for ( s = 0; s < 10; s ++ ) + { + up_mdelay( 50 ); + printf( "Ready ?\n" ); + if ( CH376DiskMount( ) == USB_INT_SUCCESS ) break; + } + s = CH376ReadBlock( buf ); + if ( s == sizeof( INQUIRY_DATA ) ) + { + buf[ s ] = 0; + printf( "UdiskInfo: %s\n", ((P_INQUIRY_DATA)buf) -> VendorIdStr ); + } + + printf( "Create /YEAR2022/DEMO2022.TXT \n" ); + s = CH376DirCreate((PUINT8)"/YEAR2022" ); + printf("CH376DirCreate:0x%02x\n",(uint16_t)s ); + + s = CH376FileCreatePath((PUINT8)"/YEAR2022/DEMO2022.TXT" ); + printf( "CH376FileCreatePath:0x%02x\n",(uint16_t)s ); + + printf( "Write some data to file\n" ); + strcpy( (char *)buf, "This is 婕旂ず鏁版嵁\xd\xa" ); + s = CH376ByteWrite(buf, strlen((char *)buf), NULL ); + printf( "CH376ByteWrite:0x%02x\n",(uint16_t)s ); + + printf( "Close\n" ); + s = CH376FileClose( TRUE ); + printf( "CH376FileClose:0x%02x\n",(uint16_t)s ); +} diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376inc.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376inc.h index 63d757a73..ec8a4d08f 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376inc.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376inc.h @@ -25,896 +25,554 @@ extern "C" { #endif -/* ********************************************************************************************************************* */ -/* 甯哥敤绫诲瀷鍜屽父閲忓畾涔 */ +/* Common types and constant definitions */ -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 #endif -#ifndef NULL -#define NULL 0 +#ifndef NULL +#define NULL 0 #endif #ifndef UINT8 -typedef unsigned char UINT8; +typedef unsigned char UINT8; #endif #ifndef UINT16 -typedef unsigned short UINT16; +typedef unsigned short UINT16; #endif #ifndef UINT32 -typedef unsigned long UINT32; +typedef unsigned long UINT32; #endif #ifndef PUINT8 -typedef unsigned char *PUINT8; +typedef unsigned char *PUINT8; #endif #ifndef PUINT16 -typedef unsigned short *PUINT16; +typedef unsigned short *PUINT16; #endif #ifndef PUINT32 -typedef unsigned long *PUINT32; +typedef unsigned long *PUINT32; #endif #ifndef UINT8V -typedef unsigned char volatile UINT8V; +typedef unsigned char volatile UINT8V; #endif #ifndef PUINT8V -typedef unsigned char volatile *PUINT8V; +typedef unsigned char volatile *PUINT8V; +#endif + +#define CH376_DAT_BLOCK_LEN 0x40 +#define CMD01_GET_IC_VER 0x01 +#define CMD21_SET_BAUDRATE 0x02 +#define CMD00_ENTER_SLEEP 0x03 +#define CMD00_RESET_ALL 0x05 +#define CMD11_CHECK_EXIST 0x06 +#define CMD20_CHK_SUSPEND 0x0B +#define CMD20_SET_SDO_INT 0x0B +#define CMD14_GET_FILE_SIZE 0x0C +#define CMD50_SET_FILE_SIZE 0x0D +#define CMD11_SET_USB_MODE 0x15 +#define CMD01_GET_STATUS 0x22 +#define CMD00_UNLOCK_USB 0x23 +#define CMD01_RD_USB_DATA0 0x27 +#define CMD01_RD_USB_DATA 0x28 +#define CMD10_WR_USB_DATA7 0x2B +#define CMD10_WR_HOST_DATA 0x2C +#define CMD01_WR_REQ_DATA 0x2D +#define CMD20_WR_OFS_DATA 0x2E +#define CMD10_SET_FILE_NAME 0x2F +#define CMD0H_DISK_CONNECT 0x30 +#define CMD0H_DISK_MOUNT 0x31 +#define CMD0H_FILE_OPEN 0x32 +#define CMD0H_FILE_ENUM_GO 0x33 +#define CMD0H_FILE_CREATE 0x34 +#define CMD0H_FILE_ERASE 0x35 +#define CMD1H_FILE_CLOSE 0x36 +#define CMD1H_DIR_INFO_READ 0x37 +#define CMD0H_DIR_INFO_SAVE 0x38 +#define CMD4H_BYTE_LOCATE 0x39 +#define CMD2H_BYTE_READ 0x3A +#define CMD0H_BYTE_RD_GO 0x3B +#define CMD2H_BYTE_WRITE 0x3C +#define CMD0H_BYTE_WR_GO 0x3D +#define CMD0H_DISK_CAPACITY 0x3E +#define CMD0H_DISK_QUERY 0x3F +#define CMD0H_DIR_CREATE 0x40 +#define CMD4H_SEC_LOCATE 0x4A +#define CMD1H_SEC_READ 0x4B +#define CMD1H_SEC_WRITE 0x4C +#define CMD0H_DISK_BOC_CMD 0x50 +#define CMD5H_DISK_READ 0x54 +#define CMD0H_DISK_RD_GO 0x55 +#define CMD5H_DISK_WRITE 0x56 +#define CMD0H_DISK_WR_GO 0x57 +#define CMD10_SET_USB_SPEED 0x04 +#define CMD11_GET_DEV_RATE 0x0A +#define CMD11_GET_TOGGLE 0x0A +#define CMD11_READ_VAR8 0x0A +#define CMD20_SET_RETRY 0x0B +#define CMD20_WRITE_VAR8 0x0B +#define CMD14_READ_VAR32 0x0C +#define CMD50_WRITE_VAR32 0x0D +#define CMD01_DELAY_100US 0x0F +#define CMD40_SET_USB_ID 0x12 +#define CMD10_SET_USB_ADDR 0x13 +#define CMD01_TEST_CONNECT 0x16 +#define CMD00_ABORT_NAK 0x17 +#define CMD10_SET_ENDP2 0x18 +#define CMD10_SET_ENDP3 0x19 +#define CMD10_SET_ENDP4 0x1A +#define CMD10_SET_ENDP5 0x1B +#define CMD10_SET_ENDP6 0x1C +#define CMD10_SET_ENDP7 0x1D +#define CMD00_DIRTY_BUFFER 0x25 +#define CMD10_WR_USB_DATA3 0x29 +#define CMD10_WR_USB_DATA5 0x2A +#define CMD1H_CLR_STALL 0x41 +#define CMD1H_SET_ADDRESS 0x45 +#define CMD1H_GET_DESCR 0x46 +#define CMD1H_SET_CONFIG 0x49 +#define CMD0H_AUTO_SETUP 0x4D +#define CMD2H_ISSUE_TKN_X 0x4E +#define CMD1H_ISSUE_TOKEN 0x4F +#define CMD0H_DISK_INIT 0x51 +#define CMD0H_DISK_RESET 0x52 +#define CMD0H_DISK_SIZE 0x53 +#define CMD0H_DISK_INQUIRY 0x58 +#define CMD0H_DISK_READY 0x59 +#define CMD0H_DISK_R_SENSE 0x5A +#define CMD0H_RD_DISK_SEC 0x5B +#define CMD0H_WR_DISK_SEC 0x5C +#define CMD0H_DISK_MAX_LUN 0x5D + +/* The following definitions are only for compatibility with the command name format in the INCLUDE file of CH375 */ + +#ifndef _NO_CH375_COMPATIBLE_ +#define CMD_GET_IC_VER CMD01_GET_IC_VER +#define CMD_SET_BAUDRATE CMD21_SET_BAUDRATE +#define CMD_ENTER_SLEEP CMD00_ENTER_SLEEP +#define CMD_RESET_ALL CMD00_RESET_ALL +#define CMD_CHECK_EXIST CMD11_CHECK_EXIST +#define CMD_CHK_SUSPEND CMD20_CHK_SUSPEND +#define CMD_SET_SDO_INT CMD20_SET_SDO_INT +#define CMD_GET_FILE_SIZE CMD14_GET_FILE_SIZE +#define CMD_SET_FILE_SIZE CMD50_SET_FILE_SIZE +#define CMD_SET_USB_MODE CMD11_SET_USB_MODE +#define CMD_GET_STATUS CMD01_GET_STATUS +#define CMD_UNLOCK_USB CMD00_UNLOCK_USB +#define CMD_RD_USB_DATA0 CMD01_RD_USB_DATA0 +#define CMD_RD_USB_DATA CMD01_RD_USB_DATA +#define CMD_WR_USB_DATA7 CMD10_WR_USB_DATA7 +#define CMD_WR_HOST_DATA CMD10_WR_HOST_DATA +#define CMD_WR_REQ_DATA CMD01_WR_REQ_DATA +#define CMD_WR_OFS_DATA CMD20_WR_OFS_DATA +#define CMD_SET_FILE_NAME CMD10_SET_FILE_NAME +#define CMD_DISK_CONNECT CMD0H_DISK_CONNECT +#define CMD_DISK_MOUNT CMD0H_DISK_MOUNT +#define CMD_FILE_OPEN CMD0H_FILE_OPEN +#define CMD_FILE_ENUM_GO CMD0H_FILE_ENUM_GO +#define CMD_FILE_CREATE CMD0H_FILE_CREATE +#define CMD_FILE_ERASE CMD0H_FILE_ERASE +#define CMD_FILE_CLOSE CMD1H_FILE_CLOSE +#define CMD_DIR_INFO_READ CMD1H_DIR_INFO_READ +#define CMD_DIR_INFO_SAVE CMD0H_DIR_INFO_SAVE +#define CMD_BYTE_LOCATE CMD4H_BYTE_LOCATE +#define CMD_BYTE_READ CMD2H_BYTE_READ +#define CMD_BYTE_RD_GO CMD0H_BYTE_RD_GO +#define CMD_BYTE_WRITE CMD2H_BYTE_WRITE +#define CMD_BYTE_WR_GO CMD0H_BYTE_WR_GO +#define CMD_DISK_CAPACITY CMD0H_DISK_CAPACITY +#define CMD_DISK_QUERY CMD0H_DISK_QUERY +#define CMD_DIR_CREATE CMD0H_DIR_CREATE +#define CMD_SEC_LOCATE CMD4H_SEC_LOCATE +#define CMD_SEC_READ CMD1H_SEC_READ +#define CMD_SEC_WRITE CMD1H_SEC_WRITE +#define CMD_DISK_BOC_CMD CMD0H_DISK_BOC_CMD +#define CMD_DISK_READ CMD5H_DISK_READ +#define CMD_DISK_RD_GO CMD0H_DISK_RD_GO +#define CMD_DISK_WRITE CMD5H_DISK_WRITE +#define CMD_DISK_WR_GO CMD0H_DISK_WR_GO +#define CMD_SET_USB_SPEED CMD10_SET_USB_SPEED +#define CMD_GET_DEV_RATE CMD11_GET_DEV_RATE +#define CMD_GET_TOGGLE CMD11_GET_TOGGLE +#define CMD_READ_VAR8 CMD11_READ_VAR8 +#define CMD_SET_RETRY CMD20_SET_RETRY +#define CMD_WRITE_VAR8 CMD20_WRITE_VAR8 +#define CMD_READ_VAR32 CMD14_READ_VAR32 +#define CMD_WRITE_VAR32 CMD50_WRITE_VAR32 +#define CMD_DELAY_100US CMD01_DELAY_100US +#define CMD_SET_USB_ID CMD40_SET_USB_ID +#define CMD_SET_USB_ADDR CMD10_SET_USB_ADDR +#define CMD_TEST_CONNECT CMD01_TEST_CONNECT +#define CMD_ABORT_NAK CMD00_ABORT_NAK +#define CMD_SET_ENDP2 CMD10_SET_ENDP2 +#define CMD_SET_ENDP3 CMD10_SET_ENDP3 +#define CMD_SET_ENDP4 CMD10_SET_ENDP4 +#define CMD_SET_ENDP5 CMD10_SET_ENDP5 +#define CMD_SET_ENDP6 CMD10_SET_ENDP6 +#define CMD_SET_ENDP7 CMD10_SET_ENDP7 +#define CMD_DIRTY_BUFFER CMD00_DIRTY_BUFFER +#define CMD_WR_USB_DATA3 CMD10_WR_USB_DATA3 +#define CMD_WR_USB_DATA5 CMD10_WR_USB_DATA5 +#define CMD_CLR_STALL CMD1H_CLR_STALL +#define CMD_SET_ADDRESS CMD1H_SET_ADDRESS +#define CMD_GET_DESCR CMD1H_GET_DESCR +#define CMD_SET_CONFIG CMD1H_SET_CONFIG +#define CMD_AUTO_SETUP CMD0H_AUTO_SETUP +#define CMD_ISSUE_TKN_X CMD2H_ISSUE_TKN_X +#define CMD_ISSUE_TOKEN CMD1H_ISSUE_TOKEN +#define CMD_DISK_INIT CMD0H_DISK_INIT +#define CMD_DISK_RESET CMD0H_DISK_RESET +#define CMD_DISK_SIZE CMD0H_DISK_SIZE +#define CMD_DISK_INQUIRY CMD0H_DISK_INQUIRY +#define CMD_DISK_READY CMD0H_DISK_READY +#define CMD_DISK_R_SENSE CMD0H_DISK_R_SENSE +#define CMD_RD_DISK_SEC CMD0H_RD_DISK_SEC +#define CMD_WR_DISK_SEC CMD0H_WR_DISK_SEC +#define CMD_DISK_MAX_LUN CMD0H_DISK_MAX_LUN #endif /* ********************************************************************************************************************* */ -/* 纭欢鐗规 */ - -#define CH376_DAT_BLOCK_LEN 0x40 /* USB鍗曚釜鏁版嵁鍖, 鏁版嵁鍧楃殑鏈澶ч暱搴, 榛樿缂撳啿鍖虹殑闀垮害 */ - -/* ********************************************************************************************************************* */ -/* 鍛戒护浠g爜 */ -/* 閮ㄥ垎鍛戒护鍏煎CH375鑺墖, 浣嗘槸杈撳叆鏁版嵁鎴栬呰緭鍑烘暟鎹殑鍙兘灞閮ㄤ笉鍚) */ -/* 涓涓懡浠ゆ搷浣滈『搴忓寘鍚: - 涓涓懡浠ょ爜(瀵逛簬涓插彛鏂瑰紡,鍛戒护鐮佷箣鍓嶈繕闇瑕佷袱涓悓姝ョ爜), - 鑻ュ共涓緭鍏ユ暟鎹(鍙互鏄0涓), - 浜х敓涓柇閫氱煡 鎴栬 鑻ュ共涓緭鍑烘暟鎹(鍙互鏄0涓), 浜岄変竴, 鏈変腑鏂氱煡鍒欎竴瀹氭病鏈夎緭鍑烘暟鎹, 鏈夎緭鍑烘暟鎹垯涓瀹氫笉浜х敓涓柇 - 浠匔MD01_WR_REQ_DATA鍛戒护渚嬪, 椤哄簭鍖呭惈: 涓涓懡浠ょ爜, 涓涓緭鍑烘暟鎹, 鑻ュ共涓緭鍏ユ暟鎹 - 鍛戒护鐮佽捣鍚嶈鍒: CMDxy_NAME - 鍏朵腑鐨剎鍜寉閮芥槸鏁板瓧, x璇存槑鏈灏戣緭鍏ユ暟鎹釜鏁(瀛楄妭鏁), y璇存槑鏈灏戣緭鍑烘暟鎹釜鏁(瀛楄妭鏁), y濡傛灉鏄疕鍒欒鏄庝骇鐢熶腑鏂氱煡, - 鏈変簺鍛戒护鑳藉瀹炵幇0鍒板涓瓧鑺傜殑鏁版嵁鍧楄鍐, 鏁版嵁鍧楁湰韬殑瀛楄妭鏁版湭鍖呭惈鍦ㄤ笂杩皒鎴杫涔嬪唴 */ -/* 鏈枃浠堕粯璁や細鍚屾椂鎻愪緵涓嶤H375鑺墖鍛戒护鐮佸吋瀹圭殑鍛戒护鐮佹牸寮忥紙鍗冲幓鎺墄鍜寉涔嬪悗), 濡傛灉涓嶉渶瑕, 閭d箞鍙互瀹氫箟_NO_CH375_COMPATIBLE_绂佹 */ - -/* ********************************************************************************************************************* */ -/* 涓昏鍛戒护(鎵嬪唽涓), 甯哥敤 */ - -#define CMD01_GET_IC_VER 0x01 /* 鑾峰彇鑺墖鍙婂浐浠剁増鏈 */ -/* 杈撳嚭: 鐗堟湰鍙( 浣7涓0, 浣6涓1, 浣5~浣0涓虹増鏈彿 ) */ -/* CH376杩斿洖鐗堟湰鍙风殑鍊间负041H鍗崇増鏈彿涓01H */ - -#define CMD21_SET_BAUDRATE 0x02 /* 涓插彛鏂瑰紡: 璁剧疆涓插彛閫氳娉㈢壒鐜(涓婄數鎴栬呭浣嶅悗鐨勯粯璁ゆ尝鐗圭巼涓9600bps,鐢盌4/D5/D6寮曡剼閫夋嫨) */ -/* 杈撳叆: 娉㈢壒鐜囧垎棰戠郴鏁, 娉㈢壒鐜囧垎棰戝父鏁 */ -/* 杈撳嚭: 鎿嶄綔鐘舵( CMD_RET_SUCCESS鎴朇MD_RET_ABORT, 鍏跺畠鍊艰鏄庢搷浣滄湭瀹屾垚 ) */ - -#define CMD00_ENTER_SLEEP 0x03 /* 杩涘叆鐫$湢鐘舵 */ - -#define CMD00_RESET_ALL 0x05 /* 鎵ц纭欢澶嶄綅 */ - -#define CMD11_CHECK_EXIST 0x06 /* 娴嬭瘯閫氳鎺ュ彛鍜屽伐浣滅姸鎬 */ -/* 杈撳叆: 浠绘剰鏁版嵁 */ -/* 杈撳嚭: 杈撳叆鏁版嵁鐨勬寜浣嶅彇鍙 */ - -#define CMD20_CHK_SUSPEND 0x0B /* 璁惧鏂瑰紡: 璁剧疆妫鏌SB鎬荤嚎鎸傝捣鐘舵佺殑鏂瑰紡 */ -/* 杈撳叆: 鏁版嵁10H, 妫鏌ユ柟寮 */ -/* 00H=涓嶆鏌SB鎸傝捣, 04H=浠50mS涓洪棿闅旀鏌SB鎸傝捣, 05H=浠10mS涓洪棿闅旀鏌SB鎸傝捣 */ - -#define CMD20_SET_SDO_INT 0x0B /* SPI鎺ュ彛鏂瑰紡: 璁剧疆SPI鐨凷DO寮曡剼鐨勪腑鏂柟寮 */ -/* 杈撳叆: 鏁版嵁16H, 涓柇鏂瑰紡 */ -/* 10H=绂佹SDO寮曡剼鐢ㄤ簬涓柇杈撳嚭,鍦⊿CS鐗囬夋棤鏁堟椂涓夋佽緭鍑虹姝, 90H=SDO寮曡剼鍦⊿CS鐗囬夋棤鏁堟椂鍏煎仛涓柇璇锋眰杈撳嚭 */ - -#define CMD14_GET_FILE_SIZE 0x0C /* 涓绘満鏂囦欢妯″紡: 鑾峰彇褰撳墠鏂囦欢闀垮害 */ -/* 杈撳叆: 鏁版嵁68H */ -/* 杈撳嚭: 褰撳墠鏂囦欢闀垮害(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - -#define CMD50_SET_FILE_SIZE 0x0D /* 涓绘満鏂囦欢妯″紡: 璁剧疆褰撳墠鏂囦欢闀垮害 */ -/* 杈撳叆: 鏁版嵁68H, 褰撳墠鏂囦欢闀垮害(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - -#define CMD11_SET_USB_MODE 0x15 /* 璁剧疆USB宸ヤ綔妯″紡 */ -/* 杈撳叆: 妯″紡浠g爜 */ -/* 00H=鏈惎鐢ㄧ殑璁惧鏂瑰紡, 01H=宸插惎鐢ㄧ殑璁惧鏂瑰紡骞朵笖浣跨敤澶栭儴鍥轰欢妯″紡(涓插彛涓嶆敮鎸), 02H=宸插惎鐢ㄧ殑璁惧鏂瑰紡骞朵笖浣跨敤鍐呯疆鍥轰欢妯″紡 */ -/* 03H=SD鍗′富鏈烘ā寮/鏈惎鐢ㄧ殑涓绘満妯″紡,鐢ㄤ簬绠$悊鍜屽瓨鍙朣D鍗′腑鐨勬枃浠 */ -/* 04H=鏈惎鐢ㄧ殑涓绘満鏂瑰紡, 05H=宸插惎鐢ㄧ殑涓绘満鏂瑰紡, 06H=宸插惎鐢ㄧ殑涓绘満鏂瑰紡骞朵笖鑷姩浜х敓SOF鍖, 07H=宸插惎鐢ㄧ殑涓绘満鏂瑰紡骞朵笖澶嶄綅USB鎬荤嚎 */ -/* 杈撳嚭: 鎿嶄綔鐘舵( CMD_RET_SUCCESS鎴朇MD_RET_ABORT, 鍏跺畠鍊艰鏄庢搷浣滄湭瀹屾垚 ) */ - -#define CMD01_GET_STATUS 0x22 /* 鑾峰彇涓柇鐘舵佸苟鍙栨秷涓柇璇锋眰 */ -/* 杈撳嚭: 涓柇鐘舵 */ - -#define CMD00_UNLOCK_USB 0x23 /* 璁惧鏂瑰紡: 閲婃斁褰撳墠USB缂撳啿鍖 */ - -#define CMD01_RD_USB_DATA0 0x27 /* 浠庡綋鍓峌SB涓柇鐨勭鐐圭紦鍐插尯鎴栬呬富鏈虹鐐圭殑鎺ユ敹缂撳啿鍖鸿鍙栨暟鎹潡 */ -/* 杈撳嚭: 闀垮害, 鏁版嵁娴 */ - -#define CMD01_RD_USB_DATA 0x28 /* 璁惧鏂瑰紡: 浠庡綋鍓峌SB涓柇鐨勭鐐圭紦鍐插尯璇诲彇鏁版嵁鍧, 骞堕噴鏀剧紦鍐插尯, 鐩稿綋浜 CMD01_RD_USB_DATA0 + CMD00_UNLOCK_USB */ -/* 杈撳嚭: 闀垮害, 鏁版嵁娴 */ - -#define CMD10_WR_USB_DATA7 0x2B /* 璁惧鏂瑰紡: 鍚慤SB绔偣2鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ -/* 杈撳叆: 闀垮害, 鏁版嵁娴 */ - -#define CMD10_WR_HOST_DATA 0x2C /* 鍚慤SB涓绘満绔偣鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ -/* 杈撳叆: 闀垮害, 鏁版嵁娴 */ - -#define CMD01_WR_REQ_DATA 0x2D /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡 */ -/* 杈撳嚭: 闀垮害 */ -/* 杈撳叆: 鏁版嵁娴 */ - -#define CMD20_WR_OFS_DATA 0x2E /* 鍚戝唴閮ㄧ紦鍐插尯鎸囧畾鍋忕Щ鍦板潃鍐欏叆鏁版嵁鍧 */ -/* 杈撳叆: 鍋忕Щ, 闀垮害, 鏁版嵁娴 */ - -#define CMD10_SET_FILE_NAME 0x2F /* 涓绘満鏂囦欢妯″紡: 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ -/* 杈撳叆: 浠0缁撴潫鐨勫瓧绗︿覆(鍚粨鏉熺0鍦ㄥ唴闀垮害涓嶈秴杩14涓瓧绗) */ - -/* ********************************************************************************************************************* */ -/* 涓昏鍛戒护(鎵嬪唽涓), 甯哥敤, 浠ヤ笅鍛戒护鎬绘槸鍦ㄦ搷浣滅粨鏉熸椂浜х敓涓柇閫氱煡, 骞朵笖鎬绘槸娌℃湁杈撳嚭鏁版嵁 */ - -#define CMD0H_DISK_CONNECT 0x30 /* 涓绘満鏂囦欢妯″紡/涓嶆敮鎸丼D鍗: 妫鏌ョ鐩樻槸鍚﹁繛鎺 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_MOUNT 0x31 /* 涓绘満鏂囦欢妯″紡: 鍒濆鍖栫鐩樺苟娴嬭瘯纾佺洏鏄惁灏辩华 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_FILE_OPEN 0x32 /* 涓绘満鏂囦欢妯″紡: 鎵撳紑鏂囦欢鎴栬呯洰褰(鏂囦欢澶),鎴栬呮灇涓炬枃浠跺拰鐩綍(鏂囦欢澶) */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_FILE_ENUM_GO 0x33 /* 涓绘満鏂囦欢妯″紡: 缁х画鏋氫妇鏂囦欢鍜岀洰褰(鏂囦欢澶) */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_FILE_CREATE 0x34 /* 涓绘満鏂囦欢妯″紡: 鏂板缓鏂囦欢,濡傛灉鏂囦欢宸茬粡瀛樺湪閭d箞鍏堝垹闄 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_FILE_ERASE 0x35 /* 涓绘満鏂囦欢妯″紡: 鍒犻櫎鏂囦欢,濡傛灉宸茬粡鎵撳紑鍒欑洿鎺ュ垹闄,鍚﹀垯瀵逛簬鏂囦欢浼氬厛鎵撳紑鍐嶅垹闄,瀛愮洰褰曞繀椤诲厛鎵撳紑 */ -/* 杈撳嚭涓柇 */ - -#define CMD1H_FILE_CLOSE 0x36 /* 涓绘満鏂囦欢妯″紡: 鍏抽棴褰撳墠宸茬粡鎵撳紑鐨勬枃浠舵垨鑰呯洰褰(鏂囦欢澶) */ -/* 杈撳叆: 鏄惁鍏佽鏇存柊鏂囦欢闀垮害 */ -/* 00H=绂佹鏇存柊闀垮害, 01H=鍏佽鏇存柊闀垮害 */ -/* 杈撳嚭涓柇 */ - -#define CMD1H_DIR_INFO_READ 0x37 /* 涓绘満鏂囦欢妯″紡: 璇诲彇鏂囦欢鐨勭洰褰曚俊鎭 */ -/* 杈撳叆: 鎸囧畾闇瑕佽鍙栫殑鐩綍淇℃伅缁撴瀯鍦ㄦ墖鍖哄唴鐨勭储寮曞彿 */ -/* 绱㈠紩鍙疯寖鍥翠负00H~0FH, 绱㈠紩鍙0FFH鍒欎负褰撳墠宸茬粡鎵撳紑鐨勬枃浠 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DIR_INFO_SAVE 0x38 /* 涓绘満鏂囦欢妯″紡: 淇濆瓨鏂囦欢鐨勭洰褰曚俊鎭 */ -/* 杈撳嚭涓柇 */ - -#define CMD4H_BYTE_LOCATE 0x39 /* 涓绘満鏂囦欢妯″紡: 浠ュ瓧鑺備负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ -/* 杈撳叆: 鍋忕Щ瀛楄妭鏁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -/* 杈撳嚭涓柇 */ - -#define CMD2H_BYTE_READ 0x3A /* 涓绘満鏂囦欢妯″紡: 浠ュ瓧鑺備负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ -/* 杈撳叆: 璇锋眰璇诲彇鐨勫瓧鑺傛暟(鎬婚暱搴16浣,浣庡瓧鑺傚湪鍓) */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_BYTE_RD_GO 0x3B /* 涓绘満鏂囦欢妯″紡: 缁х画瀛楄妭璇 */ -/* 杈撳嚭涓柇 */ - -#define CMD2H_BYTE_WRITE 0x3C /* 涓绘満鏂囦欢妯″紡: 浠ュ瓧鑺備负鍗曚綅鍚戝綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ -/* 杈撳叆: 璇锋眰鍐欏叆鐨勫瓧鑺傛暟(鎬婚暱搴16浣,浣庡瓧鑺傚湪鍓) */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_BYTE_WR_GO 0x3D /* 涓绘満鏂囦欢妯″紡: 缁х画瀛楄妭鍐 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_CAPACITY 0x3E /* 涓绘満鏂囦欢妯″紡: 鏌ヨ纾佺洏鐗╃悊瀹归噺 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_QUERY 0x3F /* 涓绘満鏂囦欢妯″紡: 鏌ヨ纾佺洏绌洪棿淇℃伅 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DIR_CREATE 0x40 /* 涓绘満鏂囦欢妯″紡: 鏂板缓鐩綍(鏂囦欢澶)骞舵墦寮,濡傛灉鐩綍宸茬粡瀛樺湪閭d箞鐩存帴鎵撳紑 */ -/* 杈撳嚭涓柇 */ - -#define CMD4H_SEC_LOCATE 0x4A /* 涓绘満鏂囦欢妯″紡: 浠ユ墖鍖轰负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ -/* 杈撳叆: 鍋忕Щ鎵囧尯鏁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -/* 杈撳嚭涓柇 */ - -#define CMD1H_SEC_READ 0x4B /* 涓绘満鏂囦欢妯″紡/涓嶆敮鎸丼D鍗: 浠ユ墖鍖轰负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ -/* 杈撳叆: 璇锋眰璇诲彇鐨勬墖鍖烘暟 */ -/* 杈撳嚭涓柇 */ - -#define CMD1H_SEC_WRITE 0x4C /* 涓绘満鏂囦欢妯″紡/涓嶆敮鎸丼D鍗: 浠ユ墖鍖轰负鍗曚綅鍦ㄥ綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ -/* 杈撳叆: 璇锋眰鍐欏叆鐨勬墖鍖烘暟 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_BOC_CMD 0x50 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 瀵筓SB瀛樺偍鍣ㄦ墽琛孊ulkOnly浼犺緭鍗忚鐨勫懡浠 */ -/* 杈撳嚭涓柇 */ - -#define CMD5H_DISK_READ 0x54 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 浠嶶SB瀛樺偍鍣ㄨ鐗╃悊鎵囧尯 */ -/* 杈撳叆: LBA鐗╃悊鎵囧尯鍦板潃(鎬婚暱搴32浣, 浣庡瓧鑺傚湪鍓), 鎵囧尯鏁(01H~FFH) */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_RD_GO 0x55 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 缁х画鎵цUSB瀛樺偍鍣ㄧ殑鐗╃悊鎵囧尯璇绘搷浣 */ -/* 杈撳嚭涓柇 */ - -#define CMD5H_DISK_WRITE 0x56 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鍚慤SB瀛樺偍鍣ㄥ啓鐗╃悊鎵囧尯 */ -/* 杈撳叆: LBA鐗╃悊鎵囧尯鍦板潃(鎬婚暱搴32浣, 浣庡瓧鑺傚湪鍓), 鎵囧尯鏁(01H~FFH) */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_WR_GO 0x57 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 缁х画鎵цUSB瀛樺偍鍣ㄧ殑鐗╃悊鎵囧尯鍐欐搷浣 */ -/* 杈撳嚭涓柇 */ - -/* ********************************************************************************************************************* */ -/* 杈呭姪鍛戒护(鎵嬪唽浜), 涓嶅お甯哥敤鎴栬呮槸涓轰簡涓嶤H375鍜孋H372鍏煎 */ - -#define CMD10_SET_USB_SPEED 0x04 /* 璁剧疆USB鎬荤嚎閫熷害, 鍦ㄦ瘡娆MD11_SET_USB_MODE璁剧疆USB宸ヤ綔妯″紡鏃朵細鑷姩鎭㈠鍒12Mbps鍏ㄩ */ -/* 杈撳叆: 鎬荤嚎閫熷害浠g爜 */ -/* 00H=12Mbps鍏ㄩ烣ullSpeed锛堥粯璁ゅ硷級, 01H=1.5Mbps锛堜粎淇敼棰戠巼锛, 02H=1.5Mbps浣庨烲owSpeed */ - -#define CMD11_GET_DEV_RATE 0x0A /* 涓绘満鏂瑰紡: 鑾峰彇褰撳墠杩炴帴鐨刄SB璁惧鐨勬暟鎹熺巼绫诲瀷 */ -/* 杈撳叆: 鏁版嵁07H */ -/* 杈撳嚭: 鏁版嵁閫熺巼绫诲瀷 */ -/* 浣4涓1鍒欐槸1.5Mbps浣庨烾SB璁惧, 鍚﹀垯鏄12Mbps鍏ㄩ烾SB璁惧 */ - -#define CMD11_GET_TOGGLE 0x0A /* 鑾峰彇OUT浜嬪姟鐨勫悓姝ョ姸鎬 */ -/* 杈撳叆: 鏁版嵁1AH */ -/* 杈撳嚭: 鍚屾鐘舵 */ -/* 浣4涓1鍒橭UT浜嬪姟鍚屾, 鍚﹀垯OUT浜嬪姟涓嶅悓姝 */ - -#define CMD11_READ_VAR8 0x0A /* 璇诲彇鎸囧畾鐨8浣嶆枃浠剁郴缁熷彉閲 */ -/* 杈撳叆: 鍙橀噺鍦板潃 */ -/* 杈撳嚭: 鏁版嵁 */ - -/*#define CMD11_GET_MAX_LUN = CMD11_READ_VAR8( VAR_UDISK_LUN )*/ /* 涓绘満鏂瑰紡: 鑾峰彇USB瀛樺偍鍣ㄦ渶澶у拰褰撳墠閫昏緫鍗曞厓鍙 */ - -#define CMD20_SET_RETRY 0x0B /* 涓绘満鏂瑰紡: 璁剧疆USB浜嬪姟鎿嶄綔鐨勯噸璇曟鏁 */ -/* 杈撳叆: 鏁版嵁25H, 閲嶈瘯娆℃暟 */ -/* 浣7涓0鍒欐敹鍒癗AK鏃朵笉閲嶈瘯, 浣7涓1浣6涓0鍒欐敹鍒癗AK鏃舵棤闄愰噸璇, 浣7涓1浣6涓1鍒欐敹鍒癗AK鏃舵渶澶氶噸璇3绉, 浣5~浣0涓鸿秴鏃跺悗鐨勯噸璇曟鏁 */ - -#define CMD20_WRITE_VAR8 0x0B /* 璁剧疆鎸囧畾鐨8浣嶆枃浠剁郴缁熷彉閲 */ -/* 杈撳叆: 鍙橀噺鍦板潃, 鏁版嵁 */ - -/*#define CMD20_SET_DISK_LUN = CMD20_WRITE_VAR8( VAR_UDISK_LUN )*/ /* 涓绘満鏂瑰紡: 璁剧疆USB瀛樺偍鍣ㄧ殑褰撳墠閫昏緫鍗曞厓鍙 */ - -#define CMD14_READ_VAR32 0x0C /* 璇诲彇鎸囧畾鐨32浣嶆枃浠剁郴缁熷彉閲 */ -/* 杈撳叆: 鍙橀噺鍦板潃 */ -/* 杈撳嚭: 鏁版嵁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - -#define CMD50_WRITE_VAR32 0x0D /* 璁剧疆鎸囧畾鐨32浣嶆枃浠剁郴缁熷彉閲 */ -/* 杈撳叆: 鍙橀噺鍦板潃, 鏁版嵁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - -#define CMD01_DELAY_100US 0x0F /* 寤舵椂100uS(涓插彛涓嶆敮鎸) */ -/* 杈撳嚭: 寤舵椂鏈熼棿杈撳嚭0,寤舵椂缁撴潫杈撳嚭闈0 */ - -#define CMD40_SET_USB_ID 0x12 /* 璁惧鏂瑰紡: 璁剧疆USB鍘傚晢VID鍜屼骇鍝丳ID */ -/* 杈撳叆: 鍘傚晢ID浣庡瓧鑺, 鍘傚晢ID楂樺瓧鑺, 浜у搧ID浣庡瓧鑺, 浜у搧ID楂樺瓧鑺 */ - -#define CMD10_SET_USB_ADDR 0x13 /* 璁剧疆USB鍦板潃 */ -/* 杈撳叆: 鍦板潃鍊 */ - -#define CMD01_TEST_CONNECT 0x16 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 妫鏌SB璁惧杩炴帴鐘舵 */ -/* 杈撳嚭: 鐘舵( USB_INT_CONNECT鎴朥SB_INT_DISCONNECT鎴朥SB_INT_USB_READY, 鍏跺畠鍊艰鏄庢搷浣滄湭瀹屾垚 ) */ - -#define CMD00_ABORT_NAK 0x17 /* 涓绘満鏂瑰紡: 鏀惧純褰撳墠NAK鐨勯噸璇 */ - -#define CMD10_SET_ENDP2 0x18 /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 璁剧疆USB绔偣0鐨勬帴鏀跺櫒 */ -/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ -/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ -/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000-灏辩华ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ - -#define CMD10_SET_ENDP3 0x19 /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 璁剧疆USB绔偣0鐨勫彂閫佸櫒 */ -/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ -/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ -/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000~1000-灏辩华ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ - -#define CMD10_SET_ENDP4 0x1A /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 璁剧疆USB绔偣1鐨勬帴鏀跺櫒 */ -/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ -/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ -/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000-灏辩华ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ - -#define CMD10_SET_ENDP5 0x1B /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 璁剧疆USB绔偣1鐨勫彂閫佸櫒 */ -/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ -/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ -/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000~1000-灏辩华ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ - -#define CMD10_SET_ENDP6 0x1C /* 璁剧疆USB绔偣2/涓绘満绔偣鐨勬帴鏀跺櫒 */ -/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ -/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ -/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000-灏辩华ACK, 1101-灏辩华浣嗕笉杩斿洖ACK, 1110-姝e繖NAK, 1111-閿欒STALL */ - -#define CMD10_SET_ENDP7 0x1D /* 璁剧疆USB绔偣2/涓绘満绔偣鐨勫彂閫佸櫒 */ -/* 杈撳叆: 宸ヤ綔鏂瑰紡 */ -/* 浣7涓1鍒欎綅6涓哄悓姝ヨЕ鍙戜綅, 鍚﹀垯鍚屾瑙﹀彂浣嶄笉鍙 */ -/* 浣3~浣0涓轰簨鍔″搷搴旀柟寮: 0000-灏辩华ACK, 1101-灏辩华浣嗘棤椤诲簲绛, 1110-姝e繖NAK, 1111-閿欒STALL */ - -#define CMD00_DIRTY_BUFFER 0x25 /* 涓绘満鏂囦欢妯″紡: 娓呴櫎鍐呴儴鐨勭鐩樺拰鏂囦欢缂撳啿鍖 */ - -#define CMD10_WR_USB_DATA3 0x29 /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 鍚慤SB绔偣0鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ -/* 杈撳叆: 闀垮害, 鏁版嵁娴 */ - -#define CMD10_WR_USB_DATA5 0x2A /* 璁惧鏂瑰紡(涓插彛涓嶆敮鎸): 鍚慤SB绔偣1鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ -/* 杈撳叆: 闀垮害, 鏁版嵁娴 */ - -/* ********************************************************************************************************************* */ -/* 杈呭姪鍛戒护(鎵嬪唽浜), 涓嶅お甯哥敤鎴栬呮槸涓轰簡涓嶤H375鍜孋H372鍏煎, 浠ヤ笅鍛戒护鎬绘槸鍦ㄦ搷浣滅粨鏉熸椂浜х敓涓柇閫氱煡, 骞朵笖鎬绘槸娌℃湁杈撳嚭鏁版嵁 */ - -#define CMD1H_CLR_STALL 0x41 /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-娓呴櫎绔偣閿欒 */ -/* 杈撳叆: 绔偣鍙 */ -/* 杈撳嚭涓柇 */ - -#define CMD1H_SET_ADDRESS 0x45 /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-璁剧疆USB鍦板潃 */ -/* 杈撳叆: 鍦板潃鍊 */ -/* 杈撳嚭涓柇 */ - -#define CMD1H_GET_DESCR 0x46 /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-鑾峰彇鎻忚堪绗 */ -/* 杈撳叆: 鎻忚堪绗︾被鍨 */ -/* 杈撳嚭涓柇 */ - -#define CMD1H_SET_CONFIG 0x49 /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-璁剧疆USB閰嶇疆 */ -/* 杈撳叆: 閰嶇疆鍊 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_AUTO_SETUP 0x4D /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鑷姩閰嶇疆USB璁惧 */ -/* 杈撳嚭涓柇 */ - -#define CMD2H_ISSUE_TKN_X 0x4E /* 涓绘満鏂瑰紡: 鍙戝嚭鍚屾浠ょ墝, 鎵ц浜嬪姟, 璇ュ懡浠ゅ彲浠f浛 CMD10_SET_ENDP6/CMD10_SET_ENDP7 + CMD1H_ISSUE_TOKEN */ -/* 杈撳叆: 鍚屾鏍囧織, 浜嬪姟灞炴 */ -/* 鍚屾鏍囧織鐨勪綅7涓轰富鏈虹鐐笽N鐨勫悓姝ヨЕ鍙戜綅, 浣6涓轰富鏈虹鐐筄UT鐨勫悓姝ヨЕ鍙戜綅, 浣5~浣0蹇呴』涓0 */ -/* 浜嬪姟灞炴х殑浣4浣嶆槸浠ょ墝, 楂4浣嶆槸绔偣鍙 */ -/* 杈撳嚭涓柇 */ - -#define CMD1H_ISSUE_TOKEN 0x4F /* 涓绘満鏂瑰紡: 鍙戝嚭浠ょ墝, 鎵ц浜嬪姟, 寤鸿鐢–MD2H_ISSUE_TKN_X鍛戒护 */ -/* 杈撳叆: 浜嬪姟灞炴 */ -/* 浣4浣嶆槸浠ょ墝, 楂4浣嶆槸绔偣鍙 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_INIT 0x51 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鍒濆鍖朥SB瀛樺偍鍣 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_RESET 0x52 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鎺у埗浼犺緭-澶嶄綅USB瀛樺偍鍣 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_SIZE 0x53 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鑾峰彇USB瀛樺偍鍣ㄧ殑瀹归噺 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_INQUIRY 0x58 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 鏌ヨUSB瀛樺偍鍣ㄧ壒鎬 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_READY 0x59 /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 妫鏌SB瀛樺偍鍣ㄥ氨缁 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_R_SENSE 0x5A /* 涓绘満鏂瑰紡/涓嶆敮鎸丼D鍗: 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_RD_DISK_SEC 0x5B /* 涓绘満鏂囦欢妯″紡: 浠庣鐩樿鍙栦竴涓墖鍖虹殑鏁版嵁鍒板唴閮ㄧ紦鍐插尯 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_WR_DISK_SEC 0x5C /* 涓绘満鏂囦欢妯″紡: 灏嗗唴閮ㄧ紦鍐插尯鐨勪竴涓墖鍖虹殑鏁版嵁鍐欏叆纾佺洏 */ -/* 杈撳嚭涓柇 */ - -#define CMD0H_DISK_MAX_LUN 0x5D /* 涓绘満鏂瑰紡: 鎺у埗浼犺緭-鑾峰彇USB瀛樺偍鍣ㄦ渶澶ч昏緫鍗曞厓鍙 */ -/* 杈撳嚭涓柇 */ - -/* ********************************************************************************************************************* */ -/* 浠ヤ笅瀹氫箟鍙槸涓轰簡鍏煎CH375鐨処NCLUDE鏂囦欢涓殑鍛戒护鍚嶇О鏍煎紡 */ - -#ifndef _NO_CH375_COMPATIBLE_ -#define CMD_GET_IC_VER CMD01_GET_IC_VER -#define CMD_SET_BAUDRATE CMD21_SET_BAUDRATE -#define CMD_ENTER_SLEEP CMD00_ENTER_SLEEP -#define CMD_RESET_ALL CMD00_RESET_ALL -#define CMD_CHECK_EXIST CMD11_CHECK_EXIST -#define CMD_CHK_SUSPEND CMD20_CHK_SUSPEND -#define CMD_SET_SDO_INT CMD20_SET_SDO_INT -#define CMD_GET_FILE_SIZE CMD14_GET_FILE_SIZE -#define CMD_SET_FILE_SIZE CMD50_SET_FILE_SIZE -#define CMD_SET_USB_MODE CMD11_SET_USB_MODE -#define CMD_GET_STATUS CMD01_GET_STATUS -#define CMD_UNLOCK_USB CMD00_UNLOCK_USB -#define CMD_RD_USB_DATA0 CMD01_RD_USB_DATA0 -#define CMD_RD_USB_DATA CMD01_RD_USB_DATA -#define CMD_WR_USB_DATA7 CMD10_WR_USB_DATA7 -#define CMD_WR_HOST_DATA CMD10_WR_HOST_DATA -#define CMD_WR_REQ_DATA CMD01_WR_REQ_DATA -#define CMD_WR_OFS_DATA CMD20_WR_OFS_DATA -#define CMD_SET_FILE_NAME CMD10_SET_FILE_NAME -#define CMD_DISK_CONNECT CMD0H_DISK_CONNECT -#define CMD_DISK_MOUNT CMD0H_DISK_MOUNT -#define CMD_FILE_OPEN CMD0H_FILE_OPEN -#define CMD_FILE_ENUM_GO CMD0H_FILE_ENUM_GO -#define CMD_FILE_CREATE CMD0H_FILE_CREATE -#define CMD_FILE_ERASE CMD0H_FILE_ERASE -#define CMD_FILE_CLOSE CMD1H_FILE_CLOSE -#define CMD_DIR_INFO_READ CMD1H_DIR_INFO_READ -#define CMD_DIR_INFO_SAVE CMD0H_DIR_INFO_SAVE -#define CMD_BYTE_LOCATE CMD4H_BYTE_LOCATE -#define CMD_BYTE_READ CMD2H_BYTE_READ -#define CMD_BYTE_RD_GO CMD0H_BYTE_RD_GO -#define CMD_BYTE_WRITE CMD2H_BYTE_WRITE -#define CMD_BYTE_WR_GO CMD0H_BYTE_WR_GO -#define CMD_DISK_CAPACITY CMD0H_DISK_CAPACITY -#define CMD_DISK_QUERY CMD0H_DISK_QUERY -#define CMD_DIR_CREATE CMD0H_DIR_CREATE -#define CMD_SEC_LOCATE CMD4H_SEC_LOCATE -#define CMD_SEC_READ CMD1H_SEC_READ -#define CMD_SEC_WRITE CMD1H_SEC_WRITE -#define CMD_DISK_BOC_CMD CMD0H_DISK_BOC_CMD -#define CMD_DISK_READ CMD5H_DISK_READ -#define CMD_DISK_RD_GO CMD0H_DISK_RD_GO -#define CMD_DISK_WRITE CMD5H_DISK_WRITE -#define CMD_DISK_WR_GO CMD0H_DISK_WR_GO -#define CMD_SET_USB_SPEED CMD10_SET_USB_SPEED -#define CMD_GET_DEV_RATE CMD11_GET_DEV_RATE -#define CMD_GET_TOGGLE CMD11_GET_TOGGLE -#define CMD_READ_VAR8 CMD11_READ_VAR8 -#define CMD_SET_RETRY CMD20_SET_RETRY -#define CMD_WRITE_VAR8 CMD20_WRITE_VAR8 -#define CMD_READ_VAR32 CMD14_READ_VAR32 -#define CMD_WRITE_VAR32 CMD50_WRITE_VAR32 -#define CMD_DELAY_100US CMD01_DELAY_100US -#define CMD_SET_USB_ID CMD40_SET_USB_ID -#define CMD_SET_USB_ADDR CMD10_SET_USB_ADDR -#define CMD_TEST_CONNECT CMD01_TEST_CONNECT -#define CMD_ABORT_NAK CMD00_ABORT_NAK -#define CMD_SET_ENDP2 CMD10_SET_ENDP2 -#define CMD_SET_ENDP3 CMD10_SET_ENDP3 -#define CMD_SET_ENDP4 CMD10_SET_ENDP4 -#define CMD_SET_ENDP5 CMD10_SET_ENDP5 -#define CMD_SET_ENDP6 CMD10_SET_ENDP6 -#define CMD_SET_ENDP7 CMD10_SET_ENDP7 -#define CMD_DIRTY_BUFFER CMD00_DIRTY_BUFFER -#define CMD_WR_USB_DATA3 CMD10_WR_USB_DATA3 -#define CMD_WR_USB_DATA5 CMD10_WR_USB_DATA5 -#define CMD_CLR_STALL CMD1H_CLR_STALL -#define CMD_SET_ADDRESS CMD1H_SET_ADDRESS -#define CMD_GET_DESCR CMD1H_GET_DESCR -#define CMD_SET_CONFIG CMD1H_SET_CONFIG -#define CMD_AUTO_SETUP CMD0H_AUTO_SETUP -#define CMD_ISSUE_TKN_X CMD2H_ISSUE_TKN_X -#define CMD_ISSUE_TOKEN CMD1H_ISSUE_TOKEN -#define CMD_DISK_INIT CMD0H_DISK_INIT -#define CMD_DISK_RESET CMD0H_DISK_RESET -#define CMD_DISK_SIZE CMD0H_DISK_SIZE -#define CMD_DISK_INQUIRY CMD0H_DISK_INQUIRY -#define CMD_DISK_READY CMD0H_DISK_READY -#define CMD_DISK_R_SENSE CMD0H_DISK_R_SENSE -#define CMD_RD_DISK_SEC CMD0H_RD_DISK_SEC -#define CMD_WR_DISK_SEC CMD0H_WR_DISK_SEC -#define CMD_DISK_MAX_LUN CMD0H_DISK_MAX_LUN +#ifndef PARA_STATE_INTB +#define PARA_STATE_INTB 0x80 +#define PARA_STATE_BUSY 0x10 #endif -/* ********************************************************************************************************************* */ -/* 骞跺彛鏂瑰紡, 鐘舵佺鍙(璇诲懡浠ょ鍙)鐨勪綅瀹氫箟 */ -#ifndef PARA_STATE_INTB -#define PARA_STATE_INTB 0x80 /* 骞跺彛鏂瑰紡鐘舵佺鍙g殑浣7: 涓柇鏍囧織,浣庢湁鏁 */ -#define PARA_STATE_BUSY 0x10 /* 骞跺彛鏂瑰紡鐘舵佺鍙g殑浣4: 蹇欐爣蹇,楂樻湁鏁 */ +#ifndef SER_CMD_TIMEOUT +#define SER_CMD_TIMEOUT 32 +#define SER_SYNC_CODE1 0x57 +#define SER_SYNC_CODE2 0xAB #endif -/* ********************************************************************************************************************* */ -/* 涓插彛鏂瑰紡, 鎿嶄綔鍛戒护鍓嶇殑寮曞鍚屾鐮 */ -#ifndef SER_CMD_TIMEOUT -#define SER_CMD_TIMEOUT 32 /* 涓插彛鍛戒护瓒呮椂鏃堕棿, 鍗曚綅涓簃S, 鍚屾鐮佷箣闂村強鍚屾鐮佷笌鍛戒护鐮佷箣闂寸殑闂撮殧搴旇灏介噺鐭, 瓒呮椂鍚庣殑澶勭悊鏂瑰紡涓轰涪寮 */ -#define SER_SYNC_CODE1 0x57 /* 鍚姩鎿嶄綔鐨勭1涓覆鍙e悓姝ョ爜 */ -#define SER_SYNC_CODE2 0xAB /* 鍚姩鎿嶄綔鐨勭2涓覆鍙e悓姝ョ爜 */ +#ifndef CMD_RET_SUCCESS +#define CMD_RET_SUCCESS 0x51 +#define CMD_RET_ABORT 0x5F #endif -/* ********************************************************************************************************************* */ -/* 鎿嶄綔鐘舵 */ +/***********************************************************************************************************************/ +#ifndef USB_INT_EP0_SETUP -#ifndef CMD_RET_SUCCESS -#define CMD_RET_SUCCESS 0x51 /* 鍛戒护鎿嶄綔鎴愬姛 */ -#define CMD_RET_ABORT 0x5F /* 鍛戒护鎿嶄綔澶辫触 */ -#endif - -/* ********************************************************************************************************************* */ -/* USB涓柇鐘舵 */ - -#ifndef USB_INT_EP0_SETUP - -/* 浠ヤ笅鐘舵佷唬鐮佷负鐗规畩浜嬩欢涓柇, 濡傛灉閫氳繃CMD20_CHK_SUSPEND鍚敤USB鎬荤嚎鎸傝捣妫鏌, 閭d箞蹇呴』澶勭悊USB鎬荤嚎鎸傝捣鍜岀潯鐪犲敜閱掔殑涓柇鐘舵 */ -#define USB_INT_USB_SUSPEND 0x05 /* USB鎬荤嚎鎸傝捣浜嬩欢 */ -#define USB_INT_WAKE_UP 0x06 /* 浠庣潯鐪犱腑琚敜閱掍簨浠 */ - -/* 浠ヤ笅鐘舵佷唬鐮0XH鐢ㄤ簬USB璁惧鏂瑰紡 */ -/* 鍐呯疆鍥轰欢妯″紡涓嬪彧闇瑕佸鐞: USB_INT_EP1_OUT, USB_INT_EP1_IN, USB_INT_EP2_OUT, USB_INT_EP2_IN */ -/* 浣7-浣4涓0000 */ -/* 浣3-浣2鎸囩ず褰撳墠浜嬪姟, 00=OUT, 10=IN, 11=SETUP */ -/* 浣1-浣0鎸囩ず褰撳墠绔偣, 00=绔偣0, 01=绔偣1, 10=绔偣2, 11=USB鎬荤嚎澶嶄綅 */ -#define USB_INT_EP0_SETUP 0x0C /* USB绔偣0鐨凷ETUP */ -#define USB_INT_EP0_OUT 0x00 /* USB绔偣0鐨凮UT */ -#define USB_INT_EP0_IN 0x08 /* USB绔偣0鐨処N */ -#define USB_INT_EP1_OUT 0x01 /* USB绔偣1鐨凮UT */ -#define USB_INT_EP1_IN 0x09 /* USB绔偣1鐨処N */ -#define USB_INT_EP2_OUT 0x02 /* USB绔偣2鐨凮UT */ -#define USB_INT_EP2_IN 0x0A /* USB绔偣2鐨処N */ -/* USB_INT_BUS_RESET 0x0000XX11B */ /* USB鎬荤嚎澶嶄綅 */ -#define USB_INT_BUS_RESET1 0x03 /* USB鎬荤嚎澶嶄綅 */ -#define USB_INT_BUS_RESET2 0x07 /* USB鎬荤嚎澶嶄綅 */ -#define USB_INT_BUS_RESET3 0x0B /* USB鎬荤嚎澶嶄綅 */ -#define USB_INT_BUS_RESET4 0x0F /* USB鎬荤嚎澶嶄綅 */ +#define USB_INT_USB_SUSPEND 0x05 +#define USB_INT_WAKE_UP 0x06 +#define USB_INT_EP0_SETUP 0x0C +#define USB_INT_EP0_OUT 0x00 +#define USB_INT_EP0_IN 0x08 +#define USB_INT_EP1_OUT 0x01 +#define USB_INT_EP1_IN 0x09 +#define USB_INT_EP2_OUT 0x02 +#define USB_INT_EP2_IN 0x0A +#define USB_INT_BUS_RESET1 0x03 +#define USB_INT_BUS_RESET2 0x07 +#define USB_INT_BUS_RESET3 0x0B +#define USB_INT_BUS_RESET4 0x0F #endif -/* 浠ヤ笅鐘舵佷唬鐮2XH-3XH鐢ㄤ簬USB涓绘満鏂瑰紡鐨勯氳澶辫触浠g爜 */ -/* 浣7-浣6涓00 */ -/* 浣5涓1 */ -/* 浣4鎸囩ず褰撳墠鎺ユ敹鐨勬暟鎹寘鏄惁鍚屾 */ -/* 浣3-浣0鎸囩ず瀵艰嚧閫氳澶辫触鏃禪SB璁惧鐨勫簲绛: 0010=ACK, 1010=NAK, 1110=STALL, 0011=DATA0, 1011=DATA1, XX00=瓒呮椂 */ -/* USB_INT_RET_ACK 0x001X0010B */ /* 閿欒:瀵逛簬IN浜嬪姟杩斿洖ACK */ -/* USB_INT_RET_NAK 0x001X1010B */ /* 閿欒:杩斿洖NAK */ -/* USB_INT_RET_STALL 0x001X1110B */ /* 閿欒:杩斿洖STALL */ -/* USB_INT_RET_DATA0 0x001X0011B */ /* 閿欒:瀵逛簬OUT/SETUP浜嬪姟杩斿洖DATA0 */ -/* USB_INT_RET_DATA1 0x001X1011B */ /* 閿欒:瀵逛簬OUT/SETUP浜嬪姟杩斿洖DATA1 */ -/* USB_INT_RET_TOUT 0x001XXX00B */ /* 閿欒:杩斿洖瓒呮椂 */ -/* USB_INT_RET_TOGX 0x0010X011B */ /* 閿欒:瀵逛簬IN浜嬪姟杩斿洖鏁版嵁涓嶅悓姝 */ -/* USB_INT_RET_PID 0x001XXXXXB */ /* 閿欒:鏈畾涔 */ -/* 浠ヤ笅鐘舵佷唬鐮1XH鐢ㄤ簬USB涓绘満鏂瑰紡鐨勬搷浣滅姸鎬佷唬鐮 */ -#ifndef USB_INT_SUCCESS -#define USB_INT_SUCCESS 0x14 /* USB浜嬪姟鎴栬呬紶杈撴搷浣滄垚鍔 */ -#define USB_INT_CONNECT 0x15 /* 妫娴嬪埌USB璁惧杩炴帴浜嬩欢, 鍙兘鏄柊杩炴帴鎴栬呮柇寮鍚庨噸鏂拌繛鎺 */ -#define USB_INT_DISCONNECT 0x16 /* 妫娴嬪埌USB璁惧鏂紑浜嬩欢 */ -#define USB_INT_BUF_OVER 0x17 /* USB浼犺緭鐨勬暟鎹湁璇垨鑰呮暟鎹お澶氱紦鍐插尯婧㈠嚭 */ -#define USB_INT_USB_READY 0x18 /* USB璁惧宸茬粡琚垵濮嬪寲(宸茬粡鍒嗛厤USB鍦板潃) */ -#define USB_INT_DISK_READ 0x1D /* USB瀛樺偍鍣ㄨ姹傛暟鎹鍑 */ -#define USB_INT_DISK_WRITE 0x1E /* USB瀛樺偍鍣ㄨ姹傛暟鎹啓鍏 */ -#define USB_INT_DISK_ERR 0x1F /* USB瀛樺偍鍣ㄦ搷浣滃け璐 */ +#ifndef USB_INT_SUCCESS +#define USB_INT_SUCCESS 0x14 +#define USB_INT_CONNECT 0x15 +#define USB_INT_DISCONNECT 0x16 +#define USB_INT_BUF_OVER 0x17 +#define USB_INT_USB_READY 0x18 +#define USB_INT_DISK_READ 0x1D +#define USB_INT_DISK_WRITE 0x1E +#define USB_INT_DISK_ERR 0x1F #endif -/* 浠ヤ笅鐘舵佷唬鐮佺敤浜庝富鏈烘枃浠舵ā寮忎笅鐨勬枃浠剁郴缁熼敊璇爜 */ -#ifndef ERR_DISK_DISCON -#define ERR_DISK_DISCON 0x82 /* 纾佺洏灏氭湭杩炴帴,鍙兘纾佺洏宸茬粡鏂紑 */ -#define ERR_LARGE_SECTOR 0x84 /* 纾佺洏鐨勬墖鍖哄お澶,鍙敮鎸佹瘡鎵囧尯512瀛楄妭 */ -#define ERR_TYPE_ERROR 0x92 /* 纾佺洏鍒嗗尯绫诲瀷涓嶆敮鎸,鍙敮鎸丗AT12/FAT16/BigDOS/FAT32,闇瑕佺敱纾佺洏绠$悊宸ュ叿閲嶆柊鍒嗗尯 */ -#define ERR_BPB_ERROR 0xA1 /* 纾佺洏灏氭湭鏍煎紡鍖,鎴栬呭弬鏁伴敊璇,闇瑕佺敱WINDOWS閲囩敤榛樿鍙傛暟閲嶆柊鏍煎紡鍖 */ -#define ERR_DISK_FULL 0xB1 /* 纾佺洏鏂囦欢澶弧,鍓╀綑绌洪棿澶皯鎴栬呭凡缁忔病鏈,闇瑕佺鐩樻暣鐞 */ -#define ERR_FDT_OVER 0xB2 /* 鐩綍(鏂囦欢澶)鍐呮枃浠跺お澶,娌℃湁绌洪棽鐨勭洰褰曢」,FAT12/FAT16鏍圭洰褰曚笅鐨勬枃浠舵暟搴旇灏戜簬512涓,闇瑕佺鐩樻暣鐞 */ -#define ERR_FILE_CLOSE 0xB4 /* 鏂囦欢宸茬粡鍏抽棴,濡傛灉闇瑕佷娇鐢,搴旇閲嶆柊鎵撳紑鏂囦欢 */ -#define ERR_OPEN_DIR 0x41 /* 鎸囧畾璺緞鐨勭洰褰(鏂囦欢澶)琚墦寮 */ -#define ERR_MISS_FILE 0x42 /* 鎸囧畾璺緞鐨勬枃浠舵病鏈夋壘鍒,鍙兘鏄枃浠跺悕绉伴敊璇 */ -#define ERR_FOUND_NAME 0x43 /* 鎼滅储鍒扮浉鍖归厤鐨勬枃浠跺悕,鎴栬呮槸瑕佹眰鎵撳紑鐩綍(鏂囦欢澶)鑰屽疄闄呯粨鏋滃嵈鎵撳紑浜嗘枃浠 */ -/* 浠ヤ笅鏂囦欢绯荤粺閿欒鐮佺敤浜庢枃浠剁郴缁熷瓙绋嬪簭 */ -#define ERR_MISS_DIR 0xB3 /* 鎸囧畾璺緞鐨勬煇涓瓙鐩綍(鏂囦欢澶)娌℃湁鎵惧埌,鍙兘鏄洰褰曞悕绉伴敊璇 */ -#define ERR_LONG_BUF_OVER 0x48 /* 闀挎枃浠剁紦鍐插尯婧㈠嚭 */ -#define ERR_LONG_NAME_ERR 0x49 /* 鐭枃浠跺悕娌℃湁瀵瑰簲鐨勯暱鏂囦欢鍚嶆垨鑰呴暱鏂囦欢鍚嶉敊璇 */ -#define ERR_NAME_EXIST 0x4A /* 鍚屽悕鐨勭煭鏂囦欢宸茬粡瀛樺湪,寤鸿閲嶆柊鐢熸垚鍙﹀涓涓煭鏂囦欢鍚 */ +#ifndef ERR_DISK_DISCON +#define ERR_DISK_DISCON 0x82 +#define ERR_LARGE_SECTOR 0x84 +#define ERR_TYPE_ERROR 0x92 +#define ERR_BPB_ERROR 0xA1 +#define ERR_DISK_FULL 0xB1 +#define ERR_FDT_OVER 0xB2 +#define ERR_FILE_CLOSE 0xB4 +#define ERR_OPEN_DIR 0x41 +#define ERR_MISS_FILE 0x42 +#define ERR_FOUND_NAME 0x43 + + +#define ERR_MISS_DIR 0xB3 +#define ERR_LONG_BUF_OVER 0x48 +#define ERR_LONG_NAME_ERR 0x49 +#define ERR_NAME_EXIST 0x4A +#endif + +/* ******************************************************************************************************************** */ +#ifndef DEF_DISK_UNKNOWN +#define DEF_DISK_UNKNOWN 0x00 +#define DEF_DISK_DISCONN 0x01 +#define DEF_DISK_CONNECT 0x02 +#define DEF_DISK_MOUNTED 0x03 +#define DEF_DISK_READY 0x10 +#define DEF_DISK_OPEN_ROOT 0x12 +#define DEF_DISK_OPEN_DIR 0x13 +#define DEF_DISK_OPEN_FILE 0x14 #endif -/* ********************************************************************************************************************* */ -/* 浠ヤ笅鐘舵佷唬鐮佺敤浜庝富鏈烘枃浠舵ā寮忎笅鐨勭鐩樺強鏂囦欢鐘舵, VAR_DISK_STATUS */ -#ifndef DEF_DISK_UNKNOWN -#define DEF_DISK_UNKNOWN 0x00 /* 灏氭湭鍒濆鍖,鏈煡鐘舵 */ -#define DEF_DISK_DISCONN 0x01 /* 纾佺洏娌℃湁杩炴帴鎴栬呭凡缁忔柇寮 */ -#define DEF_DISK_CONNECT 0x02 /* 纾佺洏宸茬粡杩炴帴,浣嗘槸灏氭湭鍒濆鍖栨垨鑰呮棤娉曡瘑鍒纾佺洏 */ -#define DEF_DISK_MOUNTED 0x03 /* 纾佺洏宸茬粡鍒濆鍖栨垚鍔,浣嗘槸灏氭湭鍒嗘瀽鏂囦欢绯荤粺鎴栬呮枃浠剁郴缁熶笉鏀寔 */ -#define DEF_DISK_READY 0x10 /* 宸茬粡鍒嗘瀽纾佺洏鐨勬枃浠剁郴缁熷苟涓旇兘澶熸敮鎸 */ -#define DEF_DISK_OPEN_ROOT 0x12 /* 宸茬粡鎵撳紑鏍圭洰褰,浣跨敤鍚庡繀椤诲叧闂,娉ㄦ剰FAT12/FAT16鏍圭洰褰曟槸鍥哄畾闀垮害 */ -#define DEF_DISK_OPEN_DIR 0x13 /* 宸茬粡鎵撳紑瀛愮洰褰(鏂囦欢澶) */ -#define DEF_DISK_OPEN_FILE 0x14 /* 宸茬粡鎵撳紑鏂囦欢 */ +/* **********************************************************************************************************************/ +#ifndef DEF_SECTOR_SIZE +#define DEF_SECTOR_SIZE 512 +#endif + +#ifndef DEF_WILDCARD_CHAR +#define DEF_WILDCARD_CHAR 0x2A +#define DEF_SEPAR_CHAR1 0x5C +#define DEF_SEPAR_CHAR2 0x2F +#define DEF_FILE_YEAR 2004 +#define DEF_FILE_MONTH 1 +#define DEF_FILE_DATE 1 #endif -/* ********************************************************************************************************************* */ -/* 鏂囦欢绯荤粺甯哥敤瀹氫箟 */ +#ifndef ATTR_DIRECTORY -#ifndef DEF_SECTOR_SIZE -#define DEF_SECTOR_SIZE 512 /* U鐩樻垨鑰匰D鍗¢粯璁ょ殑鐗╃悊鎵囧尯鐨勫ぇ灏 */ -#endif - -#ifndef DEF_WILDCARD_CHAR -#define DEF_WILDCARD_CHAR 0x2A /* 璺緞鍚嶇殑閫氶厤绗 '*' */ -#define DEF_SEPAR_CHAR1 0x5C /* 璺緞鍚嶇殑鍒嗛殧绗 '\' */ -#define DEF_SEPAR_CHAR2 0x2F /* 璺緞鍚嶇殑鍒嗛殧绗 '/' */ -#define DEF_FILE_YEAR 2004 /* 榛樿鏂囦欢鏃ユ湡: 2004骞 */ -#define DEF_FILE_MONTH 1 /* 榛樿鏂囦欢鏃ユ湡: 1鏈 */ -#define DEF_FILE_DATE 1 /* 榛樿鏂囦欢鏃ユ湡: 1鏃 */ -#endif - -#ifndef ATTR_DIRECTORY - -/* FAT鏁版嵁鍖轰腑鏂囦欢鐩綍淇℃伅 */ typedef struct _FAT_DIR_INFO { - UINT8 DIR_Name[11]; /* 00H,鏂囦欢鍚,鍏11瀛楄妭,涓嶈冻澶勫~绌烘牸 */ - UINT8 DIR_Attr; /* 0BH,鏂囦欢灞炴,鍙傝冨悗闈㈢殑璇存槑 */ - UINT8 DIR_NTRes; /* 0CH */ - UINT8 DIR_CrtTimeTenth; /* 0DH,鏂囦欢鍒涘缓鐨勬椂闂,浠0.1绉掑崟浣嶈鏁 */ - UINT16 DIR_CrtTime; /* 0EH,鏂囦欢鍒涘缓鐨勬椂闂 */ - UINT16 DIR_CrtDate; /* 10H,鏂囦欢鍒涘缓鐨勬棩鏈 */ - UINT16 DIR_LstAccDate; /* 12H,鏈杩戜竴娆″瓨鍙栨搷浣滅殑鏃ユ湡 */ - UINT16 DIR_FstClusHI; /* 14H */ - UINT16 DIR_WrtTime; /* 16H,鏂囦欢淇敼鏃堕棿,鍙傝冨墠闈㈢殑瀹廙AKE_FILE_TIME */ - UINT16 DIR_WrtDate; /* 18H,鏂囦欢淇敼鏃ユ湡,鍙傝冨墠闈㈢殑瀹廙AKE_FILE_DATE */ - UINT16 DIR_FstClusLO; /* 1AH */ - UINT32 DIR_FileSize; /* 1CH,鏂囦欢闀垮害 */ -} FAT_DIR_INFO, *P_FAT_DIR_INFO; /* 20H */ + UINT8 DIR_Name[11]; + UINT8 DIR_Attr; + UINT8 DIR_NTRes; + UINT8 DIR_CrtTimeTenth; + UINT16 DIR_CrtTime; + UINT16 DIR_CrtDate; + UINT16 DIR_LstAccDate; + UINT16 DIR_FstClusHI; + UINT16 DIR_WrtTime; + UINT16 DIR_WrtDate; + UINT16 DIR_FstClusLO; + UINT32 DIR_FileSize; +} FAT_DIR_INFO, *P_FAT_DIR_INFO; -/* 鏂囦欢灞炴 */ -#define ATTR_READ_ONLY 0x01 /* 鏂囦欢涓哄彧璇诲睘鎬 */ -#define ATTR_HIDDEN 0x02 /* 鏂囦欢涓洪殣鍚睘鎬 */ -#define ATTR_SYSTEM 0x04 /* 鏂囦欢涓虹郴缁熷睘鎬 */ -#define ATTR_VOLUME_ID 0x08 /* 鍗锋爣 */ -#define ATTR_DIRECTORY 0x10 /* 瀛愮洰褰(鏂囦欢澶) */ -#define ATTR_ARCHIVE 0x20 /* 鏂囦欢涓哄瓨妗e睘鎬 */ -#define ATTR_LONG_NAME ( ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID ) /* 闀挎枃浠跺悕灞炴 */ -#define ATTR_LONG_NAME_MASK ( ATTR_LONG_NAME | ATTR_DIRECTORY | ATTR_ARCHIVE ) -/* 鏂囦欢灞炴 UINT8 */ -/* bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 */ -/* 鍙 闅 绯 鍗 鐩 瀛 鏈畾涔 */ -/* 璇 钘 缁 鏍 褰 妗 */ -/* 鏂囦欢鏃堕棿 UINT16 */ -/* Time = (Hour<<11) + (Minute<<5) + (Second>>1) */ -#define MAKE_FILE_TIME( h, m, s ) ( (h<<11) + (m<<5) + (s>>1) ) /* 鐢熸垚鎸囧畾鏃跺垎绉掔殑鏂囦欢鏃堕棿鏁版嵁 */ -/* 鏂囦欢鏃ユ湡 UINT16 */ -/* Date = ((Year-1980)<<9) + (Month<<5) + Day */ -#define MAKE_FILE_DATE( y, m, d ) ( ((y-1980)<<9) + (m<<5) + d ) /* 鐢熸垚鎸囧畾骞存湀鏃ョ殑鏂囦欢鏃ユ湡鏁版嵁 */ +#define ATTR_READ_ONLY 0x01 +#define ATTR_HIDDEN 0x02 +#define ATTR_SYSTEM 0x04 +#define ATTR_VOLUME_ID 0x08 +#define ATTR_DIRECTORY 0x10 +#define ATTR_ARCHIVE 0x20 +#define ATTR_LONG_NAME (ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID) +#define ATTR_LONG_NAME_MASK (ATTR_LONG_NAME | ATTR_DIRECTORY | ATTR_ARCHIVE) -#define LONE_NAME_MAX_CHAR (255*2) /* 闀挎枃浠跺悕鏈澶氬瓧绗︽暟/瀛楄妭鏁 */ -#define LONG_NAME_PER_DIR (13*2) /* 闀挎枃浠跺悕鍦ㄦ瘡涓枃浠剁洰褰曚俊鎭粨鏋勪腑鐨勫瓧绗︽暟/瀛楄妭鏁 */ +#define MAKE_FILE_TIME( h, m, s ) ( (h<<11) + (m<<5) + (s>>1) ) +#define MAKE_FILE_DATE( y, m, d ) ( ((y-1980)<<9) + (m<<5) + d ) + +#define LONE_NAME_MAX_CHAR (255*2) +#define LONG_NAME_PER_DIR (13*2) #endif /* ********************************************************************************************************************* */ -/* SCSI鍛戒护鍜屾暟鎹緭鍏ヨ緭鍑虹粨鏋 */ - #ifndef SPC_CMD_INQUIRY -/* SCSI鍛戒护鐮 */ -#define SPC_CMD_INQUIRY 0x12 -#define SPC_CMD_READ_CAPACITY 0x25 -#define SPC_CMD_READ10 0x28 -#define SPC_CMD_WRITE10 0x2A -#define SPC_CMD_TEST_READY 0x00 -#define SPC_CMD_REQUEST_SENSE 0x03 -#define SPC_CMD_MODESENSE6 0x1A -#define SPC_CMD_MODESENSE10 0x5A -#define SPC_CMD_START_STOP 0x1B +#define SPC_CMD_INQUIRY 0x12 +#define SPC_CMD_READ_CAPACITY 0x25 +#define SPC_CMD_READ10 0x28 +#define SPC_CMD_WRITE10 0x2A +#define SPC_CMD_TEST_READY 0x00 +#define SPC_CMD_REQUEST_SENSE 0x03 +#define SPC_CMD_MODESENSE6 0x1A +#define SPC_CMD_MODESENSE10 0x5A +#define SPC_CMD_START_STOP 0x1B -/* BulkOnly鍗忚鐨勫懡浠ゅ潡 */ typedef struct _BULK_ONLY_CBW { - UINT32 CBW_Sig; - UINT32 CBW_Tag; - UINT8 CBW_DataLen0; /* 08H,杈撳叆: 鏁版嵁浼犺緭闀垮害,瀵逛簬杈撳叆鏁版嵁鍏舵湁鏁堝兼槸0鍒48,瀵逛簬杈撳嚭鏁版嵁鍏舵湁鏁堝间负0鍒33 */ - UINT8 CBW_DataLen1; - UINT16 CBW_DataLen2; - UINT8 CBW_Flag; /* 0CH,杈撳叆: 浼犺緭鏂瑰悜绛夋爣蹇,浣7涓1鍒欒緭鍏ユ暟鎹,浣嶄负0鍒欒緭鍑烘暟鎹垨鑰呮病鏈夋暟鎹 */ - UINT8 CBW_LUN; - UINT8 CBW_CB_Len; /* 0EH,杈撳叆: 鍛戒护鍧楃殑闀垮害,鏈夋晥鍊兼槸1鍒16 */ - UINT8 CBW_CB_Buf[16]; /* 0FH,杈撳叆: 鍛戒护鍧,璇ョ紦鍐插尯鏈澶氫负16涓瓧鑺 */ -} BULK_ONLY_CBW, *P_BULK_ONLY_CBW; /* BulkOnly鍗忚鐨勫懡浠ゅ潡, 杈撳叆CBW缁撴瀯 */ + UINT32 CBW_Sig; + UINT32 CBW_Tag; + UINT8 CBW_DataLen0; + UINT8 CBW_DataLen1; + UINT16 CBW_DataLen2; + UINT8 CBW_Flag; + UINT8 CBW_LUN; + UINT8 CBW_CB_Len; + UINT8 CBW_CB_Buf[16]; +} BULK_ONLY_CBW, *P_BULK_ONLY_CBW; -/* INQUIRY鍛戒护鐨勮繑鍥炴暟鎹 */ typedef struct _INQUIRY_DATA { - UINT8 DeviceType; /* 00H, 璁惧绫诲瀷 */ - UINT8 RemovableMedia; /* 01H, 浣7涓1璇存槑鏄Щ鍔ㄥ瓨鍌 */ - UINT8 Versions; /* 02H, 鍗忚鐗堟湰 */ - UINT8 DataFormatAndEtc; /* 03H, 鎸囧畾杩斿洖鏁版嵁鏍煎紡 */ - UINT8 AdditionalLength; /* 04H, 鍚庣画鏁版嵁鐨勯暱搴 */ - UINT8 Reserved1; - UINT8 Reserved2; - UINT8 MiscFlag; /* 07H, 涓浜涙帶鍒舵爣蹇 */ - UINT8 VendorIdStr[8]; /* 08H, 鍘傚晢淇℃伅 */ - UINT8 ProductIdStr[16]; /* 10H, 浜у搧淇℃伅 */ - UINT8 ProductRevStr[4]; /* 20H, 浜у搧鐗堟湰 */ -} INQUIRY_DATA, *P_INQUIRY_DATA; /* 24H */ + UINT8 DeviceType; + UINT8 RemovableMedia; + UINT8 Versions; + UINT8 DataFormatAndEtc; + UINT8 AdditionalLength; + UINT8 Reserved1; + UINT8 Reserved2; + UINT8 MiscFlag; + UINT8 VendorIdStr[8]; + UINT8 ProductIdStr[16]; + UINT8 ProductRevStr[4]; +} INQUIRY_DATA, *P_INQUIRY_DATA; + -/* REQUEST SENSE鍛戒护鐨勮繑鍥炴暟鎹 */ typedef struct _SENSE_DATA { - UINT8 ErrorCode; /* 00H, 閿欒浠g爜鍙婃湁鏁堜綅 */ - UINT8 SegmentNumber; - UINT8 SenseKeyAndEtc; /* 02H, 涓婚敭鐮 */ - UINT8 Information0; - UINT8 Information1; - UINT8 Information2; - UINT8 Information3; - UINT8 AdditSenseLen; /* 07H, 鍚庣画鏁版嵁鐨勯暱搴 */ - UINT8 CmdSpecInfo[4]; - UINT8 AdditSenseCode; /* 0CH, 闄勫姞閿爜 */ - UINT8 AddSenCodeQual; /* 0DH, 璇︾粏鐨勯檮鍔犻敭鐮 */ - UINT8 FieldReplaUnit; - UINT8 SenseKeySpec[3]; -} SENSE_DATA, *P_SENSE_DATA; /* 12H */ + UINT8 ErrorCode; + UINT8 SegmentNumber; + UINT8 SenseKeyAndEtc; + UINT8 Information0; + UINT8 Information1; + UINT8 Information2; + UINT8 Information3; + UINT8 AdditSenseLen; + UINT8 CmdSpecInfo[4]; + UINT8 AdditSenseCode; + UINT8 AddSenCodeQual; + UINT8 FieldReplaUnit; + UINT8 SenseKeySpec[3]; +} SENSE_DATA, *P_SENSE_DATA; #endif /* ********************************************************************************************************************* */ -/* 涓绘満鏂囦欢妯″紡涓嬬殑鏁版嵁杈撳叆鍜岃緭鍑虹粨鏋 */ +#ifndef MAX_FILE_NAME_LEN -#ifndef MAX_FILE_NAME_LEN +#define MAX_FILE_NAME_LEN (13+1) -#define MAX_FILE_NAME_LEN (13+1) /* 鏂囦欢鍚嶆渶澶ч暱搴,鏈澶ч暱搴︽槸1涓牴鐩綍绗+8涓富鏂囦欢鍚+1涓皬鏁扮偣+3涓被鍨嬪悕+缁撴潫绗=14 */ - -/* 鍛戒护鐨勮緭鍏ユ暟鎹拰杈撳嚭鏁版嵁 */ typedef union _CH376_CMD_DATA { - struct { - UINT8 mBuffer[ MAX_FILE_NAME_LEN ]; - } Default; + struct { + UINT8 mBuffer[ MAX_FILE_NAME_LEN ]; + } Default; - INQUIRY_DATA DiskMountInq; /* 杩斿洖: INQUIRY鍛戒护鐨勮繑鍥炴暟鎹 */ - /* CMD0H_DISK_MOUNT: 鍒濆鍖栫鐩樺苟娴嬭瘯纾佺洏鏄惁灏辩华,棣栨鎵ц鏃 */ + INQUIRY_DATA DiskMountInq; + FAT_DIR_INFO OpenDirInfo; + FAT_DIR_INFO EnumDirInfo; + struct { + UINT8 mUpdateFileSz; + } FileCLose; - FAT_DIR_INFO OpenDirInfo; /* 杩斿洖: 鏋氫妇鍒扮殑鏂囦欢鐩綍淇℃伅 */ - /* CMD0H_FILE_OPEN: 鏋氫妇鏂囦欢鍜岀洰褰(鏂囦欢澶) */ + struct { + UINT8 mDirInfoIndex; + } DirInfoRead; - FAT_DIR_INFO EnumDirInfo; /* 杩斿洖: 鏋氫妇鍒扮殑鏂囦欢鐩綍淇℃伅 */ - /* CMD0H_FILE_ENUM_GO: 缁х画鏋氫妇鏂囦欢鍜岀洰褰(鏂囦欢澶) */ + union { + UINT32 mByteOffset; + UINT32 mSectorLba; + } ByteLocate; - struct { - UINT8 mUpdateFileSz; /* 杈撳叆鍙傛暟: 鏄惁鍏佽鏇存柊鏂囦欢闀垮害, 0鍒欑姝㈡洿鏂伴暱搴 */ - } FileCLose; /* CMD1H_FILE_CLOSE: 鍏抽棴褰撳墠宸茬粡鎵撳紑鐨勬枃浠 */ + struct { + UINT16 mByteCount; + } ByteRead; - struct { - UINT8 mDirInfoIndex; /* 杈撳叆鍙傛暟: 鎸囧畾闇瑕佽鍙栫殑鐩綍淇℃伅缁撴瀯鍦ㄦ墖鍖哄唴鐨勭储寮曞彿, 0FFH鍒欎负褰撳墠宸茬粡鎵撳紑鐨勬枃浠 */ - } DirInfoRead; /* CMD1H_DIR_INFO_READ: 璇诲彇鏂囦欢鐨勭洰褰曚俊鎭 */ + struct { + UINT16 mByteCount; + } ByteWrite; - union { - UINT32 mByteOffset; /* 杈撳叆鍙傛暟: 鍋忕Щ瀛楄妭鏁,浠ュ瓧鑺備负鍗曚綅鐨勫亸绉婚噺(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - UINT32 mSectorLba; /* 杩斿洖: 褰撳墠鏂囦欢鎸囬拡瀵瑰簲鐨勭粷瀵圭嚎鎬ф墖鍖哄彿,0FFFFFFFFH鍒欏凡鍒版枃浠跺熬(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - } ByteLocate; /* CMD4H_BYTE_LOCATE: 浠ュ瓧鑺備负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ + union { + UINT32 mSectorOffset; + UINT32 mSectorLba; + } SectorLocate; - struct { - UINT16 mByteCount; /* 杈撳叆鍙傛暟: 璇锋眰璇诲彇鐨勫瓧鑺傛暟(鎬婚暱搴16浣,浣庡瓧鑺傚湪鍓) */ - } ByteRead; /* CMD2H_BYTE_READ: 浠ュ瓧鑺備负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ + struct { + UINT8 mSectorCount; + UINT8 mReserved1; + UINT8 mReserved2; + UINT8 mReserved3; + UINT32 mStartSector; + } SectorRead; - struct { - UINT16 mByteCount; /* 杈撳叆鍙傛暟: 璇锋眰鍐欏叆鐨勫瓧鑺傛暟(鎬婚暱搴16浣,浣庡瓧鑺傚湪鍓) */ - } ByteWrite; /* CMD2H_BYTE_WRITE: 浠ュ瓧鑺備负鍗曚綅鍚戝綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ + struct { + UINT8 mSectorCount; + UINT8 mReserved1; + UINT8 mReserved2; + UINT8 mReserved3; + UINT32 mStartSector; +} SectorWrite; - union { - UINT32 mSectorOffset; /* 杈撳叆鍙傛暟: 鍋忕Щ鎵囧尯鏁,浠ユ墖鍖轰负鍗曚綅鐨勫亸绉婚噺(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - UINT32 mSectorLba; /* 杩斿洖: 褰撳墠鏂囦欢鎸囬拡瀵瑰簲鐨勭粷瀵圭嚎鎬ф墖鍖哄彿,0FFFFFFFFH鍒欏凡鍒版枃浠跺熬(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - } SectorLocate; /* CMD4H_SEC_LOCATE: 浠ユ墖鍖轰负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ + struct { + UINT32 mDiskSizeSec; + } DiskCapacity; - struct { - UINT8 mSectorCount; /* 杈撳叆鍙傛暟: 璇锋眰璇诲彇鐨勬墖鍖烘暟 */ - /* 杩斿洖: 鍏佽璇诲彇鐨勬墖鍖烘暟 */ - UINT8 mReserved1; - UINT8 mReserved2; - UINT8 mReserved3; - UINT32 mStartSector; /* 杩斿洖: 鍏佽璇诲彇鐨勬墖鍖哄潡鐨勮捣濮嬬粷瀵圭嚎鎬ф墖鍖哄彿(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - } SectorRead; /* CMD1H_SEC_READ: 浠ユ墖鍖轰负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ + struct { + UINT32 mTotalSector; + UINT32 mFreeSector; + UINT8 mDiskFat; + } DiskQuery; - struct { - UINT8 mSectorCount; /* 杈撳叆鍙傛暟: 璇锋眰鍐欏叆鐨勬墖鍖烘暟 */ - /* 杩斿洖: 鍏佽鍐欏叆鐨勬墖鍖烘暟 */ - UINT8 mReserved1; - UINT8 mReserved2; - UINT8 mReserved3; - UINT32 mStartSector; /* 杩斿洖: 鍏佽鍐欏叆鐨勬墖鍖哄潡鐨勮捣濮嬬粷瀵圭嚎鎬ф墖鍖哄彿(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - } SectorWrite; /* CMD1H_SEC_WRITE: 浠ユ墖鍖轰负鍗曚綅鍦ㄥ綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ + BULK_ONLY_CBW DiskBocCbw; - struct { - UINT32 mDiskSizeSec; /* 杩斿洖: 鏁翠釜鐗╃悊纾佺洏鐨勬绘墖鍖烘暟(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - } DiskCapacity; /* CMD0H_DISK_CAPACITY: 鏌ヨ纾佺洏鐗╃悊瀹归噺 */ + struct { + UINT8 mMaxLogicUnit; + } DiskMaxLun; - struct { - UINT32 mTotalSector; /* 杩斿洖: 褰撳墠閫昏緫鐩樼殑鎬绘墖鍖烘暟(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - UINT32 mFreeSector; /* 杩斿洖: 褰撳墠閫昏緫鐩樼殑鍓╀綑鎵囧尯鏁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - UINT8 mDiskFat; /* 杩斿洖: 褰撳墠閫昏緫鐩樼殑FAT绫诲瀷,1-FAT12,2-FAT16,3-FAT32 */ - } DiskQuery; /* CMD_DiskQuery, 鏌ヨ纾佺洏淇℃伅 */ + INQUIRY_DATA DiskInitInq; + INQUIRY_DATA DiskInqData; + SENSE_DATA ReqSenseData; + struct { + UINT32 mDiskSizeSec; + } DiskSize; - BULK_ONLY_CBW DiskBocCbw; /* 杈撳叆鍙傛暟: CBW鍛戒护缁撴瀯 */ - /* CMD0H_DISK_BOC_CMD: 瀵筓SB瀛樺偍鍣ㄦ墽琛孊ulkOnly浼犺緭鍗忚鐨勫懡浠 */ + struct { + UINT32 mStartSector; + UINT8 mSectorCount; + } DiskRead; - struct { - UINT8 mMaxLogicUnit; /* 杩斿洖: USB瀛樺偍鍣ㄧ殑鏈澶ч昏緫鍗曞厓鍙 */ - } DiskMaxLun; /* CMD0H_DISK_MAX_LUN: 鎺у埗浼犺緭-鑾峰彇USB瀛樺偍鍣ㄦ渶澶ч昏緫鍗曞厓鍙 */ - - INQUIRY_DATA DiskInitInq; /* 杩斿洖: INQUIRY鍛戒护鐨勮繑鍥炴暟鎹 */ - /* CMD0H_DISK_INIT: 鍒濆鍖朥SB瀛樺偍鍣 */ - - INQUIRY_DATA DiskInqData; /* 杩斿洖: INQUIRY鍛戒护鐨勮繑鍥炴暟鎹 */ - /* CMD0H_DISK_INQUIRY: 鏌ヨUSB瀛樺偍鍣ㄧ壒鎬 */ - - SENSE_DATA ReqSenseData; /* 杩斿洖: REQUEST SENSE鍛戒护鐨勮繑鍥炴暟鎹 */ - /* CMD0H_DISK_R_SENSE: 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ - - struct { - UINT32 mDiskSizeSec; /* 杩斿洖: 鏁翠釜鐗╃悊纾佺洏鐨勬绘墖鍖烘暟(鎬婚暱搴32浣,楂樺瓧鑺傚湪鍓) */ - } DiskSize; /* CMD0H_DISK_SIZE: 鑾峰彇USB瀛樺偍鍣ㄧ殑瀹归噺 */ - - struct { - UINT32 mStartSector; /* 杈撳叆鍙傛暟: LBA鎵囧尯鍦板潃(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - UINT8 mSectorCount; /* 杈撳叆鍙傛暟: 璇锋眰璇诲彇鐨勬墖鍖烘暟 */ - } DiskRead; /* CMD5H_DISK_READ: 浠嶶SB瀛樺偍鍣ㄨ鏁版嵁鍧(浠ユ墖鍖轰负鍗曚綅) */ - - struct { - UINT32 mStartSector; /* 杈撳叆鍙傛暟: LBA鎵囧尯鍦板潃(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ - UINT8 mSectorCount; /* 杈撳叆鍙傛暟: 璇锋眰鍐欏叆鐨勬墖鍖烘暟 */ - } DiskWrite; /* CMD5H_DISK_WRITE: 鍚慤SB瀛樺偍鍣ㄥ啓鏁版嵁鍧(浠ユ墖鍖轰负鍗曚綅) */ + struct { + UINT32 mStartSector; + UINT8 mSectorCount; + } DiskWrite; } CH376_CMD_DATA, *P_CH376_CMD_DATA; #endif /* ********************************************************************************************************************* */ -/* 涓绘満鏂囦欢妯″紡涓嬬殑鏂囦欢绯荤粺鍙橀噺鐨勫湴鍧 */ -#ifndef VAR_FILE_SIZE +#ifndef VAR_FILE_SIZE -/* 8浣/鍗曞瓧鑺傚彉閲 */ -#define VAR_SYS_BASE_INFO 0x20 /* 褰撳墠绯荤粺鐨勫熀鏈俊鎭 */ -/* 浣6鐢ㄤ簬鎸囩ずUSB瀛樺偍璁惧鐨勫瓙绫诲埆SubClass-Code, 浣6涓0鍒欒鏄庡瓙绫诲埆涓6, 浣6涓1鍒欒鏄庡瓙绫诲埆鏄潪6鐨勫叾瀹冨 */ -/* 浣5鐢ㄤ簬鎸囩ずUSB璁惧鏂瑰紡涓嬬殑USB閰嶇疆鐘舵佸拰USB涓绘満鏂瑰紡涓嬬殑USB璁惧杩炴帴鐘舵 */ -/* USB璁惧鏂瑰紡涓, 浣5涓1鍒橴SB閰嶇疆瀹屾垚, 浣5浣0鍒欏皻鏈厤缃 */ -/* USB涓绘満鏂瑰紡涓, 浣5涓1鍒橴SB绔彛瀛樺湪USB璁惧, 浣5浣0鍒橴SB绔彛娌℃湁USB璁惧 */ -/* 浣4鐢ㄤ簬鎸囩ずUSB璁惧鏂瑰紡涓嬬殑缂撳啿鍖洪攣瀹氱姸鎬, 浣4涓1鍒欒鏄嶶SB缂撳啿鍖哄浜庨攣瀹氱姸鎬, 浣6涓1鍒欒鏄庡凡缁忛噴鏀 */ -/* 鍏跺畠浣, 淇濈暀,璇峰嬁淇敼 */ -#define VAR_RETRY_TIMES 0x25 /* USB浜嬪姟鎿嶄綔鐨勯噸璇曟鏁 */ -/* 浣7涓0鍒欐敹鍒癗AK鏃朵笉閲嶈瘯, 浣7涓1浣6涓0鍒欐敹鍒癗AK鏃舵棤闄愰噸璇(鍙互鐢–MD_ABORT_NAK鍛戒护鏀惧純閲嶈瘯), 浣7涓1浣6涓1鍒欐敹鍒癗AK鏃舵渶澶氶噸璇3绉 */ -/* 浣5~浣0涓鸿秴鏃跺悗鐨勯噸璇曟鏁 */ -#define VAR_FILE_BIT_FLAG 0x26 /* 涓绘満鏂囦欢妯″紡涓嬬殑浣嶆爣蹇 */ -/* 浣1鍜屼綅0, 閫昏緫鐩樼殑FAT鏂囦欢绯荤粺鏍囧織, 00-FAT12, 01-FAT16, 10-FAT32, 11-闈炴硶 */ -/* 浣2, 褰撳墠缂撳啿鍖轰腑鐨凢AT琛ㄦ暟鎹槸鍚﹁淇敼鏍囧織, 0-鏈慨鏀, 1-宸蹭慨鏀 */ -/* 浣3, 鏂囦欢闀垮害闇瑕佷慨鏀规爣蹇, 褰撳墠鏂囦欢琚拷鍔犳暟鎹, 0-鏈拷鍔犳棤闇淇敼, 1-宸茶拷鍔犻渶瑕佷慨鏀 */ -/* 鍏跺畠浣, 淇濈暀,璇峰嬁淇敼 */ -#define VAR_DISK_STATUS 0x2B /* 涓绘満鏂囦欢妯″紡涓嬬殑纾佺洏鍙婃枃浠剁姸鎬 */ -#define VAR_SD_BIT_FLAG 0x30 /* 涓绘満鏂囦欢妯″紡涓婼D鍗$殑浣嶆爣蹇 */ -/* 浣0, SD鍗$増鏈, 0-鍙敮鎸丼D绗竴鐗,1-鏀寔SD绗簩鐗 */ -/* 浣1, 鑷姩璇嗗埆, 0-SD鍗, 1-MMC鍗 */ -/* 浣2, 鑷姩璇嗗埆, 0-鏍囧噯瀹归噺SD鍗, 1-澶у閲廠D鍗(HC-SD) */ -/* 浣4, ACMD41鍛戒护瓒呮椂 */ -/* 浣5, CMD1鍛戒护瓒呮椂 */ -/* 浣6, CMD58鍛戒护瓒呮椂 */ -/* 鍏跺畠浣, 淇濈暀,璇峰嬁淇敼 */ -#define VAR_UDISK_TOGGLE 0x31 /* USB瀛樺偍璁惧鐨凚ULK-IN/BULK-OUT绔偣鐨勫悓姝ユ爣蹇 */ -/* 浣7, Bulk-In绔偣鐨勫悓姝ユ爣蹇 */ -/* 浣6, Bulk-In绔偣鐨勫悓姝ユ爣蹇 */ -/* 浣5~浣0, 蹇呴』涓0 */ -#define VAR_UDISK_LUN 0x34 /* USB瀛樺偍璁惧鐨勯昏緫鍗曞厓鍙 */ -/* 浣7~浣4, USB瀛樺偍璁惧鐨勫綋鍓嶉昏緫鍗曞厓鍙,CH376鍒濆鍖朥SB瀛樺偍璁惧鍚,榛樿鏄闂0#閫昏緫鍗曞厓 */ -/* 浣3~浣0, USB瀛樺偍璁惧鐨勬渶澶ч昏緫鍗曞厓鍙,鍔1鍚庣瓑浜庨昏緫鍗曞厓鏁 */ -#define VAR_SEC_PER_CLUS 0x38 /* 閫昏緫鐩樼殑姣忕皣鎵囧尯鏁 */ -#define VAR_FILE_DIR_INDEX 0x3B /* 褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄦ墖鍖哄唴鐨勭储寮曞彿 */ -#define VAR_CLUS_SEC_OFS 0x3C /* 褰撳墠鏂囦欢鎸囬拡鍦ㄧ皣鍐呯殑鎵囧尯鍋忕Щ,涓0xFF鍒欐寚鍚戞枃浠舵湯灏,绨囩粨鏉 */ +#define VAR_SYS_BASE_INFO 0x20 +#define VAR_RETRY_TIMES 0x25 +#define VAR_FILE_BIT_FLAG 0x26 +#define VAR_DISK_STATUS 0x2B +#define VAR_SD_BIT_FLAG 0x30 +#define VAR_UDISK_TOGGLE 0x31 +#define VAR_UDISK_LUN 0x34 +#define VAR_SEC_PER_CLUS 0x38 +#define VAR_FILE_DIR_INDEX 0x3B +#define VAR_CLUS_SEC_OFS 0x3C -/* 32浣/4瀛楄妭鍙橀噺 */ -#define VAR_DISK_ROOT 0x44 /* 瀵逛簬FAT16鐩樹负鏍圭洰褰曞崰鐢ㄦ墖鍖烘暟,瀵逛簬FAT32鐩樹负鏍圭洰褰曡捣濮嬬皣鍙(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_DSK_TOTAL_CLUS 0x48 /* 閫昏緫鐩樼殑鎬荤皣鏁(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_DSK_START_LBA 0x4C /* 閫昏緫鐩樼殑璧峰缁濆鎵囧尯鍙稬BA(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_DSK_DAT_START 0x50 /* 閫昏緫鐩樼殑鏁版嵁鍖哄煙鐨勮捣濮婰BA(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_LBA_BUFFER 0x54 /* 褰撳墠纾佺洏鏁版嵁缂撳啿鍖虹殑鏁版嵁瀵瑰簲鐨凩BA(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_LBA_CURRENT 0x58 /* 褰撳墠璇诲啓鐨勭鐩樿捣濮婰BA鍦板潃(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_FAT_DIR_LBA 0x5C /* 褰撳墠鏂囦欢鐩綍淇℃伅鎵鍦ㄧ殑鎵囧尯LBA鍦板潃(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_START_CLUSTER 0x60 /* 褰撳墠鏂囦欢鎴栬呯洰褰(鏂囦欢澶)鐨勮捣濮嬬皣鍙(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_CURRENT_CLUST 0x64 /* 褰撳墠鏂囦欢鐨勫綋鍓嶇皣鍙(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_FILE_SIZE 0x68 /* 褰撳墠鏂囦欢鐨勯暱搴(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ -#define VAR_CURRENT_OFFSET 0x6C /* 褰撳墠鏂囦欢鎸囬拡,褰撳墠璇诲啓浣嶇疆鐨勫瓧鑺傚亸绉(鎬婚暱搴32浣,浣庡瓧鑺傚湪鍓) */ +#define VAR_DISK_ROOT 0x44 +#define VAR_DSK_TOTAL_CLUS 0x48 +#define VAR_DSK_START_LBA 0x4C +#define VAR_DSK_DAT_START 0x50 +#define VAR_LBA_BUFFER 0x54 +#define VAR_LBA_CURRENT 0x58 +#define VAR_FAT_DIR_LBA 0x5C +#define VAR_START_CLUSTER 0x60 +#define VAR_CURRENT_CLUST 0x64 +#define VAR_FILE_SIZE 0x68 +#define VAR_CURRENT_OFFSET 0x6C #endif /* ********************************************************************************************************************* */ -/* 甯哥敤USB瀹氫箟 */ - -/* USB鐨勫寘鏍囪瘑PID, 涓绘満鏂瑰紡鍙兘鐢ㄥ埌 */ -#ifndef DEF_USB_PID_SETUP -#define DEF_USB_PID_NULL 0x00 /* 淇濈暀PID, 鏈畾涔 */ -#define DEF_USB_PID_SOF 0x05 -#define DEF_USB_PID_SETUP 0x0D -#define DEF_USB_PID_IN 0x09 -#define DEF_USB_PID_OUT 0x01 -#define DEF_USB_PID_ACK 0x02 -#define DEF_USB_PID_NAK 0x0A -#define DEF_USB_PID_STALL 0x0E -#define DEF_USB_PID_DATA0 0x03 -#define DEF_USB_PID_DATA1 0x0B -#define DEF_USB_PID_PRE 0x0C +#ifndef DEF_USB_PID_SETUP +#define DEF_USB_PID_NULL 0x00 +#define DEF_USB_PID_SOF 0x05 +#define DEF_USB_PID_SETUP 0x0D +#define DEF_USB_PID_IN 0x09 +#define DEF_USB_PID_OUT 0x01 +#define DEF_USB_PID_ACK 0x02 +#define DEF_USB_PID_NAK 0x0A +#define DEF_USB_PID_STALL 0x0E +#define DEF_USB_PID_DATA0 0x03 +#define DEF_USB_PID_DATA1 0x0B +#define DEF_USB_PID_PRE 0x0C #endif -/* USB璇锋眰绫诲瀷, 澶栫疆鍥轰欢妯″紡鍙兘鐢ㄥ埌 */ -#ifndef DEF_USB_REQ_TYPE -#define DEF_USB_REQ_READ 0x80 /* 鎺у埗璇绘搷浣 */ -#define DEF_USB_REQ_WRITE 0x00 /* 鎺у埗鍐欐搷浣 */ -#define DEF_USB_REQ_TYPE 0x60 /* 鎺у埗璇锋眰绫诲瀷 */ -#define DEF_USB_REQ_STAND 0x00 /* 鏍囧噯璇锋眰 */ -#define DEF_USB_REQ_CLASS 0x20 /* 璁惧绫昏姹 */ -#define DEF_USB_REQ_VENDOR 0x40 /* 鍘傚晢璇锋眰 */ -#define DEF_USB_REQ_RESERVE 0x60 /* 淇濈暀璇锋眰 */ +#ifndef DEF_USB_REQ_TYPE +#define DEF_USB_REQ_READ 0x80 +#define DEF_USB_REQ_WRITE 0x00 +#define DEF_USB_REQ_TYPE 0x60 +#define DEF_USB_REQ_STAND 0x00 +#define DEF_USB_REQ_CLASS 0x20 +#define DEF_USB_REQ_VENDOR 0x40 +#define DEF_USB_REQ_RESERVE 0x60 #endif -/* USB鏍囧噯璁惧璇锋眰, RequestType鐨勪綅6浣5=00(Standard), 澶栫疆鍥轰欢妯″紡鍙兘鐢ㄥ埌 */ -#ifndef DEF_USB_GET_DESCR -#define DEF_USB_CLR_FEATURE 0x01 -#define DEF_USB_SET_FEATURE 0x03 -#define DEF_USB_GET_STATUS 0x00 -#define DEF_USB_SET_ADDRESS 0x05 -#define DEF_USB_GET_DESCR 0x06 -#define DEF_USB_SET_DESCR 0x07 -#define DEF_USB_GET_CONFIG 0x08 -#define DEF_USB_SET_CONFIG 0x09 -#define DEF_USB_GET_INTERF 0x0A -#define DEF_USB_SET_INTERF 0x0B -#define DEF_USB_SYNC_FRAME 0x0C +#ifndef DEF_USB_GET_DESCR +#define DEF_USB_CLR_FEATURE 0x01 +#define DEF_USB_SET_FEATURE 0x03 +#define DEF_USB_GET_STATUS 0x00 +#define DEF_USB_SET_ADDRESS 0x05 +#define DEF_USB_GET_DESCR 0x06 +#define DEF_USB_SET_DESCR 0x07 +#define DEF_USB_GET_CONFIG 0x08 +#define DEF_USB_SET_CONFIG 0x09 +#define DEF_USB_GET_INTERF 0x0A +#define DEF_USB_SET_INTERF 0x0B +#define DEF_USB_SYNC_FRAME 0x0C #endif /* ********************************************************************************************************************* */ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c index 75be34c2c..9478b2668 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c @@ -18,25 +18,9 @@ * @date 2022.10.10 */ -/* CH376鑺墖 鏂囦欢绯荤粺灞 V1.3 */ -/* 鎻愪緵鏂囦欢绯荤粺甯哥敤瀛愮▼搴,鎻愪緵鍛戒护鎵撳寘 */ -/* 涓嶄娇鐢ㄧ殑瀛愮▼搴忓彲浠ユ敞閲婃帀,浠庤岃妭绾﹀崟鐗囨満鐨勭▼搴廟OM绌洪棿鍜屾暟鎹甊AM绌洪棿 */ -/* 杩欓噷鐨勫瓙绋嬪簭鏄氳繃鎷彿涓殑鍙橀噺浼犻掑弬鏁,濡傛灉鍙傛暟杈冨,涓轰簡鑺傜害RAM,涔熷彲浠ュ弬鑰僀H375瀛愮▼搴忓簱鏀规垚閫氳繃鍚屼竴鍏ㄥ眬鍙橀噺/鑱斿悎缁撴瀯CH376_CMD_DATA浼犻 */ - -/* name 鍙傛暟鏄寚鐭枃浠跺悕, 鍙互鍖呮嫭鏍圭洰褰曠, 浣嗕笉鍚湁璺緞鍒嗛殧绗, 鎬婚暱搴︿笉瓒呰繃1+8+1+3+1瀛楄妭 */ -/* PathName 鍙傛暟鏄寚鍏ㄨ矾寰勭殑鐭枃浠跺悕, 鍖呮嫭鏍圭洰褰曠銆佸绾у瓙鐩綍鍙婅矾寰勫垎闅旂銆佹枃浠跺悕/鐩綍鍚 */ -/* LongName 鍙傛暟鏄寚闀挎枃浠跺悕, 浠NICODE灏忕椤哄簭缂栫爜, 浠ヤ袱涓0瀛楄妭缁撴潫, 浣跨敤闀挎枃浠跺悕瀛愮▼搴忓繀椤诲厛瀹氫箟鍏ㄥ眬缂撳啿鍖篏lobalBuf, 闀垮害涓嶅皬浜64瀛楄妭, 鍙互涓庡叾瀹冨瓙绋嬪簭鍏辩敤 */ - -/* 瀹氫箟 NO_DEFAULT_CH376_INT 鐢ㄤ簬绂佹榛樿鐨刉ait376Interrupt瀛愮▼搴,绂佹鍚,搴旂敤绋嬪簭蹇呴』鑷瀹氫箟涓涓悓鍚嶅瓙绋嬪簭 */ -/* 瀹氫箟 DEF_INT_TIMEOUT 鐢ㄤ簬璁剧疆榛樿鐨刉ait376Interrupt瀛愮▼搴忎腑鐨勭瓑寰呬腑鏂殑瓒呮椂鏃堕棿/寰幆璁℃暟鍊, 0鍒欎笉妫鏌ヨ秴鏃惰屼竴鐩寸瓑寰 */ -/* 瀹氫箟 EN_DIR_CREATE 鐢ㄤ簬鎻愪緵鏂板缓澶氱骇瀛愮洰褰曠殑瀛愮▼搴,榛樿鏄笉鎻愪緵 */ -/* 瀹氫箟 EN_DISK_QUERY 鐢ㄤ簬鎻愪緵纾佺洏瀹归噺鏌ヨ鍜屽墿浣欑┖闂存煡璇㈢殑瀛愮▼搴,榛樿鏄笉鎻愪緵 */ -/* 瀹氫箟 EN_SECTOR_ACCESS 鐢ㄤ簬鎻愪緵浠ユ墖鍖轰负鍗曚綅璇诲啓鏂囦欢鐨勫瓙绋嬪簭,榛樿鏄笉鎻愪緵 */ -/* 瀹氫箟 EN_LONG_NAME 鐢ㄤ簬鎻愪緵鏀寔闀挎枃浠跺悕鐨勫瓙绋嬪簭,榛樿鏄笉鎻愪緵 */ -/* 瀹氫箟 DEF_IC_V43_U 鐢ㄤ簬鍘绘帀鏀寔浣庣増鏈殑绋嬪簭浠g爜,浠呮敮鎸乂4.3鍙婁互涓婄増鏈殑CH376鑺墖,榛樿鏄敮鎸佷綆鐗堟湰 */ #if 0 -#define DEF_IC_V43_U 1 /* 鎺ㄨ崘瀹氫箟 DEF_IC_V43_U 浠ヤ紭鍖栦唬鐮 */ +#define DEF_IC_V43_U 1 #endif #include "k210_ch376.h" @@ -46,13 +30,14 @@ ****************************************************************************/ static int fd; -/* 涓插彛鏂瑰紡鏈敤鍒 */ +/* Serial port mode is not used */ void xEndCH376Cmd(void) { } -void xWriteCH376Cmd( UINT8 cmd ) { /* 鍚慍H376鐨勫懡浠ょ鍙e啓鍏ュ懡浠,鍛ㄦ湡涓嶅皬浜2uS,濡傛灉鍗曠墖鏈鸿緝蹇垯寤舵椂 */ - UINT8 temp[3]; +void xWriteCH376Cmd(UINT8 cmd) +{ + UINT8 temp[3]; temp[0] = 0x57; temp[1] = 0xab; temp[2] = cmd; @@ -60,611 +45,615 @@ void xWriteCH376Cmd( UINT8 cmd ) { /* 鍚慍H376鐨勫懡浠ょ鍙e啓鍏ュ懡浠, write(fd, temp, 3); } -//鍐欐暟鎹 -void xWriteCH376Data( UINT8 dat ) { /* 鍚慍H376鐨勬暟鎹鍙e啓鍏ユ暟鎹,鍛ㄦ湡涓嶅皬浜1uS,濡傛灉鍗曠墖鏈鸿緝蹇垯寤舵椂 */ +void xWriteCH376Data(UINT8 dat) +{ UINT8 tmp = dat; write(fd, &tmp, 1); up_udelay(2); } -//璇绘暟鎹 -UINT8 xReadCH376Data(void) { - UINT32 i; - UINT8 data; - int res; - for(i=0;i<500000;i++) - { - res = read(fd, &data, 1); - if(res == 1) - { - return ((UINT8)data); - } - up_udelay(1); - } - return ERR_USB_UNKNOWN; +UINT8 xReadCH376Data(void) +{ + UINT32 i; + UINT8 data; + int res; + for(i=0;i<500000;i++) + { + res = read(fd, &data, 1); + if(res == 1) + { + return ((UINT8)data); + } + up_udelay(1); + } + return ERR_USB_UNKNOWN; } -UINT8 CH376ReadBlock( PUINT8 buf ) /* 浠庡綋鍓嶄富鏈虹鐐圭殑鎺ユ敹缂撳啿鍖鸿鍙栨暟鎹潡,杩斿洖闀垮害 */ +UINT8 CH376ReadBlock(PUINT8 buf) { - UINT8 s, l; - xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); - s = l = xReadCH376Data( ); /* 闀垮害 */ - if ( l ) { - do { - *buf = xReadCH376Data( ); - buf ++; - } while ( -- l ); - } - xEndCH376Cmd( ); - return( s ); + UINT8 s, l; + xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); + s = l = xReadCH376Data( ); + if ( l ) { + do { + *buf = xReadCH376Data( ); + buf ++; + } while ( -- l ); + } + xEndCH376Cmd( ); + return( s ); } -/* 鏌ヨCH376涓柇(INT#浣庣數骞) */ -UINT8 Query376Interrupt( void ) +UINT8 Query376Interrupt(void) { - //浜х敓涓柇鐨勫悓鏃讹紝涓插彛浼氭敹鍒颁竴涓暟鎹紝鐩存帴璇诲嚭鏉ヤ涪鎺 - if(xReadCH376Data() == ERR_USB_UNKNOWN) return FALSE ; - else return TRUE ; + //When an interrupt occurs, the serial port will receive a data, read it directly, and discard it + if(xReadCH376Data() == ERR_USB_UNKNOWN) return FALSE ; + else return TRUE ; } -/* CH376鍒濆鍖栦唬鐮 */ -UINT8 mInitCH376Host( void ) /* 鍒濆鍖朇H376 */ +/* CH376 INIT */ +UINT8 mInitCH376Host(void) { - UINT8 res; - up_mdelay(50); /* 涓婄數鍚庤嚦灏戝欢鏃50ms鎿嶄綔 */ + UINT8 res; + /* After power on, delay operation for at least 50ms */ + up_mdelay(50); fd = open("/dev/ttyS3", O_RDWR); up_mdelay(600); - xWriteCH376Cmd( CMD11_CHECK_EXIST ); /* 娴嬭瘯鍗曠墖鏈轰笌CH376涔嬮棿鐨勯氳鎺ュ彛 */ - xWriteCH376Data( 0x65 ); - res = xReadCH376Data( ); - xEndCH376Cmd( ); - if ( res != 0x9A ) return( ERR_USB_UNKNOWN ); /* 閫氳鎺ュ彛涓嶆甯,鍙兘鍘熷洜鏈:鎺ュ彛杩炴帴寮傚父,鍏跺畠璁惧褰卞搷(鐗囬変笉鍞竴),涓插彛娉㈢壒鐜,涓鐩村湪澶嶄綅,鏅舵尟涓嶅伐浣 */ + /* Test the communication interface between SCM and CH376 */ + xWriteCH376Cmd(CMD11_CHECK_EXIST); + xWriteCH376Data(0x65); + res = xReadCH376Data(); + xEndCH376Cmd(); + if ( res != 0x9A ) return( ERR_USB_UNKNOWN ); - xWriteCH376Cmd( CMD11_SET_USB_MODE ); /* 璁惧USB宸ヤ綔妯″紡 */ - xWriteCH376Data( 0x06 ); - up_udelay( 20 ); - res = xReadCH376Data( ); - xEndCH376Cmd( ); - if ( res == CMD_RET_SUCCESS ) return( USB_INT_SUCCESS ); - else return( ERR_USB_UNKNOWN ); /* 璁剧疆妯″紡閿欒 */ - + xWriteCH376Cmd(CMD11_SET_USB_MODE); /* SET USB MODE */ + xWriteCH376Data(0x06); + up_udelay(20); + res = xReadCH376Data(); + xEndCH376Cmd(); + if (res == CMD_RET_SUCCESS) return(USB_INT_SUCCESS); + else return(ERR_USB_UNKNOWN); /* SET MODE ERROR */ + } -UINT8 CH376WriteReqBlock( PUINT8 buf ) /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡,杩斿洖闀垮害 */ +/* Write the requested data block to the internally specified buffer, and return the length */ +UINT8 CH376WriteReqBlock(PUINT8 buf) { - UINT8 s, l; - xWriteCH376Cmd( CMD01_WR_REQ_DATA ); - s = l = xReadCH376Data( ); /* 闀垮害 */ - if ( l ) { - do { - xWriteCH376Data( *buf ); - buf ++; - } while ( -- l ); - } - xEndCH376Cmd( ); - return( s ); + UINT8 s, l; + xWriteCH376Cmd( CMD01_WR_REQ_DATA ); + s = l = xReadCH376Data(); + if ( l ) { + do { + xWriteCH376Data( *buf ); + buf ++; + } while ( -- l ); + } + xEndCH376Cmd( ); + return( s ); } -void CH376WriteHostBlock( PUINT8 buf, UINT8 len ) /* 鍚慤SB涓绘満绔偣鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ +/* Write data block to the send buffer of USB host endpoint */ +void CH376WriteHostBlock(PUINT8 buf, UINT8 len) { - xWriteCH376Cmd( CMD10_WR_HOST_DATA ); - xWriteCH376Data( len ); /* 闀垮害 */ - if ( len ) { - do { - xWriteCH376Data( *buf ); - buf ++; - } while ( -- len ); - } - xEndCH376Cmd( ); + xWriteCH376Cmd( CMD10_WR_HOST_DATA ); + xWriteCH376Data( len ); + if ( len ) { + do { + xWriteCH376Data( *buf ); + buf ++; + } while ( -- len ); + } + xEndCH376Cmd( ); } -void CH376WriteOfsBlock( PUINT8 buf, UINT8 ofs, UINT8 len ) /* 鍚戝唴閮ㄧ紦鍐插尯鎸囧畾鍋忕Щ鍦板潃鍐欏叆鏁版嵁鍧 */ +/* Specify offset address to write data block to internal buffer */ +void CH376WriteOfsBlock( PUINT8 buf, UINT8 ofs, UINT8 len ) { - xWriteCH376Cmd( CMD20_WR_OFS_DATA ); - xWriteCH376Data( ofs ); /* 鍋忕Щ鍦板潃 */ - xWriteCH376Data( len ); /* 闀垮害 */ - if ( len ) { - do { - xWriteCH376Data( *buf ); - buf ++; - } while ( -- len ); - } - xEndCH376Cmd( ); + xWriteCH376Cmd( CMD20_WR_OFS_DATA ); + xWriteCH376Data( ofs ); /* Offset address */ + xWriteCH376Data( len ); /* length */ + if ( len ) { + do { + xWriteCH376Data( *buf ); + buf ++; + } while ( -- len ); + } + xEndCH376Cmd( ); } -void CH376SetFileName( PUINT8 name ) /* 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ +/* Set the file name of the file to be operated on */ +void CH376SetFileName( PUINT8 name ) { - UINT8 c; -#ifndef DEF_IC_V43_U - UINT8 s; - xWriteCH376Cmd( CMD01_GET_IC_VER ); - if ( xReadCH376Data( ) < 0x43 ) { - if ( CH376ReadVar8( VAR_DISK_STATUS ) < DEF_DISK_READY ) { - xWriteCH376Cmd( CMD10_SET_FILE_NAME ); - xWriteCH376Data( 0 ); - s = CH376SendCmdWaitInt( CMD0H_FILE_OPEN ); - if ( s == USB_INT_SUCCESS ) { - s = CH376ReadVar8( 0xCF ); - if ( s ) { - CH376WriteVar32( 0x4C, CH376ReadVar32( 0x4C ) + ( (UINT16)s << 8 ) ); - CH376WriteVar32( 0x50, CH376ReadVar32( 0x50 ) + ( (UINT16)s << 8 ) ); - CH376WriteVar32( 0x70, 0 ); - } - } - } - } + UINT8 c; +#ifndef DEF_IC_V43_U + UINT8 s; + xWriteCH376Cmd( CMD01_GET_IC_VER ); + if ( xReadCH376Data( ) < 0x43 ) { + if ( CH376ReadVar8( VAR_DISK_STATUS ) < DEF_DISK_READY ) { + xWriteCH376Cmd( CMD10_SET_FILE_NAME ); + xWriteCH376Data( 0 ); + s = CH376SendCmdWaitInt( CMD0H_FILE_OPEN ); + if ( s == USB_INT_SUCCESS ) { + s = CH376ReadVar8( 0xCF ); + if ( s ) { + CH376WriteVar32( 0x4C, CH376ReadVar32( 0x4C ) + ( (UINT16)s << 8 ) ); + CH376WriteVar32( 0x50, CH376ReadVar32( 0x50 ) + ( (UINT16)s << 8 ) ); + CH376WriteVar32( 0x70, 0 ); + } + } + } + } #endif - xWriteCH376Cmd( CMD10_SET_FILE_NAME ); - c = *name; - xWriteCH376Data( c ); - while ( c ) { - name ++; - c = *name; - if ( c == DEF_SEPAR_CHAR1 || c == DEF_SEPAR_CHAR2 ) c = 0; /* 寮鸿灏嗘枃浠跺悕鎴 */ - xWriteCH376Data( c ); - } - xEndCH376Cmd( ); + xWriteCH376Cmd( CMD10_SET_FILE_NAME ); + c = *name; + xWriteCH376Data( c ); + while ( c ) { + name ++; + c = *name; + /* Force the file name to expire */ + if ( c == DEF_SEPAR_CHAR1 || c == DEF_SEPAR_CHAR2 ) c = 0; + xWriteCH376Data( c ); + } + xEndCH376Cmd( ); } -UINT32 CH376Read32bitDat( void ) /* 浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ +/* Read 32-bit data from CH376 chip and end the command */ +UINT32 CH376Read32bitDat( void ) { - UINT8 c0, c1, c2, c3; - c0 = xReadCH376Data( ); - c1 = xReadCH376Data( ); - c2 = xReadCH376Data( ); - c3 = xReadCH376Data( ); - xEndCH376Cmd( ); - return( c0 | (UINT16)c1 << 8 | (UINT32)c2 << 16 | (UINT32)c3 << 24 ); + UINT8 c0, c1, c2, c3; + c0 = xReadCH376Data( ); + c1 = xReadCH376Data( ); + c2 = xReadCH376Data( ); + c3 = xReadCH376Data( ); + xEndCH376Cmd( ); + return( c0 | (UINT16)c1 << 8 | (UINT32)c2 << 16 | (UINT32)c3 << 24 ); } -UINT8 CH376ReadVar8( UINT8 var ) /* 璇籆H376鑺墖鍐呴儴鐨8浣嶅彉閲 */ + +UINT8 CH376ReadVar8( UINT8 var ) { - UINT8 c0; - xWriteCH376Cmd( CMD11_READ_VAR8 ); - xWriteCH376Data( var ); - c0 = xReadCH376Data( ); - xEndCH376Cmd( ); - return( c0 ); + UINT8 c0; + xWriteCH376Cmd( CMD11_READ_VAR8 ); + xWriteCH376Data( var ); + c0 = xReadCH376Data( ); + xEndCH376Cmd( ); + return( c0 ); } -void CH376WriteVar8( UINT8 var, UINT8 dat ) /* 鍐機H376鑺墖鍐呴儴鐨8浣嶅彉閲 */ +void CH376WriteVar8( UINT8 var, UINT8 dat ) { - xWriteCH376Cmd( CMD20_WRITE_VAR8 ); - xWriteCH376Data( var ); - xWriteCH376Data( dat ); - xEndCH376Cmd( ); + xWriteCH376Cmd( CMD20_WRITE_VAR8 ); + xWriteCH376Data( var ); + xWriteCH376Data( dat ); + xEndCH376Cmd( ); } -UINT32 CH376ReadVar32( UINT8 var ) /* 璇籆H376鑺墖鍐呴儴鐨32浣嶅彉閲 */ +UINT32 CH376ReadVar32( UINT8 var ) { - xWriteCH376Cmd( CMD14_READ_VAR32 ); - xWriteCH376Data( var ); - return( CH376Read32bitDat( ) ); /* 浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ + xWriteCH376Cmd( CMD14_READ_VAR32 ); + xWriteCH376Data( var ); + return( CH376Read32bitDat( ) ); } -void CH376WriteVar32( UINT8 var, UINT32 dat ) /* 鍐機H376鑺墖鍐呴儴鐨32浣嶅彉閲 */ +void CH376WriteVar32( UINT8 var, UINT32 dat ) { - xWriteCH376Cmd( CMD50_WRITE_VAR32 ); - xWriteCH376Data( var ); - xWriteCH376Data( (UINT8)dat ); - xWriteCH376Data( (UINT8)( (UINT16)dat >> 8 ) ); - xWriteCH376Data( (UINT8)( dat >> 16 ) ); - xWriteCH376Data( (UINT8)( dat >> 24 ) ); - xEndCH376Cmd( ); + xWriteCH376Cmd( CMD50_WRITE_VAR32 ); + xWriteCH376Data( var ); + xWriteCH376Data( (UINT8)dat ); + xWriteCH376Data( (UINT8)( (UINT16)dat >> 8 ) ); + xWriteCH376Data( (UINT8)( dat >> 16 ) ); + xWriteCH376Data( (UINT8)( dat >> 24 ) ); + xEndCH376Cmd( ); } -void CH376EndDirInfo( void ) /* 鍦ㄨ皟鐢–H376DirInfoRead鑾峰彇FAT_DIR_INFO缁撴瀯涔嬪悗搴旇閫氱煡CH376缁撴潫 */ +void CH376EndDirInfo( void ) { - CH376WriteVar8( 0x0D, 0x00 ); + CH376WriteVar8( 0x0D, 0x00 ); } -UINT32 CH376GetFileSize( void ) /* 璇诲彇褰撳墠鏂囦欢闀垮害 */ +UINT32 CH376GetFileSize( void ) { - return( CH376ReadVar32( VAR_FILE_SIZE ) ); + return( CH376ReadVar32( VAR_FILE_SIZE ) ); } -UINT8 CH376GetDiskStatus( void ) /* 鑾峰彇纾佺洏鍜屾枃浠剁郴缁熺殑宸ヤ綔鐘舵 */ +UINT8 CH376GetDiskStatus( void ) { - return( CH376ReadVar8( VAR_DISK_STATUS ) ); + return( CH376ReadVar8( VAR_DISK_STATUS ) ); } -UINT8 CH376GetIntStatus( void ) /* 鑾峰彇涓柇鐘舵佸苟鍙栨秷涓柇璇锋眰 */ +UINT8 CH376GetIntStatus( void ) { - UINT8 s; - xWriteCH376Cmd( CMD01_GET_STATUS ); - s = xReadCH376Data( ); - xEndCH376Cmd( ); - return( s ); + UINT8 s; + xWriteCH376Cmd( CMD01_GET_STATUS ); + s = xReadCH376Data( ); + xEndCH376Cmd( ); + return( s ); } -#ifndef NO_DEFAULT_CH376_INT -UINT8 Wait376Interrupt( void ) /* 绛夊緟CH376涓柇(INT#浣庣數骞)锛岃繑鍥炰腑鏂姸鎬佺爜, 瓒呮椂鍒欒繑鍥濫RR_USB_UNKNOWN */ +#ifndef NO_DEFAULT_CH376_INT +UINT8 Wait376Interrupt( void ) { -#ifdef DEF_INT_TIMEOUT -#if DEF_INT_TIMEOUT < 1 - while ( Query376Interrupt( ) == FALSE ); /* 涓鐩寸瓑涓柇 */ - return( CH376GetIntStatus( ) ); /* 妫娴嬪埌涓柇 */ +#ifdef DEF_INT_TIMEOUT +#if DEF_INT_TIMEOUT < 1 + while ( Query376Interrupt( ) == FALSE ); + return( CH376GetIntStatus( ) ); #else - UINT32 i; - for ( i = 0; i < DEF_INT_TIMEOUT; i ++ ) { /* 璁℃暟闃叉瓒呮椂 */ - if ( Query376Interrupt( ) ) return( CH376GetIntStatus( ) ); /* 妫娴嬪埌涓柇 */ -/* 鍦ㄧ瓑寰匔H376涓柇鐨勮繃绋嬩腑,鍙互鍋氫簺闇瑕佸強鏃跺鐞嗙殑鍏跺畠浜嬫儏 */ - } - return( ERR_USB_UNKNOWN ); /* 涓嶅簲璇ュ彂鐢熺殑鎯呭喌 */ + UINT32 i; + for ( i = 0; i < DEF_INT_TIMEOUT; i ++ ) { + if ( Query376Interrupt( ) ) return( CH376GetIntStatus( ) ); + } + return( ERR_USB_UNKNOWN ); #endif #else - UINT32 i; - for ( i = 0; i < 5000000; i ++ ) { /* 璁℃暟闃叉瓒呮椂,榛樿鐨勮秴鏃舵椂闂,涓庡崟鐗囨満涓婚鏈夊叧 */ - if ( Query376Interrupt( ) ) return( CH376GetIntStatus( ) ); /* 妫娴嬪埌涓柇 */ -/* 鍦ㄧ瓑寰匔H376涓柇鐨勮繃绋嬩腑,鍙互鍋氫簺闇瑕佸強鏃跺鐞嗙殑鍏跺畠浜嬫儏 */ - } - return( ERR_USB_UNKNOWN ); /* 涓嶅簲璇ュ彂鐢熺殑鎯呭喌 */ + UINT32 i; + for ( i = 0; i < 5000000; i ++ ) { + if ( Query376Interrupt( ) ) return( CH376GetIntStatus( ) ); + } + return( ERR_USB_UNKNOWN ); #endif } #endif -UINT8 CH376SendCmdWaitInt( UINT8 mCmd ) /* 鍙戝嚭鍛戒护鐮佸悗,绛夊緟涓柇 */ +UINT8 CH376SendCmdWaitInt( UINT8 mCmd ) { - xWriteCH376Cmd( mCmd ); - xEndCH376Cmd( ); - return( Wait376Interrupt( ) ); + xWriteCH376Cmd( mCmd ); + xEndCH376Cmd( ); + return( Wait376Interrupt( ) ); } -UINT8 CH376SendCmdDatWaitInt( UINT8 mCmd, UINT8 mDat ) /* 鍙戝嚭鍛戒护鐮佸拰涓瀛楄妭鏁版嵁鍚,绛夊緟涓柇 */ +UINT8 CH376SendCmdDatWaitInt( UINT8 mCmd, UINT8 mDat ) { - xWriteCH376Cmd( mCmd ); - xWriteCH376Data( mDat ); - xEndCH376Cmd( ); - return( Wait376Interrupt( ) ); + xWriteCH376Cmd( mCmd ); + xWriteCH376Data( mDat ); + xEndCH376Cmd( ); + return(Wait376Interrupt()); } -UINT8 CH376DiskReqSense( void ) /* 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ +UINT8 CH376DiskReqSense( void ) { - UINT8 s; - up_mdelay( 5 ); - s = CH376SendCmdWaitInt( CMD0H_DISK_R_SENSE ); - up_mdelay( 5 ); - return( s ); + UINT8 s; + up_mdelay( 5 ); + s = CH376SendCmdWaitInt( CMD0H_DISK_R_SENSE ); + up_mdelay( 5 ); + return( s ); } -UINT8 CH376DiskConnect( void ) /* 妫鏌鐩樻槸鍚﹁繛鎺,涓嶆敮鎸丼D鍗 */ +UINT8 CH376DiskConnect( void ) { - if ( Query376Interrupt( ) ) CH376GetIntStatus( ); /* 妫娴嬪埌涓柇 */ - return( CH376SendCmdWaitInt( CMD0H_DISK_CONNECT ) ); + if ( Query376Interrupt( ) ) CH376GetIntStatus( ); + return( CH376SendCmdWaitInt( CMD0H_DISK_CONNECT ) ); } -UINT8 CH376DiskMount( void ) /* 鍒濆鍖栫鐩樺苟娴嬭瘯纾佺洏鏄惁灏辩华 */ +UINT8 CH376DiskMount( void ) { - return( CH376SendCmdWaitInt( CMD0H_DISK_MOUNT ) ); + return( CH376SendCmdWaitInt( CMD0H_DISK_MOUNT ) ); } -UINT8 CH376FileOpen( PUINT8 name ) /* 鍦ㄦ牴鐩綍鎴栬呭綋鍓嶇洰褰曚笅鎵撳紑鏂囦欢鎴栬呯洰褰(鏂囦欢澶) */ +UINT8 CH376FileOpen( PUINT8 name ) { - CH376SetFileName( name ); /* 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ -#ifndef DEF_IC_V43_U - if ( name[0] == DEF_SEPAR_CHAR1 || name[0] == DEF_SEPAR_CHAR2 ) CH376WriteVar32( VAR_CURRENT_CLUST, 0 ); + CH376SetFileName( name ); +#ifndef DEF_IC_V43_U + if ( name[0] == DEF_SEPAR_CHAR1 || name[0] == DEF_SEPAR_CHAR2 ) CH376WriteVar32( VAR_CURRENT_CLUST, 0 ); #endif - return( CH376SendCmdWaitInt( CMD0H_FILE_OPEN ) ); + return( CH376SendCmdWaitInt( CMD0H_FILE_OPEN ) ); } -UINT8 CH376FileCreate( PUINT8 name ) /* 鍦ㄦ牴鐩綍鎴栬呭綋鍓嶇洰褰曚笅鏂板缓鏂囦欢,濡傛灉鏂囦欢宸茬粡瀛樺湪閭d箞鍏堝垹闄 */ +UINT8 CH376FileCreate( PUINT8 name ) { - if ( name ) CH376SetFileName( name ); /* 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ - return( CH376SendCmdWaitInt( CMD0H_FILE_CREATE ) ); + if ( name ) CH376SetFileName( name ); + return( CH376SendCmdWaitInt( CMD0H_FILE_CREATE ) ); } -UINT8 CH376DirCreate( PUINT8 name ) /* 鍦ㄦ牴鐩綍涓嬫柊寤虹洰褰(鏂囦欢澶)骞舵墦寮,濡傛灉鐩綍宸茬粡瀛樺湪閭d箞鐩存帴鎵撳紑 */ +UINT8 CH376DirCreate( PUINT8 name ) { - CH376SetFileName( name ); /* 璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ -#ifndef DEF_IC_V43_U - if ( name[0] == DEF_SEPAR_CHAR1 || name[0] == DEF_SEPAR_CHAR2 ) CH376WriteVar32( VAR_CURRENT_CLUST, 0 ); + CH376SetFileName( name ); +#ifndef DEF_IC_V43_U + if ( name[0] == DEF_SEPAR_CHAR1 || name[0] == DEF_SEPAR_CHAR2 ) CH376WriteVar32( VAR_CURRENT_CLUST, 0 ); #endif - return( CH376SendCmdWaitInt( CMD0H_DIR_CREATE ) ); + return( CH376SendCmdWaitInt( CMD0H_DIR_CREATE ) ); } -UINT8 CH376SeparatePath( PUINT8 path ) /* 浠庤矾寰勪腑鍒嗙鍑烘渶鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰(鏂囦欢澶)鍚,杩斿洖鏈鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰曞悕鐨勫瓧鑺傚亸绉 */ +UINT8 CH376SeparatePath( PUINT8 path ) { - PUINT8 pName; - for ( pName = path; *pName != 0; ++ pName ); /* 鍒版枃浠跺悕瀛楃涓茬粨鏉熶綅缃 */ - while ( *pName != DEF_SEPAR_CHAR1 && *pName != DEF_SEPAR_CHAR2 && pName != path ) pName --; /* 鎼滅储鍊掓暟绗竴涓矾寰勫垎闅旂 */ - if ( pName != path ) pName ++; /* 鎵惧埌浜嗚矾寰勫垎闅旂,鍒欎慨鏀规寚鍚戠洰鏍囨枃浠剁殑鏈鍚庝竴绾ф枃浠跺悕,璺宠繃鍓嶉潰鐨勫绾х洰褰曞悕鍙婅矾寰勫垎闅旂 */ - return( pName - path ); + PUINT8 pName; + for ( pName = path; *pName != 0; ++ pName ); + while ( *pName != DEF_SEPAR_CHAR1 && *pName != DEF_SEPAR_CHAR2 && pName != path ) pName --; + if ( pName != path ) pName ++; + return( pName - path ); } -UINT8 CH376FileOpenDir( PUINT8 PathName, UINT8 StopName ) /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢鎴栬呯洰褰曠殑涓婄骇鐩綍,鏀寔澶氱骇鐩綍璺緞,鏀寔璺緞鍒嗛殧绗,璺緞闀垮害涓嶈秴杩255涓瓧绗 */ -/* StopName 鎸囧悜鏈鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰曞悕 */ +UINT8 CH376FileOpenDir( PUINT8 PathName, UINT8 StopName ) { - UINT8 i, s; - s = 0; - i = 1; /* 璺宠繃鏈夊彲鑳界殑鏍圭洰褰曠 */ - while ( 1 ) { - while ( PathName[i] != DEF_SEPAR_CHAR1 && PathName[i] != DEF_SEPAR_CHAR2 && PathName[i] != 0 ) ++ i; /* 鎼滅储涓嬩竴涓矾寰勫垎闅旂鎴栬呰矾寰勭粨鏉熺 */ - if ( PathName[i] ) i ++; /* 鎵惧埌浜嗚矾寰勫垎闅旂,淇敼鎸囧悜鐩爣鏂囦欢鐨勬渶鍚庝竴绾ф枃浠跺悕 */ - else i = 0; /* 璺緞缁撴潫 */ - s = CH376FileOpen( &PathName[s] ); /* 鎵撳紑鏂囦欢鎴栬呯洰褰 */ - if ( i && i != StopName ) { /* 璺緞灏氭湭缁撴潫 */ - if ( s != ERR_OPEN_DIR ) { /* 鍥犱负鏄愮骇鎵撳紑,灏氭湭鍒拌矾寰勭粨鏉,鎵浠,濡傛灉涓嶆槸鎴愬姛鎵撳紑浜嗙洰褰,閭d箞璇存槑鏈夐棶棰 */ - if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); /* 涓棿璺緞蹇呴』鏄洰褰曞悕,濡傛灉鏄枃浠跺悕鍒欏嚭閿 */ - else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); /* 涓棿璺緞鐨勬煇涓瓙鐩綍娌℃湁鎵惧埌,鍙兘鏄洰褰曞悕绉伴敊璇 */ - else return( s ); /* 鎿嶄綔鍑洪敊 */ - } - s = i; /* 浠庝笅涓绾х洰褰曞紑濮嬬户缁 */ - } - else return( s ); /* 璺緞缁撴潫,USB_INT_SUCCESS涓烘垚鍔熸墦寮鏂囦欢,ERR_OPEN_DIR涓烘垚鍔熸墦寮鐩綍(鏂囦欢澶),鍏跺畠涓烘搷浣滃嚭閿 */ - } + UINT8 i, s; + s = 0; + i = 1; + while ( 1 ) { + while ( PathName[i] != DEF_SEPAR_CHAR1 && PathName[i] != DEF_SEPAR_CHAR2 && PathName[i] != 0 ) ++ i; + if ( PathName[i] ) i ++; + else i = 0; + s = CH376FileOpen( &PathName[s] ); + if ( i && i != StopName ) { + if ( s != ERR_OPEN_DIR ) { + if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); + else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); + else return( s ); + } + s = i; + } + else return( s ); + } } -UINT8 CH376FileOpenPath( PUINT8 PathName ) /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢鎴栬呯洰褰(鏂囦欢澶),鏀寔澶氱骇鐩綍璺緞,鏀寔璺緞鍒嗛殧绗,璺緞闀垮害涓嶈秴杩255涓瓧绗 */ +UINT8 CH376FileOpenPath( PUINT8 PathName ) { - return( CH376FileOpenDir( PathName, 0xFF ) ); + return( CH376FileOpenDir( PathName, 0xFF ) ); } -UINT8 CH376FileCreatePath( PUINT8 PathName ) /* 鏂板缓澶氱骇鐩綍涓嬬殑鏂囦欢,鏀寔澶氱骇鐩綍璺緞,鏀寔璺緞鍒嗛殧绗,璺緞闀垮害涓嶈秴杩255涓瓧绗 */ +UINT8 CH376FileCreatePath( PUINT8 PathName ) { - UINT8 s; - UINT8 Name; - Name = CH376SeparatePath( PathName ); /* 浠庤矾寰勪腑鍒嗙鍑烘渶鍚庝竴绾ф枃浠跺悕,杩斿洖鏈鍚庝竴绾ф枃浠跺悕鐨勫亸绉 */ - if ( Name ) { /* 鏄绾х洰褰 */ - s = CH376FileOpenDir( PathName, Name ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏈鍚庝竴绾х洰褰,鍗虫墦寮鏂板缓鏂囦欢鐨勪笂绾х洰褰 */ - if ( s != ERR_OPEN_DIR ) { /* 鍥犱负鏄墦寮涓婄骇鐩綍,鎵浠,濡傛灉涓嶆槸鎴愬姛鎵撳紑浜嗙洰褰,閭d箞璇存槑鏈夐棶棰 */ - if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); /* 涓棿璺緞蹇呴』鏄洰褰曞悕,濡傛灉鏄枃浠跺悕鍒欏嚭閿 */ - else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); /* 涓棿璺緞鐨勬煇涓瓙鐩綍娌℃湁鎵惧埌,鍙兘鏄洰褰曞悕绉伴敊璇 */ - else return( s ); /* 鎿嶄綔鍑洪敊 */ - } - } - return( CH376FileCreate( &PathName[Name] ) ); /* 鍦ㄦ牴鐩綍鎴栬呭綋鍓嶇洰褰曚笅鏂板缓鏂囦欢 */ + UINT8 s; + UINT8 Name; + Name = CH376SeparatePath( PathName ); + if ( Name ) { + s = CH376FileOpenDir( PathName, Name ); + if ( s != ERR_OPEN_DIR ) { + if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); + else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); + else return( s ); + } + } + return( CH376FileCreate( &PathName[Name] ) ); } -#ifdef EN_DIR_CREATE -UINT8 CH376DirCreatePath( PUINT8 PathName ) /* 鏂板缓澶氱骇鐩綍涓嬬殑鐩綍(鏂囦欢澶)骞舵墦寮,鏀寔澶氱骇鐩綍璺緞,鏀寔璺緞鍒嗛殧绗,璺緞闀垮害涓嶈秴杩255涓瓧绗 */ +#ifdef EN_DIR_CREATE +UINT8 CH376DirCreatePath( PUINT8 PathName ) { - UINT8 s; - UINT8 Name; - UINT8 ClustBuf[4]; - Name = CH376SeparatePath( PathName ); /* 浠庤矾寰勪腑鍒嗙鍑烘渶鍚庝竴绾х洰褰曞悕,杩斿洖鏈鍚庝竴绾ф枃浠跺悕鐨勫亸绉 */ - if ( Name ) { /* 鏄绾х洰褰 */ - s = CH376FileOpenDir( PathName, Name ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏈鍚庝竴绾х洰褰,鍗虫墦寮鏂板缓鐩綍鐨勪笂绾х洰褰 */ - if ( s != ERR_OPEN_DIR ) { /* 鍥犱负鏄墦寮涓婄骇鐩綍,鎵浠,濡傛灉涓嶆槸鎴愬姛鎵撳紑浜嗙洰褰,閭d箞璇存槑鏈夐棶棰 */ - if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); /* 涓棿璺緞蹇呴』鏄洰褰曞悕,濡傛灉鏄枃浠跺悕鍒欏嚭閿 */ - else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); /* 涓棿璺緞鐨勬煇涓瓙鐩綍娌℃湁鎵惧埌,鍙兘鏄洰褰曞悕绉伴敊璇 */ - else return( s ); /* 鎿嶄綔鍑洪敊 */ - } - xWriteCH376Cmd( CMD14_READ_VAR32 ); - xWriteCH376Data( VAR_START_CLUSTER ); /* 涓婄骇鐩綍鐨勮捣濮嬬皣鍙 */ - for ( s = 0; s != 4; s ++ ) ClustBuf[ s ] = xReadCH376Data( ); - xEndCH376Cmd( ); - s = CH376DirCreate( &PathName[Name] ); /* 鍦ㄥ綋鍓嶇洰褰曚笅鏂板缓鐩綍 */ - if ( s != USB_INT_SUCCESS ) return( s ); - CH376WriteVar32( VAR_FILE_SIZE, sizeof(FAT_DIR_INFO) * 2 ); - s = CH376ByteLocate( sizeof(FAT_DIR_INFO) + STRUCT_OFFSET( FAT_DIR_INFO, DIR_FstClusHI ) ); /* 绉诲姩鏂囦欢鎸囬拡 */ - if ( s != USB_INT_SUCCESS ) return( s ); - s = CH376ByteWrite( &ClustBuf[2], 2, NULL ); /* 鍐欏叆涓婄骇鐩綍鐨勮捣濮嬬皣鍙风殑楂16浣 */ - if ( s != USB_INT_SUCCESS ) return( s ); - s = CH376ByteLocate( sizeof(FAT_DIR_INFO) + STRUCT_OFFSET( FAT_DIR_INFO, DIR_FstClusLO ) ); /* 绉诲姩鏂囦欢鎸囬拡 */ - if ( s != USB_INT_SUCCESS ) return( s ); - s = CH376ByteWrite( ClustBuf, 2, NULL ); /* 鍐欏叆涓婄骇鐩綍鐨勮捣濮嬬皣鍙风殑浣16浣 */ - if ( s != USB_INT_SUCCESS ) return( s ); - s = CH376ByteLocate( 0 ); /* 绉诲姩鏂囦欢鎸囬拡,鎭㈠鍒扮洰褰曞ご浣嶇疆 */ - if ( s != USB_INT_SUCCESS ) return( s ); - CH376WriteVar32( VAR_FILE_SIZE, 0 ); - return( s ); - } - else { /* 涓嶆槸澶氱骇鐩綍 */ - if ( PathName[0] == DEF_SEPAR_CHAR1 || PathName[0] == DEF_SEPAR_CHAR2 ) return( CH376DirCreate( PathName ) ); /* 鍦ㄦ牴鐩綍涓嬫柊寤虹洰褰 */ - else return( ERR_MISS_DIR ); /* 蹇呴』鎻愪緵瀹屾暣璺緞鎵嶈兘瀹炵幇鍦ㄥ綋鍓嶇洰褰曚笅鏂板缓鐩綍 */ - } + UINT8 s; + UINT8 Name; + UINT8 ClustBuf[4]; + Name = CH376SeparatePath( PathName ); + if ( Name ) { + s = CH376FileOpenDir( PathName, Name ); + if ( s != ERR_OPEN_DIR ) { + if ( s == USB_INT_SUCCESS ) return( ERR_FOUND_NAME ); + else if ( s == ERR_MISS_FILE ) return( ERR_MISS_DIR ); + else return( s ); + } + xWriteCH376Cmd( CMD14_READ_VAR32 ); + xWriteCH376Data( VAR_START_CLUSTER ); + for ( s = 0; s != 4; s ++ ) ClustBuf[ s ] = xReadCH376Data( ); + xEndCH376Cmd( ); + s = CH376DirCreate( &PathName[Name] ); + if ( s != USB_INT_SUCCESS ) return( s ); + CH376WriteVar32( VAR_FILE_SIZE, sizeof(FAT_DIR_INFO) * 2 ); + s = CH376ByteLocate( sizeof(FAT_DIR_INFO) + STRUCT_OFFSET( FAT_DIR_INFO, DIR_FstClusHI ) ); + if ( s != USB_INT_SUCCESS ) return( s ); + s = CH376ByteWrite( &ClustBuf[2], 2, NULL ); + if ( s != USB_INT_SUCCESS ) return( s ); + s = CH376ByteLocate( sizeof(FAT_DIR_INFO) + STRUCT_OFFSET( FAT_DIR_INFO, DIR_FstClusLO ) ); + if ( s != USB_INT_SUCCESS ) return( s ); + s = CH376ByteWrite( ClustBuf, 2, NULL ); + if ( s != USB_INT_SUCCESS ) return( s ); + s = CH376ByteLocate( 0 ); + if ( s != USB_INT_SUCCESS ) return( s ); + CH376WriteVar32( VAR_FILE_SIZE, 0 ); + return( s ); + } + else { + if ( PathName[0] == DEF_SEPAR_CHAR1 || PathName[0] == DEF_SEPAR_CHAR2 ) return( CH376DirCreate( PathName ) ); + else return( ERR_MISS_DIR ); + } } #endif -UINT8 CH376FileErase( PUINT8 PathName ) /* 鍒犻櫎鏂囦欢,濡傛灉宸茬粡鎵撳紑鍒欑洿鎺ュ垹闄,鍚﹀垯瀵逛簬鏂囦欢浼氬厛鎵撳紑鍐嶅垹闄,鏀寔澶氱骇鐩綍璺緞 */ +UINT8 CH376FileErase( PUINT8 PathName ) { - UINT8 s; - if ( PathName ) { /* 鏂囦欢灏氭湭鎵撳紑 */ - for ( s = 1; PathName[s] != DEF_SEPAR_CHAR1 && PathName[s] != DEF_SEPAR_CHAR2 && PathName[s] != 0; ++ s ); /* 鎼滅储涓嬩竴涓矾寰勫垎闅旂鎴栬呰矾寰勭粨鏉熺 */ - if ( PathName[s] ) { /* 鏈夎矾寰勫垎闅旂,鏄绾х洰褰曚笅鐨勬枃浠舵垨鑰呯洰褰 */ - s = CH376FileOpenPath( PathName ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢鎴栬呯洰褰 */ - if ( s != USB_INT_SUCCESS && s != ERR_OPEN_DIR ) return( s ); /* 鎿嶄綔鍑洪敊 */ - } - else CH376SetFileName( PathName ); /* 娌℃湁璺緞鍒嗛殧绗,鏄牴鐩綍鎴栬呭綋鍓嶇洰褰曚笅鐨勬枃浠舵垨鑰呯洰褰,璁剧疆灏嗚鎿嶄綔鐨勬枃浠剁殑鏂囦欢鍚 */ - } - return( CH376SendCmdWaitInt( CMD0H_FILE_ERASE ) ); + UINT8 s; + if ( PathName ) { + for ( s = 1; PathName[s] != DEF_SEPAR_CHAR1 && PathName[s] != DEF_SEPAR_CHAR2 && PathName[s] != 0; ++ s ); + if ( PathName[s] ) { + s = CH376FileOpenPath( PathName ); + if ( s != USB_INT_SUCCESS && s != ERR_OPEN_DIR ) return( s ); + } + else CH376SetFileName( PathName ); + } + return( CH376SendCmdWaitInt( CMD0H_FILE_ERASE ) ); } -UINT8 CH376FileClose( UINT8 UpdateSz ) /* 鍏抽棴褰撳墠宸茬粡鎵撳紑鐨勬枃浠舵垨鑰呯洰褰(鏂囦欢澶) */ +UINT8 CH376FileClose( UINT8 UpdateSz ) { return( CH376SendCmdDatWaitInt( CMD1H_FILE_CLOSE, UpdateSz ) ); } -UINT8 CH376DirInfoRead( void ) /* 璇诲彇褰撳墠鏂囦欢鐨勭洰褰曚俊鎭 */ +UINT8 CH376DirInfoRead( void ) { - return( CH376SendCmdDatWaitInt( CMD1H_DIR_INFO_READ, 0xFF ) ); + return( CH376SendCmdDatWaitInt( CMD1H_DIR_INFO_READ, 0xFF ) ); } -UINT8 CH376DirInfoSave( void ) /* 淇濆瓨鏂囦欢鐨勭洰褰曚俊鎭 */ +UINT8 CH376DirInfoSave( void ) { - return( CH376SendCmdWaitInt( CMD0H_DIR_INFO_SAVE ) ); + return( CH376SendCmdWaitInt( CMD0H_DIR_INFO_SAVE ) ); } -UINT8 CH376ByteLocate( UINT32 offset ) /* 浠ュ瓧鑺備负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ +UINT8 CH376ByteLocate( UINT32 offset ) { - xWriteCH376Cmd( CMD4H_BYTE_LOCATE ); - xWriteCH376Data( (UINT8)offset ); - xWriteCH376Data( (UINT8)((UINT16)offset>>8) ); - xWriteCH376Data( (UINT8)(offset>>16) ); - xWriteCH376Data( (UINT8)(offset>>24) ); - xEndCH376Cmd( ); - return( Wait376Interrupt( ) ); + xWriteCH376Cmd( CMD4H_BYTE_LOCATE ); + xWriteCH376Data( (UINT8)offset ); + xWriteCH376Data( (UINT8)((UINT16)offset>>8) ); + xWriteCH376Data( (UINT8)(offset>>16) ); + xWriteCH376Data( (UINT8)(offset>>24) ); + xEndCH376Cmd( ); + return( Wait376Interrupt( ) ); } -UINT8 CH376ByteRead( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) /* 浠ュ瓧鑺備负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡 */ +UINT8 CH376ByteRead( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) { - UINT8 s; - xWriteCH376Cmd( CMD2H_BYTE_READ ); - xWriteCH376Data( (UINT8)ReqCount ); - xWriteCH376Data( (UINT8)(ReqCount>>8) ); - xEndCH376Cmd( ); - if ( RealCount ) *RealCount = 0; - while ( 1 ) { - s = Wait376Interrupt( ); - if ( s == USB_INT_DISK_READ ) { - s = CH376ReadBlock( buf ); /* 浠庡綋鍓嶄富鏈虹鐐圭殑鎺ユ敹缂撳啿鍖鸿鍙栨暟鎹潡,杩斿洖闀垮害 */ - xWriteCH376Cmd( CMD0H_BYTE_RD_GO ); - xEndCH376Cmd( ); - buf += s; - if ( RealCount ) *RealCount += s; - } - else return( s ); /* 閿欒 */ - } + UINT8 s; + xWriteCH376Cmd( CMD2H_BYTE_READ ); + xWriteCH376Data( (UINT8)ReqCount ); + xWriteCH376Data( (UINT8)(ReqCount>>8) ); + xEndCH376Cmd( ); + if ( RealCount ) *RealCount = 0; + while ( 1 ) { + s = Wait376Interrupt( ); + if ( s == USB_INT_DISK_READ ) { + s = CH376ReadBlock( buf ); + xWriteCH376Cmd( CMD0H_BYTE_RD_GO ); + xEndCH376Cmd( ); + buf += s; + if ( RealCount ) *RealCount += s; + } + else return( s ); + } } -UINT8 CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) /* 浠ュ瓧鑺備负鍗曚綅鍚戝綋鍓嶄綅缃啓鍏ユ暟鎹潡 */ +UINT8 CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) { - UINT8 s; - xWriteCH376Cmd( CMD2H_BYTE_WRITE ); - xWriteCH376Data( (UINT8)ReqCount ); - xWriteCH376Data( (UINT8)(ReqCount>>8) ); - xEndCH376Cmd( ); - if ( RealCount ) *RealCount = 0; - while ( 1 ) { - s = Wait376Interrupt( ); - if ( s == USB_INT_DISK_WRITE ) { - s = CH376WriteReqBlock( buf ); /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡,杩斿洖闀垮害 */ + UINT8 s; + xWriteCH376Cmd( CMD2H_BYTE_WRITE ); + xWriteCH376Data( (UINT8)ReqCount ); + xWriteCH376Data( (UINT8)(ReqCount>>8) ); + xEndCH376Cmd( ); + if ( RealCount ) *RealCount = 0; + while ( 1 ) { + s = Wait376Interrupt( ); + if ( s == USB_INT_DISK_WRITE ) { + s = CH376WriteReqBlock( buf ); xWriteCH376Cmd( CMD0H_BYTE_WR_GO ); xEndCH376Cmd( ); buf += s; if ( RealCount ) *RealCount += s; } - else return( s ); /* 閿欒 */ + else return( s ); } } #ifdef EN_DISK_QUERY -UINT8 CH376DiskCapacity( PUINT32 DiskCap ) /* 鏌ヨ纾佺洏鐗╃悊瀹归噺,鎵囧尯鏁 */ +UINT8 CH376DiskCapacity( PUINT32 DiskCap ) { - UINT8 s; - s = CH376SendCmdWaitInt( CMD0H_DISK_CAPACITY ); - if ( s == USB_INT_SUCCESS ) { /* 鍙傝僀H376INC.H鏂囦欢涓瑿H376_CMD_DATA缁撴瀯鐨凞iskCapacity */ - xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); - xReadCH376Data( ); /* 闀垮害鎬绘槸sizeof(CH376_CMD_DATA.DiskCapacity) */ - *DiskCap = CH376Read32bitDat( ); /* CH376_CMD_DATA.DiskCapacity.mDiskSizeSec,浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ - } - else *DiskCap = 0; - return( s ); + UINT8 s; + s = CH376SendCmdWaitInt( CMD0H_DISK_CAPACITY ); + if ( s == USB_INT_SUCCESS ) { + xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); + xReadCH376Data( ); + *DiskCap = CH376Read32bitDat( ); + } + else *DiskCap = 0; + return( s ); } -UINT8 CH376DiskQuery( PUINT32 DiskFre ) /* 鏌ヨ纾佺洏鍓╀綑绌洪棿淇℃伅,鎵囧尯鏁 */ +UINT8 CH376DiskQuery( PUINT32 DiskFre ) { - UINT8 s; - UINT8 c0, c1, c2, c3; -#ifndef DEF_IC_V43_U - xWriteCH376Cmd( CMD01_GET_IC_VER ); - if ( xReadCH376Data( ) < 0x43 ) { - if ( CH376ReadVar8( VAR_DISK_STATUS ) >= DEF_DISK_READY ) CH376WriteVar8( VAR_DISK_STATUS, DEF_DISK_MOUNTED ); - } + UINT8 s; + UINT8 c0, c1, c2, c3; +#ifndef DEF_IC_V43_U + xWriteCH376Cmd( CMD01_GET_IC_VER ); + if ( xReadCH376Data( ) < 0x43 ) { + if ( CH376ReadVar8( VAR_DISK_STATUS ) >= DEF_DISK_READY ) CH376WriteVar8( VAR_DISK_STATUS, DEF_DISK_MOUNTED ); + } #endif - s = CH376SendCmdWaitInt( CMD0H_DISK_QUERY ); - if ( s == USB_INT_SUCCESS ) { /* 鍙傝僀H376INC.H鏂囦欢涓瑿H376_CMD_DATA缁撴瀯鐨凞iskQuery */ - xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); - xReadCH376Data( ); /* 闀垮害鎬绘槸sizeof(CH376_CMD_DATA.DiskQuery) */ - xReadCH376Data( ); /* CH376_CMD_DATA.DiskQuery.mTotalSector */ - xReadCH376Data( ); - xReadCH376Data( ); - xReadCH376Data( ); - c0 = xReadCH376Data( ); /* CH376_CMD_DATA.DiskQuery.mFreeSector */ - c1 = xReadCH376Data( ); - c2 = xReadCH376Data( ); - c3 = xReadCH376Data( ); - *DiskFre = c0 | (UINT16)c1 << 8 | (UINT32)c2 << 16 | (UINT32)c3 << 24; - xReadCH376Data( ); /* CH376_CMD_DATA.DiskQuery.mDiskFat */ - xEndCH376Cmd( ); - } - else *DiskFre = 0; - return( s ); + s = CH376SendCmdWaitInt( CMD0H_DISK_QUERY ); + if ( s == USB_INT_SUCCESS ) { + xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); + xReadCH376Data( ); + xReadCH376Data( ); + xReadCH376Data( ); + xReadCH376Data( ); + xReadCH376Data( ); + c0 = xReadCH376Data( ); + c1 = xReadCH376Data( ); + c2 = xReadCH376Data( ); + c3 = xReadCH376Data( ); + *DiskFre = c0 | (UINT16)c1 << 8 | (UINT32)c2 << 16 | (UINT32)c3 << 24; + xReadCH376Data( ); + xEndCH376Cmd( ); + } + else *DiskFre = 0; + return( s ); } #endif -UINT8 CH376SecLocate( UINT32 offset ) /* 浠ユ墖鍖轰负鍗曚綅绉诲姩褰撳墠鏂囦欢鎸囬拡 */ +UINT8 CH376SecLocate( UINT32 offset ) { - xWriteCH376Cmd( CMD4H_SEC_LOCATE ); - xWriteCH376Data( (UINT8)offset ); - xWriteCH376Data( (UINT8)((UINT16)offset>>8) ); - xWriteCH376Data( (UINT8)(offset>>16) ); - xWriteCH376Data( 0 ); /* 瓒呭嚭鏈澶ф枃浠跺昂瀵 */ - xEndCH376Cmd( ); - return( Wait376Interrupt( ) ); + xWriteCH376Cmd( CMD4H_SEC_LOCATE ); + xWriteCH376Data( (UINT8)offset ); + xWriteCH376Data( (UINT8)((UINT16)offset>>8) ); + xWriteCH376Data( (UINT8)(offset>>16) ); + xWriteCH376Data( 0 ); + xEndCH376Cmd( ); + return( Wait376Interrupt( ) ); } #ifdef EN_SECTOR_ACCESS -UINT8 CH376DiskReadSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ) /* 浠嶶鐩樿鍙栧涓墖鍖虹殑鏁版嵁鍧楀埌缂撳啿鍖,涓嶆敮鎸丼D鍗 */ -/* iLbaStart 鏄噯澶囪鍙栫殑绾挎ц捣濮嬫墖鍖哄彿, iSectorCount 鏄噯澶囪鍙栫殑鎵囧尯鏁 */ +UINT8 CH376DiskReadSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ) + { - UINT8 s, err; - UINT16 mBlockCount; - for ( err = 0; err != 3; ++ err ) { /* 鍑洪敊閲嶈瘯 */ - xWriteCH376Cmd( CMD5H_DISK_READ ); /* 浠嶶SB瀛樺偍鍣ㄨ鎵囧尯 */ - xWriteCH376Data( (UINT8)iLbaStart ); /* LBA鐨勬渶浣8浣 */ - xWriteCH376Data( (UINT8)( (UINT16)iLbaStart >> 8 ) ); - xWriteCH376Data( (UINT8)( iLbaStart >> 16 ) ); - xWriteCH376Data( (UINT8)( iLbaStart >> 24 ) ); /* LBA鐨勬渶楂8浣 */ - xWriteCH376Data( iSectorCount ); /* 鎵囧尯鏁 */ - xEndCH376Cmd( ); - for ( mBlockCount = iSectorCount * DEF_SECTOR_SIZE / CH376_DAT_BLOCK_LEN; mBlockCount != 0; -- mBlockCount ) { /* 鏁版嵁鍧楄鏁 */ - s = Wait376Interrupt( ); /* 绛夊緟涓柇骞惰幏鍙栫姸鎬 */ - if ( s == USB_INT_DISK_READ ) { /* USB瀛樺偍鍣ㄨ鏁版嵁鍧,璇锋眰鏁版嵁璇诲嚭 */ - s = CH376ReadBlock( buf ); /* 浠庡綋鍓嶄富鏈虹鐐圭殑鎺ユ敹缂撳啿鍖鸿鍙栨暟鎹潡,杩斿洖闀垮害 */ - xWriteCH376Cmd( CMD0H_DISK_RD_GO ); /* 缁х画鎵цUSB瀛樺偍鍣ㄧ殑璇绘搷浣 */ - xEndCH376Cmd( ); - buf += s; - } - else break; /* 杩斿洖閿欒鐘舵 */ - } - if ( mBlockCount == 0 ) { - s = Wait376Interrupt( ); /* 绛夊緟涓柇骞惰幏鍙栫姸鎬 */ - if ( s == USB_INT_SUCCESS ) return( USB_INT_SUCCESS ); /* 鎿嶄綔鎴愬姛 */ - } - if ( s == USB_INT_DISCONNECT ) return( s ); /* U鐩樿绉婚櫎 */ - CH376DiskReqSense( ); /* 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ - } - return( s ); /* 鎿嶄綔澶辫触 */ + UINT8 s, err; + UINT16 mBlockCount; + for ( err = 0; err != 3; ++ err ) { + xWriteCH376Cmd( CMD5H_DISK_READ ); + xWriteCH376Data( (UINT8)iLbaStart ); + xWriteCH376Data( (UINT8)( (UINT16)iLbaStart >> 8 ) ); + xWriteCH376Data( (UINT8)( iLbaStart >> 16 ) ); + xWriteCH376Data( (UINT8)( iLbaStart >> 24 ) ); + xWriteCH376Data( iSectorCount ); + xEndCH376Cmd( ); + for ( mBlockCount = iSectorCount * DEF_SECTOR_SIZE / CH376_DAT_BLOCK_LEN; mBlockCount != 0; -- mBlockCount ) { + s = Wait376Interrupt( ); + if ( s == USB_INT_DISK_READ ) { + s = CH376ReadBlock( buf ); + xWriteCH376Cmd( CMD0H_DISK_RD_GO ); + xEndCH376Cmd( ); + buf += s; + } + else break; + } + if ( mBlockCount == 0 ) { + s = Wait376Interrupt( ); + if ( s == USB_INT_SUCCESS ) return( USB_INT_SUCCESS ); + } + if ( s == USB_INT_DISCONNECT ) return( s ); + CH376DiskReqSense( ); + } + return( s ); } -UINT8 CH376DiskWriteSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ) /* 灏嗙紦鍐插尯涓殑澶氫釜鎵囧尯鐨勬暟鎹潡鍐欏叆U鐩,涓嶆敮鎸丼D鍗 */ -/* iLbaStart 鏄啓鍏ョ殑绾胯捣濮嬫ф墖鍖哄彿, iSectorCount 鏄啓鍏ョ殑鎵囧尯鏁 */ +UINT8 CH376DiskWriteSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ) { UINT8 s, err; UINT16 mBlockCount; - for ( err = 0; err != 3; ++ err ) { /* 鍑洪敊閲嶈瘯 */ - xWriteCH376Cmd( CMD5H_DISK_WRITE ); /* 鍚慤SB瀛樺偍鍣ㄥ啓鎵囧尯 */ - xWriteCH376Data( (UINT8)iLbaStart ); /* LBA鐨勬渶浣8浣 */ + for ( err = 0; err != 3; ++ err ) { + xWriteCH376Cmd( CMD5H_DISK_WRITE ); + xWriteCH376Data( (UINT8)iLbaStart ); xWriteCH376Data( (UINT8)( (UINT16)iLbaStart >> 8 ) ); xWriteCH376Data( (UINT8)( iLbaStart >> 16 ) ); - xWriteCH376Data( (UINT8)( iLbaStart >> 24 ) ); /* LBA鐨勬渶楂8浣 */ - xWriteCH376Data( iSectorCount ); /* 鎵囧尯鏁 */ + xWriteCH376Data( (UINT8)( iLbaStart >> 24 ) ); + xWriteCH376Data( iSectorCount ); xEndCH376Cmd( ); - for ( mBlockCount = iSectorCount * DEF_SECTOR_SIZE / CH376_DAT_BLOCK_LEN; mBlockCount != 0; -- mBlockCount ) { /* 鏁版嵁鍧楄鏁 */ - s = Wait376Interrupt( ); /* 绛夊緟涓柇骞惰幏鍙栫姸鎬 */ - if ( s == USB_INT_DISK_WRITE ) { /* USB瀛樺偍鍣ㄥ啓鏁版嵁鍧,璇锋眰鏁版嵁鍐欏叆 */ - CH376WriteHostBlock( buf, CH376_DAT_BLOCK_LEN ); /* 鍚慤SB涓绘満绔偣鐨勫彂閫佺紦鍐插尯鍐欏叆鏁版嵁鍧 */ - xWriteCH376Cmd( CMD0H_DISK_WR_GO ); /* 缁х画鎵цUSB瀛樺偍鍣ㄧ殑鍐欐搷浣 */ + for ( mBlockCount = iSectorCount * DEF_SECTOR_SIZE / CH376_DAT_BLOCK_LEN; mBlockCount != 0; -- mBlockCount ) { + s = Wait376Interrupt( ); + if ( s == USB_INT_DISK_WRITE ) { + CH376WriteHostBlock( buf, CH376_DAT_BLOCK_LEN ); + xWriteCH376Cmd( CMD0H_DISK_WR_GO ); xEndCH376Cmd( ); buf += CH376_DAT_BLOCK_LEN; } - else break; /* 杩斿洖閿欒鐘舵 */ + else break; } if ( mBlockCount == 0 ) { - s = Wait376Interrupt( ); /* 绛夊緟涓柇骞惰幏鍙栫姸鎬 */ - if ( s == USB_INT_SUCCESS ) return( USB_INT_SUCCESS ); /* 鎿嶄綔鎴愬姛 */ + s = Wait376Interrupt( ); + if ( s == USB_INT_SUCCESS ) return( USB_INT_SUCCESS ); } - if ( s == USB_INT_DISCONNECT ) return( s ); /* U鐩樿绉婚櫎 */ - CH376DiskReqSense( ); /* 妫鏌SB瀛樺偍鍣ㄩ敊璇 */ + if ( s == USB_INT_DISCONNECT ) return( s ); + CH376DiskReqSense( ); } - return( s ); /* 鎿嶄綔澶辫触 */ + return( s ); } -UINT8 CH376SecRead( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) /* 浠ユ墖鍖轰负鍗曚綅浠庡綋鍓嶄綅缃鍙栨暟鎹潡,涓嶆敮鎸丼D鍗 */ +UINT8 CH376SecRead( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) { UINT8 s; UINT8 cnt; @@ -705,14 +694,14 @@ UINT8 CH376SecRead( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) /* 浠ユ墖鍖 #endif if ( s != USB_INT_SUCCESS ) return( s ); xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); - xReadCH376Data( ); /* 闀垮害鎬绘槸sizeof(CH376_CMD_DATA.SectorRead) */ - cnt = xReadCH376Data( ); /* CH376_CMD_DATA.SectorRead.mSectorCount */ + xReadCH376Data( ); + cnt = xReadCH376Data( ); xReadCH376Data( ); xReadCH376Data( ); xReadCH376Data( ); - StaSec = CH376Read32bitDat( ); /* CH376_CMD_DATA.SectorRead.mStartSector,浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ + StaSec = CH376Read32bitDat( ); if ( cnt == 0 ) break; - s = CH376DiskReadSec( buf, StaSec, cnt ); /* 浠嶶鐩樿鍙栧涓墖鍖虹殑鏁版嵁鍧楀埌缂撳啿鍖 */ + s = CH376DiskReadSec( buf, StaSec, cnt ); if ( s != USB_INT_SUCCESS ) return( s ); buf += cnt * DEF_SECTOR_SIZE; if ( RealCount ) *RealCount += cnt; @@ -721,7 +710,7 @@ UINT8 CH376SecRead( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) /* 浠ユ墖鍖 return( s ); } -UINT8 CH376SecWrite( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) /* 浠ユ墖鍖轰负鍗曚綅鍦ㄥ綋鍓嶄綅缃啓鍏ユ暟鎹潡,涓嶆敮鎸丼D鍗 */ +UINT8 CH376SecWrite( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) { UINT8 s; UINT8 cnt; @@ -734,14 +723,14 @@ UINT8 CH376SecWrite( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) /* 浠ユ墖 s = Wait376Interrupt( ); if ( s != USB_INT_SUCCESS ) return( s ); xWriteCH376Cmd( CMD01_RD_USB_DATA0 ); - xReadCH376Data( ); /* 闀垮害鎬绘槸sizeof(CH376_CMD_DATA.SectorWrite) */ - cnt = xReadCH376Data( ); /* CH376_CMD_DATA.SectorWrite.mSectorCount */ + xReadCH376Data( ); + cnt = xReadCH376Data( ); xReadCH376Data( ); xReadCH376Data( ); xReadCH376Data( ); - StaSec = CH376Read32bitDat( ); /* CH376_CMD_DATA.SectorWrite.mStartSector,浠嶤H376鑺墖璇诲彇32浣嶇殑鏁版嵁骞剁粨鏉熷懡浠 */ + StaSec = CH376Read32bitDat( ); if ( cnt == 0 ) break; - s = CH376DiskWriteSec( buf, StaSec, cnt ); /* 灏嗙紦鍐插尯涓殑澶氫釜鎵囧尯鐨勬暟鎹潡鍐欏叆U鐩 */ + s = CH376DiskWriteSec( buf, StaSec, cnt ); if ( s != USB_INT_SUCCESS ) return( s ); buf += cnt * DEF_SECTOR_SIZE; if ( RealCount ) *RealCount += cnt; @@ -754,7 +743,7 @@ UINT8 CH376SecWrite( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ) /* 浠ユ墖 #ifdef EN_LONG_NAME -UINT8 CH376LongNameWrite( PUINT8 buf, UINT16 ReqCount ) /* 闀挎枃浠跺悕涓撶敤鐨勫瓧鑺傚啓瀛愮▼搴 */ +UINT8 CH376LongNameWrite( PUINT8 buf, UINT16 ReqCount ) { UINT8 s; #ifndef DEF_IC_V43_U @@ -769,26 +758,25 @@ UINT8 CH376LongNameWrite( PUINT8 buf, UINT16 ReqCount ) /* 闀挎枃浠跺悕涓撶敤 while ( 1 ) { s = Wait376Interrupt( ); if ( s == USB_INT_DISK_WRITE ) { - if ( buf ) buf += CH376WriteReqBlock( buf ); /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡,杩斿洖闀垮害 */ + if ( buf ) buf += CH376WriteReqBlock( buf ); else { - xWriteCH376Cmd( CMD01_WR_REQ_DATA ); /* 鍚戝唴閮ㄦ寚瀹氱紦鍐插尯鍐欏叆璇锋眰鐨勬暟鎹潡 */ - s = xReadCH376Data( ); /* 闀垮害 */ - while ( s -- ) xWriteCH376Data( 0 ); /* 濉厖0 */ + xWriteCH376Cmd( CMD01_WR_REQ_DATA ); + s = xReadCH376Data( ); + while ( s -- ) xWriteCH376Data( 0 ); } xWriteCH376Cmd( CMD0H_BYTE_WR_GO ); xEndCH376Cmd( ); } -/* else if ( s == USB_INT_SUCCESS ) return( s );*/ /* 缁撴潫 */ else { #ifndef DEF_IC_V43_U if ( c == DEF_DISK_OPEN_ROOT ) CH376WriteVar8( VAR_DISK_STATUS, c ); #endif - return( s ); /* 閿欒 */ + return( s ); } } } -UINT8 CH376CheckNameSum( PUINT8 DirName ) /* 璁$畻闀挎枃浠跺悕鐨勭煭鏂囦欢鍚嶆楠屽拰,杈撳叆涓烘棤灏忔暟鐐瑰垎闅旂鐨勫浐瀹11瀛楄妭鏍煎紡 */ +UINT8 CH376CheckNameSum( PUINT8 DirName ) { UINT8 NameLen; UINT8 CheckSum; @@ -797,181 +785,175 @@ UINT8 CH376CheckNameSum( PUINT8 DirName ) /* 璁$畻闀挎枃浠跺悕鐨勭煭鏂囦欢鍚 return( CheckSum ); } -UINT8 CH376LocateInUpDir( PUINT8 PathName ) /* 鍦ㄤ笂绾х洰褰(鏂囦欢澶)涓Щ鍔ㄦ枃浠舵寚閽堝埌褰撳墠鏂囦欢鐩綍淇℃伅鎵鍦ㄧ殑鎵囧尯 */ -/* 鍙﹀,椤轰究灏嗗綋鍓嶆枃浠剁洰褰曚俊鎭墍鍦ㄧ殑鎵囧尯鐨勫墠涓涓墖鍖虹殑LBA鍦板潃鍐欏叆CH376鍐呴儴VAR_FAT_DIR_LBA鍙橀噺(涓轰簡鏂逛究鏀堕泦闀挎枃浠跺悕鏃跺悜鍓嶆悳绱,鍚﹀垯瑕佸绉诲姩涓娆) */ -/* 浣跨敤浜嗗叏灞缂撳啿鍖篏lobalBuf鐨勫墠12涓瓧鑺 */ +UINT8 CH376LocateInUpDir( PUINT8 PathName ) { UINT8 s; xWriteCH376Cmd( CMD14_READ_VAR32 ); - xWriteCH376Data( VAR_FAT_DIR_LBA ); /* 褰撳墠鏂囦欢鐩綍淇℃伅鎵鍦ㄧ殑鎵囧尯LBA鍦板潃 */ - for ( s = 4; s != 8; s ++ ) GlobalBuf[ s ] = xReadCH376Data( ); /* 涓存椂淇濆瓨浜庡叏灞缂撳啿鍖轰腑,鑺傜害RAM */ + xWriteCH376Data( VAR_FAT_DIR_LBA ); + for ( s = 4; s != 8; s ++ ) GlobalBuf[ s ] = xReadCH376Data( ); xEndCH376Cmd( ); - s = CH376SeparatePath( PathName ); /* 浠庤矾寰勪腑鍒嗙鍑烘渶鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰曞悕,杩斿洖鏈鍚庝竴绾ф枃浠跺悕鎴栬呯洰褰曞悕鐨勫亸绉 */ - if ( s ) s = CH376FileOpenDir( PathName, s ); /* 鏄绾х洰褰,鎵撳紑澶氱骇鐩綍涓嬬殑鏈鍚庝竴绾х洰褰,鍗虫墦寮鏂囦欢鐨勪笂绾х洰褰 */ - else s = CH376FileOpen( "/" ); /* 鏍圭洰褰曚笅鐨勬枃浠,鍒欐墦寮鏍圭洰褰 */ + s = CH376SeparatePath( PathName ); + if ( s ) s = CH376FileOpenDir( PathName, s ); + else s = CH376FileOpen( "/" ); if ( s != ERR_OPEN_DIR ) return( s ); - *(PUINT32)(&GlobalBuf[0]) = 0; /* 鐩綍鎵囧尯鍋忕Щ鎵囧尯鏁,淇濆瓨鍦ㄥ叏灞缂撳啿鍖轰腑,鑺傜害RAM */ - while ( 1 ) { /* 涓嶆柇绉诲姩鏂囦欢鎸囬拡,鐩村埌涓庡綋鍓嶆枃浠剁洰褰曚俊鎭墍鍦ㄧ殑鎵囧尯LBA鍦板潃鍖归厤 */ - s = CH376SecLocate( *(PUINT32)(&GlobalBuf[0]) ); /* 浠ユ墖鍖轰负鍗曚綅鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡 */ + *(PUINT32)(&GlobalBuf[0]) = 0; + while ( 1 ) { + s = CH376SecLocate( *(PUINT32)(&GlobalBuf[0]) ); if ( s != USB_INT_SUCCESS ) return( s ); - CH376ReadBlock( &GlobalBuf[8] ); /* 浠庡唴瀛樼紦鍐插尯璇诲彇CH376_CMD_DATA.SectorLocate.mSectorLba鏁版嵁鍧,杩斿洖闀垮害鎬绘槸sizeof(CH376_CMD_DATA.SectorLocate) */ - if ( *(PUINT32)(&GlobalBuf[8]) == *(PUINT32)(&GlobalBuf[4]) ) return( USB_INT_SUCCESS ); /* 宸插埌褰撳墠鏂囦欢鐩綍淇℃伅鎵囧尯 */ + CH376ReadBlock( &GlobalBuf[8] ); + if ( *(PUINT32)(&GlobalBuf[8]) == *(PUINT32)(&GlobalBuf[4]) ) return( USB_INT_SUCCESS ); xWriteCH376Cmd( CMD50_WRITE_VAR32 ); - xWriteCH376Data( VAR_FAT_DIR_LBA ); /* 寰楀埌鍓嶄竴涓墖鍖,璁剧疆涓烘柊鐨勬枃浠剁洰褰曚俊鎭墖鍖篖BA鍦板潃 */ + xWriteCH376Data( VAR_FAT_DIR_LBA ); for ( s = 8; s != 12; s ++ ) xWriteCH376Data( GlobalBuf[ s ] ); xEndCH376Cmd( ); ++ *(PUINT32)(&GlobalBuf[0]); } } -UINT8 CH376GetLongName( PUINT8 PathName, PUINT8 LongName ) /* 鐢辩煭鏂囦欢鍚嶆垨鑰呯洰褰(鏂囦欢澶)鍚嶈幏寰楃浉搴旂殑闀挎枃浠跺悕 */ -/* 闇瑕佽緭鍏ョ煭鏂囦欢鍚嶇殑瀹屾暣璺緞PathName,闇瑕佹彁渚涚紦鍐插尯鎺ユ敹闀挎枃浠跺悕LongName(浠NICODE灏忕缂栫爜,浠ュ弻0缁撴潫) */ -/* 浣跨敤浜嗗叏灞缂撳啿鍖篏lobalBuf鐨勫墠34涓瓧鑺,sizeof(GlobalBuf)>=sizeof(FAT_DIR_INFO)+2 */ +UINT8 CH376GetLongName( PUINT8 PathName, PUINT8 LongName ) { UINT8 s; - UINT16 NameCount; /* 闀挎枃浠跺悕瀛楄妭璁℃暟 */ - s = CH376FileOpenPath( PathName ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢鎴栬呯洰褰 */ + UINT16 NameCount; + s = CH376FileOpenPath( PathName ); if ( s != USB_INT_SUCCESS && s != ERR_OPEN_DIR ) return( s ); - s = CH376DirInfoRead( ); /* 璇诲彇褰撳墠鏂囦欢鐨勭洰褰曚俊鎭疐AT_DIR_INFO,灏嗙浉鍏虫暟鎹皟鍒板唴瀛樹腑 */ + s = CH376DirInfoRead( ); if ( s != USB_INT_SUCCESS ) return( s ); - CH376ReadBlock( GlobalBuf ); /* 浠庡唴瀛樼紦鍐插尯璇诲彇FAT_DIR_INFO鏁版嵁鍧,杩斿洖闀垮害鎬绘槸sizeof(FAT_DIR_INFO) */ - CH376EndDirInfo( ); /* 鑾峰彇瀹孎AT_DIR_INFO缁撴瀯 */ - GlobalBuf[32] = CH376CheckNameSum( GlobalBuf ); /* 璁$畻闀挎枃浠跺悕鐨勭煭鏂囦欢鍚嶆楠屽拰,淇濆瓨鍦ㄥ叏灞缂撳啿鍖轰腑,鑺傜害RAM */ - GlobalBuf[33] = CH376ReadVar8( VAR_FILE_DIR_INDEX ); /* 褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄦ墖鍖哄唴鐨勭储寮曞彿,淇濆瓨鍦ㄥ叏灞缂撳啿鍖轰腑,鑺傜害RAM */ + CH376ReadBlock( GlobalBuf ); + CH376EndDirInfo( ); + GlobalBuf[32] = CH376CheckNameSum( GlobalBuf ); + GlobalBuf[33] = CH376ReadVar8( VAR_FILE_DIR_INDEX ); NameCount = 0; while ( 1 ) { - if ( GlobalBuf[33] == 0 ) { /* 褰撳墠鐨勬枃浠剁洰褰曚俊鎭墖鍖哄鐞嗙粨鏉,杞埌鍓嶄竴涓墖鍖 */ - s = CH376LocateInUpDir( PathName ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭墍鍦ㄧ殑鎵囧尯 */ + if ( GlobalBuf[33] == 0 ) { + s = CH376LocateInUpDir( PathName ); if ( s != USB_INT_SUCCESS ) break; - if ( CH376ReadVar32( VAR_CURRENT_OFFSET ) == 0 ) { /* 褰撳墠宸茬粡澶勪簬鐩綍鎵囧尯鐨勫紑濮,鏃犳硶鑾峰彇闀挎枃浠跺悕 */ + if ( CH376ReadVar32( VAR_CURRENT_OFFSET ) == 0 ) { s = ERR_LONG_NAME_ERR; break; } - GlobalBuf[33] = DEF_SECTOR_SIZE / sizeof( FAT_DIR_INFO ); /* 鎸囧悜鍓嶄竴涓墖鍖虹殑鏈鍚庝竴涓枃浠剁洰褰曚俊鎭 */ + GlobalBuf[33] = DEF_SECTOR_SIZE / sizeof( FAT_DIR_INFO ); } - GlobalBuf[33] --; /* 浠庡悗鍚戝墠鎼滅储鏂囦欢鐩綍淇℃伅 */ - s = CH376SendCmdDatWaitInt( CMD1H_DIR_INFO_READ, GlobalBuf[33] ); /* 璇诲彇鎸囧畾鐨勭洰褰曚俊鎭疐AT_DIR_INFO,灏嗙浉鍏虫暟鎹皟鍒板唴瀛樹腑 */ + GlobalBuf[33] --; + s = CH376SendCmdDatWaitInt( CMD1H_DIR_INFO_READ, GlobalBuf[33] ); if ( s != USB_INT_SUCCESS ) break; - CH376ReadBlock( GlobalBuf ); /* 浠庡唴瀛樼紦鍐插尯璇诲彇FAT_DIR_INFO鏁版嵁鍧,杩斿洖闀垮害鎬绘槸sizeof(FAT_DIR_INFO) */ - CH376EndDirInfo( ); /* 鑾峰彇瀹孎AT_DIR_INFO缁撴瀯 */ - if ( ( GlobalBuf[11] & ATTR_LONG_NAME_MASK ) != ATTR_LONG_NAME || GlobalBuf[13] != GlobalBuf[32] ) { /* 绫诲瀷閿欒鎴栬呮牎楠屽拰閿欒 */ + CH376ReadBlock( GlobalBuf ); + CH376EndDirInfo( ); + if ( ( GlobalBuf[11] & ATTR_LONG_NAME_MASK ) != ATTR_LONG_NAME || GlobalBuf[13] != GlobalBuf[32] ) { s = ERR_LONG_NAME_ERR; - break; /* 娌℃湁鐩存帴杩斿洖鏄洜涓哄鏋滄槸鎵撳紑浜嗘牴鐩綍閭d箞蹇呴』瑕佸叧闂悗鎵嶈兘杩斿洖 */ + break; } - for ( s = 1; s < sizeof( FAT_DIR_INFO ); s += 2 ) { /* 鏀堕泦闀挎枃浠跺悕,闀挎枃浠跺悕鐨勫瓧绗﹀湪纾佺洏涓奤NICODE鐢ㄥ皬绔柟寮忓瓨鏀 */ - if ( s == 1 + 5 * 2 ) s = 14; /* 浠庨暱鏂囦欢鍚嶇殑绗竴缁1-5涓瓧绗﹁烦鍒扮浜岀粍6-11涓瓧绗 */ - else if ( s == 14 + 6 * 2 ) s = 28; /* 浠庨暱鏂囦欢鍚嶇殑绗簩缁6-11涓瓧绗﹁烦鍒扮涓夌粍12-13涓瓧绗 */ + for ( s = 1; s < sizeof( FAT_DIR_INFO ); s += 2 ) { + if ( s == 1 + 5 * 2 ) s = 14; + else if ( s == 14 + 6 * 2 ) s = 28; LongName[ NameCount++ ] = GlobalBuf[ s ]; LongName[ NameCount++ ] = GlobalBuf[ s + 1 ]; - if ( GlobalBuf[ s ] == 0 && GlobalBuf[ s + 1 ] == 0 ) break; /* 闀挎枃浠跺悕缁撴潫 */ - if ( NameCount >= LONG_NAME_BUF_LEN ) { /* 闀挎枃浠跺悕缂撳啿鍖烘孩鍑 */ + if ( GlobalBuf[ s ] == 0 && GlobalBuf[ s + 1 ] == 0 ) break; + if ( NameCount >= LONG_NAME_BUF_LEN ) { s = ERR_LONG_BUF_OVER; goto CH376GetLongNameE; } } - if ( GlobalBuf[0] & 0x40 ) { /* 闀挎枃浠跺悕鐩綍淇℃伅鍧楃粨鏉 */ - if ( s >= sizeof( FAT_DIR_INFO ) ) *(PUINT16)( &LongName[ NameCount ] ) = 0x0000; /* 灏氭湭鏀堕泦鍒伴暱鏂囦欢鍚嶇殑缁撴潫绗,鍒欏己鍒剁粨鏉 */ - s = USB_INT_SUCCESS; /* 鎴愬姛瀹屾垚闀挎枃浠跺悕鏀堕泦瀹屾垚 */ + if ( GlobalBuf[0] & 0x40 ) { + if ( s >= sizeof( FAT_DIR_INFO ) ) *(PUINT16)( &LongName[ NameCount ] ) = 0x0000; + s = USB_INT_SUCCESS; break; } } CH376GetLongNameE: - CH376FileClose( FALSE ); /* 瀵逛簬鏍圭洰褰曞垯蹇呴』瑕佸叧闂 */ + CH376FileClose( FALSE ); return( s ); } -UINT8 CH376CreateLongName( PUINT8 PathName, PUINT8 LongName ) /* 鏂板缓鍏锋湁闀挎枃浠跺悕鐨勬枃浠,鍏抽棴鏂囦欢鍚庤繑鍥,LongName杈撳叆璺緞蹇呴』鍦≧AM涓 */ -/* 闇瑕佽緭鍏ョ煭鏂囦欢鍚嶇殑瀹屾暣璺緞PathName(璇蜂簨鍏堝弬鑰僃AT瑙勮寖鐢遍暱鏂囦欢鍚嶈嚜琛屼骇鐢),闇瑕佽緭鍏ヤ互UNICODE灏忕缂栫爜鐨勪互鍙0缁撴潫鐨勯暱鏂囦欢鍚峀ongName */ -/* 浣跨敤浜嗗叏灞缂撳啿鍖篏lobalBuf鐨勫墠64涓瓧鑺,sizeof(GlobalBuf)>=sizeof(FAT_DIR_INFO)*2 */ +UINT8 CH376CreateLongName( PUINT8 PathName, PUINT8 LongName ) { UINT8 s, i; - UINT8 DirBlockCnt; /* 闀挎枃浠跺悕鍗犵敤鏂囦欢鐩綍缁撴瀯鐨勪釜鏁 */ - UINT16 count; /* 涓存椂鍙橀噺,鐢ㄤ簬璁℃暟,鐢ㄤ簬瀛楄妭璇绘枃浠舵柟寮忎笅瀹為檯璇诲彇鐨勫瓧鑺傛暟 */ - UINT16 NameCount; /* 闀挎枃浠跺悕瀛楄妭璁℃暟 */ - UINT32 NewFileLoc; /* 褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄤ笂绾х洰褰曚腑鐨勮捣濮嬩綅缃,鍋忕Щ鍦板潃 */ - for ( count = 0; count < LONG_NAME_BUF_LEN; count += 2 ) if ( *(PUINT16)(&LongName[count]) == 0 ) break; /* 鍒扮粨鏉熶綅缃 */ - if ( count == 0 || count >= LONG_NAME_BUF_LEN || count > LONE_NAME_MAX_CHAR ) return( ERR_LONG_NAME_ERR ); /* 闀挎枃浠跺悕鏃犳晥 */ - DirBlockCnt = count / LONG_NAME_PER_DIR; /* 闀挎枃浠跺悕鍗犵敤鏂囦欢鐩綍缁撴瀯鐨勪釜鏁 */ + UINT8 DirBlockCnt; + UINT16 count; + UINT16 NameCount; + UINT32 NewFileLoc; + for ( count = 0; count < LONG_NAME_BUF_LEN; count += 2 ) if ( *(PUINT16)(&LongName[count]) == 0 ) break; + if ( count == 0 || count >= LONG_NAME_BUF_LEN || count > LONE_NAME_MAX_CHAR ) return( ERR_LONG_NAME_ERR ); + DirBlockCnt = count / LONG_NAME_PER_DIR; i = count - DirBlockCnt * LONG_NAME_PER_DIR; - if ( i ) { /* 鏈夐浂澶 */ - if ( ++ DirBlockCnt * LONG_NAME_PER_DIR > LONG_NAME_BUF_LEN ) return( ERR_LONG_BUF_OVER ); /* 缂撳啿鍖烘孩鍑 */ - count += 2; /* 鍔犱笂0缁撴潫绗﹀悗鐨勯暱搴 */ + if ( i ) { + if ( ++ DirBlockCnt * LONG_NAME_PER_DIR > LONG_NAME_BUF_LEN ) return( ERR_LONG_BUF_OVER ); + count += 2; i += 2; - if ( i < LONG_NAME_PER_DIR ) { /* 鏈鏈殑鏂囦欢鐩綍缁撴瀯涓嶆弧 */ - while ( i++ < LONG_NAME_PER_DIR ) LongName[count++] = 0xFF; /* 鎶婂墿浣欐暟鎹~涓0xFF */ + if ( i < LONG_NAME_PER_DIR ) { + while ( i++ < LONG_NAME_PER_DIR ) LongName[count++] = 0xFF; } } - s = CH376FileOpenPath( PathName ); /* 鎵撳紑澶氱骇鐩綍涓嬬殑鏂囦欢 */ - if ( s == USB_INT_SUCCESS ) { /* 鐭枃浠跺悕瀛樺湪鍒欒繑鍥為敊璇 */ + s = CH376FileOpenPath( PathName ); + if ( s == USB_INT_SUCCESS ) { s = ERR_NAME_EXIST; goto CH376CreateLongNameE; } if ( s != ERR_MISS_FILE ) return( s ); - s = CH376FileCreatePath( PathName ); /* 鏂板缓澶氱骇鐩綍涓嬬殑鏂囦欢 */ + s = CH376FileCreatePath( PathName ); if ( s != USB_INT_SUCCESS ) return( s ); - i = CH376ReadVar8( VAR_FILE_DIR_INDEX ); /* 涓存椂鐢ㄤ簬淇濆瓨褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄦ墖鍖哄唴鐨勭储寮曞彿 */ - s = CH376LocateInUpDir( PathName ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭墍鍦ㄧ殑鎵囧尯 */ - if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; /* 娌℃湁鐩存帴杩斿洖鏄洜涓哄鏋滄槸鎵撳紑浜嗘牴鐩綍閭d箞蹇呴』瑕佸叧闂悗鎵嶈兘杩斿洖 */ - NewFileLoc = CH376ReadVar32( VAR_CURRENT_OFFSET ) + i * sizeof(FAT_DIR_INFO); /* 璁$畻褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄤ笂绾х洰褰曚腑鐨勮捣濮嬩綅缃,鍋忕Щ鍦板潃 */ - s = CH376ByteLocate( NewFileLoc ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭殑浣嶇疆 */ + i = CH376ReadVar8( VAR_FILE_DIR_INDEX ); + s = CH376LocateInUpDir( PathName ); + if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; + NewFileLoc = CH376ReadVar32( VAR_CURRENT_OFFSET ) + i * sizeof(FAT_DIR_INFO); + s = CH376ByteLocate( NewFileLoc ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; - s = CH376ByteRead( &GlobalBuf[ sizeof(FAT_DIR_INFO) ], sizeof(FAT_DIR_INFO), NULL ); /* 浠ュ瓧鑺備负鍗曚綅璇诲彇鏁版嵁,鑾峰緱褰撳墠鏂囦欢鐨勭洰褰曚俊鎭疐AT_DIR_INFO */ + s = CH376ByteRead( &GlobalBuf[ sizeof(FAT_DIR_INFO) ], sizeof(FAT_DIR_INFO), NULL ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; - for ( i = DirBlockCnt; i != 0; -- i ) { /* 鎼滅储绌洪棽鐨勬枃浠剁洰褰曠粨鏋勭敤浜庡瓨鏀鹃暱鏂囦欢鍚 */ - s = CH376ByteRead( GlobalBuf, sizeof(FAT_DIR_INFO), &count ); /* 浠ュ瓧鑺備负鍗曚綅璇诲彇鏁版嵁,鑾峰緱涓嬩竴涓枃浠剁洰褰曚俊鎭疐AT_DIR_INFO */ + for ( i = DirBlockCnt; i != 0; -- i ) { + s = CH376ByteRead( GlobalBuf, sizeof(FAT_DIR_INFO), &count ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; - if ( count == 0 ) break; /* 鏃犳硶璇诲嚭鏁版嵁,涓婄骇鐩綍缁撴潫浜 */ - if ( GlobalBuf[0] && GlobalBuf[0] != 0xE5 ) { /* 鍚庨潰鏈夋鍦ㄤ娇鐢ㄧ殑鏂囦欢鐩綍缁撴瀯,鐢变簬闀挎枃浠跺悕蹇呴』杩炴帴瀛樻斁,鎵浠ョ┖闂翠笉澶,蹇呴』鏀惧純褰撳墠浣嶇疆骞跺悜鍚庤浆绉 */ - s = CH376ByteLocate( NewFileLoc ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭殑浣嶇疆 */ + if ( count == 0 ) break; + if ( GlobalBuf[0] && GlobalBuf[0] != 0xE5 ) { + s = CH376ByteLocate( NewFileLoc ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; - GlobalBuf[ 0 ] = 0xE5; /* 鏂囦欢鍒犻櫎鏍囧織 */ + GlobalBuf[ 0 ] = 0xE5; for ( s = 1; s != sizeof(FAT_DIR_INFO); s ++ ) GlobalBuf[ s ] = GlobalBuf[ sizeof(FAT_DIR_INFO) + s ]; - s = CH376LongNameWrite( GlobalBuf, sizeof(FAT_DIR_INFO) ); /* 鍐欏叆涓涓枃浠剁洰褰曠粨鏋,鐢ㄤ簬鍒犻櫎涔嬪墠鏂板缓鐨勬枃浠,瀹為檯涓婄◢鍚庝細灏嗕箣杞Щ鍒扮洰褰曠殑鏈鏈綅缃 */ + s = CH376LongNameWrite( GlobalBuf, sizeof(FAT_DIR_INFO) ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; - do { /* 鍚戝悗鎼滅储绌洪棽鐨勬枃浠剁洰褰曠粨鏋 */ - s = CH376ByteRead( GlobalBuf, sizeof(FAT_DIR_INFO), &count ); /* 浠ュ瓧鑺備负鍗曚綅璇诲彇鏁版嵁,鑾峰緱涓嬩竴涓枃浠剁洰褰曚俊鎭疐AT_DIR_INFO */ + do { + s = CH376ByteRead( GlobalBuf, sizeof(FAT_DIR_INFO), &count ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; - } while ( count && GlobalBuf[0] ); /* 濡傛灉浠嶇劧鏄鍦ㄤ娇鐢ㄧ殑鏂囦欢鐩綍缁撴瀯鍒欑户缁悜鍚庢悳绱,鐩村埌涓婄骇鐩綍缁撴潫鎴栬呮湁灏氭湭浣跨敤杩囩殑鏂囦欢鐩綍缁撴瀯 */ - NewFileLoc = CH376ReadVar32( VAR_CURRENT_OFFSET ); /* 鐢ㄤ笂绾х洰褰曠殑褰撳墠鏂囦欢鎸囬拡浣滀负褰撳墠鏂囦欢鐩綍淇℃伅鍦ㄤ笂绾х洰褰曚腑鐨勮捣濮嬩綅缃 */ - i = DirBlockCnt + 1; /* 闇瑕佺殑绌洪棽鐨勬枃浠剁洰褰曠粨鏋勭殑涓暟,鍖呮嫭鐭枃浠跺悕鏈韩涓涓拰闀挎枃浠跺悕 */ - if ( count == 0 ) break; /* 鏃犳硶璇诲嚭鏁版嵁,涓婄骇鐩綍缁撴潫浜 */ - NewFileLoc -= sizeof(FAT_DIR_INFO); /* 鍊掑洖鍒板垰鎵嶆悳绱㈠埌鐨勭┖闂茬殑鏂囦欢鐩綍缁撴瀯鐨勮捣濮嬩綅缃 */ + } while ( count && GlobalBuf[0] ); + NewFileLoc = CH376ReadVar32( VAR_CURRENT_OFFSET ); + i = DirBlockCnt + 1; + if ( count == 0 ) break; + NewFileLoc -= sizeof(FAT_DIR_INFO); } } - if ( i ) { /* 绌洪棽鐨勬枃浠剁洰褰曠粨鏋勪笉瓒充互瀛樻斁闀挎枃浠跺悕,鍘熷洜鏄笂绾х洰褰曠粨鏉熶簡,涓嬮潰澧炲姞涓婄骇鐩綍鐨勯暱搴 */ - s = CH376ReadVar8( VAR_SEC_PER_CLUS ); /* 姣忕皣鎵囧尯鏁 */ - if ( s == 128 ) { /* FAT12/FAT16鐨勬牴鐩綍,瀹归噺鏄浐瀹氱殑,鏃犳硶澧炲姞鏂囦欢鐩綍缁撴瀯 */ - s = ERR_FDT_OVER; /* FAT12/FAT16鏍圭洰褰曚笅鐨勬枃浠舵暟搴旇灏戜簬512涓,闇瑕佺鐩樻暣鐞 */ + if ( i ) { + s = CH376ReadVar8( VAR_SEC_PER_CLUS ); + if ( s == 128 ) { + s = ERR_FDT_OVER; goto CH376CreateLongNameE; } - count = s * DEF_SECTOR_SIZE; /* 姣忕皣瀛楄妭鏁 */ - if ( count < i * sizeof(FAT_DIR_INFO) ) count <<= 1; /* 涓绨囦笉澶熷垯澧炲姞涓绨,杩欑鎯呭喌鍙細鍙戠敓浜庢瘡绨囦负512瀛楄妭鐨勬儏鍐典笅 */ - s = CH376LongNameWrite( NULL, count ); /* 浠ュ瓧鑺備负鍗曚綅鍚戝綋鍓嶄綅缃啓鍏ュ叏0鏁版嵁鍧,娓呯┖鏂板鍔犵殑鏂囦欢鐩綍绨 */ + count = s * DEF_SECTOR_SIZE; + if ( count < i * sizeof(FAT_DIR_INFO) ) count <<= 1; + s = CH376LongNameWrite( NULL, count ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; } - s = CH376ByteLocate( NewFileLoc ); /* 鍦ㄤ笂绾х洰褰曚腑绉诲姩鏂囦欢鎸囬拡鍒板綋鍓嶆枃浠剁洰褰曚俊鎭殑浣嶇疆 */ + s = CH376ByteLocate( NewFileLoc ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; GlobalBuf[11] = ATTR_LONG_NAME; GlobalBuf[12] = 0x00; - GlobalBuf[13] = CH376CheckNameSum( &GlobalBuf[ sizeof(FAT_DIR_INFO) ] ); /* 璁$畻闀挎枃浠跺悕鐨勭煭鏂囦欢鍚嶆楠屽拰 */ + GlobalBuf[13] = CH376CheckNameSum( &GlobalBuf[ sizeof(FAT_DIR_INFO) ] ); GlobalBuf[26] = 0x00; GlobalBuf[27] = 0x00; - for ( s = 0; DirBlockCnt != 0; ) { /* 闀挎枃浠跺悕鍗犵敤鐨勬枃浠剁洰褰曠粨鏋勮鏁 */ - GlobalBuf[0] = s ? DirBlockCnt : DirBlockCnt | 0x40; /* 棣栨瑕佺疆闀挎枃浠跺悕鍏ュ彛鏍囧織 */ + for ( s = 0; DirBlockCnt != 0; ) { + GlobalBuf[0] = s ? DirBlockCnt : DirBlockCnt | 0x40; DirBlockCnt --; NameCount = DirBlockCnt * LONG_NAME_PER_DIR; - for ( s = 1; s < sizeof( FAT_DIR_INFO ); s += 2 ) { /* 杈撳嚭闀挎枃浠跺悕,闀挎枃浠跺悕鐨勫瓧绗﹀湪纾佺洏涓奤NICODE鐢ㄥ皬绔柟寮忓瓨鏀 */ - if ( s == 1 + 5 * 2 ) s = 14; /* 浠庨暱鏂囦欢鍚嶇殑绗竴缁1-5涓瓧绗﹁烦鍒扮浜岀粍6-11涓瓧绗 */ - else if ( s == 14 + 6 * 2 ) s = 28; /* 浠庨暱鏂囦欢鍚嶇殑绗簩缁6-11涓瓧绗﹁烦鍒扮涓夌粍12-13涓瓧绗 */ + for ( s = 1; s < sizeof( FAT_DIR_INFO ); s += 2 ) { + if ( s == 1 + 5 * 2 ) s = 14; + else if ( s == 14 + 6 * 2 ) s = 28; GlobalBuf[ s ] = LongName[ NameCount++ ]; GlobalBuf[ s + 1 ] = LongName[ NameCount++ ]; } - s = CH376LongNameWrite( GlobalBuf, sizeof(FAT_DIR_INFO) ); /* 浠ュ瓧鑺備负鍗曚綅鍐欏叆涓涓枃浠剁洰褰曠粨鏋,闀挎枃浠跺悕 */ + s = CH376LongNameWrite( GlobalBuf, sizeof(FAT_DIR_INFO) ); if ( s != USB_INT_SUCCESS ) goto CH376CreateLongNameE; } - s = CH376LongNameWrite( &GlobalBuf[ sizeof(FAT_DIR_INFO) ], sizeof(FAT_DIR_INFO) ); /* 浠ュ瓧鑺備负鍗曚綅鍐欏叆涓涓枃浠剁洰褰曠粨鏋,杩欐槸杞Щ鏉ョ殑涔嬪墠鏂板缓鐨勬枃浠剁殑鐩綍淇℃伅 */ + s = CH376LongNameWrite( &GlobalBuf[ sizeof(FAT_DIR_INFO) ], sizeof(FAT_DIR_INFO) ); CH376CreateLongNameE: - CH376FileClose( FALSE ); /* 瀵逛簬鏍圭洰褰曞垯蹇呴』瑕佸叧闂 */ + CH376FileClose( FALSE ); return( s ); } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.h index f87a8169a..23f6b7838 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.h @@ -40,79 +40,85 @@ #define ERR_USB_UNKNOWN 0xFA -void xEndCH376Cmd( void ); -void xWriteCH376Cmd( UINT8 mCmd ); -void xWriteCH376Data( UINT8 mData ); -UINT8 xReadCH376Data( void ); -UINT8 Query376Interrupt( void ); -UINT8 mInitCH376Host( void ); +void xEndCH376Cmd( void ); +void xWriteCH376Cmd( UINT8 mCmd ); +void xWriteCH376Data( UINT8 mData ); +UINT8 xReadCH376Data( void ); +UINT8 Query376Interrupt( void ); +UINT8 mInitCH376Host( void ); -#define STRUCT_OFFSET( s, m ) ( (UINT8)( & ((s *)0) -> m ) ) +#define STRUCT_OFFSET( s, m ) ( (UINT8)( & ((s *)0) -> m ) ) -#ifdef EN_LONG_NAME -#ifndef LONG_NAME_BUF_LEN -#define LONG_NAME_BUF_LEN ( LONG_NAME_PER_DIR * 20 ) +#ifdef EN_LONG_NAME +#ifndef LONG_NAME_BUF_LEN +#define LONG_NAME_BUF_LEN ( LONG_NAME_PER_DIR * 20 ) #endif #endif -UINT8 CH376ReadBlock( PUINT8 buf ); -UINT8 CH376WriteReqBlock( PUINT8 buf ); +UINT8 CH376ReadBlock( PUINT8 buf ); +UINT8 CH376WriteReqBlock( PUINT8 buf ); +void CH376WriteHostBlock( PUINT8 buf, UINT8 len ); +void CH376WriteOfsBlock( PUINT8 buf, UINT8 ofs, UINT8 len ); +void CH376SetFileName( PUINT8 name ); +UINT32 CH376Read32bitDat( void ); +UINT8 CH376ReadVar8( UINT8 var ); +void CH376WriteVar8( UINT8 var, UINT8 dat ); +UINT32 CH376ReadVar32( UINT8 var ); +void CH376WriteVar32( UINT8 var, UINT32 dat ); +void CH376EndDirInfo( void ); +UINT32 CH376GetFileSize( void ); +UINT8 CH376GetDiskStatus( void ); +UINT8 CH376GetIntStatus( void ); -void CH376WriteHostBlock( PUINT8 buf, UINT8 len ); -void CH376WriteOfsBlock( PUINT8 buf, UINT8 ofs, UINT8 len ); -void CH376SetFileName( PUINT8 name ); -UINT32 CH376Read32bitDat( void ); -UINT8 CH376ReadVar8( UINT8 var ); - -void CH376WriteVar8( UINT8 var, UINT8 dat ); -UINT32 CH376ReadVar32( UINT8 var ); -void CH376WriteVar32( UINT8 var, UINT32 dat ); -void CH376EndDirInfo( void ); -UINT32 CH376GetFileSize( void ); -UINT8 CH376GetDiskStatus( void ); -UINT8 CH376GetIntStatus( void ); - -#ifndef NO_DEFAULT_CH376_INT -UINT8 Wait376Interrupt( void ); +#ifndef NO_DEFAULT_CH376_INT +UINT8 Wait376Interrupt( void ); #endif -UINT8 CH376SendCmdWaitInt( UINT8 mCmd ); -UINT8 CH376SendCmdDatWaitInt( UINT8 mCmd, UINT8 mDat ); -UINT8 CH376DiskReqSense( void ); -UINT8 CH376DiskConnect( void ); -UINT8 CH376DiskMount( void ); -UINT8 CH376FileOpen( PUINT8 name ); -UINT8 CH376FileCreate( PUINT8 name ); -UINT8 CH376DirCreate( PUINT8 name ); -UINT8 CH376SeparatePath( PUINT8 path ); -UINT8 CH376FileOpenDir( PUINT8 PathName, UINT8 StopName ); -UINT8 CH376FileOpenPath( PUINT8 PathName ); -UINT8 CH376FileCreatePath( PUINT8 PathName ); +UINT8 CH376SendCmdWaitInt( UINT8 mCmd ); +UINT8 CH376SendCmdDatWaitInt( UINT8 mCmd, UINT8 mDat ); +UINT8 CH376DiskReqSense( void ); +UINT8 CH376DiskConnect( void ); +UINT8 CH376DiskMount( void ); +UINT8 CH376FileOpen( PUINT8 name ); +UINT8 CH376FileCreate( PUINT8 name ); +UINT8 CH376DirCreate( PUINT8 name ); +UINT8 CH376SeparatePath( PUINT8 path ); +UINT8 CH376FileOpenDir( PUINT8 PathName, UINT8 StopName ); +UINT8 CH376FileOpenPath( PUINT8 PathName ); +UINT8 CH376FileCreatePath( PUINT8 PathName ); -#ifdef EN_DIR_CREATE -UINT8 CH376DirCreatePath( PUINT8 PathName ); -UINT8 CH376FileErase( PUINT8 PathName ); -UINT8 CH376FileClose( UINT8 UpdateSz ); -UINT8 CH376DirInfoRead( void ); -UINT8 CH376DirInfoSave( void ); -UINT8 CH376ByteLocate( UINT32 offset ); -UINT8 CH376ByteRead( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ); -UINT8 CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ); -UINT8 CH376DiskCapacity( PUINT32 DiskCap ); -UINT8 CH376DiskQuery( PUINT32 DiskFre ); -UINT8 CH376SecLocate( UINT32 offset ); -UINT8 CH376DiskReadSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ); -UINT8 CH376DiskWriteSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ); -UINT8 CH376SecRead( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ); -UINT8 CH376SecWrite( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ); +#ifdef EN_DIR_CREATE +UINT8 CH376DirCreatePath( PUINT8 PathName ); #endif -#ifdef EN_LONG_NAME -UINT8 CH376LongNameWrite( PUINT8 buf, UINT16 ReqCount ); -UINT8 CH376CheckNameSum( PUINT8 DirName ); -UINT8 CH376LocateInUpDir( PUINT8 PathName ); -UINT8 CH376GetLongName( PUINT8 PathName, PUINT8 LongName ); -UINT8 CH376CreateLongName( PUINT8 PathName, PUINT8 LongName ); +UINT8 CH376FileErase( PUINT8 PathName ); +UINT8 CH376FileClose( UINT8 UpdateSz ); +UINT8 CH376DirInfoRead( void ); +UINT8 CH376DirInfoSave( void ); +UINT8 CH376ByteLocate( UINT32 offset ); +UINT8 CH376ByteRead( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ); +UINT8 CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ); + +#ifdef EN_DISK_QUERY +UINT8 CH376DiskCapacity( PUINT32 DiskCap ); +UINT8 CH376DiskQuery( PUINT32 DiskFre ); +#endif + +UINT8 CH376SecLocate( UINT32 offset ); + +#ifdef EN_SECTOR_ACCESS +UINT8 CH376DiskReadSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ); +UINT8 CH376DiskWriteSec( PUINT8 buf, UINT32 iLbaStart, UINT8 iSectorCount ); +UINT8 CH376SecRead( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ); +UINT8 CH376SecWrite( PUINT8 buf, UINT8 ReqCount, PUINT8 RealCount ); +#endif + +#ifdef EN_LONG_NAME +UINT8 CH376LongNameWrite( PUINT8 buf, UINT16 ReqCount ); +UINT8 CH376CheckNameSum( PUINT8 DirName ); +UINT8 CH376LocateInUpDir( PUINT8 PathName ); +UINT8 CH376GetLongName( PUINT8 PathName, PUINT8 LongName ); +UINT8 CH376CreateLongName( PUINT8 PathName, PUINT8 LongName ); #endif #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig index df719b23e..e0e603faf 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig @@ -547,6 +547,10 @@ config NSH_DISABLE_XD bool "Disable xd" default DEFAULT_SMALL +config NSH_DISABLE_CH376 + bool "Disable the ch376 demo." + default n + config NSH_DISABLE_CH438 bool "Disable the ch438 demo." default n diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index a54df4a9c..0df886d26 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1450,6 +1450,10 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, FAR void *arg); #endif +#if defined(CONFIG_BSP_USING_CH376) && !defined(CONFIG_NSH_DISABLE_CH376) + int cmd_Ch376(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + #if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 65507a192..7bac913da 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -38,6 +38,19 @@ extern int FrameworkInit(void); +/**************************************************************************** + * Name: cmd_Ch376 + ****************************************************************************/ +#if defined(CONFIG_BSP_USING_CH376) && !defined(CONFIG_NSH_DISABLE_CH376) +extern void CH376Demo(void); +int cmd_Ch376(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, world!\n"); + CH376Demo(); + return OK; +} +#endif + /**************************************************************************** * Name: cmd_Ch438 ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index 5dbd550c6..c0132baf6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -596,6 +596,10 @@ static const struct cmdmap_s g_cmdmap[] = { "xd", cmd_xd, 3, 3, " " }, #endif +#if defined(CONFIG_BSP_USING_CH376) && !defined(CONFIG_NSH_DISABLE_CH376) + { "ch376", cmd_Ch376, 1, 1, "[ch376 demo cmd.]" }, +#endif + #if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) { "ch438", cmd_Ch438, 1, 1, "[ch438 demo cmd.]" }, #endif From b073c38035c9c40026fd0d9b778c28dac4aeadea Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Wed, 12 Oct 2022 12:40:33 +0800 Subject: [PATCH 17/30] add ch376 usb and sd card demo on xidatong-riscv64 --- .../Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig | 5 +++++ .../aiit_board/xidatong-riscv64/src/ch376_demo.c | 2 ++ .../aiit_board/xidatong-riscv64/src/k210_ch376.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig index 90cfa7ee5..336704c35 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig @@ -24,6 +24,11 @@ config CH376_SD_FUNCTION bool "select ch376 sd function" endchoice +config CH376_WORK_MODE + hex "ch376 work mode set:0x03 sd,0x06 u-disk" + default 0x03 if CH376_SD_FUNCTION + default 0x06 if CH376_USB_FUNCTION + endif # BSP_USING_CH376 menuconfig BSP_USING_CH438 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376_demo.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376_demo.c index d4302842a..f8d439e52 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376_demo.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/ch376_demo.c @@ -31,11 +31,13 @@ void CH376Demo(void) s = mInitCH376Host(); printf ("ch376 init stat=0x%02x\n",(uint16_t)s); +#ifdef CONFIG_CH376_USB_FUNCTION printf( "Wait Udisk/SD\n" ); while ( CH376DiskConnect( ) != USB_INT_SUCCESS ) { up_mdelay( 100 ); } +#endif for ( s = 0; s < 10; s ++ ) { diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c index 9478b2668..e1223e086 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch376.c @@ -107,7 +107,7 @@ UINT8 mInitCH376Host(void) if ( res != 0x9A ) return( ERR_USB_UNKNOWN ); xWriteCH376Cmd(CMD11_SET_USB_MODE); /* SET USB MODE */ - xWriteCH376Data(0x06); + xWriteCH376Data(CONFIG_CH376_WORK_MODE); up_udelay(20); res = xReadCH376Data(); xEndCH376Cmd(); From 891addbfc0e286c8643ab7f2a118f0c6b9ed246f Mon Sep 17 00:00:00 2001 From: wlyu Date: Thu, 13 Oct 2022 20:12:02 +0800 Subject: [PATCH 18/30] fixed the bug of wifi test losing parameter --- .../app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 78373cdf6..f19fdc9d4 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -364,12 +364,12 @@ int cmd_recvzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif #if defined(CONFIG_ADAPTER_ESP07S_WIFI) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) -extern int AdapterWifiTest(int argc, char *argv[]); +extern int AdapterWifiTestWithParam(int argc, char *argv[]); int cmd_AdapterWifiTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, world!\n"); FrameworkInit(); - AdapterWifiTest(argc, argv); + AdapterWifiTestWithParam(argc, argv); return OK; } #endif From 256857b6c5e3948bc2a727790ff4bdaf47dbef46 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Fri, 14 Oct 2022 16:57:21 +0800 Subject: [PATCH 19/30] move gpio define to board.h on xidatong-riscv64 --- .../connection/wifi/esp8285_wifi/Kconfig | 2 +- .../xidatong-riscv64/include/board.h | 67 ++++++++++++++++--- .../xidatong-riscv64/src/k210_bringup.c | 4 +- .../xidatong-riscv64/src/k210_ch438.h | 34 +--------- .../xidatong-riscv64/src/k210_gpio.c | 10 +-- .../xidatong-riscv64/src/k210_leds.c | 2 +- 6 files changed, 63 insertions(+), 56 deletions(-) diff --git a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig index 4b3b5b8d9..f44e5d47a 100644 --- a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig +++ b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig @@ -5,6 +5,6 @@ config ADAPTER_WIFI_ESP8285 if ADD_NUTTX_FETURES config ADAPTER_ESP8285_DRIVER string "ESP8285 device uart driver path" - default "/dev/ttyS2" + default "/dev/ttyS1" endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h index 5677e9855..1a8415a8d 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h @@ -39,12 +39,10 @@ * Pre-processor Definitions ****************************************************************************/ -#define BOARD_LED_PAD 14 /* Connected to red led */ + /* Map pad 14 to gpiohs io 0 */ - #define BOARD_LED_IO_FUNC K210_IO_FUNC_GPIOHS0 -#define BOARD_LED_IO 0 #define LED_STARTED 0 /* N/C */ #define LED_HEAPALLOCATE 1 /* N/C */ @@ -79,26 +77,75 @@ extern "C" #define EXTERN extern #endif +/*************************** GPIO define ***************************/ +/* Connected to red led */ +#define BOARD_LED_PAD 14 -#define GPIO_CAN_RXD 18 -#define GPIO_CAN_TXD 19 - +/* UART IO */ +#define GPIO_WIFI_RXD 7 +#define GPIO_WIFI_TXD 6 #define GPIO_EC200T_RXD 21 #define GPIO_EC200T_TXD 20 +#define GPIO_CH376T_RXD 22 +#define GPIO_CH376T_TXD 23 -#define GPIO_CH376T_RXD 22 -#define GPIO_CH376T_TXD 23 +/* ch438 IO */ +#define CH438_ALE_PIN 24 +#define CH438_NWR_PIN 25 +#define CH438_NRD_PIN 26 +#define CH438_D0_PIN 27 +#define CH438_D1_PIN 28 +#define CH438_D2_PIN 29 +#define CH438_D3_PIN 30 +#define CH438_D4_PIN 31 +#define CH438_D5_PIN 32 +#define CH438_D6_PIN 33 +#define CH438_D7_PIN 34 +#define CH438_INT_PIN 35 + +/* other mode io */ +#define GPIO_E220_M0 44 +#define GPIO_E220_M1 45 +#define GPIO_E18_MODE 46 +#define GPIO_WIFI_EN 8 + +/************************** end GPIO define **************************/ +/*************************** FPIOA define ***************************/ +#define BOARD_LED_IO 0 + +/* UART FPOA */ #define FPOA_USART1_RX K210_IO_FUNC_UART1_RX #define FPOA_USART1_TX K210_IO_FUNC_UART1_TX - #define FPOA_USART2_RX K210_IO_FUNC_UART2_RX #define FPOA_USART2_TX K210_IO_FUNC_UART2_TX - #define FPOA_USART3_RX K210_IO_FUNC_UART3_RX #define FPOA_USART3_TX K210_IO_FUNC_UART3_TX +/* ch438 FPIOA */ +#define FPIOA_CH438_ALE 11 +#define FPIOA_CH438_NWR 12 +#define FPIOA_CH438_NRD 13 +#define FPIOA_CH438_D0 14 +#define FPIOA_CH438_D1 15 +#define FPIOA_CH438_D2 16 +#define FPIOA_CH438_D3 17 +#define FPIOA_CH438_D4 18 +#define FPIOA_CH438_D5 29 +#define FPIOA_CH438_D6 20 +#define FPIOA_CH438_D7 31 +#define FPIOA_CH438_INT 22 + +/* other mode FPIOA */ +#define FPIOA_E220_M0 1 +#define FPIOA_E220_M1 2 +#define FPIOA_E18_MODE 3 +#define FPIOA_WIFI_EN 4 + +/************************** end FPIOA define **************************/ + + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c index 227696b1e..3ad5aea69 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c @@ -90,8 +90,8 @@ int k210_bringup(void) #ifdef CONFIG_K210_16550_UART1 sysctl_clock_enable(SYSCTL_CLOCK_UART1); sysctl_reset(SYSCTL_RESET_UART1); - fpioa_set_function(GPIO_CAN_RXD, FPOA_USART1_RX); - fpioa_set_function(GPIO_CAN_TXD, FPOA_USART1_TX); + fpioa_set_function(GPIO_WIFI_RXD, FPOA_USART1_RX); + fpioa_set_function(GPIO_WIFI_TXD, FPOA_USART1_TX); #endif #ifdef CONFIG_K210_16550_UART2 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch438.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch438.h index f952320e8..510e5757b 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch438.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_ch438.h @@ -53,6 +53,7 @@ #include #include +#include #include #include "riscv_internal.h" @@ -289,39 +290,6 @@ #define Fpclk 1843200 /* Define the internal clock frequency*/ - -/* Define CH438 PIN NUM */ -#define CH438_ALE_PIN 24 -#define CH438_NWR_PIN 25 -#define CH438_NRD_PIN 26 - -#define CH438_D0_PIN 27 -#define CH438_D1_PIN 28 -#define CH438_D2_PIN 29 -#define CH438_D3_PIN 30 -#define CH438_D4_PIN 31 -#define CH438_D5_PIN 32 -#define CH438_D6_PIN 33 -#define CH438_D7_PIN 34 - -#define CH438_INT_PIN 35 - -/* Define ch438 FPIOA NUMBER */ -#define FPIOA_CH438_ALE 11 -#define FPIOA_CH438_NWR 12 -#define FPIOA_CH438_NRD 13 - -#define FPIOA_CH438_D0 14 -#define FPIOA_CH438_D1 15 -#define FPIOA_CH438_D2 16 -#define FPIOA_CH438_D3 17 -#define FPIOA_CH438_D4 18 -#define FPIOA_CH438_D5 29 -#define FPIOA_CH438_D6 20 -#define FPIOA_CH438_D7 31 - -#define FPIOA_CH438_INT 22 - /* ch438 debug */ #ifdef CONFIG_DEBUG_CH438_ERROR # define ch438err _err diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_gpio.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_gpio.c index a54b3714d..ab1b880a7 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_gpio.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_gpio.c @@ -34,7 +34,7 @@ #include #include - +#include #include #include "k210_fpioa.h" @@ -48,15 +48,7 @@ /* Pin 1 and 2 are used for this example as GPIO outputs. */ -#define GPIO_E220_M0 44 -#define GPIO_E220_M1 45 -#define GPIO_E18_MODE 46 -#define GPIO_WIFI_EN 8 -#define FPIOA_E220_M0 1 -#define FPIOA_E220_M1 2 -#define FPIOA_E18_MODE 3 -#define FPIOA_WIFI_EN 4 /**************************************************************************** * Private Types diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_leds.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_leds.c index 709d74107..76d1fa14a 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_leds.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_leds.c @@ -25,7 +25,7 @@ #include #include - +#include #include #include "k210_fpioa.h" From 2b099b8bf54b106c1bf89c9df72adceb859632e2 Mon Sep 17 00:00:00 2001 From: wlyu Date: Fri, 14 Oct 2022 16:57:30 +0800 Subject: [PATCH 20/30] support lcd and wifi and ethernet test on xidatong-arm32 --- .../Applications/app_test/test_lcd.c | 2 +- .../socket_demo/lwip_tcp_socket_demo.c | 1 + APP_Framework/Framework/connection/adapter.c | 4 +- .../Framework/connection/adapter_agent.c | 5 +- .../Framework/connection/wifi/adapter_wifi.c | 41 ++++++++---- .../connection/wifi/esp07s_wifi/esp07s_wifi.c | 24 ++++++- .../Framework/connection/zigbee/e18/Kconfig | 14 ++++- .../Framework/connection/zigbee/e18/e18.c | 63 ++++++++++++++++++- .../apps/nshlib/nsh_Applicationscmd.c | 4 +- 9 files changed, 132 insertions(+), 26 deletions(-) diff --git a/APP_Framework/Applications/app_test/test_lcd.c b/APP_Framework/Applications/app_test/test_lcd.c index 14a6146f1..9133f9628 100755 --- a/APP_Framework/Applications/app_test/test_lcd.c +++ b/APP_Framework/Applications/app_test/test_lcd.c @@ -374,7 +374,7 @@ int test_lcd(int argc, FAR char *argv[]) close(state.fd); return EXIT_FAILURE; } - + printf("2022-10-14 Mr. Wang commit LCD\n"); printf("VideoInfo:\n"); printf(" fmt: %u\n", state.vinfo.fmt); printf(" xres: %u\n", state.vinfo.xres); diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c index 56b24ddb6..da1dff600 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c @@ -181,6 +181,7 @@ static void TcpSocketSendTask(void *arg) int ret; char send_msg[128]; + lw_print("2022-10-14 Mr. Wang commit TCP\n"); lw_print("%s start\n", __func__); memset(send_msg, 0, sizeof(send_msg)); diff --git a/APP_Framework/Framework/connection/adapter.c b/APP_Framework/Framework/connection/adapter.c index a4b0f4cc9..eb1356c14 100644 --- a/APP_Framework/Framework/connection/adapter.c +++ b/APP_Framework/Framework/connection/adapter.c @@ -169,7 +169,7 @@ int AdapterDeviceOpen(struct Adapter *adapter) result = priv_done->open(adapter); if (0 == result) { - printf("Device %s open success.\n", adapter->name); + printf("Device %s %p open success.\n", adapter->name, adapter->adapter_param); adapter->adapter_status = INSTALL; } else { if (adapter->fd) { @@ -187,7 +187,7 @@ int AdapterDeviceOpen(struct Adapter *adapter) result = ip_done->open(adapter); if (0 == result) { - printf("Device %s open success.\n", adapter->name); + printf("Device %s param %p open success.\n", adapter->name, adapter->adapter_param); adapter->adapter_status = INSTALL; } else { if (adapter->fd) { diff --git a/APP_Framework/Framework/connection/adapter_agent.c b/APP_Framework/Framework/connection/adapter_agent.c index db52a67c3..344674bfb 100755 --- a/APP_Framework/Framework/connection/adapter_agent.c +++ b/APP_Framework/Framework/connection/adapter_agent.c @@ -211,8 +211,7 @@ int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check) ret = -1; goto __exit; } - printf("[reply result :\n"); - printf("%s]\n", result); + printf("[reply result: %s]\n", result); if(!strstr(result, check)) { printf("%s %d check[%s] reply[%s] failed.\n",__func__,__LINE__,check,result); ret = -1; @@ -522,7 +521,7 @@ static int ATAgentInit(ATAgentType agent) #ifdef ADD_NUTTX_FETURES pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER; attr.priority = 18; - attr.stacksize = 4096; + attr.stacksize = 8192; #else pthread_attr_t attr; diff --git a/APP_Framework/Framework/connection/wifi/adapter_wifi.c b/APP_Framework/Framework/connection/wifi/adapter_wifi.c index c5d5b47af..53f46603f 100644 --- a/APP_Framework/Framework/connection/wifi/adapter_wifi.c +++ b/APP_Framework/Framework/connection/wifi/adapter_wifi.c @@ -168,13 +168,13 @@ int AdapterWifiTest(void) const char *wifi_msg = "Wifi Test"; int len = strlen(wifi_msg); - for(int i = 0;i < 10; ++i) { + for(int i = 0; i < 10; ++i) { AdapterDeviceSend(adapter, wifi_msg, len); PrivTaskDelay(4000); } char wifi_recv_msg[128]; - for(int j=0;j<10;++j){ + for(int j = 0; j < 10; ++j){ AdapterDeviceRecv(adapter, wifi_recv_msg, 128); PrivTaskDelay(1000); } @@ -198,7 +198,7 @@ PRIV_SHELL_CMD_FUNCTION(WifiClose, a WiFi close sample, PRIV_SHELL_CMD_MAIN_ATTR int WifiSetup(int argc, char *argv[]) { struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); - struct WifiParam param; + static struct WifiParam param; memset(¶m,0,sizeof(struct WifiParam)); strncpy((char *)param.wifi_ssid, argv[1], strlen(argv[1])); strncpy((char *)param.wifi_pwd, argv[2], strlen(argv[2])); @@ -292,7 +292,7 @@ enum APT_WIFI_PARAM_NUM }; -#define APT_WIFI_PARAM_LEN 20 +#define APT_WIFI_PARAM_LEN 128 char wifi_param[APT_WIFI_PARAM_NUM][APT_WIFI_PARAM_LEN] = {0}; @@ -301,6 +301,7 @@ ret = __func; \ if(ret != 0){ \ printf("%s %d failed\n", __func__, __LINE__); \ AdapterDeviceClose(adapter); \ + free(adapter->adapter_param); \ return ret; \ }; @@ -309,7 +310,16 @@ void AdapterWifiGetParam(int argc, char *argv[]) int i, j; char *param_str[] = {"ip", "port", "ssid", "pwd", "gw", "server", "mask", "ping"}; char *default_str[] = - {"192.168.137.34", "12345", "test", "tttttttt", "192.168.137.71", "192.168.137.1", "255.255.255.0", "220.181.38.251"}; + { + "192.168.137.34", + "12345", + "test", + "tttttttt", + "192.168.137.71", + "192.168.137.1", + "255.255.255.0", + "220.181.38.251" + }; for(i = 0; i < APT_WIFI_PARAM_NUM; i ++) { @@ -342,17 +352,20 @@ int AdapterWifiTestWithParam(int argc, char *argv[]) { int i, ret; - struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); + struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); AdapterWifiGetParam(argc, argv); enum NetRoleType net_role = CLIENT; enum IpType ip_type = IPV4; - struct WifiParam param; - memset(¶m, 0, sizeof(struct WifiParam)); - strncpy((char *)param.wifi_ssid, wifi_param[APT_WIFI_PARAM_SSID], strlen(wifi_param[APT_WIFI_PARAM_SSID])); - strncpy((char *)param.wifi_pwd, wifi_param[APT_WIFI_PARAM_PWD], strlen(wifi_param[APT_WIFI_PARAM_PWD])); - adapter->adapter_param = ¶m; + adapter->adapter_param = malloc(sizeof(struct WifiParam)); + memset(adapter->adapter_param, 0, sizeof(struct WifiParam)); + struct WifiParam *apt_param = (struct WifiParam *)adapter->adapter_param; + strcpy(apt_param->wifi_ssid, wifi_param[APT_WIFI_PARAM_SSID]); + strcpy(apt_param->wifi_pwd, wifi_param[APT_WIFI_PARAM_PWD]); + + printf("2022-10-14 Mr. Wang commit Wifi\n"); + printf("apt %p ssid %p %s\n", apt_param, apt_param->wifi_ssid); CHECK_RET(AdapterDeviceOpen(adapter)); CHECK_RET(AdapterDeviceSetUp(adapter)); @@ -373,8 +386,9 @@ int AdapterWifiTestWithParam(int argc, char *argv[]) PrivTaskDelay(4000); } - char wifi_recv_msg[128]; - for(i = 0; i < 10; i ++) + char wifi_recv_msg[APT_WIFI_PARAM_LEN]; + memset(wifi_recv_msg, 0, APT_WIFI_PARAM_LEN); + for(i = 0; i < APT_WIFI_PARAM_NUM; i ++) { AdapterDeviceRecv(adapter, wifi_recv_msg, 128); PrivTaskDelay(1000); @@ -385,6 +399,7 @@ int AdapterWifiTestWithParam(int argc, char *argv[]) // CHECK_RET(AdapterDevicePing(adapter, wifi_param[APT_WIFI_PARAM_PING])); // AdapterDeviceDisconnect(adapter, NULL); ret = AdapterDeviceClose(adapter); + free(adapter->adapter_param); return ret; } diff --git a/APP_Framework/Framework/connection/wifi/esp07s_wifi/esp07s_wifi.c b/APP_Framework/Framework/connection/wifi/esp07s_wifi/esp07s_wifi.c index 20558699e..4a1aa830d 100755 --- a/APP_Framework/Framework/connection/wifi/esp07s_wifi/esp07s_wifi.c +++ b/APP_Framework/Framework/connection/wifi/esp07s_wifi/esp07s_wifi.c @@ -196,39 +196,59 @@ static int Esp07sWifiSetUp(struct Adapter *adapter) return -1; } PrivTaskDelay(2000); + + printf("%s check %d adapter %p wifi %p param %p\n", __func__, __LINE__, adapter, param, + adapter->adapter_param); + /* config as softAP+station mode */ ret = AtCmdConfigAndCheck(agent, "AT+CWMODE=3\r\n", "OK"); if(ret < 0) { printf("%s %d cmd[AT+CWMODE=3] config failed!\n",__func__,__LINE__); return -1; } + +// printf("%s check %d pwd %s\n", __func__, __LINE__, param->wifi_pwd); + PrivTaskDelay(2000); /* connect the router */ memset(cmd,0,sizeof(cmd)); - strncpy(cmd,"AT+CWJAP=",strlen("AT+CWJAP=")); + strcpy(cmd,"AT+CWJAP=");//strlen("AT+CWJAP=")); strncat(cmd,"\"",1); - strncat(cmd,param->wifi_ssid,strlen(param->wifi_ssid)); + +// printf("%s check %d len %d\n", __func__, __LINE__, strlen(param->wifi_pwd)); + + strncat(cmd,param->wifi_ssid,128); strncat(cmd,"\"",1); strncat(cmd,",",1); strncat(cmd,"\"",1); + +// printf("%s check %d len %d\n", __func__, __LINE__, strlen(param->wifi_pwd)); + strncat(cmd,param->wifi_pwd,strlen(param->wifi_pwd)); strncat(cmd,"\"",1); strcat(cmd,"\r\n"); + printf("%s check %d\n", __func__, __LINE__); + ret = AtCmdConfigAndCheck(agent, cmd, "OK"); if(ret < 0) { printf("%s %d cmd[%s] connect[%s] failed!\n",__func__,__LINE__,cmd,param->wifi_ssid); return -1; } + printf("%s check %d\n", __func__, __LINE__); + /* check the wifi ip address */ ATReplyType reply = CreateATReply(256); if (NULL == reply) { printf("%s %d at_create_resp failed!\n",__func__,__LINE__); return -1; } + + printf("%s check %d\n", __func__, __LINE__); + ret = ATOrderSend(agent, REPLY_TIME_OUT, reply, "AT+CIFSR\r\n"); if(ret < 0){ printf("%s %d ATOrderSend AT+CIFSR failed.\n",__func__,__LINE__); diff --git a/APP_Framework/Framework/connection/zigbee/e18/Kconfig b/APP_Framework/Framework/connection/zigbee/e18/Kconfig index 05751a4dc..0551d4cbf 100644 --- a/APP_Framework/Framework/connection/zigbee/e18/Kconfig +++ b/APP_Framework/Framework/connection/zigbee/e18/Kconfig @@ -47,14 +47,24 @@ if ADD_XIZI_FETURES endif if ADD_NUTTX_FETURES +if ARCH_BOARD_XIDATONG_ARM32 + config ADAPTER_E18_MODEPIN + int "E18 MODE pin number" + default "61" + + config ADAPTER_E18_PIN_DRIVER + string "E18 device pin driver path" + default "/dev/gpio0" +endif +if ARCH_BOARD_XIDATONG_ARM32 config ADAPTER_E18_MODE_PATH string "E18 MODE pin device" default "/dev/gpio2" - +endif config ADAPTER_E18_DRIVER_EXTUART bool "Using extra uart to support zigbee" default y - + config ADAPTER_E18_DRIVER string "E18 device uart driver path" default "/dev/ttyS1" diff --git a/APP_Framework/Framework/connection/zigbee/e18/e18.c b/APP_Framework/Framework/connection/zigbee/e18/e18.c index 41197dc5a..b07a4c3ea 100644 --- a/APP_Framework/Framework/connection/zigbee/e18/e18.c +++ b/APP_Framework/Framework/connection/zigbee/e18/e18.c @@ -40,10 +40,35 @@ char *cmd_set_ch = "AT+CH=11"; /*set channel as 11*/ #define E18_AS_HEX_MODE 0 #define E18_AS_AT_MODE 1 + static int E18HardwareModeGet() { #ifdef ADD_NUTTX_FETURES +#ifdef CONFIG_ARCH_BOARD_XIDATONG_ARM32 + int ret = 0; + int pin_fd; + + pin_fd = PrivOpen(ADAPTER_E18_PIN_DRIVER, O_RDWR); + + struct PinStat pin_stat; + pin_stat.pin = ADAPTER_E18_MODEPIN; + + ret = PrivRead(pin_fd, &pin_stat, 1); + + PrivTaskDelay(200); + + PrivClose(pin_fd); + + if(pin_stat.val == GPIO_HIGH) { + printf(" E18 as AT mode\n"); + return E18_AS_AT_MODE; + } else { + printf(" E18 as HEX mode\n"); + return E18_AS_HEX_MODE; + } +#else return E18_AS_HEX_MODE; +#endif #else int ret = 0; int pin_fd; @@ -66,7 +91,41 @@ static int E18HardwareModeGet() printf(" E18 as HEX mode\n"); return E18_AS_HEX_MODE; } -#endif +#endif +} + +static int E18HardwareModeSet(void) +{ +#ifdef ADD_NUTTX_FETURES +#ifdef CONFIG_ARCH_BOARD_XIDATONG_ARM32 + int ret = 0; + int pin_fd; + + pin_fd = PrivOpen(ADAPTER_E18_PIN_DRIVER, O_RDWR); + + struct PinStat pin_stat; + pin_stat.pin = ADAPTER_E18_MODEPIN; + pin_stat.val = GPIO_HIGH; + +// ret = PrivWrite(pin_fd, &pin_stat, 1); + + ioctl(pin_fd, GPIOC_WRITE, (unsigned long)0); + + PrivTaskDelay(200); + + ret = PrivRead(pin_fd, &pin_stat, 1); + + PrivClose(pin_fd); + + if(pin_stat.val == GPIO_HIGH) { + printf(" E18 set AT mode\n"); + return E18_AS_AT_MODE; + } else { + printf(" E18 set HEX mode\n"); + return E18_AS_HEX_MODE; + } +#endif +#endif } static int E18UartOpen(struct Adapter *adapter) @@ -186,6 +245,8 @@ static int E18NetRoleConfig(struct Adapter *adapter) int ret = 0; int mode = -1; + printf("start %s\n", __func__); +// E18HardwareModeSet(); if (NULL == adapter) { printf("%s %d adapter is null!\n",__func__,__LINE__); diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 78373cdf6..f19fdc9d4 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -364,12 +364,12 @@ int cmd_recvzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif #if defined(CONFIG_ADAPTER_ESP07S_WIFI) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) -extern int AdapterWifiTest(int argc, char *argv[]); +extern int AdapterWifiTestWithParam(int argc, char *argv[]); int cmd_AdapterWifiTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { nsh_output(vtbl, "Hello, world!\n"); FrameworkInit(); - AdapterWifiTest(argc, argv); + AdapterWifiTestWithParam(argc, argv); return OK; } #endif From ba84afb1799b3f4cb736ab3649dfa845eb30096b Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Fri, 14 Oct 2022 18:08:41 +0800 Subject: [PATCH 21/30] add w5500 for xidatong-riscv64 --- .../aiit_board/xidatong-riscv64/Kconfig | 4 + .../xidatong-riscv64/include/board.h | 16 + .../aiit_board/xidatong-riscv64/src/Makefile | 3 + .../xidatong-riscv64/src/k210_bringup.c | 5 - .../xidatong-riscv64/src/k210_leds.c | 1 - .../aiit_board/xidatong-riscv64/src/w5500.c | 683 ++++++++++++++++++ .../aiit_board/xidatong-riscv64/src/w5500.h | 299 ++++++++ 7 files changed, 1005 insertions(+), 6 deletions(-) create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.c create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.h diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig index 336704c35..78bb7ffd2 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig @@ -31,6 +31,10 @@ config CH376_WORK_MODE endif # BSP_USING_CH376 +menuconfig BSP_USING_ENET + bool "Using ENET device" + default n + menuconfig BSP_USING_CH438 bool "Using CH438 device" default n diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h index 1a8415a8d..b3b197955 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h @@ -103,6 +103,14 @@ extern "C" #define CH438_D7_PIN 34 #define CH438_INT_PIN 35 +/* w5500 IO */ +#define BSP_ENET_SCLK 9 +#define BSP_ENET_MISO 10 +#define BSP_ENET_MOSI 11 +#define BSP_ENET_NCS 12 +#define BSP_ENET_NRST 13 +#define BSP_ENET_NINT 14 + /* other mode io */ #define GPIO_E220_M0 44 #define GPIO_E220_M1 45 @@ -137,6 +145,14 @@ extern "C" #define FPIOA_CH438_D7 31 #define FPIOA_CH438_INT 22 +/* w5500 FPIOA */ +#define FPIOA_ENET_NRST 5 +#define FPIOA_ENET_NINT 6 +#define FPIOA_ENET_SCLK 7 +#define FPIOA_ENET_MISO 8 +#define FPIOA_ENET_MOSI 9 +#define FPIOA_ENET_NCS 10 + /* other mode FPIOA */ #define FPIOA_E220_M0 1 #define FPIOA_E220_M1 2 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile index 90a9d8f65..bf7a0eb95 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile @@ -50,4 +50,7 @@ ifeq ($(CONFIG_BSP_USING_CH376),y) CSRCS += k210_ch376.c ch376_demo.c endif +ifeq ($(CONFIG_BSP_USING_ENET),y) +CSRCS += w5500.c +endif include $(TOPDIR)/boards/Board.mk diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c index 3ad5aea69..1fed3801b 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_bringup.c @@ -108,10 +108,5 @@ int k210_bringup(void) fpioa_set_function(GPIO_CH376T_TXD, FPOA_USART3_TX); #endif -#ifdef CONFIG_BSP_USING_ENET - k210_sysctl_init(); - board_enet_initialize(); -#endif - return ret; } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_leds.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_leds.c index 76d1fa14a..5d255a6f4 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_leds.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_leds.c @@ -24,7 +24,6 @@ #include -#include #include #include diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.c new file mode 100644 index 000000000..720152814 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.c @@ -0,0 +1,683 @@ +/* +* Copyright (c) 2022 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file w5500.c +* @brief w5500 driver based on simulated SPI +* @version 1.0 +* @author AIIT XUOS Lab +* @date 2022-9-14 +*/ + +#include "nuttx/arch.h" +#include "w5500.h" +#include "k210_gpio_common.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ +w5500_param_t w5500_param; + +/**************************************************************************** + * Name: spi_read_byte + * Description: Read one byte spi data returned + * input: None + * output: None + * return:Read register data + ****************************************************************************/ +static uint8_t spi_read_byte(void) +{ + uint8_t i, dat = 0; + SCLK_L(); + + for(i = 0; i < 8; i++) + { + SCLK_H(); + dat <<= 1; + dat |= k210_gpiohs_get_value(FPIOA_ENET_MISO); + up_udelay(1); + SCLK_L(); + } + + return dat; +} + +/**************************************************************************** + * Name: spi_write_byte + * Description: send 1 byte to spi + * input: data + * output: None + * return: None + ****************************************************************************/ +static void spi_write_byte(uint8_t dat) +{ + uint8_t i; + + for(i = 0; i < 8; i++) + { + SCLK_L(); + + if((dat << i) & 0x80) + { + MOSI_H(); + } + else + { + MOSI_L(); + } + + SCLK_H(); + } + + SCLK_L(); +} + +/**************************************************************************** + * Name: spi_write_short + * Description: send 2 bytes to spi + * input: data + * output: None + * return: None + ****************************************************************************/ +static void spi_write_short(uint16_t dat) +{ + spi_write_byte((uint8_t)(dat / 256)); + spi_write_byte(dat); +} + +/**************************************************************************** + * Name: w5500_write_byte + *Description: Write 1 byte data to the specified address register through SPI + *Input: reg: 16 bit register address, dat: data to be written + * output: None + * return: None + ****************************************************************************/ +static void w5500_write_byte(uint16_t reg, uint8_t dat) +{ + NCS_L(); + spi_write_short(reg); + spi_write_byte(FDM1 | RWB_WRITE | COMMON_R); + spi_write_byte(dat); + NCS_H(); +} + +/**************************************************************************** + * Name: w5500_write_short + * Description: Write 2 bytes data to the specified address register through SPI + * Input: reg: 16 bit register address, dat: data to be written + * output: None + * return: None + ****************************************************************************/ +static void w5500_write_short(uint16_t reg, uint16_t dat) +{ + NCS_L(); + spi_write_short(reg); + spi_write_byte(FDM2 | RWB_WRITE | COMMON_R); + spi_write_short(dat); + NCS_H(); +} + +/**************************************************************************** + * Name: w5500_write_bytes + * Description: Write n bytes data to the specified address register through SPI + * Input: reg: 16 bit register address, dat: data to be written,size:Length of data to be written + * output: None + * return: None + ****************************************************************************/ +static void w5500_write_bytes(uint16_t reg, uint8_t *dat, uint16_t size) +{ + uint16_t i; + NCS_L(); + spi_write_short(reg); + spi_write_byte(VDM | RWB_WRITE | COMMON_R); + + for(i = 0; i < size; i++) + { + spi_write_byte(*dat++); + } + + NCS_H(); +} + +/**************************************************************************** + * Name: w5500_write_sock_byte + * Description: Write 1 byte data to the specified port register through SPI + * Input: sock: port number, reg: 16 bit register address, dat: data to be written + * Output: None + * return: None + ****************************************************************************/ +void w5500_write_sock_byte(socket_t sock, uint16_t reg, uint8_t dat) +{ + NCS_L(); + spi_write_short(reg); + spi_write_byte(FDM1 | RWB_WRITE | (sock * 0x20 + 0x08)); + spi_write_byte(dat); + NCS_H(); +} + +/**************************************************************************** + * Name: w5500_write_sock_short + * Description: Write 2 bytes data to the specified port register through SPI + * Input: sock: port number, reg: 16 bit register address, dat: data to be written + * Output: None + * return: None + ****************************************************************************/ +void w5500_write_sock_short(socket_t sock, uint16_t reg, uint16_t dat) +{ + NCS_L(); + spi_write_short(reg); + spi_write_byte(FDM2 | RWB_WRITE | (sock * 0x20 + 0x08)); + spi_write_short(dat); + NCS_H(); +} + +/**************************************************************************** + * Name: w5500_write_sock_long + * Description: Write 4 bytes data to the specified port register through SPI + * Input: sock: port number, reg: 16 bit register address, dat: 4 byte buffer pointers to be written + * Output: None + * return: None + ****************************************************************************/ +void w5500_write_sock_long(socket_t sock, uint16_t reg, uint8_t *dat) +{ + NCS_L(); + spi_write_short(reg); + spi_write_byte(FDM4 | RWB_WRITE | (sock * 0x20 + 0x08)); + spi_write_byte(*dat++); + spi_write_byte(*dat++); + spi_write_byte(*dat++); + spi_write_byte(*dat++); + NCS_H(); +} + +/******************************************************************************* +*Function name: w5500_read_byte +*Description: Read 1 byte data of W5500 specified address register +*Input: reg: 16 bit register address +*Output: None +*Return : 1 byte data read from the register +*******************************************************************************/ +uint8_t w5500_read_byte(uint16_t reg) +{ + uint8_t val; + NCS_L(); + spi_write_short(reg); + spi_write_byte(FDM1 | RWB_READ | COMMON_R); + val = spi_read_byte(); + NCS_H(); + return val; +} + +/******************************************************************************* +*Function name: w5500_read_sock_byte +*Description: Read 1 byte data of W5500 specified port register +*Input: sock: port number, reg: 16 bit register address +*Output: None +*Return: 1 byte data read from the register +*Description: None +*******************************************************************************/ +uint8_t w5500_read_sock_byte(socket_t sock, uint16_t reg) +{ + uint8_t val; + NCS_L(); + spi_write_short(reg); + spi_write_byte(FDM1 | RWB_READ | (sock * 0x20 + 0x08)); + val = spi_read_byte(); + NCS_H(); + return val; +} + +/******************************************************************************* +*Function name: w5500_read_sock_short +*Description: Read 2 bytes of W5500 specified port register +*Input: sock: port number, reg: 16 bit register address +*Output: None +*Return: read 2 bytes of data from the register (16 bits) +*******************************************************************************/ +uint16_t w5500_read_sock_short(socket_t sock, uint16_t reg) +{ + uint16_t val; + NCS_L(); + spi_write_short(reg); + spi_write_byte(FDM2 | RWB_READ |(sock * 0x20 + 0x08)); + val = spi_read_byte(); + val *= 256; + val |= spi_read_byte(); + NCS_H(); + return val; +} + +/******************************************************************************* +*Function name: w5500_read_sock_bytes +*Description: Read data from W5500 receive data buffer +*Input: sock: port number, * dat: data saving buffer pointer +*Output: None +*Return: read data length +*******************************************************************************/ +uint16_t w5500_read_sock_bytes(socket_t sock, uint8_t *dat) +{ + uint16_t recv_size, write_addr; + uint16_t recv_addr; + uint16_t i; + uint8_t val; + recv_size = w5500_read_sock_short(sock, W5500_SN_RX_RSR_REG); + + //no receive data + if(recv_size == 0) + { + return 0; + } + + if(recv_size > W5500_MAX_PACK_SIZE) + { + recv_size = W5500_MAX_PACK_SIZE; + } + + recv_addr = w5500_read_sock_short(sock, W5500_SN_RX_RD_REG); + write_addr = recv_addr; + + //calculate physical address + recv_addr &= (SOCK_RECV_SIZE - 1); + NCS_L(); + spi_write_short(recv_addr); + spi_write_byte(VDM | RWB_READ | (sock * 0x20 + 0x18)); + + if((recv_addr + recv_size) < SOCK_RECV_SIZE) + { + for(i = 0; i < recv_size; i++) + { + val = spi_read_byte(); + *dat = val; + dat++; + } + } + else + { + recv_addr = SOCK_RECV_SIZE - recv_addr; + + for(i = 0; i < recv_addr; i++) + { + val = spi_read_byte(); + *dat = val; + dat++; + } + + NCS_H(); + NCS_L(); + spi_write_short(0x00); + spi_write_byte(VDM | RWB_READ | (sock * 0x20 + 0x18)); + + for(; i < recv_size; i++) + { + val= spi_read_byte(); + *dat = val; + dat++; + } + } + + NCS_H(); + write_addr += recv_size; + + w5500_write_sock_short(sock, W5500_SN_RX_RD_REG, write_addr); + //start receive + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_RECV); + return recv_size; +} + +/******************************************************************************* +*Function name: w5500_write_sock_bytes +*Description: Write data to the data sending buffer of W5500 +*Input: sock: port number, dat: data storage buffer pointer, size: length of data to be written +*Output: None +*Return: None +*******************************************************************************/ +void w5500_write_sock_bytes(socket_t sock, uint8_t *dat, uint16_t size) +{ + uint16_t recv_addr, write_addr; + uint16_t i; + + // if udp mode, set ip and port + if(w5500_read_sock_byte(sock, W5500_SN_MR_REG) != SOCK_UDP) + { + w5500_write_sock_long(sock, W5500_SN_DIPR_REG, w5500_param.udp_ip); + w5500_write_sock_short(sock, W5500_SN_DPORTR_REG, w5500_param.udp_port); + } + + recv_addr = w5500_read_sock_short(sock, W5500_SN_TX_WR_REG); + write_addr = recv_addr; + recv_addr &= (SOCK_SEND_SIZE - 1); + + NCS_L(); + spi_write_short(recv_addr); + spi_write_byte(VDM | RWB_WRITE | (sock * 0x20 + 0x10)); + + if((recv_addr + size) < SOCK_SEND_SIZE) + { + for(i = 0; i < size; i++) + { + spi_write_byte(*dat++); + } + } + else + { + recv_addr = SOCK_SEND_SIZE - recv_addr; + + for(i = 0; i < recv_addr; i++) + { + spi_write_byte(*dat++); + } + + NCS_H(); + NCS_L(); + + spi_write_short(0x00); + spi_write_byte(VDM | RWB_WRITE | (sock * 0x20 + 0x10)); + + for(; i < size; i++) + { + spi_write_byte(*dat++); + } + } + + NCS_H(); + write_addr += size; + + w5500_write_sock_short(sock, W5500_SN_TX_WR_REG, write_addr); + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_SEND); +} + +/******************************************************************************* +*Function name: w5500_reset +*Description: Hardware reset W5500 +*Input: None +*Output: None +*Return value: None +*Note: The reset pin of the W5500 can be encircled only when the low level is at least 500us +*******************************************************************************/ +void w5500_reset(void) +{ + uint8_t dat = 0; + + RST_L(); + RST_H(); + + //wait connect ok + while((dat & LINK) == 0) + { + up_mdelay(500); + dat = w5500_read_byte(W5500_PHYCFGR_REG); + } +} + +/******************************************************************************* +*Function name: w5500_config_init +*Description: Initialize W5500 register functions +*Input: None +*Output: None +*Return value: None +*Note: Before using W5500, initialize W5500 +*******************************************************************************/ +void w5500_config_init(void) +{ + uint8_t i = 0; + + //software reset, set 1 and auto clear 0 + w5500_write_byte(W5500_MR_REG, MR_RST); + up_mdelay(100); + + w5500_write_bytes(W5500_GAR_REG, w5500_param.gw_addr, 4); + w5500_write_bytes(W5500_SUBR_REG, w5500_param.ip_mask, 4); + w5500_write_bytes(W5500_SHAR_REG, w5500_param.mac_addr, 6); + w5500_write_bytes(W5500_SIPR_REG, w5500_param.ip_addr, 4); + + //set socket rx and tx memory size 2k + for(i = 0; i < 8; i++) + { + w5500_write_sock_byte(i, W5500_SN_RXBUF_SIZE_REG, 0x02); + w5500_write_sock_byte(i, W5500_SN_TXBUF_SIZE_REG, 0x02); + } + + //set retry time 200ms (0x07d0 = 2000) + w5500_write_short(W5500_RTR_REG, 0x07d0); + + //retry time with 8, when exceed it, produce overtime interrupt, set W5500_SN_IR_REG(TIMEOUT) + w5500_write_byte(W5500_RCR_REG, 8); +} + +/******************************************************************************* +*Function name: Detect_Gateway +*Description: Check the gateway server +*Input: None +*Output: None +*Return value: TRUE (0xFF) for success, FALSE (0x00) for failure +*******************************************************************************/ +uint8_t w5500_detect_gateway(void) +{ + uint8_t ip_addr[4] = {w5500_param.ip_addr[0] + 1, w5500_param.ip_addr[1] + 1, w5500_param.ip_addr[2] + 1, w5500_param.ip_addr[3] + 1}; + + //check gateway and get gateway phyiscal address + w5500_write_sock_long(0, W5500_SN_DIPR_REG, ip_addr); + w5500_write_sock_byte(0, W5500_SN_MR_REG, SN_MR_TCP); + w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_OPEN); + up_mdelay(5); + + if(w5500_read_sock_byte(0, W5500_SN_SR_REG) != SOCK_INIT) + { + w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CLOSE); + return FALSE; + } + + //set socket connection mode + w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CONNECT); + + do + { + uint8_t val = 0; + //read socket0 interrupt register + val = w5500_read_sock_byte(0, W5500_SN_IR_REG); + + if(val != 0) + { + w5500_write_sock_byte(0, W5500_SN_IR_REG, val); + } + + up_mdelay(5); + + if((val & IR_TIMEOUT) == IR_TIMEOUT) + { + return FALSE; + } + else if(w5500_read_sock_byte(0, W5500_SN_DHAR_REG) != 0xff) + { + //close socket + w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CLOSE); + return TRUE; + } + } while(1); + return TRUE; +} + +/******************************************************************************* +*Function name: w5500_socket_init +*Description: Specify Socket (0~7) initialization +*Input: sock: port to be initialized +*Output: None +*Return value: None +*******************************************************************************/ +void w5500_socket_init(socket_t sock) +{ + //max partition bytes = 30 + w5500_write_sock_short(0, W5500_SN_MSSR_REG, 30); + + switch(sock) + { + case 0: + w5500_write_sock_short(0, W5500_SN_PORT_REG, w5500_param.sock.local_port); + w5500_write_sock_short(0, W5500_SN_DPORTR_REG, w5500_param.sock.dst_port); + w5500_write_sock_long(0, W5500_SN_DIPR_REG, w5500_param.sock.dst_ip); + break; + + default: + break; + } +} + +/******************************************************************************* +*Function name: w5500_socket_connect +*Description: Set the specified Socket (0~7) as the client to connect with the remote server +*Input: sock: port to be set +*Output: None +*Return value: TRUE (0xFF) for success, FALSE (0x00) for failure +*******************************************************************************/ +uint8_t w5500_socket_connect(socket_t sock) +{ + w5500_write_sock_byte(sock, W5500_SN_MR_REG, SN_MR_TCP); + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_OPEN); + up_mdelay(5); + + if(w5500_read_sock_byte(sock, W5500_SN_SR_REG) != SOCK_INIT) + { + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_CLOSE); + return FALSE; + } + + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_CONNECT); + return TRUE; +} + +/******************************************************************************* +*Function name: w5500_socket_listen +*Description: Set the specified Socket (0~7) as the server to wait for the connection of the remote host +*Input: sock: port to be set +*Output: None +*Return value: TRUE (0xFF) for success, FALSE (0x00) for failure +*******************************************************************************/ +uint8_t w5500_socket_listen(socket_t sock) +{ + w5500_write_sock_byte(sock, W5500_SN_MR_REG, SN_MR_TCP); + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_OPEN); + up_mdelay(5); + + if(w5500_read_sock_byte(sock, W5500_SN_SR_REG) != SOCK_INIT) + { + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_CLOSE); + return FALSE; + } + + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_LISTEN); + up_mdelay(5); + + if(w5500_read_sock_byte(sock, W5500_SN_SR_REG) != SOCK_LISTEN) + { + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_CLOSE); + return FALSE; + } + + return TRUE; +} + +/******************************************************************************* +*Function name: w5500_socket_set_udp +*Description: Set the specified Socket (0~7) to UDP mode +*Input: sock: port to be set +*Output: None +*Return value: TRUE (0xFF) for success, FALSE (0x00) for failure +*******************************************************************************/ +uint8_t w5500_socket_set_udp(socket_t sock) +{ + w5500_write_sock_byte(sock, W5500_SN_MR_REG, SN_MR_UDP); + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_OPEN); + up_mdelay(5); + + if(w5500_read_sock_byte(sock, W5500_SN_SR_REG) != SOCK_UDP) + { + w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_CLOSE); + return FALSE; + } + return TRUE; +} + +/******************************************************************************* +*Function name: w5500_irq_process +*Description: W5500 interrupt handler framework +*Input: None +*Output: None +*Return value: None +*Description: None +*******************************************************************************/ +void w5500_irq_process(void) +{ + uint8_t ir_flag, sn_flag; + ir_flag = w5500_read_byte(W5500_SIR_REG); + do + { + //handle socket0 event + if((ir_flag & S0_INT) == S0_INT) + { + sn_flag = w5500_read_sock_byte(0, W5500_SN_IR_REG); + w5500_write_sock_byte(0, W5500_SN_IR_REG, sn_flag); + + if(sn_flag & IR_CON) + { + //socket connection finished + w5500_param.sock.flag |= SOCK_FLAG_CONN; + } + + if(sn_flag & IR_DISCON) + { + //disconnect state + w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CLOSE); + w5500_socket_init(0); + w5500_param.sock.flag = 0; + } + + if(sn_flag & IR_SEND_OK) + { + //send one package ok + w5500_param.sock.state |= SOCK_STAT_SEND; + } + + if(sn_flag & IR_RECV) + { + w5500_param.sock.state |= SOCK_STAT_RECV; + } + + if(sn_flag & IR_TIMEOUT) + { + //close socket, connection failed + w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CLOSE); + w5500_param.sock.flag = 0; + } + } + ir_flag = w5500_read_byte(W5500_SIR_REG); + }while(ir_flag); +} + +/******************************************************************************* +*Function name: w5500_load_param +*Description: load param to w5500_param +*Input: src: source param +*Output: None +*Return value: None +*******************************************************************************/ +void w5500_load_param(w5500_param_t *src) +{ + w5500_param_t *dest = &w5500_param; + memcpy(dest->ip_addr, src->ip_addr, sizeof(src->ip_addr)); + memcpy(dest->ip_mask, src->ip_mask, sizeof(src->ip_mask)); + memcpy(dest->gw_addr, src->gw_addr, sizeof(src->gw_addr)); + memcpy(dest->mac_addr, src->mac_addr, sizeof(src->mac_addr)); + memcpy(dest->sock.dst_ip, src->sock.dst_ip, sizeof(src->sock.dst_ip)); + dest->sock.local_port = src->sock.local_port; + dest->sock.dst_port = src->sock.dst_port; + dest->sock.mode = src->sock.mode; +} diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.h new file mode 100644 index 000000000..ca2e41599 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.h @@ -0,0 +1,299 @@ +/* +* Copyright (c) 2022 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file w5500.h +* @brief w5500 driver +* @version 1.0 +* @author AIIT XUOS Lab +* @date 2022-9-15 +*/ + +#ifndef _W5500_H_ +#define _W5500_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "k210_config.h" +#include "k210_fpioa.h" +#include "k210_gpiohs.h" +#include "nuttx/arch.h" +#include "k210_gpio_common.h" + +/***************** Common Register *****************/ +#define W5500_MR_REG 0x0000 +#define MR_RST 0x80 +#define MR_WOL 0x20 +#define MR_PB 0x10 +#define MR_PPP 0x08 +#define MR_FARP 0x02 + +#define W5500_GAR_REG 0x0001 +#define W5500_SUBR_REG 0x0005 +#define W5500_SHAR_REG 0x0009 +#define W5500_SIPR_REG 0x000f + +#define W5500_INT_REG 0x0013 + +#define W5500_IR_REG 0x0015 +#define IR_CONFLICT 0x80 +#define IR_UNREACH 0x40 +#define IR_PPPOE 0x20 +#define IR_MP 0x10 + +#define W5500_IMR_REG 0x0016 +#define IMR_IR7 0x80 +#define IMR_IR6 0x40 +#define IMR_IR5 0x20 +#define IMR_IR4 0x10 + +#define W5500_SIR_REG 0x0017 +#define S7_INT 0x80 +#define S6_INT 0x40 +#define S5_INT 0x20 +#define S4_INT 0x10 +#define S3_INT 0x08 +#define S2_INT 0x04 +#define S1_INT 0x02 +#define S0_INT 0x01 + +#define W5500_SIMR_REG 0x0018 +#define S7_IMR 0x80 +#define S6_IMR 0x40 +#define S5_IMR 0x20 +#define S4_IMR 0x10 +#define S3_IMR 0x08 +#define S2_IMR 0x04 +#define S1_IMR 0x02 +#define S0_IMR 0x01 + +#define W5500_RTR_REG 0x0019 +#define W5500_RCR_REG 0x001B + +#define W5500_PTIMER_REG 0x001C +#define W5500_PMAGIC_REG 0x001D +#define W5500_PHA_REG 0x001E +#define W5500_PSID_REG 0x0024 +#define W5500_PMRU_REG 0x0026 + +#define W5500_UIPR_REG 0x0028 +#define W5500_UPORT_REG 0x002C + +#define W5500_PHYCFGR_REG 0x002E +#define RST_PHY 0x80 +#define OPMODE 0x40 +#define DPX 0x04 +#define SPD 0x02 +#define LINK 0x01 + +#define W5500_VER_REG 0x0039 + +/********************* Socket Register *******************/ +#define W5500_SN_MR_REG 0x0000 +#define SN_MR_MULTI_MFEN 0x80 +#define SN_MR_BCASTB 0x40 +#define SN_MR_ND_MC_MMB 0x20 +#define SN_MR_UCASTB_MIP6B 0x10 +#define SN_MR_CLOSE 0x00 +#define SN_MR_TCP 0x01 +#define SN_MR_UDP 0x02 +#define SN_MR_MACRAW 0x04 + +#define W5500_SN_CR_REG 0x0001 +#define SN_CR_OPEN 0x01 +#define SN_CR_LISTEN 0x02 +#define SN_CR_CONNECT 0x04 +#define SN_CR_DISCON 0x08 +#define SN_CR_CLOSE 0x10 +#define SN_CR_SEND 0x20 +#define SN_CR_SEND_MAC 0x21 +#define SN_CR_SEND_KEEP 0x22 +#define SN_CR_RECV 0x40 + +#define W5500_SN_IR_REG 0x0002 +#define IR_SEND_OK 0x10 +#define IR_TIMEOUT 0x08 +#define IR_RECV 0x04 +#define IR_DISCON 0x02 +#define IR_CON 0x01 + +#define W5500_SN_SR_REG 0x0003 +#define SOCK_CLOSED 0x00 +#define SOCK_INIT 0x13 +#define SOCK_LISTEN 0x14 +#define SOCK_ESTABLISHED 0x17 +#define SOCK_CLOSE_WAIT 0x1C +#define SOCK_UDP 0x22 +#define SOCK_MACRAW 0x02 + +#define SOCK_SYNSEND 0x15 +#define SOCK_SYNRECV 0x16 +#define SOCK_FIN_WAI 0x18 +#define SOCK_CLOSING 0x1A +#define SOCK_TIME_WAIT 0x1B +#define SOCK_LAST_ACK 0x1D + +#define W5500_SN_PORT_REG 0x0004 +#define W5500_SN_DHAR_REG 0x0006 +#define W5500_SN_DIPR_REG 0x000C +#define W5500_SN_DPORTR_REG 0x0010 + +#define W5500_SN_MSSR_REG 0x0012 +#define W5500_SN_TOS_REG 0x0015 +#define W5500_SN_TTL_REG 0x0016 + +#define W5500_SN_RXBUF_SIZE_REG 0x001E +#define W5500_SN_TXBUF_SIZE_REG 0x001F +#define W5500_SN_TX_FSR_REG 0x0020 +#define W5500_SN_TX_RD_REG 0x0022 +#define W5500_SN_TX_WR_REG 0x0024 +#define W5500_SN_RX_RSR_REG 0x0026 +#define W5500_SN_RX_RD_REG 0x0028 +#define W5500_SN_RX_WR_REG 0x002A + +#define W5500_SN_IMR_REG 0x002C +#define IMR_SENDOK 0x10 +#define IMR_TIMEOUT 0x08 +#define IMR_RECV 0x04 +#define IMR_DISCON 0x02 +#define IMR_CON 0x01 + +#define W5500_SN_FRAG_REG 0x002D +#define W5500_SN_KPALVTR_REG 0x002F + +/************************ SPI Control Data *************************/ + +/* Operation mode bits */ + +#define VDM 0x00 +#define FDM1 0x01 +#define FDM2 0x02 +#define FDM4 0x03 + +/* Read_Write control bit */ +#define RWB_READ 0x00 +#define RWB_WRITE 0x04 + +/* Block select bits */ +#define COMMON_R 0x00 + +/* Socket 0 */ +#define S0_REG 0x08 +#define S0_TX_BUF 0x10 +#define S0_RX_BUF 0x18 + +/* Socket 1 */ +#define S1_REG 0x28 +#define S1_TX_BUF 0x30 +#define S1_RX_BUF 0x38 + +/* Socket 2 */ +#define S2_REG 0x48 +#define S2_TX_BUF 0x50 +#define S2_RX_BUF 0x58 + +/* Socket 3 */ +#define S3_REG 0x68 +#define S3_TX_BUF 0x70 +#define S3_RX_BUF 0x78 + +/* Socket 4 */ +#define S4_REG 0x88 +#define S4_TX_BUF 0x90 +#define S4_RX_BUF 0x98 + +/* Socket 5 */ +#define S5_REG 0xa8 +#define S5_TX_BUF 0xb0 +#define S5_RX_BUF 0xb8 + +/* Socket 6 */ +#define S6_REG 0xc8 +#define S6_TX_BUF 0xd0 +#define S6_RX_BUF 0xd8 + +/* Socket 7 */ +#define S7_REG 0xe8 +#define S7_TX_BUF 0xf0 +#define S7_RX_BUF 0xf8 + +// socket receive buffer size based on RMSR +#define SOCK_RECV_SIZE 2048 +// socket send buffer size based on RMSR +#define SOCK_SEND_SIZE 2048 + +#define W5500_IP_ADDR_LEN 4 +#define W5500_IP_MASK_LEN 4 +#define W5500_GW_ADDR_LEN 4 +#define W5500_MAC_ADDR_LEN 6 + +//for every socket + +// socket mode +#define SOCK_TCP_SVR 0 //server mode +#define SOCK_TCP_CLI 1 //client mode +#define SOCK_UDP_MOD 2 //udp mode + +// socket flag +#define SOCK_FLAG_INIT 1 +#define SOCK_FLAG_CONN 2 + +// socket data state +#define SOCK_STAT_RECV 1 +#define SOCK_STAT_SEND 2 + +typedef struct w5500_socket_s +{ + uint16_t local_port; + uint8_t dst_ip[W5500_IP_ADDR_LEN]; + uint16_t dst_port; + uint8_t mode; // 0: TCP Server; 1: TCP client; 2: UDP + uint8_t flag; // 1: init ok; 2: connected + uint8_t state; // 1: receive one; 2: send ok +}w5500_socket_t; + +typedef struct +{ + uint8_t ip_addr[W5500_IP_ADDR_LEN]; + uint8_t ip_mask[W5500_IP_MASK_LEN]; + uint8_t gw_addr[W5500_GW_ADDR_LEN]; + uint8_t mac_addr[W5500_MAC_ADDR_LEN]; + uint8_t udp_ip[4]; + uint16_t udp_port; + w5500_socket_t sock; +}w5500_param_t; + + +#define W5500_MAX_PACK_SIZE 1460 +typedef unsigned char socket_t; + +#define NCS_L() k210_gpiohs_set_value(FPIOA_ENET_NCS, GPIO_PV_LOW); up_udelay(1); +#define NCS_H() k210_gpiohs_set_value(FPIOA_ENET_NCS, GPIO_PV_HIGH); up_udelay(1); +#define SCLK_L() k210_gpiohs_set_value(FPIOA_ENET_SCLK, GPIO_PV_LOW); up_udelay(1); +#define SCLK_H() k210_gpiohs_set_value(FPIOA_ENET_SCLK, GPIO_PV_HIGH); up_udelay(1); +#define MOSI_L() k210_gpiohs_set_value(FPIOA_ENET_MOSI, GPIO_PV_LOW); up_udelay(1); +#define MOSI_H() k210_gpiohs_set_value(FPIOA_ENET_MOSI, GPIO_PV_HIGH); up_udelay(1); +#define RST_L() k210_gpiohs_set_value(FPIOA_ENET_NRST, GPIO_PV_LOW); up_mdelay(200); +#define RST_H() k210_gpiohs_set_value(FPIOA_ENET_NRST, GPIO_PV_HIGH); up_mdelay(200); + +int w5500_net_test(void); + +#endif From f573bc391c768dff5ce0345509ba7c47d9a9201f Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 17 Oct 2022 11:28:16 +0800 Subject: [PATCH 22/30] add w5500 for xidatong-riscv64 --- .../aiit_board/xidatong-riscv64/src/Makefile | 2 +- .../src/{w5500.c => k210_w5500.c} | 176 ++++++++++++++++-- .../src/{w5500.h => k210_w5500.h} | 27 ++- 3 files changed, 185 insertions(+), 20 deletions(-) rename Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/{w5500.c => k210_w5500.c} (78%) rename Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/{w5500.h => k210_w5500.h} (87%) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile index bf7a0eb95..b3bd1fa1f 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile @@ -51,6 +51,6 @@ CSRCS += k210_ch376.c ch376_demo.c endif ifeq ($(CONFIG_BSP_USING_ENET),y) -CSRCS += w5500.c +CSRCS += k210_w5500.c endif include $(TOPDIR)/boards/Board.mk diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.c similarity index 78% rename from Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.c rename to Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.c index 720152814..12cb92c6f 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.c @@ -11,7 +11,7 @@ */ /** -* @file w5500.c +* @file k210_w5500.c * @brief w5500 driver based on simulated SPI * @version 1.0 * @author AIIT XUOS Lab @@ -19,7 +19,7 @@ */ #include "nuttx/arch.h" -#include "w5500.h" +#include "k210_w5500.h" #include "k210_gpio_common.h" /**************************************************************************** @@ -27,6 +27,18 @@ ****************************************************************************/ w5500_param_t w5500_param; +static uint8_t rx_buf[30]; +static uint8_t tx_buf[30]; + +static uint8_t config_ip_addr[] = {10, 0, 30, 50}; +static uint8_t config_ip_mask[] = {255, 255, 255, 0}; +static uint8_t config_gw_addr[] = {10, 0, 30, 1}; +static uint8_t config_mac_addr[] = {0x0C, 0x29, 0xAB, 0x7C, 0x00, 0x01}; +static uint8_t config_dst_ip[] = {10, 0, 30, 57}; +static uint16_t config_local_port = 5000; +static uint16_t config_dst_port = 6000; +static uint8_t config_mode = SOCK_TCP_CLI; + /**************************************************************************** * Name: spi_read_byte * Description: Read one byte spi data returned @@ -663,21 +675,155 @@ void w5500_irq_process(void) } /******************************************************************************* -*Function name: w5500_load_param -*Description: load param to w5500_param -*Input: src: source param +*Function name: w5500_intialization +*Description: W5500 initial configuration +*Input: None *Output: None *Return value: None *******************************************************************************/ -void w5500_load_param(w5500_param_t *src) +void w5500_intialization(void) { - w5500_param_t *dest = &w5500_param; - memcpy(dest->ip_addr, src->ip_addr, sizeof(src->ip_addr)); - memcpy(dest->ip_mask, src->ip_mask, sizeof(src->ip_mask)); - memcpy(dest->gw_addr, src->gw_addr, sizeof(src->gw_addr)); - memcpy(dest->mac_addr, src->mac_addr, sizeof(src->mac_addr)); - memcpy(dest->sock.dst_ip, src->sock.dst_ip, sizeof(src->sock.dst_ip)); - dest->sock.local_port = src->sock.local_port; - dest->sock.dst_port = src->sock.dst_port; - dest->sock.mode = src->sock.mode; + w5500_config_init(); + w5500_detect_gateway(); + w5500_socket_init(0); +} + +/******************************************************************************* +*Function name: w5500_load_param +*Description: load param to w5500_param +*Input: None +*Output: None +*Return value: None +*******************************************************************************/ +void w5500_load_param(void) +{ + w5500_param_t *param = &w5500_param; + memcpy(param->ip_addr, config_ip_addr, sizeof(config_ip_addr)); + memcpy(param->ip_mask, config_ip_mask, sizeof(config_ip_mask)); + memcpy(param->gw_addr, config_gw_addr, sizeof(config_gw_addr)); + memcpy(param->mac_addr, config_mac_addr, sizeof(config_mac_addr)); + memcpy(param->sock.dst_ip, config_dst_ip, sizeof(config_dst_ip)); + param->sock.local_port = config_local_port; + param->sock.dst_port = config_dst_port; + param->sock.mode = config_mode; +} + +/******************************************************************************* +*Function name: w5500_socket_config +*Description: W5500 port initialization configuration +*Input: None +*Output: None +*Return value: None +*******************************************************************************/ +void w5500_socket_config(void) +{ + if(w5500_param.sock.flag == 0) + { + /* TCP Sever */ + if(w5500_param.sock.mode == SOCK_TCP_SVR) + { + if(w5500_socket_listen(0) == TRUE) + w5500_param.sock.flag = SOCK_FLAG_INIT; + else + w5500_param.sock.flag = 0; + } + + /* TCP Client */ + else if(w5500_param.sock.mode == SOCK_TCP_CLI) + { + if(w5500_socket_connect(0) == TRUE) + w5500_param.sock.flag = SOCK_FLAG_INIT; + else + w5500_param.sock.flag = 0; + } + + /* UDP */ + else + { + if(w5500_socket_set_udp(0) == TRUE) + w5500_param.sock.flag = SOCK_FLAG_INIT|SOCK_FLAG_CONN; + else + w5500_param.sock.flag = 0; + } + } +} + +/******************************************************************************* +*Function name: Process_Socket_Data +*Description: W5500 receives and sends the received data +*Input: sock: port number +*Output: None +*Return value: None +*******************************************************************************/ +void Process_Socket_Data(socket_t sock) +{ + uint16_t size; + size = w5500_read_sock_bytes(sock, rx_buf); + memcpy(tx_buf, rx_buf, size); + w5500_write_sock_bytes(sock, tx_buf, size); +} + +/**************************************************************************** + * Name: SPI_Configuration + * Description: spi pin mode configure + * input: None + * output: None + * return:none + ****************************************************************************/ +void SPI_Configuration(void) +{ + /* simluate SPI bus */ + k210_fpioa_config(BSP_ENET_SCLK, HS_GPIO(FPIOA_ENET_SCLK) | K210_IOFLAG_GPIOHS); + k210_fpioa_config(BSP_ENET_NRST, HS_GPIO(FPIOA_ENET_NRST) | K210_IOFLAG_GPIOHS); + k210_fpioa_config(BSP_ENET_MOSI, HS_GPIO(FPIOA_ENET_MOSI) | K210_IOFLAG_GPIOHS); + k210_fpioa_config(BSP_ENET_MISO, HS_GPIO(FPIOA_ENET_MISO) | K210_IOFLAG_GPIOHS); + k210_fpioa_config(BSP_ENET_NCS, HS_GPIO(FPIOA_ENET_NCS) | K210_IOFLAG_GPIOHS); + k210_fpioa_config(BSP_ENET_NINT, HS_GPIO(FPIOA_ENET_NINT) | K210_IOFLAG_GPIOHS); + + k210_gpiohs_set_direction(FPIOA_ENET_MISO, GPIO_DM_INPUT); + k210_gpiohs_set_direction(FPIOA_ENET_NRST, GPIO_DM_OUTPUT); + k210_gpiohs_set_direction(FPIOA_ENET_SCLK, GPIO_DM_OUTPUT); + k210_gpiohs_set_direction(FPIOA_ENET_MOSI, GPIO_DM_OUTPUT); + k210_gpiohs_set_direction(FPIOA_ENET_NCS, GPIO_DM_OUTPUT); + k210_gpiohs_set_direction(FPIOA_ENET_NINT, GPIO_DM_INPUT); + + k210_gpiohs_set_value(FPIOA_ENET_SCLK, GPIO_PV_HIGH); + k210_gpiohs_set_value(FPIOA_ENET_MOSI, GPIO_PV_HIGH); + k210_gpiohs_set_value(FPIOA_ENET_NCS, GPIO_PV_LOW); + k210_gpiohs_set_value(FPIOA_ENET_NRST, GPIO_PV_HIGH); +} + +void w5500_test(void) +{ + uint32_t cnt = 0; + SPI_Configuration(); + w5500_load_param(); + w5500_reset(); + w5500_intialization(); + while(1) + { + w5500_socket_config(); + w5500_irq_process(); + + if((w5500_param.sock.state & SOCK_STAT_RECV) == SOCK_STAT_RECV) + { + w5500_param.sock.state &= ~SOCK_STAT_RECV; + Process_Socket_Data(0); + } + + else if(cnt >= 10) + { + if(w5500_param.sock.flag == (SOCK_FLAG_INIT|SOCK_FLAG_CONN)) + { + w5500_param.sock.state &= ~SOCK_STAT_SEND; + memcpy(tx_buf, "\r\nWelcome To internet!\r\n", 21); + w5500_write_sock_bytes(0, tx_buf, 21); + break; + } + cnt = 0; + } + up_mdelay(1000); + cnt++; + } + } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.h similarity index 87% rename from Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.h rename to Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.h index ca2e41599..0e8ad87f1 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/w5500.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.h @@ -11,15 +11,15 @@ */ /** -* @file w5500.h +* @file k210_w5500.h * @brief w5500 driver * @version 1.0 * @author AIIT XUOS Lab * @date 2022-9-15 */ -#ifndef _W5500_H_ -#define _W5500_H_ +#ifndef _K210_W5500_H_ +#define _K210_W5500_H_ #include #include @@ -294,6 +294,25 @@ typedef unsigned char socket_t; #define RST_L() k210_gpiohs_set_value(FPIOA_ENET_NRST, GPIO_PV_LOW); up_mdelay(200); #define RST_H() k210_gpiohs_set_value(FPIOA_ENET_NRST, GPIO_PV_HIGH); up_mdelay(200); -int w5500_net_test(void); +void w5500_write_sock_byte(socket_t sock, uint16_t reg, uint8_t dat); +void w5500_write_sock_short(socket_t sock, uint16_t reg, uint16_t dat); +void w5500_write_sock_long(socket_t sock, uint16_t reg, uint8_t *dat); +uint8_t w5500_read_byte(uint16_t reg); +uint8_t w5500_read_sock_byte(socket_t sock, uint16_t reg); +uint16_t w5500_read_sock_short(socket_t sock, uint16_t reg); +void w5500_write_sock_bytes(socket_t sock, uint8_t *dat, uint16_t size); +void w5500_reset(void); +void w5500_config_init(void); +uint8_t w5500_detect_gateway(void); +void w5500_socket_init(socket_t sock); +uint8_t w5500_socket_connect(socket_t sock); +uint8_t w5500_socket_listen(socket_t sock); +uint8_t w5500_socket_set_udp(socket_t sock); +void w5500_irq_process(void); +void w5500_intialization(void); +void w5500_load_param(void); +void w5500_socket_config(void); +void Process_Socket_Data(socket_t sock); +void SPI_Configuration(void); #endif From b7a3657c831f3c3a826882e5a8d3dc254183903c Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 17 Oct 2022 17:22:28 +0800 Subject: [PATCH 23/30] add w5500 cmd to nuttx shell --- .../xidatong-riscv64/include/board.h | 12 ++-- .../xidatong-riscv64/src/k210_w5500.c | 69 +++++++++++-------- .../xidatong-riscv64/src/k210_w5500.h | 3 +- .../app_match_nuttx/apps/nshlib/Kconfig | 4 ++ .../app_match_nuttx/apps/nshlib/nsh.h | 4 ++ .../apps/nshlib/nsh_Applicationscmd.c | 13 ++++ .../app_match_nuttx/apps/nshlib/nsh_command.c | 4 ++ 7 files changed, 73 insertions(+), 36 deletions(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h index b3b197955..32d32f02f 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h @@ -146,12 +146,12 @@ extern "C" #define FPIOA_CH438_INT 22 /* w5500 FPIOA */ -#define FPIOA_ENET_NRST 5 -#define FPIOA_ENET_NINT 6 -#define FPIOA_ENET_SCLK 7 -#define FPIOA_ENET_MISO 8 -#define FPIOA_ENET_MOSI 9 -#define FPIOA_ENET_NCS 10 +#define FPIOA_ENET_NRST 0 +#define FPIOA_ENET_NINT 9 +#define FPIOA_ENET_SCLK 28 +#define FPIOA_ENET_MISO 29 +#define FPIOA_ENET_MOSI 23 +#define FPIOA_ENET_NCS 31 /* other mode FPIOA */ #define FPIOA_E220_M0 1 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.c index 12cb92c6f..755404f91 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.c @@ -27,8 +27,8 @@ ****************************************************************************/ w5500_param_t w5500_param; -static uint8_t rx_buf[30]; -static uint8_t tx_buf[30]; +static uint8_t rx_buf[256]; +static uint8_t tx_buf[256]; static uint8_t config_ip_addr[] = {10, 0, 30, 50}; static uint8_t config_ip_mask[] = {255, 255, 255, 0}; @@ -283,7 +283,7 @@ uint16_t w5500_read_sock_bytes(socket_t sock, uint8_t *dat) uint8_t val; recv_size = w5500_read_sock_short(sock, W5500_SN_RX_RSR_REG); - //no receive data + /* no receive data */ if(recv_size == 0) { return 0; @@ -297,7 +297,7 @@ uint16_t w5500_read_sock_bytes(socket_t sock, uint8_t *dat) recv_addr = w5500_read_sock_short(sock, W5500_SN_RX_RD_REG); write_addr = recv_addr; - //calculate physical address + /* calculate physical address */ recv_addr &= (SOCK_RECV_SIZE - 1); NCS_L(); spi_write_short(recv_addr); @@ -340,7 +340,7 @@ uint16_t w5500_read_sock_bytes(socket_t sock, uint8_t *dat) write_addr += recv_size; w5500_write_sock_short(sock, W5500_SN_RX_RD_REG, write_addr); - //start receive + /* start receive */ w5500_write_sock_byte(sock, W5500_SN_CR_REG, SN_CR_RECV); return recv_size; } @@ -357,7 +357,7 @@ void w5500_write_sock_bytes(socket_t sock, uint8_t *dat, uint16_t size) uint16_t recv_addr, write_addr; uint16_t i; - // if udp mode, set ip and port + /* if udp mode, set ip and port */ if(w5500_read_sock_byte(sock, W5500_SN_MR_REG) != SOCK_UDP) { w5500_write_sock_long(sock, W5500_SN_DIPR_REG, w5500_param.udp_ip); @@ -422,7 +422,7 @@ void w5500_reset(void) RST_L(); RST_H(); - //wait connect ok + /* wait connect ok */ while((dat & LINK) == 0) { up_mdelay(500); @@ -442,7 +442,7 @@ void w5500_config_init(void) { uint8_t i = 0; - //software reset, set 1 and auto clear 0 + /* software reset, set 1 and auto clear 0 */ w5500_write_byte(W5500_MR_REG, MR_RST); up_mdelay(100); @@ -451,17 +451,17 @@ void w5500_config_init(void) w5500_write_bytes(W5500_SHAR_REG, w5500_param.mac_addr, 6); w5500_write_bytes(W5500_SIPR_REG, w5500_param.ip_addr, 4); - //set socket rx and tx memory size 2k + /* set socket rx and tx memory size 2k */ for(i = 0; i < 8; i++) { w5500_write_sock_byte(i, W5500_SN_RXBUF_SIZE_REG, 0x02); w5500_write_sock_byte(i, W5500_SN_TXBUF_SIZE_REG, 0x02); } - //set retry time 200ms (0x07d0 = 2000) + /* set retry time 200ms (0x07d0 = 2000) */ w5500_write_short(W5500_RTR_REG, 0x07d0); - //retry time with 8, when exceed it, produce overtime interrupt, set W5500_SN_IR_REG(TIMEOUT) + /* retry time with 8, when exceed it, produce overtime interrupt, set W5500_SN_IR_REG(TIMEOUT) */ w5500_write_byte(W5500_RCR_REG, 8); } @@ -476,7 +476,7 @@ uint8_t w5500_detect_gateway(void) { uint8_t ip_addr[4] = {w5500_param.ip_addr[0] + 1, w5500_param.ip_addr[1] + 1, w5500_param.ip_addr[2] + 1, w5500_param.ip_addr[3] + 1}; - //check gateway and get gateway phyiscal address + /* check gateway and get gateway phyiscal address */ w5500_write_sock_long(0, W5500_SN_DIPR_REG, ip_addr); w5500_write_sock_byte(0, W5500_SN_MR_REG, SN_MR_TCP); w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_OPEN); @@ -488,13 +488,13 @@ uint8_t w5500_detect_gateway(void) return FALSE; } - //set socket connection mode + /* set socket connection mode */ w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CONNECT); do { uint8_t val = 0; - //read socket0 interrupt register + /* read socket0 interrupt register */ val = w5500_read_sock_byte(0, W5500_SN_IR_REG); if(val != 0) @@ -510,7 +510,7 @@ uint8_t w5500_detect_gateway(void) } else if(w5500_read_sock_byte(0, W5500_SN_DHAR_REG) != 0xff) { - //close socket + /* close socket */ w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CLOSE); return TRUE; } @@ -527,7 +527,7 @@ uint8_t w5500_detect_gateway(void) *******************************************************************************/ void w5500_socket_init(socket_t sock) { - //max partition bytes = 30 + /* max partition bytes = 30 */ w5500_write_sock_short(0, W5500_SN_MSSR_REG, 30); switch(sock) @@ -632,7 +632,7 @@ void w5500_irq_process(void) ir_flag = w5500_read_byte(W5500_SIR_REG); do { - //handle socket0 event + /* handle socket0 event */ if((ir_flag & S0_INT) == S0_INT) { sn_flag = w5500_read_sock_byte(0, W5500_SN_IR_REG); @@ -640,13 +640,13 @@ void w5500_irq_process(void) if(sn_flag & IR_CON) { - //socket connection finished + /* socket connection finished */ w5500_param.sock.flag |= SOCK_FLAG_CONN; } if(sn_flag & IR_DISCON) { - //disconnect state + /* disconnect state */ w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CLOSE); w5500_socket_init(0); w5500_param.sock.flag = 0; @@ -654,7 +654,7 @@ void w5500_irq_process(void) if(sn_flag & IR_SEND_OK) { - //send one package ok + /* send one package ok */ w5500_param.sock.state |= SOCK_STAT_SEND; } @@ -665,7 +665,7 @@ void w5500_irq_process(void) if(sn_flag & IR_TIMEOUT) { - //close socket, connection failed + /* close socket, connection failed */ w5500_write_sock_byte(0, W5500_SN_CR_REG, SN_CR_CLOSE); w5500_param.sock.flag = 0; } @@ -753,14 +753,17 @@ void w5500_socket_config(void) *Description: W5500 receives and sends the received data *Input: sock: port number *Output: None -*Return value: None +*Return value: receive data length *******************************************************************************/ -void Process_Socket_Data(socket_t sock) +uint16_t Process_Socket_Data(socket_t sock) { uint16_t size; size = w5500_read_sock_bytes(sock, rx_buf); memcpy(tx_buf, rx_buf, size); w5500_write_sock_bytes(sock, tx_buf, size); + + return size; + } /**************************************************************************** @@ -772,7 +775,7 @@ void Process_Socket_Data(socket_t sock) ****************************************************************************/ void SPI_Configuration(void) { - /* simluate SPI bus */ + /* config simluate SPI bus */ k210_fpioa_config(BSP_ENET_SCLK, HS_GPIO(FPIOA_ENET_SCLK) | K210_IOFLAG_GPIOHS); k210_fpioa_config(BSP_ENET_NRST, HS_GPIO(FPIOA_ENET_NRST) | K210_IOFLAG_GPIOHS); k210_fpioa_config(BSP_ENET_MOSI, HS_GPIO(FPIOA_ENET_MOSI) | K210_IOFLAG_GPIOHS); @@ -795,7 +798,8 @@ void SPI_Configuration(void) void w5500_test(void) { - uint32_t cnt = 0; + uint8_t cnt = 0; + uint8_t length = 0; SPI_Configuration(); w5500_load_param(); w5500_reset(); @@ -805,24 +809,31 @@ void w5500_test(void) w5500_socket_config(); w5500_irq_process(); + /* If Socket0 receives data */ if((w5500_param.sock.state & SOCK_STAT_RECV) == SOCK_STAT_RECV) { w5500_param.sock.state &= ~SOCK_STAT_RECV; - Process_Socket_Data(0); + length = Process_Socket_Data(0); + printf("w5500 receive: "); + for(int i = 0; i < length; i++) + { + printf("%x ", rx_buf[i]); + } + printf("\n"); } - else if(cnt >= 10) + /* Otherwise, send data regularly */ + else if(cnt >= 5) { if(w5500_param.sock.flag == (SOCK_FLAG_INIT|SOCK_FLAG_CONN)) { w5500_param.sock.state &= ~SOCK_STAT_SEND; memcpy(tx_buf, "\r\nWelcome To internet!\r\n", 21); w5500_write_sock_bytes(0, tx_buf, 21); - break; } cnt = 0; } - up_mdelay(1000); + up_mdelay(100); cnt++; } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.h index 0e8ad87f1..86e238b03 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_w5500.h @@ -312,7 +312,8 @@ void w5500_irq_process(void); void w5500_intialization(void); void w5500_load_param(void); void w5500_socket_config(void); -void Process_Socket_Data(socket_t sock); +uint16_t Process_Socket_Data(socket_t sock); void SPI_Configuration(void); +void w5500_test(void); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig index e0e603faf..eb17d6b8a 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig @@ -551,6 +551,10 @@ config NSH_DISABLE_CH376 bool "Disable the ch376 demo." default n +config NSH_DISABLE_W5500 + bool "Disable the w5500 demo." + default n + config NSH_DISABLE_CH438 bool "Disable the ch438 demo." default n diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index 0df886d26..fbb8043c5 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1454,6 +1454,10 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, int cmd_Ch376(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif +#if defined(CONFIG_BSP_USING_ENET) && !defined(CONFIG_NSH_DISABLE_W5500) + int cmd_w5500(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + #if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 7bac913da..9b7dfa14b 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -51,6 +51,19 @@ int cmd_Ch376(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +/**************************************************************************** + * Name: cmd_w5500 + ****************************************************************************/ +#if defined(CONFIG_BSP_USING_ENET) && !defined(CONFIG_NSH_DISABLE_W5500) +extern void w5500_test(void); +int cmd_w5500(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, world!\n"); + w5500_test(); + return OK; +} +#endif + /**************************************************************************** * Name: cmd_Ch438 ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index c0132baf6..c8d5eee23 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -600,6 +600,10 @@ static const struct cmdmap_s g_cmdmap[] = { "ch376", cmd_Ch376, 1, 1, "[ch376 demo cmd.]" }, #endif +#if defined(CONFIG_BSP_USING_ENET) && !defined(CONFIG_NSH_DISABLE_W5500) + { "w5500", cmd_w5500, 1, 1, "[w5500 demo cmd.]" }, +#endif + #if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) { "ch438", cmd_Ch438, 1, 1, "[ch438 demo cmd.]" }, #endif From deb247165aaedda2bfdd84fb67502d74a01e2ab0 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 17 Oct 2022 18:16:28 +0800 Subject: [PATCH 24/30] add ch376 and w5500 defconfig --- .../configs/ch376nsh/defconfig | 63 +++++++++++++++++++ .../configs/w5500nsh/defconfig | 61 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/ch376nsh/defconfig create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/w5500nsh/defconfig diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/ch376nsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/ch376nsh/defconfig new file mode 100644 index 000000000..b9aefbaa3 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/ch376nsh/defconfig @@ -0,0 +1,63 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_DISABLE_LOSMART is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ADD_NUTTX_FETURES=y +CONFIG_ARCH="risc-v" +CONFIG_ARCH_BOARD="xidatong-riscv64" +CONFIG_ARCH_BOARD_XIDATONG_RISCV64=y +CONFIG_ARCH_CHIP="k210" +CONFIG_ARCH_CHIP_K210=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BINFMT_DISABLE=y +CONFIG_BOARD_LOOPSPERMSEC=46000 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_IFUPDOWN=y +CONFIG_NSH_DISABLE_MKDIR=y +CONFIG_NSH_DISABLE_RM=y +CONFIG_NSH_DISABLE_RMDIR=y +CONFIG_NSH_DISABLE_UMOUNT=y +CONFIG_NSH_READLINE=y +CONFIG_NSH_STRERROR=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=2097152 +CONFIG_RAM_START=0x80400000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=100 +CONFIG_READLINE_CMD_HISTORY_LINELEN=120 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=28 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2019 +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=20 +CONFIG_TESTING_GETPRIME=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SCHED_HPWORK=y +CONFIG_DEV_GPIO=y +CONFIG_BOARDCTL_RESET=y +CONFIG_BSP_USING_CH376=y +CONFIG_CH376_USB_FUNCTION=y +CONFIG_CH376_WORK_MODE=0x06 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/w5500nsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/w5500nsh/defconfig new file mode 100644 index 000000000..6075ce1b8 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/w5500nsh/defconfig @@ -0,0 +1,61 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_DISABLE_LOSMART is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ADD_NUTTX_FETURES=y +CONFIG_ARCH="risc-v" +CONFIG_ARCH_BOARD="xidatong-riscv64" +CONFIG_ARCH_BOARD_XIDATONG_RISCV64=y +CONFIG_ARCH_CHIP="k210" +CONFIG_ARCH_CHIP_K210=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BINFMT_DISABLE=y +CONFIG_BOARD_LOOPSPERMSEC=46000 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_IFUPDOWN=y +CONFIG_NSH_DISABLE_MKDIR=y +CONFIG_NSH_DISABLE_RM=y +CONFIG_NSH_DISABLE_RMDIR=y +CONFIG_NSH_DISABLE_UMOUNT=y +CONFIG_NSH_READLINE=y +CONFIG_NSH_STRERROR=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=2097152 +CONFIG_RAM_START=0x80400000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=100 +CONFIG_READLINE_CMD_HISTORY_LINELEN=120 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=28 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2019 +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=20 +CONFIG_TESTING_GETPRIME=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SCHED_HPWORK=y +CONFIG_DEV_GPIO=y +CONFIG_BOARDCTL_RESET=y +CONFIG_BSP_USING_ENET=y From a4f183c62a7abd724d37f9f8d538dc13668bf083 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Thu, 20 Oct 2022 16:35:05 +0800 Subject: [PATCH 25/30] resolve Conflicts --- .../app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 23157bfeb..bf665058e 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -352,7 +352,7 @@ int cmd_recvzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif -#if (defined(CONFIG_ADAPTER_ESP07S_WIFI) || defined(CONFIG_ADAPTER_ESP8285_WIFI)) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) +#if defined(CONFIG_ADAPTER_ESP07S_WIFI) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) extern int AdapterWifiTest(int argc, char *argv[]); int cmd_AdapterWifiTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { From df32ed24ed411d55e659418e665c7e6c4759346c Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Thu, 20 Oct 2022 16:45:14 +0800 Subject: [PATCH 26/30] change nsh_Applicationscmd.c --- .../app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 254255532..1f9bfe2ff 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -389,7 +389,7 @@ int cmd_recvzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif -#if defined(CONFIG_ADAPTER_ESP07S_WIFI) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) +#if (defined(CONFIG_ADAPTER_ESP07S_WIFI) || defined(CONFIG_ADAPTER_ESP8285_WIFI)) && !defined(CONFIG_NSH_DISABLE_ADAPTER_WIFI_TEST) extern int AdapterWifiTestWithParam(int argc, char *argv[]); int cmd_AdapterWifiTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { From c815bb3b6e8a4b322f8cd690a5f220aff5262dbe Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Fri, 21 Oct 2022 18:13:41 +0800 Subject: [PATCH 27/30] support gpio on k210 on nuttx --- .../nuttx/arch/risc-v/src/k210/k210_gpio.c | 152 ++++++++++------- .../nuttx/arch/risc-v/src/k210/k210_gpio.h | 157 +++++++++++++----- 2 files changed, 206 insertions(+), 103 deletions(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_gpio.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_gpio.c index b79966c01..eb3c0e93e 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_gpio.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_gpio.c @@ -39,82 +39,110 @@ #include "k210_memorymap.h" #include "k210_gpio.h" #include "k210_fpioa.h" +#include "k210_sysctl.h" + +#define GPIO_MAX_PINNO 8 /**************************************************************************** - * Pre-processor Definitions + * Private Function declaration ****************************************************************************/ - -#define GPIO_INPUT_VAL_OFFSET 0x00 -#define GPIO_INPUT_EN_OFFSET 0x04 -#define GPIO_OUTPUT_EN_OFFSET 0x08 -#define GPIO_OUTPUT_VAL_OFFSET 0x0c -#define GPIO_PULLUP_EN_OFFSET 0x10 -#define GPIO_DRIVE_OFFSET 0x14 - -#define GPIO_INPUT (K210_GPIO_BASE + GPIO_INPUT_VAL_OFFSET) -#define GPIO_INPUT_EN (K210_GPIO_BASE + GPIO_INPUT_EN_OFFSET) -#define GPIO_OUTPUT (K210_GPIO_BASE + GPIO_OUTPUT_VAL_OFFSET) -#define GPIO_OUTPUT_EN (K210_GPIO_BASE + GPIO_OUTPUT_EN_OFFSET) +static void set_bit(volatile uint32_t *bits, uint32_t mask, uint32_t value); +static void set_bit_offset(volatile uint32_t *bits, uint32_t mask, size_t offset, uint32_t value); +static void set_gpio_bit(volatile uint32_t *bits, size_t offset, uint32_t value); +static uint32_t get_bit(volatile uint32_t *bits, uint32_t mask, size_t offset); +static uint32_t get_gpio_bit(volatile uint32_t *bits, size_t offset); /**************************************************************************** - * Public Functions + * Private Data ****************************************************************************/ -void k210_gpio_set_direction(uint32_t io, gpio_drive_mode_t mode) +volatile gpio_t *const gpio = (volatile gpio_t *)K210_GPIO_BASE; + +/**************************************************************************** + * Private Function definition + ****************************************************************************/ +static void set_bit(volatile uint32_t *bits, uint32_t mask, uint32_t value) { - DEBUGASSERT(io < K210_GPIO_MAX_PINNO); - int io_number = k210_fpioa_get_io_by_function(K210_IO_FUNC_GPIO0 + io); - DEBUGASSERT(io_number >= 0); - - fpioa_pull_t pull = FPIOA_PULL_NONE; - uint32_t dir = 0; - - switch (mode) - { - case GPIO_DM_INPUT: - pull = FPIOA_PULL_NONE; - dir = 0; - break; - case GPIO_DM_INPUT_PULL_DOWN: - pull = FPIOA_PULL_DOWN; - dir = 0; - break; - case GPIO_DM_INPUT_PULL_UP: - pull = FPIOA_PULL_UP; - dir = 0; - break; - case GPIO_DM_OUTPUT: - pull = FPIOA_PULL_DOWN; - dir = 1; - break; - default: - DEBUGASSERT(!"GPIO drive mode is not supported."); - break; - } - - fpioa_set_io_pull(io_number, pull); - uint32_t outbit = dir << io; - uint32_t inbit = (!dir) << io; - modifyreg32(GPIO_OUTPUT_EN, inbit, outbit); - modifyreg32(GPIO_INPUT_EN, outbit, inbit); + uint32_t org = (*bits) & ~mask; + *bits = org | (value & mask); } -void k210_gpio_set_value(uint32_t io, bool val) +static void set_bit_offset(volatile uint32_t *bits, uint32_t mask, size_t offset, uint32_t value) { - uint32_t setbit = val << io; - uint32_t clrbit = (!val) << io; - modifyreg32(GPIO_OUTPUT, clrbit, setbit); + set_bit(bits, mask << offset, value << offset); } -bool k210_gpio_get_value(uint32_t io) +static void set_gpio_bit(volatile uint32_t *bits, size_t offset, uint32_t value) { - uint32_t reg = getreg32(GPIO_INPUT); + set_bit_offset(bits, 1, offset, value); +} - if (reg & (1 << io)) +static uint32_t get_bit(volatile uint32_t *bits, uint32_t mask, size_t offset) +{ + return ((*bits) & (mask << offset)) >> offset; +} + +static uint32_t get_gpio_bit(volatile uint32_t *bits, size_t offset) +{ + return get_bit(bits, 1, offset); +} + + +/**************************************************************************** + * Public Function definition + ****************************************************************************/ +int gpio_init(void) +{ + return sysctl_clock_enable(SYSCTL_CLOCK_GPIO); +} + +void gpio_set_drive_mode(uint8_t pin, gpio_drive_mode_t mode) +{ + DEBUGASSERT(pin < GPIO_MAX_PINNO); + int io_number = fpioa_get_io_by_function(K210_IO_FUNC_GPIO0 + pin); + DEBUGASSERT(io_number >= 0); + + fpioa_pull_t pull; + uint32_t dir; + + switch(mode) { - return true; - } - else - { - return false; + case GPIO_DM_INPUT: + pull = FPIOA_PULL_NONE; + dir = 0; + break; + case GPIO_DM_INPUT_PULL_DOWN: + pull = FPIOA_PULL_DOWN; + dir = 0; + break; + case GPIO_DM_INPUT_PULL_UP: + pull = FPIOA_PULL_UP; + dir = 0; + break; + case GPIO_DM_OUTPUT: + pull = FPIOA_PULL_DOWN; + dir = 1; + break; + default: + break; } + + fpioa_set_io_pull(io_number, pull); + set_gpio_bit(gpio->direction.u32, pin, dir); +} + +gpio_pin_value_t gpio_get_pin(uint8_t pin) +{ + DEBUGASSERT(pin < GPIO_MAX_PINNO); + uint32_t dir = get_gpio_bit(gpio->direction.u32, pin); + volatile uint32_t *reg = dir ? gpio->data_output.u32 : gpio->data_input.u32; + return get_gpio_bit(reg, pin); +} + +void gpio_set_pin(uint8_t pin, gpio_pin_value_t value) +{ + DEBUGASSERT(pin < GPIO_MAX_PINNO); + uint32_t dir = get_gpio_bit(gpio->direction.u32, pin); + volatile uint32_t *reg = dir ? gpio->data_output.u32 : gpio->data_input.u32; + DEBUGASSERT(dir == 1); + set_gpio_bit(reg, pin, value); } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_gpio.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_gpio.h index 13d98e04d..1ac4a2ef6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_gpio.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/arch/risc-v/src/k210/k210_gpio.h @@ -38,52 +38,127 @@ #include #include "k210_gpio_common.h" +typedef struct _gpio_bits +{ + uint32_t b0 : 1; + uint32_t b1 : 1; + uint32_t b2 : 1; + uint32_t b3 : 1; + uint32_t b4 : 1; + uint32_t b5 : 1; + uint32_t b6 : 1; + uint32_t b7 : 1; + uint32_t b8 : 1; + uint32_t b9 : 1; + uint32_t b10 : 1; + uint32_t b11 : 1; + uint32_t b12 : 1; + uint32_t b13 : 1; + uint32_t b14 : 1; + uint32_t b15 : 1; + uint32_t b16 : 1; + uint32_t b17 : 1; + uint32_t b18 : 1; + uint32_t b19 : 1; + uint32_t b20 : 1; + uint32_t b21 : 1; + uint32_t b22 : 1; + uint32_t b23 : 1; + uint32_t b24 : 1; + uint32_t b25 : 1; + uint32_t b26 : 1; + uint32_t b27 : 1; + uint32_t b28 : 1; + uint32_t b29 : 1; + uint32_t b30 : 1; + uint32_t b31 : 1; +} __attribute__((packed, aligned(4))) gpio_bits_t; + +/* Structure of templates for accessing GPIO registers */ +typedef union _gpio_access_tp +{ + /* 32x1 bit mode */ + uint32_t u32[1]; + /* 16x2 bit mode */ + uint16_t u16[2]; + /* 8x4 bit mode */ + uint8_t u8[4]; + /* 1 bit mode */ + gpio_bits_t bits; +} __attribute__((packed, aligned(4))) gpio_access_tp_t; + +/* The GPIO address map */ +typedef struct _gpio +{ + /* Offset 0x00: Data (output) registers */ + gpio_access_tp_t data_output; + /* Offset 0x04: Data direction registers */ + gpio_access_tp_t direction; + /* Offset 0x08: Data source registers */ + gpio_access_tp_t source; + /* Offset 0x10 - 0x2f: Unused registers, 9x4 bytes */ + uint32_t unused_0[9]; + /* Offset 0x30: Interrupt enable/disable registers */ + gpio_access_tp_t interrupt_enable; + /* Offset 0x34: Interrupt mask registers */ + gpio_access_tp_t interrupt_mask; + /* Offset 0x38: Interrupt level registers */ + gpio_access_tp_t interrupt_level; + /* Offset 0x3c: Interrupt polarity registers */ + gpio_access_tp_t interrupt_polarity; + /* Offset 0x40: Interrupt status registers */ + gpio_access_tp_t interrupt_status; + /* Offset 0x44: Raw interrupt status registers */ + gpio_access_tp_t interrupt_status_raw; + /* Offset 0x48: Interrupt debounce registers */ + gpio_access_tp_t interrupt_debounce; + /* Offset 0x4c: Registers for clearing interrupts */ + gpio_access_tp_t interrupt_clear; + /* Offset 0x50: External port (data input) registers */ + gpio_access_tp_t data_input; + /* Offset 0x54 - 0x5f: Unused registers, 3x4 bytes */ + uint32_t unused_1[3]; + /* Offset 0x60: Sync level registers */ + gpio_access_tp_t sync_level; + /* Offset 0x64: ID code */ + gpio_access_tp_t id_code; + /* Offset 0x68: Interrupt both edge type */ + gpio_access_tp_t interrupt_bothedge; +} __attribute__((packed, aligned(4))) gpio_t; + +/* Bus GPIO object instance */ +extern volatile gpio_t *const gpio; + /**************************************************************************** * Public Functions Prototypes ****************************************************************************/ +/** + * @brief Gpio initialize + * @return - 0:Success,Other:Fail + */ +int gpio_init(void); -/**************************************************************************** - * Name: k210_gpio_set_direction - * - * Description: - * Set gpiohs direction - * - * Input Parameters: - * io - IO number - * dir - true for output, false for input - * - ****************************************************************************/ +/** + * @brief Set Gpio drive mode + * @param[in] pin Gpio pin + * @param[in] mode Gpio pin drive mode + */ +void gpio_set_drive_mode(uint8_t pin, gpio_drive_mode_t mode); -void k210_gpio_set_direction(uint32_t io, gpio_drive_mode_t mode); +/** + * @brief Get Gpio pin value + * @param[in] pin Gpio pin + * @return Pin value + * GPIO_PV_Low Gpio pin low + * GPIO_PV_High Gpio pin high + */ +gpio_pin_value_t gpio_get_pin(uint8_t pin); -/**************************************************************************** - * Name: k210_gpio_set_value - * - * Description: - * Set gpiohs direction - * - * Input Parameters: - * io - IO number - * dir - true for high level, false for low level - * - ****************************************************************************/ - -void k210_gpio_set_value(uint32_t io, bool val); - -/**************************************************************************** - * Name: k210_gpio_get_value - * - * Description: - * Get gpiohs level - * - * Input Parameters: - * io - IO number - * - * Returned Value: - * true for high level, false for low level - * - ****************************************************************************/ - -bool k210_gpio_get_value(uint32_t io); +/** + * @brief Set Gpio pin value + * @param[in] pin Gpio pin + * @param[in] value Gpio pin value + */ +void gpio_set_pin(uint8_t pin, gpio_pin_value_t value); #endif /* __ARCH_RISCV_SRC_K210_K210_GPIO_H */ From 6794cb03a83dcd87d1ddf2ed51dac3300dcefb50 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 25 Oct 2022 16:27:25 +0800 Subject: [PATCH 28/30] support touch screen for xidatong-riscv64 on nuttx --- .../aiit_board/xidatong-riscv64/Kconfig | 6 +- .../xidatong-riscv64/include/board.h | 8 + .../aiit_board/xidatong-riscv64/src/Makefile | 5 + .../xidatong-riscv64/src/k210_touch.c | 409 ++++++++++++++++++ .../xidatong-riscv64/src/k210_touch.h | 88 ++++ 5 files changed, 515 insertions(+), 1 deletion(-) create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.c create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.h diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig index 78bb7ffd2..a4a4dac80 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/Kconfig @@ -6,7 +6,7 @@ if ARCH_BOARD_XIDATONG_RISCV64 menuconfig BSP_USING_CH376 - bool "Using ch376 device" + bool "Using CH376 device" default n select K210_16550_UART select K210_16550_UART3 @@ -35,6 +35,10 @@ menuconfig BSP_USING_ENET bool "Using ENET device" default n +menuconfig BSP_USING_TOUCH + bool "Using touch device" + default n + menuconfig BSP_USING_CH438 bool "Using CH438 device" default n diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h index 32d32f02f..5757d2b3f 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/include/board.h @@ -111,6 +111,10 @@ extern "C" #define BSP_ENET_NRST 13 #define BSP_ENET_NINT 14 +/* I2C */ +#define BSP_IIC_SDA 15 +#define BSP_IIC_SCL 17 + /* other mode io */ #define GPIO_E220_M0 44 #define GPIO_E220_M1 45 @@ -153,6 +157,10 @@ extern "C" #define FPIOA_ENET_MOSI 23 #define FPIOA_ENET_NCS 31 +/* I2C */ +#define FPIOA_IIC_SDA 7 +#define FPIOA_IIC_SCL 8 + /* other mode FPIOA */ #define FPIOA_E220_M0 1 #define FPIOA_E220_M1 2 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile index b3bd1fa1f..04afe7e33 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/Makefile @@ -53,4 +53,9 @@ endif ifeq ($(CONFIG_BSP_USING_ENET),y) CSRCS += k210_w5500.c endif + +ifeq ($(CONFIG_BSP_USING_TOUCH),y) +CSRCS += k210_touch.c +endif + include $(TOPDIR)/boards/Board.mk diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.c new file mode 100644 index 000000000..8d79cc121 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.c @@ -0,0 +1,409 @@ +/* +* Copyright (c) 2022 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file k210_touch.c + * @brief gt911 touch driver + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.10.25 + */ + + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include "k210_touch.h" + +/**************************************************************************** + * Name: IIC_Init + * Description: i2c pin mode configure + * input: None + * output: None + * return:none + ****************************************************************************/ +void IIC_Init(void) +{ + /* config simluate IIC bus */ + k210_fpioa_config(BSP_IIC_SDA, GT911_FUNC_GPIO(FPIOA_IIC_SDA)); + k210_fpioa_config(BSP_IIC_SCL, GT911_FUNC_GPIO(FPIOA_IIC_SCL)); + + k210_gpiohs_set_direction(FPIOA_IIC_SDA, GPIO_DM_OUTPUT); + k210_gpiohs_set_direction(FPIOA_IIC_SCL, GPIO_DM_OUTPUT); +} + +/**************************************************************************** + * Name: SDA_IN + * Description: set sda input mode + * input: None + * output: None + * return:none + ****************************************************************************/ +void SDA_IN(void) +{ + k210_gpiohs_set_direction(FPIOA_IIC_SDA, GPIO_DM_INPUT_PULL_UP); +} + +/**************************************************************************** + * Name: SDA_OUT + * Description: set sda output mode + * input: None + * output: None + * return:none + ****************************************************************************/ +void SDA_OUT(void) +{ + k210_gpiohs_set_direction(FPIOA_IIC_SDA, GPIO_DM_OUTPUT); +} + +/**************************************************************************** + * Name: READ_SDA + * Description: read sda value + * input: None + * output: None + * return: sda pin value + ****************************************************************************/ +uint8_t READ_SDA(void) +{ + return k210_gpiohs_get_value(FPIOA_IIC_SDA); +} + +/**************************************************************************** + * Name: IIC_SCL + * Description: set the value of scl + * input: val:the value to be set + * output: None + * return: None + ****************************************************************************/ +void IIC_SCL(uint8_t val) +{ + if (val) + k210_gpiohs_set_value(FPIOA_IIC_SCL,GPIO_PV_HIGH); + else + { + k210_gpiohs_set_value(FPIOA_IIC_SCL,GPIO_PV_LOW); + } +} + +/**************************************************************************** + * Name: IIC_SDA + * Description: set the value of sda + * input: val:the value to be set + * output: None + * return: None + ****************************************************************************/ +void IIC_SDA(uint8_t val) +{ + if (val) + k210_gpiohs_set_value(FPIOA_IIC_SDA,GPIO_PV_HIGH); + else + { + k210_gpiohs_set_value(FPIOA_IIC_SDA,GPIO_PV_LOW); + } +} + +/**************************************************************************** + * Name: IIC_Start + * Description: Generate i2c start signal + * input: None + * output: None + * return: None + ****************************************************************************/ +void IIC_Start(void) +{ + SDA_OUT(); + IIC_SDA(1); + IIC_SCL(1); + up_mdelay(30); + IIC_SDA(0); + up_mdelay(2); + IIC_SCL(0); +} + +/**************************************************************************** + * Name: IIC_Start + * Description: Generate i2c stop signal + * input: None + * output: None + * return: None + ****************************************************************************/ +void IIC_Stop(void) +{ + SDA_OUT(); + IIC_SCL(1); + up_mdelay(30); + IIC_SDA(0); + up_mdelay(2); + IIC_SDA(1); +} + +/******************************************************************************************* + * Name: IIC_Wait_Ack + * Description: Wait for the reply signal to arrive + * input: None + * output: None + * return: Return value: 1:failed to receive response,0:the received response is successful. +********************************************************************************************/ +uint8_t IIC_Wait_Ack(void) +{ + uint16_t ucErrTime=0; + SDA_IN(); + IIC_SDA(1); + IIC_SCL(1); + up_mdelay(2); + while(READ_SDA()) + { + ucErrTime++; + if(ucErrTime>2500) + { + IIC_Stop(); + return 1; + } + up_mdelay(2); + } + IIC_SCL(0); + return 0; +} + +/**************************************************************************** + * Name: IIC_Ack + * Description: generate ack response + * input: None + * output: None + * return: None + ****************************************************************************/ +void IIC_Ack(void) +{ + IIC_SCL(0); + SDA_OUT(); + up_mdelay(2); + IIC_SDA(0); + up_mdelay(2); + IIC_SCL(1); + up_mdelay(2); + IIC_SCL(0); +} + +/**************************************************************************** + * Name: IIC_NAck + * Description: No ACK response is generated + * input: None + * output: None + * return: None + ****************************************************************************/ +void IIC_NAck(void) +{ + IIC_SCL(0); + SDA_OUT(); + up_mdelay(2); + IIC_SDA(1); + up_mdelay(2); + IIC_SCL(1); + up_mdelay(2); + IIC_SCL(0); +} + +/**************************************************************************** + * Name: IIC_Send_Byte + * Description: IIC sends a byte,Return whether the slave has a response + * input: None + * output: None + * return: 1:there is a response,0:no response + ****************************************************************************/ +void IIC_Send_Byte(uint8_t txd) +{ + uint8_t t; + SDA_OUT(); + IIC_SCL(0); + up_mdelay(2); + for(t=0;t<8;t++) + { + IIC_SDA((txd&0x80)>>7); + txd<<=1; + IIC_SCL(1); + up_mdelay(2); + IIC_SCL(0); + up_mdelay(2); + } +} + +/**************************************************************************** + * Name: IIC_Read_Byte + * Description: Read 1 byte, when ack=1, send ACK, when ack=0, send nACK + * input: None + * output: None + * return: Returns one byte of data read + ****************************************************************************/ +uint8_t IIC_Read_Byte(uint8_t ack) +{ + uint8_t i,receive=0; + SDA_IN(); + up_mdelay(30); + for(i=0;i<8;i++ ) + { + IIC_SCL(0); + up_mdelay(2); + IIC_SCL(1); + up_udelay(1); + receive<<=1; + if(READ_SDA())receive++; + up_udelay(1); + } + if (!ack) + IIC_NAck(); + else + IIC_Ack(); + return receive; +} + +/*********************************************************************************** + * Name: GT911_WR_Reg + * Description: Write data to GT911 once + * input: reg: start register address,buf: data cache area,len: write data length + * output: None + * return: Return value: 0, success; 1, failure. + ***********************************************************************************/ +static uint8_t GT911_WR_Reg(uint16_t reg,uint8_t *buf,uint8_t len) +{ + uint8_t i; + uint8_t ret=0; + IIC_Start(); + IIC_Send_Byte(CT_CMD_WR); + IIC_Wait_Ack(); + IIC_Send_Byte(reg>>8); + IIC_Wait_Ack(); + IIC_Send_Byte(reg&0XFF); + IIC_Wait_Ack(); + for(i=0;i>8); + IIC_Wait_Ack(); + IIC_Send_Byte(reg&0XFF); + IIC_Wait_Ack(); + IIC_Stop(); + + IIC_Start(); + IIC_Send_Byte(CT_CMD_RD); + IIC_Wait_Ack(); + for(i=0;i 5) || (Dev_Now.TouchCount == 0) ) + { + GT911_WR_Reg(GT911_READ_XY_REG, (uint8_t *)&Clearbuf, 1); + return false; + } + GT911_RD_Reg(GT911_READ_XY_REG + 1, &buf[1], Dev_Now.TouchCount*8); + GT911_WR_Reg(GT911_READ_XY_REG, (uint8_t *)&Clearbuf, 1); + + for (uint8_t i = 0;i < Dev_Now.TouchCount; i++) + { + Dev_Now.Touchkeytrackid[i] = buf[1+(8*i)]; + Dev_Now.X[i] = ((uint16_t)buf[3+(8*i)] << 8) + buf[2+(8*i)]; + Dev_Now.Y[i] = ((uint16_t)buf[5+(8*i)] << 8) + buf[4+(8*i)]; + Dev_Now.S[i] = ((uint16_t)buf[7+(8*i)] << 8) + buf[6+(8*i)]; + + + if(Dev_Now.Y[i] < 20) Dev_Now.Y[i] = 20; + if(Dev_Now.Y[i] > GT911_MAX_HEIGHT -20) Dev_Now.Y[i]=GT911_MAX_HEIGHT - 20; + if(Dev_Now.X[i] < 20) Dev_Now.X[i] = 20; + if(Dev_Now.X[i] > GT911_MAX_WIDTH-20) Dev_Now.X[i] = GT911_MAX_WIDTH - 20; + point->X = Dev_Now.X[i]; + point->Y = Dev_Now.Y[i]; + } + } + return true; +} + +/*********************************************************************************** + * Name: GT911_test + * Description: gt911 test code + * input: None + * output: None + * return: Returns true for touch, false for no touch + ***********************************************************************************/ +void GT911_test(void) +{ + uint16_t res; + POINT point = {0, 0}; + IIC_Init(); + res = GT911_ReadFirmwareVersion(); + printf("FirmwareVersion:%2x\n",res); + while(1) + { + if(GT911_Scan(&point)) + { + printf("Now touch point:(%d,%d)\n",point.X,point.X); + } + } +} \ No newline at end of file diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.h new file mode 100644 index 000000000..26ad5ed32 --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.h @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2022 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file k210_touch.h + * @brief gt911 touch driver + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.10.25 + */ + +#ifndef _K210_TOUCH_H_ +#define _K210_TOUCH_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "k210_config.h" +#include "k210_fpioa.h" +#include "k210_gpiohs.h" +#include "nuttx/arch.h" +#include "k210_gpio_common.h" + +#define GT911_FUNC_GPIO(n) ((K210_IO_FUNC_GPIOHS0 + n) | K210_IOFLAG_GPIOHS) + +#define GT911_MAX_WIDTH (uint16_t)800 +#define GT911_MAX_HEIGHT (uint16_t)480 +#define CT_CMD_WR (uint8_t)0XBA +#define CT_CMD_RD (uint8_t)0XBB +#define CT_MAX_TOUCH (uint8_t)5 +#define GT911_COMMAND_REG (uint16_t)0x8040 +#define GT911_CONFIG_REG (uint16_t)0x8047 +#define GT911_PRODUCT_ID_REG (uint16_t)0x8140 +#define GT911_FIRMWARE_VERSION_REG (uint16_t)0x8144 +#define GT911_READ_XY_REG (uint16_t)0x814E + +typedef struct +{ + uint8_t TouchCount; + uint8_t Touchkeytrackid[CT_MAX_TOUCH]; + uint16_t X[CT_MAX_TOUCH]; + uint16_t Y[CT_MAX_TOUCH]; + uint16_t S[CT_MAX_TOUCH]; +}GT911_Dev; + +typedef struct +{ + uint16_t X; + uint16_t Y; +}POINT; + +void IIC_Init(void); +void SDA_IN(void); +void SDA_OUT(void); +uint8_t READ_SDA(void); +void IIC_SCL(uint8_t val); +void IIC_SDA(uint8_t val); +void IIC_Start(void); +void IIC_Stop(void); +uint8_t IIC_Wait_Ack(void); +void IIC_Ack(void); +void IIC_NAck(void); +void IIC_Send_Byte(uint8_t txd); +uint8_t IIC_Read_Byte(uint8_t ack); +bool GT911_Scan(POINT* point); +void GT911_test(void); + +#endif From 490d372b4724e62f302d9434811a66511ea0d583 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 25 Oct 2022 17:41:08 +0800 Subject: [PATCH 29/30] add touchnsh/defconfig --- .../configs/touchnsh/defconfig | 63 +++++++++++++++++++ .../app_match_nuttx/apps/nshlib/Kconfig | 4 ++ .../app_match_nuttx/apps/nshlib/nsh.h | 4 ++ .../apps/nshlib/nsh_Applicationscmd.c | 13 ++++ .../app_match_nuttx/apps/nshlib/nsh_command.c | 4 ++ 5 files changed, 88 insertions(+) create mode 100644 Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/touchnsh/defconfig diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/touchnsh/defconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/touchnsh/defconfig new file mode 100644 index 000000000..67f5f8c4a --- /dev/null +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/configs/touchnsh/defconfig @@ -0,0 +1,63 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_DISABLE_LOSMART is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ADD_NUTTX_FETURES=y +CONFIG_ARCH="risc-v" +CONFIG_ARCH_BOARD="xidatong-riscv64" +CONFIG_ARCH_BOARD_XIDATONG_RISCV64=y +CONFIG_ARCH_CHIP="k210" +CONFIG_ARCH_CHIP_K210=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BINFMT_DISABLE=y +CONFIG_BOARD_LOOPSPERMSEC=46000 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_IFUPDOWN=y +CONFIG_NSH_DISABLE_MKDIR=y +CONFIG_NSH_DISABLE_RM=y +CONFIG_NSH_DISABLE_RMDIR=y +CONFIG_NSH_DISABLE_UMOUNT=y +CONFIG_NSH_READLINE=y +CONFIG_NSH_STRERROR=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=2097152 +CONFIG_RAM_START=0x80400000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=100 +CONFIG_READLINE_CMD_HISTORY_LINELEN=120 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=28 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2019 +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=20 +CONFIG_TESTING_GETPRIME=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SCHED_HPWORK=y +CONFIG_DEV_GPIO=y +CONFIG_BOARDCTL_RESET=y +CONFIG_K210_16550_UART=y +CONFIG_K210_16550_UART3=y +CONFIG_BSP_USING_TOUCH=y diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig index eb17d6b8a..fcffc9750 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig @@ -555,6 +555,10 @@ config NSH_DISABLE_W5500 bool "Disable the w5500 demo." default n +config NSH_DISABLE_TOUCH + bool "Disable the gt911 touch screen demo." + default n + config NSH_DISABLE_CH438 bool "Disable the ch438 demo." default n diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index a7ddcb302..918ba31a7 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1458,6 +1458,10 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, int cmd_w5500(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif +#if defined(CONFIG_BSP_USING_TOUCH) && !defined(CONFIG_NSH_DISABLE_TOUCH) + int cmd_Touch(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + #if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 1f9bfe2ff..820d3360d 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -64,6 +64,19 @@ int cmd_w5500(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +/**************************************************************************** + * Name: cmd_Touch + ****************************************************************************/ +#if defined(CONFIG_BSP_USING_TOUCH) && !defined(CONFIG_NSH_DISABLE_TOUCH) +extern void GT911_test(void); +int cmd_Touch(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, world!\n"); + GT911_test(); + return OK; +} +#endif + /**************************************************************************** * Name: cmd_Ch438 ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index 4f2486cd5..1b03f5cc9 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -604,6 +604,10 @@ static const struct cmdmap_s g_cmdmap[] = { "w5500", cmd_w5500, 1, 1, "[w5500 demo cmd.]" }, #endif +#if defined(CONFIG_BSP_USING_TOUCH) && !defined(CONFIG_NSH_DISABLE_TOUCH) + { "touch", cmd_Touch, 1, 1, "[gt911 touch screen demo cmd.]" }, +#endif + #if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) { "ch438", cmd_Ch438, 1, 1, "[ch438 demo cmd.]" }, #endif From a04a4288a767606205e57106e44585eb63a2b45c Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 25 Oct 2022 18:21:32 +0800 Subject: [PATCH 30/30] add printf point.x and point.y in test case --- .../aiit_board/xidatong-riscv64/src/k210_touch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.c index 8d79cc121..4649cf1d4 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-riscv64/src/k210_touch.c @@ -403,7 +403,7 @@ void GT911_test(void) { if(GT911_Scan(&point)) { - printf("Now touch point:(%d,%d)\n",point.X,point.X); + printf("Now touch point:(%d,%d)\n",point.X,point.Y); } } } \ No newline at end of file