diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ccbec3964d7fd911bd07a543cf36fc83aeec8bc8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +三个实验/001_OH_KP_Thread/thread_sample.c +三个实验/GPS/gps.c +三个实验/EBox_IoT_028_Env_GPIO_LED/gpio_out_led.c diff --git a/001_OH_KP_Thread/BUILD.gn b/001_OH_KP_Thread/BUILD.gn index 30a40169ca0c4b91817c4935c6817d73fe7338f2..023e75b7c60ef1113cba626c2653693c049475ad 100644 --- a/001_OH_KP_Thread/BUILD.gn +++ b/001_OH_KP_Thread/BUILD.gn @@ -1,6 +1,6 @@ -static_library("thread_sample") { - sources = [ - "thread_sample.c", - ] - -} +static_library("thread_sample") { + sources = [ + "thread_sample.c", + ] + +} diff --git a/001_OH_KP_Thread/BUILD.gn.bak b/001_OH_KP_Thread/BUILD.gn.bak index a92df9eb5ce1e11570f245d417bf0f91391af7d2..85ab0e03f704d43d338ef18bfe660f2d6d1bf11c 100644 --- a/001_OH_KP_Thread/BUILD.gn.bak +++ b/001_OH_KP_Thread/BUILD.gn.bak @@ -1,19 +1,19 @@ -# Copyright (c) 2020 Huawei Device Co., Ltd. -# 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. - -static_library("task_test") { - sources = [ - "task_test.c", - ] - -} +# Copyright (c) 2020 Huawei Device Co., Ltd. +# 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. + +static_library("task_test") { + sources = [ + "task_test.c", + ] + +} diff --git a/001_OH_KP_Thread/thread_sample.c b/001_OH_KP_Thread/thread_sample.c index f680e663746d1821219ea22368304a4f3355f727..9f5a5a7bb64a35c888770fe271f317cc6a6206d4 100644 --- a/001_OH_KP_Thread/thread_sample.c +++ b/001_OH_KP_Thread/thread_sample.c @@ -1,83 +1,83 @@ -#include -//#include -#include -#include "ohos_init.h" -#include "cmsis_os2.h" - - -void thread1(void) -{ - int sum = 0; - while (1) - { - printf("This is thread1----%d\r\n", sum++); - usleep(1000000); - } -} - - -void thread2(void) -{ - int sum = 0; - while (1) - { - printf("This is thread2----%d\r\n", sum++); - usleep(500000); - } -} - - -static void Thread_sample(void) -{ - osThreadAttr_t attr; - - attr.name = "thread1"; - attr.attr_bits = 0U; - attr.cb_mem = NULL; - attr.cb_size = 0U; - attr.stack_mem = NULL; - attr.stack_size = 1024 * 4; - attr.priority = 25; - - osThreadId_t threadID1 = osThreadNew((osThreadFunc_t)thread1, NULL, &attr); - if (threadID1 == NULL) - { - printf("Falied to create thread1!\n"); - } - - attr.name = "thread2"; - - osThreadId_t threadID2 = osThreadNew((osThreadFunc_t)thread2, NULL, &attr); - if (threadID2 == NULL) - { - printf("Falied to create thread2!\n"); - } - - int sum = 0; - usleep(1000000); - osStatus_t status = osThreadSuspend(threadID1); - printf("This is main thread: suspend thread1, result:%d\r\n", status); - - for (int i = 0; i < 5; i++) - { - printf("This is main thread----%d\r\n", sum++); - usleep(1000000); - } - - status = osThreadResume(threadID1); - printf("This is main thread: resume thread1, result:%d\r\n", status); - - usleep(1000000); - status = osThreadTerminate(threadID1); - printf("This is main thread: terminate thread1, result:%d\r\n", status); - status = osThreadTerminate(threadID2); - printf("This is main thread: terminate thread2, result:%d\r\n", status); - - while (1) - { - printf("This is main thread----%d\r\n", sum++); - usleep(1000000); - } -} - -APP_FEATURE_INIT(Thread_sample); +#include +//#include +#include +#include "ohos_init.h" +#include "cmsis_os2.h" + + +void thread1(void) +{ + int sum = 0; + while (1) + { + printf("This is thread1----%d\r\n", sum++); + usleep(1000000); + } +} + + +void thread2(void) +{ + int sum = 0; + while (1) + { + printf("This is thread2----%d\r\n", sum++); + usleep(500000); + } +} + + +static void Thread_sample(void) +{ + osThreadAttr_t attr; + + attr.name = "thread1"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = 1024 * 4; + attr.priority = 25; + + osThreadId_t threadID1 = osThreadNew((osThreadFunc_t)thread1, NULL, &attr); + if (threadID1 == NULL) + { + printf("Falied to create thread1!\n"); + } + + attr.name = "thread2"; + + osThreadId_t threadID2 = osThreadNew((osThreadFunc_t)thread2, NULL, &attr); + if (threadID2 == NULL) + { + printf("Falied to create thread2!\n"); + } + + int sum = 0; + usleep(1000000); + osStatus_t status = osThreadSuspend(threadID1); + printf("This is main thread: suspend thread1, result:%d\r\n", status); + + for (int i = 0; i < 5; i++) + { + printf("This is main thread----%d\r\n", sum++); + usleep(1000000); + } + + status = osThreadResume(threadID1); + printf("This is main thread: resume thread1, result:%d\r\n", status); + + usleep(1000000); + status = osThreadTerminate(threadID1); + printf("This is main thread: terminate thread1, result:%d\r\n", status); + status = osThreadTerminate(threadID2); + printf("This is main thread: terminate thread2, result:%d\r\n", status); + + while (1) + { + printf("This is main thread----%d\r\n", sum++); + usleep(1000000); + } +} + +APP_FEATURE_INIT(Thread_sample); diff --git a/BUILD.gn b/BUILD.gn index 0c82df64dbb585c18cdbbc9d229c4883fcb3a60e..237f84e1298a64d8b2868a119bfb2c0ecdae9a15 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2,9 +2,14 @@ import("//build/lite/config/component/lite_component.gni") lite_component("app") { features = [ + "EBox_IoT_033_SHT30_Env:Env_module_sample", + #"EBox_IoT_032_MPU6050_manhole_GUE:Manhole_module_sample", + #"EBox_IoT_049_OLED_Env_GUE:Env_oled_sample", + #"EBox_IoT_038_MQ7_Gas_GUE:Gas_module_sample", + #"my_adc:adc_example", #"GPS:gps", #"EBox_IoT_028_Env_GPIO_LED:gpio_out_led", - "001_OH_KP_Thread:thread_sample", + #"001_OH_KP_Thread:thread_sample", # "002_OH_KP_Event:Event_sample", # "003_OH_KP_Timer:Timer_sample", ] diff --git a/D3_iot_udp_client/BUILD.gn b/D3_iot_udp_client/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4e35706cb9328b420bb25aea38c808895ee4a414 --- /dev/null +++ b/D3_iot_udp_client/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. +# 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. + +static_library("udp_client") { + sources = [ + "udp_client_demo.c", + "wifi/wifi_connect.c", + ] + + cflags = [ "-Wno-unused-variable" ] + include_dirs = [ + "//foundation/communication/wifi_lite/interfaces/wifiservice", + "wifi" + + ] + + +} diff --git a/D3_iot_udp_client/README.md b/D3_iot_udp_client/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e05171d8fa7b21d280f56ab1351361ee2a33c8bf --- /dev/null +++ b/D3_iot_udp_client/README.md @@ -0,0 +1,130 @@ +# BearPi-HM_Nano开发板WiFi编程开发——UDP客户端 +本示例将演示如何在BearPi-HM_Nano开发板上使用socket编程创建UDP客户端,就收客户端消息并回复固定消息。 + + +## socket API分析 +本案例主要使用了以下几个API完socket编程实验。 +### socket() + +```c +sock_fd = socket(AF_INET, SOCK_STREAM, 0)) //AF_INT:ipv4, SOCK_STREAM:tcp协议 +``` +**描述:** + +在网络编程中所需要进行的第一件事情就是创建一个socket,无论是客户端还是服务器端,都需要创建一个socket,该函数返回socket文件描述符,类似于文件描述符。socket是一个结构体,被创建在内核中。 +### sendto() +```c +int sendto ( socket s , const void * msg, int len, unsigned int flags, +const struct sockaddr * to , int tolen ) ; +``` +**描述:** + +sendto() 用来将数据由指定的socket传给对方主机。参数s为已建好连线的socket。参数msg指向欲连线的数据内容,参数flags 一般设0。 + +### recvfrom() +```c +int recvfrom(int s, void *buf, int len, unsigned int flags, struct sockaddr *from, int *fromlen); +``` +**描述:** +从指定地址接收UDP数据报。 + + +**参数:** + +|参数名|描述| +|:--|:------| +| s | socket描述符。 | +| buf | UDP数据报缓存地址。 | +| len | UDP数据报长度。 | +| flags | 该参数一般为0。 | +| from | 对方地址。 | +| fromlen | 对方地址长度。 | + + + +## 软件设计 + +**主要代码分析** + +完成Wifi热点的连接需要以下几步。 + +1. 通过 `socket` 接口创建一个socket,`AF_INT`表示ipv4,`SOCK_STREAM`表示使用tcp协议。 +2. 调用 `sendto` 接口发送数据到服务端。 +3. 调用 `recvfrom` 接口接收服务端发来的数据。 + + +```c +static void UDPClientTask(void) +{ + //在sock_fd 进行监听,在 new_fd 接收新的链接 + int sock_fd; + + //服务器的地址信息 + struct sockaddr_in send_addr; + socklen_t addr_length = sizeof(send_addr); + char recvBuf[512]; + + //连接Wifi + WifiConnect(CONFIG_WIFI_SSID, CONFIG_WIFI_PWD); + + //创建socket + if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + perror("create socket failed!\r\n"); + exit(1); + } + + //初始化预连接的服务端地址 + send_addr.sin_family = AF_INET; + send_addr.sin_port = htons(CONFIG_SERVER_PORT); + send_addr.sin_addr.s_addr = inet_addr(CONFIG_SERVER_IP); + addr_length = sizeof(send_addr); + + //总计发送 count 次数据 + while (1) { + bzero(recvBuf, sizeof(recvBuf)); + + //发送数据到服务远端 + sendto(sock_fd, send_data, strlen(send_data), 0, (struct sockaddr *)&send_addr, addr_length); + + //线程休眠一段时间 + sleep(TASK_DELAY_10S); + + //接收服务端返回的字符串 + recvfrom(sock_fd, recvBuf, sizeof(recvBuf), 0, (struct sockaddr *)&send_addr, &addr_length); + printf("%s:%d=>%s\n", inet_ntoa(send_addr.sin_addr), ntohs(send_addr.sin_port), recvBuf); + } + + //关闭这个 socket + closesocket(sock_fd); +} +``` + +## 编译调试 + +### 修改 BUILD.gn 文件 + +修改 `device\bearpi\bearpi_hm_nano\app` 路径下 BUILD.gn 文件,指定 `udp_client` 参与编译。 +```r +#"D1_iot_wifi_sta:wifi_sta", +#"D2_iot_wifi_sta_connect:wifi_sta_connect", +"D3_iot_udp_client:udp_client", +#"D4_iot_tcp_server:tcp_server", +#"D5_iot_mqtt:iot_mqtt", +#"D6_iot_cloud_oc:oc_mqtt", +``` + + + +### 运行结果 + +使用 Socket tool 创建UDP服务端用于测试,如下图所示。 + +![创建UDP服务端](../../docs/figures/D3_iot_udp_client/创建UDP服务端.png) + +示例代码编译烧录代码后,按下开发板的RESET按键,在数据发送窗口输入要发送的数据,点击发送后开发板会回复固定消息,如下图所示,且开发板收到消息后会通过日志打印出来。 + +``` +192.168.0.175:8888=>Hello! BearPi-HM_nano UDP Client! +``` + +![UDP发送数据](../../docs/figures/D3_iot_udp_client/UDP发送数据.png) \ No newline at end of file diff --git a/D3_iot_udp_client/udp_client_demo.c b/D3_iot_udp_client/udp_client_demo.c new file mode 100644 index 0000000000000000000000000000000000000000..7c30ea95e14d52e867303a6f90302246bbb7267e --- /dev/null +++ b/D3_iot_udp_client/udp_client_demo.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. + * 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 +#include +#include + +#include "ohos_init.h" +#include "cmsis_os2.h" + +#include "wifi_device.h" +#include "lwip/netifapi.h" +#include "lwip/api_shell.h" + +#include "lwip/sockets.h" +#include "wifi_connect.h" + +#define TASK_STACK_SIZE (1024 * 10) +#define TASK_DELAY_10S 10 +#define CONFIG_WIFI_SSID "Alice" // 要连接的WiFi 热点账号 +#define CONFIG_WIFI_PWD "31415926" // 要连接的WiFi 热点密码 +#define CONFIG_SERVER_IP "192.168.43.158" // 要连接的服务器IP +#define CONFIG_SERVER_PORT 8888 // 要连接的服务器端口 + +static const char *send_data = "Hello! I'm 2000301532韦长江!\r\n"; + +static void UDPClientTask(void) +{ + // 在sock_fd 进行监听,在 new_fd 接收新的链接 + int sock_fd; + + // 服务器的地址信息 + struct sockaddr_in send_addr; + socklen_t addr_length = sizeof(send_addr); + char recvBuf[512]; + + // 连接Wifi + WifiConnect(CONFIG_WIFI_SSID, CONFIG_WIFI_PWD); + + // 创建socket + if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + perror("create socket failed!\r\n"); + exit(1); + } + + // 初始化预连接的服务端地址 + send_addr.sin_family = AF_INET; + send_addr.sin_port = htons(CONFIG_SERVER_PORT); + send_addr.sin_addr.s_addr = inet_addr(CONFIG_SERVER_IP); + addr_length = sizeof(send_addr); + + // 总计发送 count 次数据 + while (1) { + bzero(recvBuf, sizeof(recvBuf)); + + // 发送数据到服务远端 + sendto(sock_fd, send_data, strlen(send_data), 0, (struct sockaddr *)&send_addr, addr_length); + + // 线程休眠一段时间 + sleep(TASK_DELAY_10S); + + // 接收服务端返回的字符串 + recvfrom(sock_fd, recvBuf, sizeof(recvBuf), 0, (struct sockaddr *)&send_addr, &addr_length); + printf("%s:%d=>%s\n", inet_ntoa(send_addr.sin_addr), ntohs(send_addr.sin_port), recvBuf); + } + + // 关闭这个 socket + closesocket(sock_fd); +} + +static void UDPClientDemo(void) +{ + osThreadAttr_t attr; + + attr.name = "UDPClientTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + if (osThreadNew((osThreadFunc_t)UDPClientTask, NULL, &attr) == NULL) { + printf("[UDPClientDemo] Failed to create UDPClientTask!\n"); + } +} + +APP_FEATURE_INIT(UDPClientDemo); diff --git a/D3_iot_udp_client/wifi/wifi_connect.c b/D3_iot_udp_client/wifi/wifi_connect.c new file mode 100644 index 0000000000000000000000000000000000000000..76ad7a6a99bd249a530a88fa371f5fd4bc65fdb8 --- /dev/null +++ b/D3_iot_udp_client/wifi/wifi_connect.c @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. + * 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 + +#include "lwip/api_shell.h" +#include "lwip/ip4_addr.h" +#include "lwip/netif.h" +#include "lwip/netifapi.h" + +#include "cmsis_os2.h" +#include "ohos_init.h" +#include "wifi_device.h" +#include "wifi_error_code.h" + +#define DEF_TIMEOUT 15 +#define ONE_SECOND 1 +#define DHCP_DELAY 100 + +static int WiFiInit(void); +static void WaitSacnResult(void); +static int WaitConnectResult(void); +static void OnWifiScanStateChangedHandler(int state, int size); +static void OnWifiConnectionChangedHandler(int state, WifiLinkedInfo *info); +static void OnHotspotStaJoinHandler(StationInfo *info); +static void OnHotspotStateChangedHandler(int state); +static void OnHotspotStaLeaveHandler(StationInfo *info); + +static int g_staScanSuccess = 0; +static int g_ConnectSuccess = 0; +static int g_ssid_count = 0; +static struct netif *g_lwip_netif = NULL; +static WifiEvent g_wifiEventHandler = { 0 }; +WifiErrorCode error; + +#define SELECT_WLAN_PORT "wlan0" + + +int WifiConnectAp(const char *ssid, const char *psk, WifiScanInfo *info, int i) +{ + if (strcmp(ssid, info[i].ssid) == 0) { + int result; + printf("Select:%3d wireless, Waiting...\r\n", i + 1); + + // 拷贝要连接的热点信息 + WifiDeviceConfig select_ap_config = { 0 }; + strcpy_s(select_ap_config.ssid, sizeof(select_ap_config.ssid), info[i].ssid); + strcpy_s(select_ap_config.preSharedKey, sizeof(select_ap_config.preSharedKey), psk); + select_ap_config.securityType = WIFI_SEC_TYPE_PSK; + + if (AddDeviceConfig(&select_ap_config, &result) == WIFI_SUCCESS) { + if (ConnectTo(result) == WIFI_SUCCESS && WaitConnectResult() == 1) { + g_lwip_netif = netifapi_netif_find(SELECT_WLAN_PORT); + return 0; + } + } + } + return -1; +} + +int WifiConnect(const char *ssid, const char *psk) +{ + unsigned int size = WIFI_SCAN_HOTSPOT_LIMIT; + + // 初始化WIFI + if (WiFiInit() != WIFI_SUCCESS) { + printf("WiFiInit failed, error = %d\r\n", error); + return -1; + } + // 分配空间,保存WiFi信息 + WifiScanInfo *info = malloc(sizeof(WifiScanInfo) * WIFI_SCAN_HOTSPOT_LIMIT); + if (info == NULL) { + return -1; + } + // 轮询查找WiFi列表 + do { + Scan(); + WaitSacnResult(); + error = GetScanInfoList(info, &size); + } while (g_staScanSuccess != 1); + // 打印WiFi列表 + printf("********************\r\n"); + for (uint8_t i = 0; i < g_ssid_count; i++) { + printf("no:%03d, ssid:%-30s, rssi:%5d\r\n", i + 1, info[i].ssid, info[i].rssi); + } + printf("********************\r\n"); + // 连接指定的WiFi热点 + for (uint8_t i = 0; i < g_ssid_count; i++) { + if (WifiConnectAp(ssid, psk, info, i) == WIFI_SUCCESS) { + printf("WiFi connect succeed!\r\n"); + break; + } + + if (i == g_ssid_count - 1) { + printf("ERROR: No wifi as expected\r\n"); + while (1) + osDelay(DHCP_DELAY); + } + } + + // 启动DHCP + if (g_lwip_netif) { + dhcp_start(g_lwip_netif); + printf("begain to dhcp\r\n"); + } + // 等待DHCP + for (;;) { + if (dhcp_is_bound(g_lwip_netif) == ERR_OK) { + printf("<-- DHCP state:OK -->\r\n"); + // 打印获取到的IP信息 + netifapi_netif_common(g_lwip_netif, dhcp_clients_info_show, NULL); + break; + } + osDelay(DHCP_DELAY); + } + return 0; +} + +int WiFiInit(void) +{ + g_wifiEventHandler.OnWifiScanStateChanged = OnWifiScanStateChangedHandler; + g_wifiEventHandler.OnWifiConnectionChanged = OnWifiConnectionChangedHandler; + g_wifiEventHandler.OnHotspotStaJoin = OnHotspotStaJoinHandler; + g_wifiEventHandler.OnHotspotStaLeave = OnHotspotStaLeaveHandler; + g_wifiEventHandler.OnHotspotStateChanged = OnHotspotStateChangedHandler; + error = RegisterWifiEvent(&g_wifiEventHandler); + if (error != WIFI_SUCCESS) { + printf("register wifi event fail!\r\n"); + return -1; + } + // 使能WIFI + if (EnableWifi() != WIFI_SUCCESS) { + printf("EnableWifi failed, error = %d\r\n", error); + return -1; + } + // 判断WIFI是否激活 + if (IsWifiActive() == 0) { + printf("Wifi station is not actived.\r\n"); + return -1; + } + return 0; +} + +static void OnWifiScanStateChangedHandler(int state, int size) +{ + if (size > 0) { + g_ssid_count = size; + g_staScanSuccess = 1; + } + printf("callback function for wifi scan:%d, %d\r\n", state, size); + return; +} + +static void OnWifiConnectionChangedHandler(int state, WifiLinkedInfo *info) +{ + if (info == NULL) { + printf("WifiConnectionChanged:info is null, stat is %d.\n", state); + } else { + if (state == WIFI_STATE_AVALIABLE) { + g_ConnectSuccess = 1; + } else { + g_ConnectSuccess = 0; + } + } +} + +static void OnHotspotStaJoinHandler(StationInfo *info) +{ + (void)info; + printf("STA join AP\n"); + return; +} + +static void OnHotspotStaLeaveHandler(StationInfo *info) +{ + (void)info; + printf("HotspotStaLeave:info is null.\n"); + return; +} + +static void OnHotspotStateChangedHandler(int state) +{ + printf("HotspotStateChanged:state is %d.\n", state); + return; +} + +static void WaitSacnResult(void) +{ + int scanTimeout = DEF_TIMEOUT; + while (scanTimeout > 0) { + sleep(ONE_SECOND); + scanTimeout--; + if (g_staScanSuccess == 1) { + printf("WaitSacnResult:wait success[%d]s\n", (DEF_TIMEOUT - scanTimeout)); + break; + } + } + if (scanTimeout <= 0) { + printf("WaitSacnResult:timeout!\n"); + } +} + +static int WaitConnectResult(void) +{ + int ConnectTimeout = DEF_TIMEOUT; + while (ConnectTimeout > 0) { + sleep(ONE_SECOND); + ConnectTimeout--; + if (g_ConnectSuccess == 1) { + printf("WaitConnectResult:wait success[%d]s\n", (DEF_TIMEOUT - ConnectTimeout)); + break; + } + } + if (ConnectTimeout <= 0) { + printf("WaitConnectResult:timeout!\n"); + return 0; + } + return 1; +} diff --git a/D3_iot_udp_client/wifi/wifi_connect.h b/D3_iot_udp_client/wifi/wifi_connect.h new file mode 100644 index 0000000000000000000000000000000000000000..fe83a633c5e1a9a52b280e3e9a47f365c81a12bf --- /dev/null +++ b/D3_iot_udp_client/wifi/wifi_connect.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. + * 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. + */ + +#ifndef __WIFI_CONNECT_H__ +#define __WIFI_CONNECT_H__ + +int WifiConnect(const char *ssid, const char *psk); + +#endif /* __WIFI_CONNECT_H__ */ + diff --git a/D4_iot_tcp_server/BUILD.gn b/D4_iot_tcp_server/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..db3b8766a3141413e41828ebede5bf41c1239d90 --- /dev/null +++ b/D4_iot_tcp_server/BUILD.gn @@ -0,0 +1,26 @@ +# Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. +# 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. + +static_library("tcp_server") { + sources = [ + "tcp_server_demo.c", + "wifi/wifi_connect.c", + ] + cflags = [ "-Wno-unused-variable" ] + include_dirs = [ + "//foundation/communication/wifi_lite/interfaces/wifiservice", + "wifi" + ] + + +} diff --git a/D4_iot_tcp_server/README.md b/D4_iot_tcp_server/README.md new file mode 100644 index 0000000000000000000000000000000000000000..23deb76c770844c647b85fdc75fe53e021f1954d --- /dev/null +++ b/D4_iot_tcp_server/README.md @@ -0,0 +1,200 @@ +# BearPi-HM_Nano开发板WiFi编程开发——TCP服务器 +本示例将演示如何在BearPi-HM_Nano开发板上使用socket编程创建TCP服务端,接收客户端消息并回复固定消息。 + + +## socket API分析 +本案例主要使用了以下几个API完socket编程实验。 +### socket() + +```c +sock_fd = socket(AF_INET, SOCK_STREAM, 0)) //AF_INT:ipv4, SOCK_STREAM:tcp协议 +``` +**描述:** + +在网络编程中所需要进行的第一件事情就是创建一个socket,无论是客户端还是服务器端,都需要创建一个socket,该函数返回socket文件描述符,类似于文件描述符。socket是一个结构体,被创建在内核中。 +### bind() +```c +bind(sockfd,(struct sockaddr*)&serveraddr,sizeof(serveraddr)) +``` +**描述:** + +把一个本地协议地址和套接口绑定,比如把本机的2222端口绑定到套接口。注意:为什么在上图中客户端不需要调用bind函数?这是因为如果没有调用bind函数绑定一个端口的话,当调用connect函数时,内核会为该套接口临时选定一个端口,因此可以不用绑定。而服务器之所以需要绑定的原因就是,所以客户端都需要知道服务器使用的哪个端口,所以需要提前绑定。 + + +### listen() +```c +int listen(int s, int backlog) +``` +**描述:** + +当socket创建后,它通常被默认为是主动套接口,也就是说是默认为要马上调用connect函数的,而作为服务器是需要被动接受的,所以需要调用linsten函数将主动套接口转换成被动套接口。调用linsten函数后,内核将从该套接口接收连接请求。 + + + +### accept() +```c +int accept(s, addr, addrlen) +``` +**描述:** + +此函数返回已经握手完成的连接的套接口。注意:此处的套接口不同于服务器开始创建的监听套接口,此套接口是已经完成连接的套接口,监听套接口只是用来监听。 + +### recv() +```c +int recv( SOCKET s, char *buf, int len, int flags) +``` +**描述:** + +recv函数用来从TCP连接的另一端接收数据。 + +### send() +```c +int send( SOCKET s,char *buf,int len,int flags ) +``` +**描述:** +send函数用来向TCP连接的另一端发送数据。 + + + + +## 软件设计 + +**主要代码分析** + +完成Wifi热点的连接需要以下几步。 + +1. 通过 `socket` 接口创建一个socket,`AF_INT`表示ipv4,`SOCK_STREAM`表示使用tcp协议。 +2. 调用 `bind` 接口绑定socket和地址。 +3. 调用 `listen` 接口监听(指定port监听),通知操作系统区接受来自客户端链接请求,第二个参数:指定队列长度。 +4. 调用`accept`接口从队列中获得一个客户端的请求链接。 +5. 调用 `recv` 接口接收客户端发来的数据。 +6. 调用 `send` 接口向客户端回复固定的数据。 + +```c +static void TCPServerTask(void) +{ + //在sock_fd 进行监听,在 new_fd 接收新的链接 + int sock_fd, new_fd; + + //服务端地址信息 + struct sockaddr_in server_sock; + + //客户端地址信息 + struct sockaddr_in client_sock; + int sin_size; + + struct sockaddr_in *cli_addr; + + //连接Wifi + WifiConnect(CONFIG_WIFI_SSID, CONFIG_WIFI_PWD); + + //创建socket + if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + perror("socket is error\r\n"); + exit(1); + } + + bzero(&server_sock, sizeof(server_sock)); + server_sock.sin_family = AF_INET; + server_sock.sin_addr.s_addr = htonl(INADDR_ANY); + server_sock.sin_port = htons(CONFIG_CLIENT_PORT); + + //调用bind函数绑定socket和地址 + if (bind(sock_fd, (struct sockaddr *)&server_sock, sizeof(struct sockaddr)) == -1) { + exit(1); + } + + //调用listen函数监听(指定port监听) + if (listen(sock_fd, TCP_BACKLOG) == -1) { + exit(1); + } + + printf("start accept\n"); + + //调用accept函数从队列中 + while (1) { + sin_size = sizeof(struct sockaddr_in); + + if ((new_fd = accept(sock_fd, (struct sockaddr *)&client_sock, (socklen_t *)&sin_size)) == -1) { + perror("accept"); + continue; + } + + cli_addr = malloc(sizeof(struct sockaddr)); + + printf("accept addr\r\n"); + + if (cli_addr != NULL) { + int ret = memcpy_s(cli_addr, sizeof(cli_addr), &client_sock, sizeof(struct sockaddr)); + if (!ret) { + perror("memcpy is error\r\n"); + exit(1); + } + } + //处理目标 + ssize_t ret; + + while (1) { + memset_s(recvbuf, sizeof(recvbuf), 0, sizeof(recvbuf)); + if ((ret = recv(new_fd, recvbuf, sizeof(recvbuf), 0)) == -1) { + printf("recv error \r\n"); + } + printf("recv :%s\r\n", recvbuf); + sleep(TASK_DELAY_2S); + if ((ret = send(new_fd, buf, strlen(buf) + 1, 0)) == -1) { + perror("send : "); + } + sleep(TASK_DELAY_2S); + } + close(new_fd); + } +} +``` + +## 编译调试 + +### 修改 BUILD.gn 文件 + +修改 `device\bearpi\bearpi_hm_nano\app` 路径下 BUILD.gn 文件,指定 `tcp_server` 参与编译。 +```r +#"D1_iot_wifi_sta:wifi_sta", +#"D2_iot_wifi_sta_connect:wifi_sta_connect", +#"D3_iot_udp_client:udp_client", +"D4_iot_tcp_server:tcp_server", +#"D5_iot_mqtt:iot_mqtt", +#"D6_iot_cloud_oc:oc_mqtt", +``` + + +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,会打印模块的本地IP,如本例程中的 `192.168.0.164` ,并开始准备获取客户端的请求链接。 +``` +g_connected: 1 +netifapi_dhcp_start: 0 +server : + server_id : 192.168.0.1 + mask : 255.255.255.0, 1 + gw : 192.168.0.1 + T0 : 7200 + T1 : 3600 + T2 : 6300 +clients <1> : + mac_idx mac addr state lease tries rto + 0 181131a48f7a 192.168.0.164 10 0 1 2 +netifapi_netif_common: 0 +start accept +``` +使用 Socket tool 创建客户端用于测试,如下图所示。 + +![创建TCP_Clien](../../docs/figures/D4_iot_tcp_server/创建TCP_Clien.png) + +在创建客户端后点击“连接”,在数据发送窗口输入要发送的数据,点击发送后服务端会回复固定消息,如下图所示,且开发板收到消息后会通过日志打印出来。 + +``` +start accept +accept addr +recv :Hello! BearPi-HM_nano TCP Server! +``` + +![TCP发送数据](../../docs/figures/D4_iot_tcp_server/TCP发送数据.png) \ No newline at end of file diff --git a/D4_iot_tcp_server/tcp_server_demo.c b/D4_iot_tcp_server/tcp_server_demo.c new file mode 100644 index 0000000000000000000000000000000000000000..261cb48d65d84760e320c19a30cdc0e153b1df9c --- /dev/null +++ b/D4_iot_tcp_server/tcp_server_demo.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. + * 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 "cmsis_os2.h" +#include "ohos_init.h" + +#include "lwip/sockets.h" +#include "wifi_connect.h" + +#define TASK_STACK_SIZE (1024 * 10) +#define TASK_DELAY_2S 2 +#define CONFIG_WIFI_SSID "Alice" // 要连接的WiFi 热点账号 +#define CONFIG_WIFI_PWD "31415926" // 要连接的WiFi 热点密码 +#define CONFIG_CLIENT_PORT 8888 // 要连接的服务器端口 +#define TCP_BACKLOG 10 + +char recvbuf[512]; +char *buf = "Hello! I'm qihang 2000301532wcj TCP Server!"; + +static void TCPServerTask(void) +{ + // 在sock_fd 进行监听,在 new_fd 接收新的链接 + int sock_fd, new_fd; + + // 服务端地址信息 + struct sockaddr_in server_sock; + + // 客户端地址信息 + struct sockaddr_in client_sock, *cli_addr; + int sin_size; + + // 连接Wifi + WifiConnect(CONFIG_WIFI_SSID, CONFIG_WIFI_PWD); + + // 创建socket + if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + perror("socket is error\r\n"); + exit(1); + } + + bzero(&server_sock, sizeof(server_sock)); + server_sock.sin_family = AF_INET; + server_sock.sin_addr.s_addr = htonl(INADDR_ANY); + server_sock.sin_port = htons(CONFIG_CLIENT_PORT); + + // 调用bind函数绑定socket和地址 + if (bind(sock_fd, (struct sockaddr *)&server_sock, sizeof(struct sockaddr)) == -1) { + exit(1); + } + + // 调用listen函数监听(指定port监听) + if (listen(sock_fd, TCP_BACKLOG) == -1) { + exit(1); + } + + printf("start accept\n"); + + // 调用accept函数从队列中 + while (1) { + sin_size = sizeof(struct sockaddr_in); + + if ((new_fd = accept(sock_fd, (struct sockaddr *)&client_sock, (socklen_t *)&sin_size)) == -1) { + perror("accept"); + continue; + } + + cli_addr = malloc(sizeof(struct sockaddr)); + + printf("accept addr\r\n"); + + if (cli_addr != NULL) { + int ret; + if (ret = memcpy_s(cli_addr, sizeof(struct sockaddr), &client_sock, sizeof(struct sockaddr)) != 0) { + perror("memcpy is error\r\n"); + exit(1); + } + } + // 处理目标 + ssize_t ret; + + while (1) { + memset_s(recvbuf, sizeof(recvbuf), 0, sizeof(recvbuf)); + if ((ret = recv(new_fd, recvbuf, sizeof(recvbuf), 0)) == -1) { + printf("recv error \r\n"); + } + printf("recv :%s\r\n", recvbuf); + sleep(TASK_DELAY_2S); + if ((ret = send(new_fd, buf, strlen(buf) + 1, 0)) == -1) { + perror("send : "); + } + sleep(TASK_DELAY_2S); + } + close(new_fd); + } +} + +static void TCPServerDemo(void) +{ + osThreadAttr_t attr; + + attr.name = "TCPServerTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + if (osThreadNew((osThreadFunc_t)TCPServerTask, NULL, &attr) == NULL) { + printf("[TCPServerDemo] Failed to create TCPServerTask!\n"); + } +} + +APP_FEATURE_INIT(TCPServerDemo); diff --git a/D4_iot_tcp_server/wifi/wifi_connect.c b/D4_iot_tcp_server/wifi/wifi_connect.c new file mode 100644 index 0000000000000000000000000000000000000000..76ad7a6a99bd249a530a88fa371f5fd4bc65fdb8 --- /dev/null +++ b/D4_iot_tcp_server/wifi/wifi_connect.c @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. + * 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 + +#include "lwip/api_shell.h" +#include "lwip/ip4_addr.h" +#include "lwip/netif.h" +#include "lwip/netifapi.h" + +#include "cmsis_os2.h" +#include "ohos_init.h" +#include "wifi_device.h" +#include "wifi_error_code.h" + +#define DEF_TIMEOUT 15 +#define ONE_SECOND 1 +#define DHCP_DELAY 100 + +static int WiFiInit(void); +static void WaitSacnResult(void); +static int WaitConnectResult(void); +static void OnWifiScanStateChangedHandler(int state, int size); +static void OnWifiConnectionChangedHandler(int state, WifiLinkedInfo *info); +static void OnHotspotStaJoinHandler(StationInfo *info); +static void OnHotspotStateChangedHandler(int state); +static void OnHotspotStaLeaveHandler(StationInfo *info); + +static int g_staScanSuccess = 0; +static int g_ConnectSuccess = 0; +static int g_ssid_count = 0; +static struct netif *g_lwip_netif = NULL; +static WifiEvent g_wifiEventHandler = { 0 }; +WifiErrorCode error; + +#define SELECT_WLAN_PORT "wlan0" + + +int WifiConnectAp(const char *ssid, const char *psk, WifiScanInfo *info, int i) +{ + if (strcmp(ssid, info[i].ssid) == 0) { + int result; + printf("Select:%3d wireless, Waiting...\r\n", i + 1); + + // 拷贝要连接的热点信息 + WifiDeviceConfig select_ap_config = { 0 }; + strcpy_s(select_ap_config.ssid, sizeof(select_ap_config.ssid), info[i].ssid); + strcpy_s(select_ap_config.preSharedKey, sizeof(select_ap_config.preSharedKey), psk); + select_ap_config.securityType = WIFI_SEC_TYPE_PSK; + + if (AddDeviceConfig(&select_ap_config, &result) == WIFI_SUCCESS) { + if (ConnectTo(result) == WIFI_SUCCESS && WaitConnectResult() == 1) { + g_lwip_netif = netifapi_netif_find(SELECT_WLAN_PORT); + return 0; + } + } + } + return -1; +} + +int WifiConnect(const char *ssid, const char *psk) +{ + unsigned int size = WIFI_SCAN_HOTSPOT_LIMIT; + + // 初始化WIFI + if (WiFiInit() != WIFI_SUCCESS) { + printf("WiFiInit failed, error = %d\r\n", error); + return -1; + } + // 分配空间,保存WiFi信息 + WifiScanInfo *info = malloc(sizeof(WifiScanInfo) * WIFI_SCAN_HOTSPOT_LIMIT); + if (info == NULL) { + return -1; + } + // 轮询查找WiFi列表 + do { + Scan(); + WaitSacnResult(); + error = GetScanInfoList(info, &size); + } while (g_staScanSuccess != 1); + // 打印WiFi列表 + printf("********************\r\n"); + for (uint8_t i = 0; i < g_ssid_count; i++) { + printf("no:%03d, ssid:%-30s, rssi:%5d\r\n", i + 1, info[i].ssid, info[i].rssi); + } + printf("********************\r\n"); + // 连接指定的WiFi热点 + for (uint8_t i = 0; i < g_ssid_count; i++) { + if (WifiConnectAp(ssid, psk, info, i) == WIFI_SUCCESS) { + printf("WiFi connect succeed!\r\n"); + break; + } + + if (i == g_ssid_count - 1) { + printf("ERROR: No wifi as expected\r\n"); + while (1) + osDelay(DHCP_DELAY); + } + } + + // 启动DHCP + if (g_lwip_netif) { + dhcp_start(g_lwip_netif); + printf("begain to dhcp\r\n"); + } + // 等待DHCP + for (;;) { + if (dhcp_is_bound(g_lwip_netif) == ERR_OK) { + printf("<-- DHCP state:OK -->\r\n"); + // 打印获取到的IP信息 + netifapi_netif_common(g_lwip_netif, dhcp_clients_info_show, NULL); + break; + } + osDelay(DHCP_DELAY); + } + return 0; +} + +int WiFiInit(void) +{ + g_wifiEventHandler.OnWifiScanStateChanged = OnWifiScanStateChangedHandler; + g_wifiEventHandler.OnWifiConnectionChanged = OnWifiConnectionChangedHandler; + g_wifiEventHandler.OnHotspotStaJoin = OnHotspotStaJoinHandler; + g_wifiEventHandler.OnHotspotStaLeave = OnHotspotStaLeaveHandler; + g_wifiEventHandler.OnHotspotStateChanged = OnHotspotStateChangedHandler; + error = RegisterWifiEvent(&g_wifiEventHandler); + if (error != WIFI_SUCCESS) { + printf("register wifi event fail!\r\n"); + return -1; + } + // 使能WIFI + if (EnableWifi() != WIFI_SUCCESS) { + printf("EnableWifi failed, error = %d\r\n", error); + return -1; + } + // 判断WIFI是否激活 + if (IsWifiActive() == 0) { + printf("Wifi station is not actived.\r\n"); + return -1; + } + return 0; +} + +static void OnWifiScanStateChangedHandler(int state, int size) +{ + if (size > 0) { + g_ssid_count = size; + g_staScanSuccess = 1; + } + printf("callback function for wifi scan:%d, %d\r\n", state, size); + return; +} + +static void OnWifiConnectionChangedHandler(int state, WifiLinkedInfo *info) +{ + if (info == NULL) { + printf("WifiConnectionChanged:info is null, stat is %d.\n", state); + } else { + if (state == WIFI_STATE_AVALIABLE) { + g_ConnectSuccess = 1; + } else { + g_ConnectSuccess = 0; + } + } +} + +static void OnHotspotStaJoinHandler(StationInfo *info) +{ + (void)info; + printf("STA join AP\n"); + return; +} + +static void OnHotspotStaLeaveHandler(StationInfo *info) +{ + (void)info; + printf("HotspotStaLeave:info is null.\n"); + return; +} + +static void OnHotspotStateChangedHandler(int state) +{ + printf("HotspotStateChanged:state is %d.\n", state); + return; +} + +static void WaitSacnResult(void) +{ + int scanTimeout = DEF_TIMEOUT; + while (scanTimeout > 0) { + sleep(ONE_SECOND); + scanTimeout--; + if (g_staScanSuccess == 1) { + printf("WaitSacnResult:wait success[%d]s\n", (DEF_TIMEOUT - scanTimeout)); + break; + } + } + if (scanTimeout <= 0) { + printf("WaitSacnResult:timeout!\n"); + } +} + +static int WaitConnectResult(void) +{ + int ConnectTimeout = DEF_TIMEOUT; + while (ConnectTimeout > 0) { + sleep(ONE_SECOND); + ConnectTimeout--; + if (g_ConnectSuccess == 1) { + printf("WaitConnectResult:wait success[%d]s\n", (DEF_TIMEOUT - ConnectTimeout)); + break; + } + } + if (ConnectTimeout <= 0) { + printf("WaitConnectResult:timeout!\n"); + return 0; + } + return 1; +} diff --git a/D4_iot_tcp_server/wifi/wifi_connect.h b/D4_iot_tcp_server/wifi/wifi_connect.h new file mode 100644 index 0000000000000000000000000000000000000000..fe83a633c5e1a9a52b280e3e9a47f365c81a12bf --- /dev/null +++ b/D4_iot_tcp_server/wifi/wifi_connect.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. + * 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. + */ + +#ifndef __WIFI_CONNECT_H__ +#define __WIFI_CONNECT_H__ + +int WifiConnect(const char *ssid, const char *psk); + +#endif /* __WIFI_CONNECT_H__ */ + diff --git a/EBox_IoT_028_Env_GPIO_LED/BUILD.gn b/EBox_IoT_028_Env_GPIO_LED/BUILD.gn index e950f9739872689c1c45a9cd0cbcf2af605627dc..0df21916cd42d121946edd7dcce367502b086304 100644 --- a/EBox_IoT_028_Env_GPIO_LED/BUILD.gn +++ b/EBox_IoT_028_Env_GPIO_LED/BUILD.gn @@ -1,10 +1,22 @@ -static_library("gpio_out_led") { +<<<<<<< HEAD +static_library("gps") { sources = [ - "gpio_out_led.c", + "gps.c", ] include_dirs = [ "//base/iot_hardware/peripheral/interfaces/kits", "../../iot_hardware_hals/include", ] +======= +static_library("gpio_out_led") { + sources = [ + "gpio_out_led.c", + ] + + include_dirs = [ + "//base/iot_hardware/peripheral/interfaces/kits", + "../../iot_hardware_hals/include", + ] +>>>>>>> 467b595 (“2”) } \ No newline at end of file diff --git a/EBox_IoT_028_Env_GPIO_LED/gpio_out_led.c b/EBox_IoT_028_Env_GPIO_LED/gpio_out_led.c index c4b1662f1b481a0337128fb123f650c68731e0be..e8667e956990e0d0ffcf43026aca7dc837795a42 100644 --- a/EBox_IoT_028_Env_GPIO_LED/gpio_out_led.c +++ b/EBox_IoT_028_Env_GPIO_LED/gpio_out_led.c @@ -1,121 +1,121 @@ -#include -// #include -#include -#include "ohos_init.h" -#include "cmsis_os2.h" -#include "los_task.h" -//#include "los_debug.h" -#include "iot_gpio_ex.h" -#include "iot_gpio.h" -#define LED_OFF 0 -#define LED_ON 1 -#define LED_SPARK 2 -#define LED_NAME_GPIO_5 5 -#define LED_SPARK_INTERVAL_TIME 50 -int g_ledState; - - -void LedGpioInit(void) -// 初始化LED引脚 -{ - int ret = IoTGpioInit(LED_NAME_GPIO_5); - if (ret != 0) - { - printf("IoTGpioInit failed :%#x \r\n", ret); - return; - } - /*设置复用为GPIO功能*/ - ret = IoTGpioSetFunc(LED_NAME_GPIO_5, IOT_GPIO_FUNC_GPIO_5_GPIO); - if (ret != 0) - { - printf("IoTGpioSetFunc failed :%#x \r\n", ret); - return; - } - /*设置方向为输出*/ - ret = IoTGpioSetDir(LED_NAME_GPIO_5, IOT_GPIO_DIR_OUT); - if (ret != 0) - { - printf("IoTGpioSetDir failed :%#x \r\n", ret); - return; - } - printf("----- LedGpioInit success! -----\r\n"); -} -void LedGpioCtrl(unsigned short ledSta) -{ - switch (ledSta) - { - - case LED_ON: - { - IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_ON); - break; - } - case LED_OFF: - { - IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_OFF); - break; - } - case LED_SPARK: - { - IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_ON); - osDelay(LED_SPARK_INTERVAL_TIME); - IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_OFF); - osDelay(LED_SPARK_INTERVAL_TIME); - IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_ON); - osDelay(LED_SPARK_INTERVAL_TIME); - IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_OFF); - break; - } - default: - break; - } -} -static void GpiooutTask(void) -{ - /*循环检测按键状态并处理*/ - while (1) - { - switch (g_ledState) - { - case LED_ON: - g_ledState = LED_SPARK; - printf("led State : SPART \r\n"); - break; - case LED_OFF: - g_ledState = LED_ON; - printf("led State : ON \r\n"); - break; - case LED_SPARK: - g_ledState = LED_OFF; - printf("led State : OFF \r\n"); - break; - default: - g_ledState = LED_OFF; - break; - } - LedGpioCtrl(g_ledState); - osDelay(LED_SPARK_INTERVAL_TIME); - } - return; -} -void GpiooutSamp1e(void) -{ - // 初始化 - LedGpioInit(); - /*设置线程属性*/ - osThreadAttr_t attr; - attr.name = "GpioutTask"; - attr.attr_bits = 0U; - attr.cb_mem = NULL; - attr.cb_size = 0U; - attr.stack_mem = NULL; - attr.stack_size = 1024 * 4; - attr.priority = 20; - /*创建定时控制LED灯线程*/ - osThreadId_t threadID1 = osThreadNew((osThreadFunc_t)GpiooutTask, NULL, &attr); - if (threadID1 = NULL) - { - printf("Falied to create GpiooutTask!\r\n"); - } -} +#include +// #include +#include +#include "ohos_init.h" +#include "cmsis_os2.h" +#include "los_task.h" +//#include "los_debug.h" +#include "iot_gpio_ex.h" +#include "iot_gpio.h" +#define LED_OFF 0 +#define LED_ON 1 +#define LED_SPARK 2 +#define LED_NAME_GPIO_5 5 +#define LED_SPARK_INTERVAL_TIME 50 +int g_ledState; + + +void LedGpioInit(void) +// 初始化LED引脚 +{ + int ret = IoTGpioInit(LED_NAME_GPIO_5); + if (ret != 0) + { + printf("IoTGpioInit failed :%#x \r\n", ret); + return; + } + /*设置复用为GPIO功能*/ + ret = IoTGpioSetFunc(LED_NAME_GPIO_5, IOT_GPIO_FUNC_GPIO_5_GPIO); + if (ret != 0) + { + printf("IoTGpioSetFunc failed :%#x \r\n", ret); + return; + } + /*设置方向为输出*/ + ret = IoTGpioSetDir(LED_NAME_GPIO_5, IOT_GPIO_DIR_OUT); + if (ret != 0) + { + printf("IoTGpioSetDir failed :%#x \r\n", ret); + return; + } + printf("----- LedGpioInit success! -----\r\n"); +} +void LedGpioCtrl(unsigned short ledSta) +{ + switch (ledSta) + { + + case LED_ON: + { + IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_ON); + break; + } + case LED_OFF: + { + IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_OFF); + break; + } + case LED_SPARK: + { + IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_ON); + osDelay(LED_SPARK_INTERVAL_TIME); + IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_OFF); + osDelay(LED_SPARK_INTERVAL_TIME); + IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_ON); + osDelay(LED_SPARK_INTERVAL_TIME); + IoTGpioSetOutputVal(LED_NAME_GPIO_5, LED_OFF); + break; + } + default: + break; + } +} +static void GpiooutTask(void) +{ + /*循环检测按键状态并处理*/ + while (1) + { + switch (g_ledState) + { + case LED_ON: + g_ledState = LED_SPARK; + printf("led State : SPART \r\n"); + break; + case LED_OFF: + g_ledState = LED_ON; + printf("led State : ON \r\n"); + break; + case LED_SPARK: + g_ledState = LED_OFF; + printf("led State : OFF \r\n"); + break; + default: + g_ledState = LED_OFF; + break; + } + LedGpioCtrl(g_ledState); + osDelay(LED_SPARK_INTERVAL_TIME); + } + return; +} +void GpiooutSamp1e(void) +{ + // 初始化 + LedGpioInit(); + /*设置线程属性*/ + osThreadAttr_t attr; + attr.name = "GpioutTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = 1024 * 4; + attr.priority = 20; + /*创建定时控制LED灯线程*/ + osThreadId_t threadID1 = osThreadNew((osThreadFunc_t)GpiooutTask, NULL, &attr); + if (threadID1 = NULL) + { + printf("Falied to create GpiooutTask!\r\n"); + } +} APP_FEATURE_INIT(GpiooutSamp1e); \ No newline at end of file diff --git a/EBox_IoT_032_MPU6050_manhole_GUE/BUILD.gn b/EBox_IoT_032_MPU6050_manhole_GUE/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..43161937b1fadd04bed1ef36d47ef679b76285e4 --- /dev/null +++ b/EBox_IoT_032_MPU6050_manhole_GUE/BUILD.gn @@ -0,0 +1,12 @@ +static_library("Manhole_module_sample") { + sources = [ + "ebox_manhole_module.c", + "ebox_manhole_mpu6050.c", + "ebox_manhole_led_7.c", + ] + + include_dirs = [ + "//base/iot_hardware/peripheral/interfaces/kits", + "../../iot_hardware_hals/include", + ] +} diff --git a/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_led_7.c b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_led_7.c new file mode 100644 index 0000000000000000000000000000000000000000..577648ed24f8201050bc072cd75fc3f537b50303 --- /dev/null +++ b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_led_7.c @@ -0,0 +1,41 @@ +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "ebox_manhole_led_7.h" + +#define LED_NAME_GPIO_7 7 + + +/* 按照注释要求补全函数功能代码 */ +/* 初始化LED */ +void ManholeLedInit(void) +{ +int ret = IoTGpioInit(LED_NAME_GPIO_7); + if (ret != 0) + { + printf("IoTGpioInit failed :%#x \r\n", ret); + return; + } + /*设置复用为GPIO功能*/ + ret = IoTGpioSetFunc(LED_NAME_GPIO_7, IOT_GPIO_FUNC_GPIO_5_GPIO); + if (ret != 0) + { + printf("IoTGpioSetFunc failed :%#x \r\n", ret); + return; + } + + /*设置方向为输出*/ + ret = IoTGpioSetDir(LED_NAME_GPIO_7, IOT_GPIO_DIR_OUT); + if (ret != 0) + { + printf("IoTGpioSetDir failed :%#x \r\n", ret); + return; + } + printf("ManholeLedInit success!\r\n"); +} + +/* 按照注释要求补全函数功能代码 */ +/* 根据入参state点亮或熄灭LED灯 */ +void ManholeLedCtrl(u32 state) +{ + IoTGpioSetOutputVal(LED_NAME_GPIO_7, state); +} \ No newline at end of file diff --git a/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_led_7.h b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_led_7.h new file mode 100644 index 0000000000000000000000000000000000000000..a4627c63572f9f6de8780954bbcb5232d9803660 --- /dev/null +++ b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_led_7.h @@ -0,0 +1,15 @@ +#ifndef __EBOX_MANHOLE_LED_7_H__ +#define __EBOX_MANHOLE_LED_7_H__ + +#include "kp_base_type.h" + + +//初始化烟雾探测模块的LED报警灯 +void ManholeLedInit(void); + +//控制烟雾探测模块的LED报警灯,1:点亮; 2:熄灭 +void ManholeLedCtrl(u32 state); + + +#endif + diff --git a/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_module.c b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_module.c new file mode 100644 index 0000000000000000000000000000000000000000..f5626fdb08167e906e4372aeb17e2691512ae648 --- /dev/null +++ b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_module.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include "cmsis_os2.h" +#include "ohos_init.h" +#include "ebox_manhole_mpu6050.h" +#include "ebox_manhole_led_7.h" + +#define SENSOR_TASK_STACK_SIZE (1024 * 4) +#define SENSOR_TASK_PRIO 25 +#define TASK_DELAY 3 +#define FLIP_THRESHOLD 100 + +int g_coverStatus = 0; + +/* 按照注释要求补全函数功能代码 */ +static int ManholeModuleTask(void) +{ + uint8_t ret; + MPU6050Data data; + int X = 0, Y = 0, Z = 0; + + /* MPU6050模块初始化 */ + ret = ManholeInit(); + if(ret != 0){ + printf("ManholeInit failed!\r\n"); + return; + } + + /* 1、从MPU6050获取检测到的加速度数据并打印 + 2、如果X、Y和Z方向有一个变化超出阈值FLIP_THRESHOLD,则LED灯亮,否则LED灯灭 + 3、周期检测,时间间隔TASK_DELAY + */ + while(1){ + ret = ManholeReadData(&data); + if(ret != 0){ + printf("E53_SC2 Read Data!\r\n"); + return; + } + printf("\r\nTemperature is %d\r\n",(int)data.Temperature); + printf("Accel[ACCEL_X_AXIS] is %d\r\n",(int)data.Accel[ACCEL_X_AXIS]); + printf("Accel[ACCEL_Y_AXIS] is %d\r\n",(int)data.Accel[ACCEL_Y_AXIS]); + printf("Accel[ACCEL_Z_AXIS] is %d\r\n",(int)data.Accel[ACCEL_Z_AXIS]); + if (X == 0 && Y == 0 && Z == 0) { + X = (int)data.Accel[ACCEL_X_AXIS]; + Y = (int)data.Accel[ACCEL_Y_AXIS]; + Z = (int)data.Accel[ACCEL_Z_AXIS]; + }else { + if (X + FLIP_THRESHOLD < data.Accel[ACCEL_X_AXIS] || X - FLIP_THRESHOLD > + data.Accel[ACCEL_X_AXIS] || + Y+ FLIP_THRESHOLD < data.Accel[ACCEL_Y_AXIS] || Y - FLIP_THRESHOLD > + data.Accel[ACCEL_Y_AXIS] || + Z + FLIP_THRESHOLD < data.Accel[ACCEL_Z_AXIS] || Z - FLIP_THRESHOLD > + data.Accel[ACCEL_Z_AXIS]) { + ManholeLedCtrl(LED_ON); + printf("Manhole cover flipped, LED ON!\r\n"); + g_coverStatus = 1; + } else { + ManholeLedCtrl(LED_OFF); + printf("Manhole cover restored, LED OFF!\r\n"); + g_coverStatus = 0; + } + } + sleep(TASK_DELAY); + } + + return 0; + +} + +static void ManholeModuleSample(void) +{ + /* Manhole 模块初始化 */ + ManholeLedInit(); + + /* 设置线程属性 */ + osThreadAttr_t attr; + attr.name = "ManholeModuleTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = SENSOR_TASK_STACK_SIZE; + attr.priority = SENSOR_TASK_PRIO; + /* 创建智慧井盖检测任务 */ + if (osThreadNew((osThreadFunc_t)ManholeModuleTask, NULL, &attr) == NULL) { + printf("Failed to create ManholeModuleTask!\n"); + } +} + +APP_FEATURE_INIT(ManholeModuleSample); + diff --git a/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_mpu6050.c b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_mpu6050.c new file mode 100644 index 0000000000000000000000000000000000000000..c4f58e3147263820083d7552ad08040cddfbdcce --- /dev/null +++ b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_mpu6050.c @@ -0,0 +1,382 @@ +#include +#include +#include +#include "cmsis_os2.h" +#include "iot_errno.h" +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "iot_i2c.h" +#include "iot_i2c_ex.h" +#include "ebox_manhole_mpu6050.h" +#include "kp_base_type.h" + +#define MPU6050_IO_GPIO_0 0 +#define MPU6050_IO_GPIO_1 1 +#define MPU6050_IIC_IDX_1 1 +#define MPU6050_IIC_BAUDRATE 400000 + + +/* 按照注释要求补全函数功能代码 */ +static void MPU6050IoInit(void) +{ + /* 初始化MPU6050 SDA引脚,编号为GPIO0 */ + u32 ret = IoTGpioInit(MPU6050_IO_GPIO_0); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioInit failed : %#x \r\n",ret); + return; + } + /* 将GPIO0设置复用为IIC功能 */ + ret = IoTGpioSetFunc(MPU6050_IO_GPIO_0,IOT_GPIO_FUNC_GPIO_0_I2C1_SDA); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioSetFunc failed : %#x \r\n",ret); + return; + } + + /* 初始化MPU6050 SCL引脚,编号为GPIO1 */ + ret = IoTGpioInit(MPU6050_IO_GPIO_1); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioInit failed : %#x \r\n",ret); + return; + } + /* 将GPIO1设置复用为IIC功能 */ + ret = IoTGpioSetFunc(MPU6050_IO_GPIO_1,IOT_GPIO_FUNC_GPIO_1_I2C1_SCL); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioSetFunc failed : %#x \r\n",ret); + return; + } + + /* MPU6050对应的IIC初始化 */ + ret = IoTI2cInit(MPU6050_IIC_IDX_1,MPU6050_IIC_BAUDRATE); + if(ret !=0){ + printf("IoTI2cInit failed : %#x \r\n",ret); + return; + } + + /* MPU6050对应的IIC设置波特率 */ + ret = IoTI2cSetBaudrate(MPU6050_IIC_IDX_1,MPU6050_IIC_BAUDRATE); + if(ret !=0){ + printf("IoTI2cSetBaudrate failed : %#x \r\n",ret); + return; + } + + + printf("MPU6050IoInit success!\r\n"); +} + +/*************************************************************** + * 函数功能: 通过I2C写入一个值到指定寄存器内 + * 输入参数: Addr:I2C设备地址 + * Reg:目标寄存器 + * Value:值 + * 返 回 值: 无 + * 说 明: 无 + **************************************************************/ +static int MPU6050WriteData(uint8_t Reg, uint8_t Value) +{ + uint32_t ret; + uint8_t send_data[MPU6050_DATA_2_BYTE] = { Reg, Value }; + ret = IoTI2cWrite(MPU6050_IIC_IDX_1, (MPU6050_ADDRESS << 1) | 0x00, send_data, sizeof(send_data)); + if (ret != 0) { + printf("===== Error: I2C write ret = 0x%x! =====\r\n", ret); + return -1; + } + return 0; +} + +/*************************************************************** + * 函数功能: 通过I2C写入一段数据到指定寄存器内 + * 输入参数: Addr:I2C设备地址 + * Reg:目标寄存器 + * RegSize:寄存器尺寸(8位或者16位) + * pBuffer:缓冲区指针 + * Length:缓冲区长度 + * 返 回 值: HAL_StatusTypeDef:操作结果 + * 说 明: 在循环调用是需加一定延时时间 + **************************************************************/ +static int MPU6050WriteBuffer(uint8_t Reg, uint8_t *pBuffer, uint16_t Length) +{ + uint32_t ret = 0; + uint8_t send_data[MPU6050_DATA_256_BYTE] = { 0 }; + + send_data[0] = Reg; + for (int j = 0; j < Length; j++) { + send_data[j + 1] = pBuffer[j]; + } + + ret = IoTI2cWrite(MPU6050_IIC_IDX_1, (MPU6050_ADDRESS << 1) | 0x00, send_data, Length + 1); + if (ret != 0) { + printf("===== Error: I2C write ret = 0x%x! =====\r\n", ret); + return -1; + } + return 0; +} + +/*************************************************************** + * 函数功能: 通过I2C读取一段寄存器内容存放到指定的缓冲区内 + * 输入参数: Addr:I2C设备地址 + * Reg:目标寄存器 + * RegSize:寄存器尺寸(8位或者16位) + * pBuffer:缓冲区指针 + * Length:缓冲区长度 + * 返 回 值: HAL_StatusTypeDef:操作结果 + * 说 明: 无 + **************************************************************/ +static int MPU6050ReadBuffer(uint8_t Reg, uint8_t *pBuffer, uint16_t Length) +{ + uint32_t ret = 0; + IotI2cData mpu6050_i2c_data = { 0 }; + uint8_t buffer[1] = { Reg }; + mpu6050_i2c_data.sendBuf = buffer; + mpu6050_i2c_data.sendLen = 1; + mpu6050_i2c_data.receiveBuf = pBuffer; + mpu6050_i2c_data.receiveLen = Length; + ret = IoTI2cWriteread(MPU6050_IIC_IDX_1, (MPU6050_ADDRESS << 1) | 0x00, &mpu6050_i2c_data); + if (ret != 0) { + printf("===== Error: I2C writeread ret = 0x%x! =====\r\n", ret); + return -1; + } + return 0; +} + +/*************************************************************** + * 函数功能: 写数据到MPU6050寄存器 + * 输入参数: 无 + * 返 回 值: 无 + * 说 明: 无 + ***************************************************************/ +static void MPU6050WriteReg(uint8_t reg_add, uint8_t reg_dat) +{ + MPU6050WriteData(reg_add, reg_dat); +} + +/*************************************************************** + * 函数功能: 从MPU6050寄存器读取数据 + * 输入参数: 无 + * 返 回 值: 无 + * 说 明: 无 + ***************************************************************/ +static int MPU6050ReadData(uint8_t reg_add, unsigned char *read, uint8_t num) +{ + return MPU6050ReadBuffer(reg_add, read, num); +} + +/*************************************************************** + * 函数功能: 读取MPU6050的加速度数据 + * 输入参数: 读取的加速度数据保存地址 + * 返 回 值: 成功返回0,失败返回-1 + * 说 明: 无 + ***************************************************************/ + /* 按照注释要求补全函数功能代码 */ +static int MPU6050ReadAcc(short *accData) +{ + int ret; + uint8_t buf[ACCEL_DATA_LEN]; + /* 从MPU6050的寄存器MPU6050_ACC_OUT读取长度为ACCEL_DATA_LEN的数据 */ + ret = MPU6050ReadData(MPU6050_ACC_OUT,buf,ACCEL_DATA_LEN); + if(ret !=0){ + return -1; + } + accData[ACCEL_X_AXIS]=(buf[ACCEL_X_AXIS_LSB]<Temperature = Temp ; + ReadData->Accel [ACCEL_X_AXIS] = Accel[ACCEL_X_AXIS]; + ReadData->Accel [ ACCEL_Y_AXIS] = Accel[ACCEL_Y_AXIS]; + ReadData->Accel [ ACCEL_Z_AXIS] = Accel[ACCEL_Z_AXIS]; + + + usleep(READ_DATA_DELAY_US); + return 0; +} + diff --git a/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_mpu6050.h b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_mpu6050.h new file mode 100644 index 0000000000000000000000000000000000000000..a1a6a54c98a5286015cbc3289364379f980d1916 --- /dev/null +++ b/EBox_IoT_032_MPU6050_manhole_GUE/ebox_manhole_mpu6050.h @@ -0,0 +1,70 @@ +#ifndef __EBOX_MANHOLE_MPU6050_H__ +#define __EBOX_MANHOLE_MPU6050_H__ + + +/* 宏定义 --------------------------------------------------------------------*/ +#define MPU6050_GYRO_OUT 0x43 // MPU6050陀螺仪数据寄存器地址 +#define MPU6050_ACC_OUT 0x3B // MPU6050加速度数据寄存器地址 +#define MPU6050_ADDRESS 0x68 // MPU6050器件读地址 +#define MPU6050_ADDRESS_AD0_LOW 0x68 // address pin low (GND), default for InvenSense evaluation board +#define MPU6050_RA_CONFIG 0x1A +#define MPU6050_RA_ACCEL_CONFIG 0x1C +#define MPU6050_RA_FF_THR 0x1D +#define MPU6050_RA_FF_DUR 0x1E +#define MPU6050_RA_MOT_THR 0x1F // 运动检测阀值设置寄存器 +#define MPU6050_RA_MOT_DUR 0x20 // 运动检测时间阀值 +#define MPU6050_RA_ZRMOT_THR 0x21 +#define MPU6050_RA_ZRMOT_DUR 0x22 +#define MPU6050_RA_FIFO_EN 0x23 +#define MPU6050_RA_INT_PIN_CFG 0x37 // 中断/旁路设置寄存器 +#define MPU6050_RA_INT_ENABLE 0x38 // 中断使能寄存器 +#define MPU6050_RA_TEMP_OUT_H 0x41 +#define MPU6050_RA_USER_CTRL 0x6A +#define MPU6050_RA_PWR_MGMT_1 0x6B +#define MPU6050_RA_WHO_AM_I 0x75 +#define MPU6050_DATA_2_BYTE 2 +#define MPU6050_DATA_256_BYTE 256 +#define MPU6050_DATA_DELAY 100 + +#define SENSOR_DATA_WIDTH_8_BIT 8 // 8 bit +#define ACCEL_DATA_LEN 6 +#define TEMP_DATA_LEN 2 + +#define MPU6050_CONSTANT_1 13200 +#define MPU6050_CONSTANT_2 280 +#define MPU6050_CONSTANT_3 13 + +#define RESET_DELAY_US 20000 +#define READ_DATA_DELAY_US 50000 + +enum AccelAxisNum { + ACCEL_X_AXIS = 0, + ACCEL_Y_AXIS = 1, + ACCEL_Z_AXIS = 2, + ACCEL_AXIS_NUM = 3, +}; +enum AccelAxisPart { + ACCEL_X_AXIS_LSB = 0, + ACCEL_X_AXIS_MSB = 1, + ACCEL_Y_AXIS_LSB = 2, + ACCEL_Y_AXIS_MSB = 3, + ACCEL_Z_AXIS_LSB = 4, + ACCEL_Z_AXIS_MSB = 5, + ACCEL_AXIS_BUTT, +}; +enum TempPart { + TEMP_LSB = 0, + TEMP_MSB = 1, +}; +/* E53_SC2传感器数据类型定义 ------------------------------------------------------------*/ +typedef struct { + short Temperature; + short Accel[3]; +} MPU6050Data; + +int ManholeInit(void); +int ManholeReadData(MPU6050Data *ReadData); + + +#endif + diff --git a/EBox_IoT_032_MPU6050_manhole_GUE/kp_base_type.h b/EBox_IoT_032_MPU6050_manhole_GUE/kp_base_type.h new file mode 100644 index 0000000000000000000000000000000000000000..3913556f34220f973f2977edec0bcae8ce09b4b8 --- /dev/null +++ b/EBox_IoT_032_MPU6050_manhole_GUE/kp_base_type.h @@ -0,0 +1,53 @@ +#ifndef __KP_BASE_TYPE_H__ +#define __KP_BASE_TYPE_H__ + +#include + +/* 基本数据类型 */ +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef unsigned long ulong; +typedef char s8; +typedef short s16; +typedef int s32; +typedef long long s64; +typedef long slong; + +#undef ERROR +#define ERROR (-1) + +#define KP_ERR_SUCCESS 0 +#define KP_ERR_FAILURE (-1) + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define KP_U16_MAX 0xFFFF +#define KP_U32_MAX 0xFFFFFFFF +#define KP_U64_MAX 0xFFFFFFFFFFFFFFFFUL + +#include +#define msleep(x) usleep((x)*1000) + +typedef enum { + GPIO_OUT_LOW = 0, /**< Low level.CNcomment:低电平CNend*/ + GPIO_OUT_HIGH /**< High level.CNcomment:高电平CNend*/ +} gpio_out_value; + +typedef enum { + LED_OFF = 0, + LED_ON, + LED_SPARK +} led_state; + +#define KP_DEBUG(fmt, args...) do { \ + printf("[KP][%s][%d]", __FILE__, __LINE__); \ + printf(fmt, ##args); \ + printf("\r\n"); \ + } while (0) + + +#endif \ No newline at end of file diff --git a/EBox_IoT_033_SHT30_Env/BUILD.gn b/EBox_IoT_033_SHT30_Env/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9331abf96969665233fad0d2abcb1e91482784e8 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/BUILD.gn @@ -0,0 +1,17 @@ + +static_library("Env_module_sample") { + sources = [ + "ebox_env_module.c", + "ebox_env_led.c", + "ebox_env_motor.c", + "ebox_env_sht30.c", + "wifiiot_pwm.c", + ] + + + include_dirs = [ + "//base/iot_hardware/peripheral/interfaces/kits", + "../../iot_hardware_hals/include", + #"include" + ] +} diff --git a/EBox_IoT_033_SHT30_Env/ebox_env_led.c b/EBox_IoT_033_SHT30_Env/ebox_env_led.c new file mode 100644 index 0000000000000000000000000000000000000000..46240491de676010f7db7017f753037e8f797f2e --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/ebox_env_led.c @@ -0,0 +1,65 @@ +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "ebox_env_led.h" + +#define LED_IO_GPIO_05 5 + + +/* 初始化LED */ +void EnvLedInit(void) +{ + /* LED报警灯连接芯片的GPIO6引脚,初始化GPIO-06引脚 */ + u8 ret = IoTGpioInit(LED_IO_GPIO_05); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioInit failed :%#x \r\n",ret); + return; + } + + /* 设置复用为GPIO功能 */ + ret = IoTGpioSetFunc(LED_IO_GPIO_05, IOT_GPIO_FUNC_GPIO_5_GPIO); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioSetFunc failed :%#x \r\n",ret); + return; + } + + /* 设置成输出有效,通过输出高电平点亮LED灯 */ + ret = IoTGpioSetDir(LED_IO_GPIO_05, IOT_GPIO_DIR_OUT); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioSetDir failed :%#x \r\n",ret); + return; + } + + printf("EnvLedInit success! \r\n"); +} + +/* 点亮或熄灭LED灯 */ +void EnvLedCtrl(u32 state) +{ + switch (state){ + case LED_OFF: + { + IoTGpioSetOutputVal(LED_IO_GPIO_05, GPIO_OUT_LOW); + break; + } + case LED_ON: + { + IoTGpioSetOutputVal(LED_IO_GPIO_05, GPIO_OUT_HIGH); + break; + } + case LED_SPARK: + { + IoTGpioSetOutputVal(LED_IO_GPIO_05, GPIO_OUT_HIGH); + osDelay(LED_SPARK_INTERVAL_TIME); + IoTGpioSetOutputVal(LED_IO_GPIO_05, GPIO_OUT_LOW); + osDelay(LED_SPARK_INTERVAL_TIME); + IoTGpioSetOutputVal(LED_IO_GPIO_05, GPIO_OUT_HIGH); + osDelay(LED_SPARK_INTERVAL_TIME); + IoTGpioSetOutputVal(LED_IO_GPIO_05, GPIO_OUT_LOW); + break; + } + default: + printf("invalid LED state \r\n"); + break; + } +} + diff --git a/EBox_IoT_033_SHT30_Env/ebox_env_led.h b/EBox_IoT_033_SHT30_Env/ebox_env_led.h new file mode 100644 index 0000000000000000000000000000000000000000..91a90c28d7118dd387b25d3ccb32d7be9982dac4 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/ebox_env_led.h @@ -0,0 +1,14 @@ +#ifndef __EBOX_ENV_LED_H__ +#define __EBOX_ENV_LED_H__ + +#include "kp_base_type.h" + + +//初始化智慧环境监测模块的LED报警灯 +void EnvLedInit(void); + +//控制智慧环境监测模块的LED报警灯, 0:熄灭;1:点亮; +void EnvLedCtrl(u32 state); + + +#endif diff --git a/EBox_IoT_033_SHT30_Env/ebox_env_module.c b/EBox_IoT_033_SHT30_Env/ebox_env_module.c new file mode 100644 index 0000000000000000000000000000000000000000..703ed1cb08488e50dc5eb1fac19b084cb8df7969 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/ebox_env_module.c @@ -0,0 +1,90 @@ +#include +#include +#include "ohos_init.h" +#include "cmsis_os2.h" +#include "iot_gpio.h" +#include "kp_base_type.h" +#include "ebox_env_led.h" +#include "ebox_env_motor.h" + +#define TASK_DELAY 200 + + +/* 温湿度传感器处理任务,周期查询温度和湿度数据 */ +void EnvShtTask(void) +{ + ShtIICInit(); + //osDelay(TASK_DELAY); + SHT3XInit(); + osDelay(TASK_DELAY); + + /* 初始化变量 */ + float temperature = 0.0; + float humidity = 0.0; + static motor_speed_level motorSpeed = MOTOR_SPEED_LEVEL_0; + + while (1) { + /* 查询温度和湿度数据 */ + SHT3XReadMeasurementBuffer(&temperature, &humidity); + //hi_watchdog_feed(); + printf("2000301532\r\n"); + printf("temperature:%.2f, humidity:%.2f \r\n", temperature, humidity); + if (humidity > 80.0) { + if (motorSpeed != MOTOR_SPEED_LEVEL_3) { + EnvMotorCtrl(MOTOR_SPEED_LEVEL_3); + motorSpeed = MOTOR_SPEED_LEVEL_3; + printf("adjust motor speed to level 3 \r\n"); + } + } else if (humidity > 70.0) { + if (motorSpeed != MOTOR_SPEED_LEVEL_2) { + EnvMotorCtrl(MOTOR_SPEED_LEVEL_2); + motorSpeed = MOTOR_SPEED_LEVEL_2; + printf("adjust motor speed to level 2 \r\n"); + } + } else if (humidity > 60.0) { + if (motorSpeed != MOTOR_SPEED_LEVEL_1) { + EnvMotorCtrl(MOTOR_SPEED_LEVEL_1); + motorSpeed = MOTOR_SPEED_LEVEL_1; + printf("adjust motor speed to level 1 \r\n"); + } + } else { + if (motorSpeed != MOTOR_SPEED_LEVEL_0) { + EnvMotorCtrl(MOTOR_SPEED_LEVEL_0); + motorSpeed = MOTOR_SPEED_LEVEL_0; + printf("adjust motor speed to level 0 \r\n"); + } + } + osDelay(TASK_DELAY); + } + + return; +} + +void EnvSht30Sample(void) +{ + /* 各模块初始化 */ + EnvLedInit(); + EnvMotorInit(); + //ShtIICInit(); + //SHT3XInit(); + osDelay(TASK_DELAY); + + /* 设置线程属性 */ + osThreadAttr_t attr; + attr.name = "EnvShtTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = 1024 * 4; + attr.priority = 20; + + /* 创建温湿度处理线程 */ + osThreadId_t threadIDSht = osThreadNew((osThreadFunc_t)EnvShtTask, NULL, &attr); + if (threadIDSht == NULL) + { + printf("Falied to create EnvShtTask!\r\n"); + } +} + +APP_FEATURE_INIT(EnvSht30Sample); diff --git a/EBox_IoT_033_SHT30_Env/ebox_env_module.h b/EBox_IoT_033_SHT30_Env/ebox_env_module.h new file mode 100644 index 0000000000000000000000000000000000000000..e7434f25c0e28d9a8f67d5dbef6fe57b3c815f52 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/ebox_env_module.h @@ -0,0 +1,14 @@ +#ifndef __EBOX_ENV_MODULE_H__ +#define __EBOX_ENV_MODULE_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + + +#endif diff --git a/EBox_IoT_033_SHT30_Env/ebox_env_motor.c b/EBox_IoT_033_SHT30_Env/ebox_env_motor.c new file mode 100644 index 0000000000000000000000000000000000000000..e7a9a57aaab11fc01eb04801299ecf9a7e7f6df6 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/ebox_env_motor.c @@ -0,0 +1,99 @@ +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "kp_base_type.h" +#include "ebox_env_motor.h" +#include "wifiiot_pwm.h" + +#define MOTOR_IO_GPIO_02 2 +#define MOTOR_PWM_PORT_02 2 +#define MOTOR_PWM_CLOCK_TYPE 0 +#define MOTOR_PWM_CLOCK_160M 160000000 +#define freq 2442 //min + + +/* 初始化电机模块 */ +void EnvMotorInit(void) +{ + /* 电机接在GPIO-02引脚,初始化GPIO-02引脚 */ + u32 ret = IoTGpioInit(MOTOR_IO_GPIO_02); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioInit failed :%#x \r\n",ret); + return; + } + + /* 设置复用为PWM功能 */ + ret = IoTGpioSetFunc(MOTOR_IO_GPIO_02, IOT_GPIO_FUNC_GPIO_2_PWM2_OUT); + if(ret != KP_ERR_SUCCESS){ + printf("IoTGpioSetFunc failed :%#x \r\n",ret); + return; + } + + /* PWM初始化 */ + ret = PwmDeinit(MOTOR_PWM_PORT_02); + if(ret != KP_ERR_SUCCESS){ + printf("PwmDeinit failed :%#x \r\n",ret); + return; + } + + ret = PwmInit(MOTOR_PWM_CLOCK_TYPE, MOTOR_PWM_PORT_02); + if(ret != KP_ERR_SUCCESS){ + printf("PwmInit failed :%#x \r\n",ret); + return; + } + + printf("----- EnvMotorInit success! -----\r\n"); +} + +/* 电机控制转动 */ +void EnvMotorCtrl(motor_speed_level state) +{ + /* 初始化变量 */ + u32 ret = 0; + + switch (state) { + case MOTOR_SPEED_LEVEL_0: + /* 关闭电机 */ + ret = PwmStop(MOTOR_PWM_PORT_02); + if (ret != KP_ERR_SUCCESS) { + printf("PwmStop failed ret : %#x \r\n", ret); + return; + } + printf("stop motor \r\n"); + return; + case MOTOR_SPEED_LEVEL_1: + /* 一档风扇 */ + //ret = PwmStart(MOTOR_PWM_PORT_02, MOTOR_PWM_CLOCK_160M, PWM_DUTY_MAX * MOTOR_SPEED_LEVEL_1 / MOTOR_SPEED_LEVEL_MAX, freq); + ret = PwmStart(MOTOR_PWM_PORT_02, MOTOR_PWM_CLOCK_160M, 40, freq); + if (ret != KP_ERR_SUCCESS) { + printf("PwmStart failed ret : %#x \r\n", ret); + return; + } + printf("start motor level 1 \r\n"); + return; + case MOTOR_SPEED_LEVEL_2: + /* 二档风扇 */ + //ret = PwmStart(MOTOR_PWM_PORT_02, MOTOR_PWM_CLOCK_160M, PWM_DUTY_MAX * MOTOR_SPEED_LEVEL_2 / MOTOR_SPEED_LEVEL_MAX, freq); + ret = PwmStart(MOTOR_PWM_PORT_02, MOTOR_PWM_CLOCK_160M, 60, freq); + if (ret != KP_ERR_SUCCESS) { + printf("PwmStart failed ret : %#x \r\n", ret); + return; + } + printf("start motor level 2 \r\n"); + return; + case MOTOR_SPEED_LEVEL_3: + /* 三档风扇 */ + //ret = PwmStart(MOTOR_PWM_PORT_02, MOTOR_PWM_CLOCK_160M, PWM_DUTY_MAX * MOTOR_SPEED_LEVEL_3 / MOTOR_SPEED_LEVEL_MAX, freq); + ret = PwmStart(MOTOR_PWM_PORT_02, MOTOR_PWM_CLOCK_160M, 80, freq); + if (ret != KP_ERR_SUCCESS) { + printf("PwmStart failed ret : %#x \r\n", ret); + return; + } + printf("start motor level 3 \r\n"); + return; + default: + /* 无效风扇转速 */ + printf("invalid motor level \r\n"); + return; + } +} + diff --git a/EBox_IoT_033_SHT30_Env/ebox_env_motor.h b/EBox_IoT_033_SHT30_Env/ebox_env_motor.h new file mode 100644 index 0000000000000000000000000000000000000000..7b7ad88011f7ab46b370eb7227c6d9ff34d4462d --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/ebox_env_motor.h @@ -0,0 +1,21 @@ +#ifndef __EBOX_ENV_MOTOR_H__ +#define __EBOX_ENV_MOTOR_H__ + +typedef enum { + MOTOR_SPEED_LEVEL_0 = 0, /* stop */ + MOTOR_SPEED_LEVEL_1, + MOTOR_SPEED_LEVEL_2, + MOTOR_SPEED_LEVEL_3, + MOTOR_SPEED_LEVEL_MAX /* invalid */ +} motor_speed_level; + + +/* 初始化电机 */ +void EnvMotorInit(void); + +/* 电机控制转动 */ +void EnvMotorCtrl(motor_speed_level state); + + +#endif + diff --git a/EBox_IoT_033_SHT30_Env/ebox_env_sht30.c b/EBox_IoT_033_SHT30_Env/ebox_env_sht30.c new file mode 100644 index 0000000000000000000000000000000000000000..389807e54b915500e3d8aaf5f574f15b044548d2 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/ebox_env_sht30.c @@ -0,0 +1,296 @@ +#include +#include +#include "ohos_init.h" +#include "cmsis_os2.h" +#include "hi_errno.h" +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "iot_i2c.h" +#include "kp_base_type.h" +#include "ebox_env_sht30.h" + +#define SHT30_SDA_IO_GPIO_00 0 +#define SHT30_SCL_IO_GPIO_01 1 +#define SHT30_IIC_IDX_1 1 +#define SHT30_IIC_BAUDRATE 400000 + + +/* IIC功能初始化 */ +void ShtIICInit(void) +{ + // 初始化SHT30 SDA引脚 + u32 ret = IoTGpioInit(SHT30_SDA_IO_GPIO_00); + if(ret != 0){ + printf("IoTGpioInit failed :%#x \r\n",ret); + return; + } + + /* 设置复用为IIC功能 */ + ret = IoTGpioSetFunc(SHT30_SDA_IO_GPIO_00, IOT_GPIO_FUNC_GPIO_0_I2C1_SDA); + if(ret != 0){ + printf("IoTGpioSetFunc failed :%#x \r\n",ret); + return; + } + + // 初始化SHT30 SCL引脚 + ret = IoTGpioInit(SHT30_SCL_IO_GPIO_01); + if(ret != 0){ + printf("IoTGpioInit failed :%#x \r\n",ret); + return; + } + + /* 设置复用为IIC功能 */ + ret = IoTGpioSetFunc(SHT30_SCL_IO_GPIO_01, IOT_GPIO_FUNC_GPIO_1_I2C1_SCL); + if(ret != 0){ + printf("IoTGpioSetFunc failed :%#x \r\n",ret); + return; + } + + /* IIC初始化 */ + ret = IoTI2cInit(SHT30_IIC_IDX_1, SHT30_IIC_BAUDRATE); + if (ret != 0) { + printf("IoTI2cInit failed :%#x \r\n",ret); + return; + } + + /* IIC设置波特率 */ + ret = IoTI2cSetBaudrate(SHT30_IIC_IDX_1, SHT30_IIC_BAUDRATE); + if (ret != 0) { + printf("IoTI2cSetBaudrate failed :%#x \r\n",ret); + return; + } + + printf("----- ShtIICInit success! -----\r\n"); +} + +static unsigned char SHT3XCalcCrc(unsigned char data[], unsigned int nbrOfBytes) +{ + unsigned char bit; // bit mask + unsigned char crc = 0xFF; // calculated checksum + unsigned char byteCtr; // byte counter + + // calculates 8-Bit checksum with given polynomial + for(byteCtr = 0; byteCtr < nbrOfBytes; byteCtr++) + { + crc ^= (data[byteCtr]); + for(bit = 8; bit > 0; --bit) + { + if(crc & 0x80) + crc = (crc << 1) ^ POLYNOMIAL; + else + crc = (crc << 1); + } + } + + return crc; +} + +static etError SHT3XCheckCrc(unsigned char data[],\ + unsigned int nbrOfBytes, unsigned char checksum) +{ + unsigned char crc; // calculated checksum + + // calculates 8-Bit checksum + crc = SHT3XCalcCrc(data, nbrOfBytes); + + // verify checksum + if(crc != checksum) + return CHECKSUM_ERROR; + else + return NO_ERROR; +} + +static int SHT3xReadSerialNumber(unsigned int *serialNumber) +{ + unsigned int ret = 0; + unsigned char serialNumWords[6] = {0}; + unsigned char cmd[2] = {0x37,0x80,}; + + ret = IoTI2cWrite(SHT30_IIC_IDX_1, ((unsigned char)0x44) << 1, cmd, sizeof(cmd)); + if(ret != 0){ + printf("SHT3xReadSerialNumber IoTI2cWrite failed ret :%#x \r\n",ret); + return ret; + } + + ret = IoTI2cRead(SHT30_IIC_IDX_1, ((unsigned char)0x44) << 1 | 0x01, serialNumWords, sizeof(serialNumWords)); + if(ret != 0){ + printf("SHT3xReadSerialNumber IoTI2cRead failed ret :%#x \r\n",ret); + return ret; + } + //dump_buf(serialNumWords,sizeof(serialNumWords)); + + ret = SHT3XCheckCrc(serialNumWords,2,serialNumWords[2]); + if(ret != NO_ERROR){ + printf("read serial number crc check failed \r\n"); + return ret; + } + + ret = SHT3XCheckCrc(&serialNumWords[3],2,serialNumWords[5]); + if(ret != NO_ERROR){ + printf("read serial number crc check failed \r\n"); + return ret; + } + return ret; +} + +static int SHT3xWriteCMD(unsigned short cmd) +{ + unsigned int ret = 0; + unsigned char sendbuf[2] = {0}; + unsigned char rcvbuf[2] = {0}; + + sendbuf[0] = (cmd & 0xff00) >> 8; + sendbuf[1] = cmd & 0xff; + //dump_buf(sendbuf,2); + ret = IoTI2cWrite(SHT30_IIC_IDX_1, ((unsigned char)0x44) << 1, sendbuf, sizeof(sendbuf)); + if(ret != 0){ + printf("SHT3x_WriteCMD IoTI2cWrite failed, cmd : %#x, ret :%#x \r\n", cmd, ret); + return ret; + } + return 0; +} + +static int SHT3xRead4BytesDataAndCrc(unsigned short *data) +{ + unsigned int ret = 0; + unsigned char sendbuf[2] = {0}; + unsigned char rcvbuf[6] = {0}; + + if(data == NULL){ + printf("SHT3xRead4BytesDataAndCrc invalid para \r\n"); + return ret; + } + + ret = IoTI2cRead(SHT30_IIC_IDX_1, ((unsigned char)0x44) << 1 | 0x01, rcvbuf, sizeof(rcvbuf)); + if(ret != 0){ + printf("SHT3xRead4BytesDataAndCrc IoTI2cRead failed ret :%#x \r\n",ret); + return ret; + } + + ret = SHT3XCheckCrc(rcvbuf,2,rcvbuf[2]); + if(ret != NO_ERROR){ + printf("read serial number crc check failed \r\n"); + return ret; + } + + ret = SHT3XCheckCrc(&rcvbuf[3],2,rcvbuf[5]); + if(ret != NO_ERROR){ + printf("read serial number crc check failed \r\n"); + return ret; + } + + data[0] = rcvbuf[0] << 8 | rcvbuf[1]; + data[1] = rcvbuf[3] << 8 | rcvbuf[4]; + + return 0; +} + +static int SHT3xRead2BytesDataAndCrc(unsigned short *data) +{ + unsigned int ret = -1; + unsigned char sendbuf[2] = {0}; + unsigned char rcvbuf[3] = {0}; + + if(data == NULL){ + printf("SHT3xRead2BytesDataAndCrc invalid para \r\n"); + return ret; + } + + ret = IoTI2cRead(SHT30_IIC_IDX_1, ((unsigned char)0x44) << 1 | 0x01, rcvbuf, sizeof(rcvbuf)); + if(ret != 0){ + printf("SHT3xRead2BytesDataAndCrc IoTI2cRead failed ret :%#x \r\n",ret); + return ret; + } + + ret = SHT3XCheckCrc(rcvbuf,2,rcvbuf[2]); + if(ret != NO_ERROR){ + printf("read serial number crc check failed \r\n"); + return ret; + } + + data[0] = rcvbuf[0] << 8 | rcvbuf[1]; + return 0; +} + +void SHT3XSoftReset(void) +{ + SHT3xWriteCMD(CMD_SOFT_RESET); +} + +static void SHT3XReadStatus(unsigned short* status) +{ + SHT3xWriteCMD(CMD_READ_STATUS); + SHT3xRead2BytesDataAndCrc(status); +} + +static void SHT3XClearAllAlertFlags(void) +{ + SHT3xWriteCMD(CMD_CLEAR_STATUS); +} + +/* +static void SHT3X_StartPeriodicMeasurment(void) +{ + // medium repeatability, 2.0 Hz + SHT3x_WriteCMD(CMD_MEAS_PERI_2_M); +} +*/ +static float SHT3XCalcTemperature(unsigned short rawValue) +{ + return 175.0f * (float)rawValue / 65535.0f - 45.0f; +} + +static float SHT3XCalcHumidity(unsigned short rawValue) +{ + return 100.0f * (float)rawValue / 65535.0f; +} + +/* SHT3X模块IIC功能初始化 */ +void SHT3XInit(void) +{ + int ret = 0; + unsigned short data[2] = {0}; + //SHT3X_SoftReset_t(); + SHT3xWriteCMD(CMD_READ_SERIALNBR); + osDelay(100); + SHT3xWriteCMD(CMD_MEAS_PERI_2_M); + //SHT3X_StartPeriodicMeasurment(); +} + +/* 利用IIC从SHT30设备读取温度和湿度数据 */ +void SHT3XReadMeasurementBuffer(float* temperature, float* humidity) +{ + + unsigned int rawValueTemp = 0; + + SHT3xWriteCMD(CMD_FETCH_DATA); + SHT3xRead4BytesDataAndCrc((unsigned short *)&rawValueTemp); + + //dump_buf((unsigned char *)&rawValueTemp,sizeof(rawValueTemp)); + + *temperature = SHT3XCalcTemperature(rawValueTemp); + *humidity = SHT3XCalcHumidity(*((unsigned short *)(&rawValueTemp)+1)); +} + +static void SHT3XReadMeasurementVal(unsigned int para) +{ + (void) para; + static int cunt = 0; + static float humidity = 0.0; + static float temperature = 0.0; + + SHT3XReadMeasurementBuffer(&temperature,&humidity); + +} + +void *MonitorShtTask(void * para) /* 温湿度传感器处理函数 */ +{ + while(1){ + sleep(2); + SHT3XReadMeasurementVal(0); + printf("sth task \r\n"); + } + return NULL; +} + + diff --git a/EBox_IoT_033_SHT30_Env/ebox_env_sht30.h b/EBox_IoT_033_SHT30_Env/ebox_env_sht30.h new file mode 100644 index 0000000000000000000000000000000000000000..6dc1b5e3b73902dd789397d6beaa36a62698671b --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/ebox_env_sht30.h @@ -0,0 +1,99 @@ +#ifndef __EBOX_ENV_SHT30_H__ +#define __EBOX_ENV_SHT30_H__ + + +#define I2C_REG_ARRAY_LEN 64 +#define SHT3X_DEV_ADDR 0x80 /* 11000 0 */ +#define ES8311_REG_ADDR 0x10 +#define I2C_SEND_LEN_2 2 +#define I2C_RECV_LEN_1 1 + +#define POLYNOMIAL 0x131 // P(x) = x^8 + x^5 + x^4 + 1 = 100110001 + +typedef enum{ + NO_ERROR = 0x00, // no error + ACK_ERROR = 0x01, // no acknowledgment error + CHECKSUM_ERROR = 0x02, // checksum mismatch error + TIMEOUT_ERROR = 0x04, // timeout error + PARM_ERROR = 0x80, // parameter out of range error +}etError; + +typedef enum{ + CMD_READ_SERIALNBR = 0x3780, // read serial number + CMD_READ_STATUS = 0xF32D, // read status register + CMD_CLEAR_STATUS = 0x3041, // clear status register + CMD_HEATER_ENABLE = 0x306D, // enabled heater + CMD_HEATER_DISABLE = 0x3066, // disable heater + CMD_SOFT_RESET = 0x30A2, // soft reset + CMD_MEAS_CLOCKSTR_H = 0x2C06, // measurement: clock stretching, high repeatability + CMD_MEAS_CLOCKSTR_M = 0x2C0D, // measurement: clock stretching, medium repeatability + CMD_MEAS_CLOCKSTR_L = 0x2C10, // measurement: clock stretching, low repeatability + CMD_MEAS_POLLING_H = 0x2400, // measurement: polling, high repeatability + CMD_MEAS_POLLING_M = 0x240B, // measurement: polling, medium repeatability + CMD_MEAS_POLLING_L = 0x2416, // measurement: polling, low repeatability + CMD_MEAS_PERI_05_H = 0x2032, // measurement: periodic 0.5 mps, high repeatability + CMD_MEAS_PERI_05_M = 0x2024, // measurement: periodic 0.5 mps, medium repeatability + CMD_MEAS_PERI_05_L = 0x202F, // measurement: periodic 0.5 mps, low repeatability + CMD_MEAS_PERI_1_H = 0x2130, // measurement: periodic 1 mps, high repeatability + CMD_MEAS_PERI_1_M = 0x2126, // measurement: periodic 1 mps, medium repeatability + CMD_MEAS_PERI_1_L = 0x212D, // measurement: periodic 1 mps, low repeatability + CMD_MEAS_PERI_2_H = 0x2236, // measurement: periodic 2 mps, high repeatability + CMD_MEAS_PERI_2_M = 0x2220, // measurement: periodic 2 mps, medium repeatability + CMD_MEAS_PERI_2_L = 0x222B, // measurement: periodic 2 mps, low repeatability + CMD_MEAS_PERI_4_H = 0x2334, // measurement: periodic 4 mps, high repeatability + CMD_MEAS_PERI_4_M = 0x2322, // measurement: periodic 4 mps, medium repeatability + CMD_MEAS_PERI_4_L = 0x2329, // measurement: periodic 4 mps, low repeatability + CMD_MEAS_PERI_10_H = 0x2737, // measurement: periodic 10 mps, high repeatability + CMD_MEAS_PERI_10_M = 0x2721, // measurement: periodic 10 mps, medium repeatability + CMD_MEAS_PERI_10_L = 0x272A, // measurement: periodic 10 mps, low repeatability + CMD_FETCH_DATA = 0xE000, // readout measurements for periodic mode + CMD_R_AL_LIM_LS = 0xE102, // read alert limits, low set + CMD_R_AL_LIM_LC = 0xE109, // read alert limits, low clear + CMD_R_AL_LIM_HS = 0xE11F, // read alert limits, high set + CMD_R_AL_LIM_HC = 0xE114, // read alert limits, high clear + CMD_W_AL_LIM_HS = 0x611D, // write alert limits, high set + CMD_W_AL_LIM_HC = 0x6116, // write alert limits, high clear + CMD_W_AL_LIM_LC = 0x610B, // write alert limits, low clear + CMD_W_AL_LIM_LS = 0x6100, // write alert limits, low set + CMD_NO_SLEEP = 0x303E, +}etCommands; + +#define LITTLE_ENDIAN + +typedef union { + unsigned short u16; + struct{ +#ifdef LITTLE_ENDIAN // bit-order is little endian + unsigned short CrcStatus : 1; // write data checksum status + unsigned short CmdStatus : 1; // command status + unsigned short Reserve0 : 2; // reserved + unsigned short ResetDetected : 1; // system reset detected + unsigned short Reserve1 : 5; // reserved + unsigned short T_Alert : 1; // temperature tracking alert + unsigned short RH_Alert : 1; // humidity tracking alert + unsigned short Reserve2 : 1; // reserved + unsigned short HeaterStatus : 1; // heater status + unsigned short Reserve3 : 1; // reserved + unsigned short AlertPending : 1; // alert pending status +#else // bit-order is big endian + unsigned short AlertPending : 1; + unsigned short Reserve3 : 1; + unsigned short HeaterStatus : 1; + unsigned short Reserve2 : 1; + unsigned short RH_Alert : 1; + unsigned short T_Alert : 1; + unsigned short Reserve1 : 5; + unsigned short ResetDetected : 1; + unsigned short Reserve0 : 2; + unsigned short CmdStatus : 1; + unsigned short CrcStatus : 1; +#endif + }bit; +} regStatus; +void ShtIICInit(void); +void SHT3XSoftReset(void); +void SHT3XInit(void); +static int SHT3xReadSerialNumber(unsigned int *serialNumber); +void SHT3XReadMeasurementBuffer(float* temperature, float* humidity); +#endif + diff --git a/EBox_IoT_033_SHT30_Env/kp_base_type.h b/EBox_IoT_033_SHT30_Env/kp_base_type.h new file mode 100644 index 0000000000000000000000000000000000000000..7064a85a7f7c7a26a245e31edf1bfa142cb4a8a7 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/kp_base_type.h @@ -0,0 +1,54 @@ +#ifndef __KP_BASE_TYPE_H__ +#define __KP_BASE_TYPE_H__ + +#include + +/* 基本数据类型 */ +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef unsigned long ulong; +typedef char s8; +typedef short s16; +typedef int s32; +typedef long long s64; +typedef long slong; + +#undef ERROR +#define ERROR (-1) + +#define KP_ERR_SUCCESS 0 +#define KP_ERR_FAILURE (-1) + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define KP_U16_MAX 0xFFFF +#define KP_U32_MAX 0xFFFFFFFF +#define KP_U64_MAX 0xFFFFFFFFFFFFFFFFUL + +#include +#define msleep(x) usleep((x)*1000) + +typedef enum { + GPIO_OUT_LOW = 0, /**< Low level.CNcomment:低电平CNend*/ + GPIO_OUT_HIGH /**< High level.CNcomment:高电平CNend*/ +} gpio_out_value; + +typedef enum { + LED_OFF = 0, + LED_ON, + LED_SPARK +} led_state; +#define LED_SPARK_INTERVAL_TIME 30 + +#define KP_DEBUG(fmt, args...) do { \ + printf("[KP][%s][%d]", __FILE__, __LINE__); \ + printf(fmt, ##args); \ + printf("\r\n"); \ + } while (0) + + +#endif \ No newline at end of file diff --git a/EBox_IoT_033_SHT30_Env/wifiiot_pwm.c b/EBox_IoT_033_SHT30_Env/wifiiot_pwm.c new file mode 100644 index 0000000000000000000000000000000000000000..213a2c2a99cbc372b6059673b638713998c8a555 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/wifiiot_pwm.c @@ -0,0 +1,50 @@ +#include "hi_pwm.h" +#include "hi_errno.h" + +#define PWM_DUTY_MIN 0 +#define PWM_DUTY_MAX 100 +#define PWM_SHORT_MAX 0xFFFF + +unsigned int PwmInit(unsigned int clock, unsigned int port) +{ + /*if (hi_pwm_set_clock((hi_pwm_clk_source)clock) != HI_ERR_SUCCESS) { + return HI_ERR_FAILURE; + } + return hi_pwm_init((hi_pwm_port)port);*/ + if (hi_pwm_init((hi_pwm_port)port) != HI_ERR_SUCCESS) { + return HI_ERR_FAILURE; + } + return hi_pwm_set_clock((hi_pwm_clk_source)clock); +} + +unsigned int PwmDeinit(unsigned int port) +{ + return hi_pwm_deinit((hi_pwm_port)port); +} + +unsigned int PwmStart(unsigned int port, unsigned int clock, unsigned short duty, unsigned int freq) +{ + unsigned short hiDuty; + unsigned short hiFreq; + + if ((freq == 0) || (duty >= PWM_DUTY_MAX) || (duty == PWM_DUTY_MIN)) { + printf("%s %s %d HI_ERR_FAILURE \r\n", __FILE__, __FUNCTION__, __LINE__); + return HI_ERR_FAILURE; + } + + if ((clock / freq) > PWM_SHORT_MAX) { + printf("%s %s %d HI_ERR_FAILURE \r\n", __FILE__, __FUNCTION__, __LINE__); + return HI_ERR_FAILURE; + } + + hiFreq = (unsigned short)(clock / freq); + hiDuty = (duty * hiFreq) / PWM_DUTY_MAX; + + return hi_pwm_start((hi_pwm_port)port, hiDuty, hiFreq); +} + +unsigned int PwmStop(unsigned int port) +{ + return hi_pwm_stop((hi_pwm_port)port); +} + diff --git a/EBox_IoT_033_SHT30_Env/wifiiot_pwm.h b/EBox_IoT_033_SHT30_Env/wifiiot_pwm.h new file mode 100644 index 0000000000000000000000000000000000000000..c5eec73b3a260e725c061fcc1395a5f4dc303b84 --- /dev/null +++ b/EBox_IoT_033_SHT30_Env/wifiiot_pwm.h @@ -0,0 +1,31 @@ +#ifndef __WIFIIOT_PWM_H__ +#define __WIFIIOT_PWM_H__ + +typedef enum { + /** 160 MHz working clock */ + WIFI_IOT_PWM_CLK_160M, + /** 24 MHz or 40 MHz external crystal */ + WIFI_IOT_PWM_CLK_XTAL, + /** Maximum value */ + WIFI_IOT_PWM_CLK_MAX +} WifiIotPwmClkSource; + +typedef enum { + WIFI_IOT_PWM_PORT_PWM0 = 0, + WIFI_IOT_PWM_PORT_PWM1 = 1, + WIFI_IOT_PWM_PORT_PWM2 = 2, + WIFI_IOT_PWM_PORT_PWM3 = 3, + WIFI_IOT_PWM_PORT_PWM4 = 4, + WIFI_IOT_PWM_PORT_PWM5 = 5, + WIFI_IOT_PWM_PORT_MAX +} WifiIotPwmPort; + +unsigned int PwmInit(unsigned int clock, unsigned int port); + +unsigned int PwmDeinit(unsigned int port); + +unsigned int PwmStart(unsigned int port, unsigned int clock, unsigned short duty, unsigned int freq); + +unsigned int PwmStop(unsigned int port); + +#endif diff --git a/EBox_IoT_038_MQ7_Gas_GUE/BUILD.gn b/EBox_IoT_038_MQ7_Gas_GUE/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3b79cc0cab109e2b750fa6ca94f495fb8ee6efc3 --- /dev/null +++ b/EBox_IoT_038_MQ7_Gas_GUE/BUILD.gn @@ -0,0 +1,14 @@ +static_library("Gas_module_sample") { + sources = [ + "ebox_gas_module.c", + "ebox_gas_mq7.c", + "ebox_gas_led.c", + ] + + + include_dirs = [ + "//base/iot_hardware/peripheral/interfaces/kits", + "../../iot_hardware_hals/include", + ] +} + diff --git a/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_led.c b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_led.c new file mode 100644 index 0000000000000000000000000000000000000000..ab070d76691d9ac8b66e6eae5afd24beb6ce3497 --- /dev/null +++ b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_led.c @@ -0,0 +1,41 @@ +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "kp_base_type.h" +#include "ebox_gas_led.h" + +#define LED_NAME_GPIO_5 5 + + +/* 初始化LED */ +void LedInit(void) +{ + int ret = IoTGpioInit(LED_NAME_GPIO_5); + if (ret != 0) + { + printf("IoTGpioInit failed :%#x \r\n", ret); + return; + } + /*设置复用为GPIO功能*/ + ret = IoTGpioSetFunc(LED_NAME_GPIO_5, IOT_GPIO_FUNC_GPIO_5_GPIO); + if (ret != 0) + { + printf("IoTGpioSetFunc failed :%#x \r\n", ret); + return; + } + + /*设置方向为输出*/ + ret = IoTGpioSetDir(LED_NAME_GPIO_5, IOT_GPIO_DIR_OUT); + if (ret != 0) + { + printf("IoTGpioSetDir failed :%#x \r\n", ret); + return; + } + printf("LedInit success! \r\n"); +} + +/* 点亮或熄灭LED灯 */ +void LedCtrl(u32 state) +{ + /* 根据传入的参数来控制LED点亮、熄灭或闪烁 */ + IoTGpioSetOutputVal(LED_NAME_GPIO_5, state); +} \ No newline at end of file diff --git a/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_led.h b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_led.h new file mode 100644 index 0000000000000000000000000000000000000000..64f1ecb7cb0565dd47728a43c30ee59fb726768d --- /dev/null +++ b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_led.h @@ -0,0 +1,12 @@ +#ifndef __EBOX_GAS_LED_H__ +#define __EBOX_GAS_LED_H__ + + +//初始化可燃气体检测模块的LED报警灯 +void LedInit(void); + +//控制可燃气体检测模块的LED报警灯,0:熄灭;1:点亮; 2:闪烁 +void LedCtrl(u32 state); + + +#endif diff --git a/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_module.c b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_module.c new file mode 100644 index 0000000000000000000000000000000000000000..bf367087814acfb8b380dae0e86c5bcc0fad8753 --- /dev/null +++ b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_module.c @@ -0,0 +1,73 @@ +#include +#include +#include "ohos_init.h" +#include "ebox_gas_mq7.h" +#include "ebox_gas_led.h" + +/* 使用PWM驱动蜂鸣器发声,可以通过占空比来调整音量,目前暂时固化成50%占空比 */ +#define BUZZER_PWM_DUTY 50 +#define TASK_DELAY 200 + + +/* 可燃气体传感器处理任务,周期检测可燃气体电压数据 */ +void GasModuleTask(void) +{ + float vlt = 0; + static int smoke = 0; + /* 10秒后可燃气体传感器才能正常检测 */ + osDelay(1000); + while(1){ + u32 ret = Mq7GatherVoltage(&vlt); + if (ret != KP_ERR_SUCCESS) { + KP_DEBUG("Mq7GatherVoltage failed"); + continue; + } + printf("vlotage is %.3f\r\n", vlt); + //为了实验安全起见,建议此值不要设置过高 + //可以比正常环境略高即可,即低浓度烟雾也可以触发报警 + if (vlt > 0.6) + { + /* 检测到可燃气体,如果之前没有报警,则点亮LED灯,如果之前已经点亮了,则不再点亮 */ + if(smoke==0){ + printf("alarm start!\r\n"); + smoke = 1; + LedCtrl(LED_ON); + } + } else { + /* 未检测到可燃气体,如果之前有报警,则熄灭LED灯,如果之前已经熄灭了,则不再熄灭 */ + if(smoke==1){ + printf("alarm stop!\r\n"); + smoke = 0; + LedCtrl(LED_OFF); + + } + } + + //控制检测频率,目前暂定2秒一次 + osDelay(TASK_DELAY); + } + return; +} + +void GasModuleSample(void) +{ + LedInit(); + + /* 设置线程属性 */ + osThreadAttr_t attr; + attr.name = "GasModuleTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = 1024 * 4; + attr.priority = 20; + + /* 创建烟雾传感器处理任务 */ + if (osThreadNew((osThreadFunc_t)GasModuleTask, NULL, &attr) == NULL) + { + printf("Falied to create GasModuleTask!\r\n"); + } +} + +APP_FEATURE_INIT(GasModuleSample); \ No newline at end of file diff --git a/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_mq7.c b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_mq7.c new file mode 100644 index 0000000000000000000000000000000000000000..fc2d286017c706a7b182139ec22d5dc84a950084 --- /dev/null +++ b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_mq7.c @@ -0,0 +1,54 @@ +#include +#include +#include "ebox_gas_mq7.h" + +/* MQ7传感器ADC通道号 */ +#define MQ7_ADC_IDX_06 6 + +#define ADC_BUF_LENGTH 128 +u16 s_adc_buf[ADC_BUF_LENGTH] = { 0 }; + +/* 将内部值转换成电压值,取多次采样的最高电压值 */ +float Mq7ValueToVoltage(u32 data_len) +{ + u32 i; + float vlt_max = 0; + u16 vlt = 0; + /* 循环处理采集得到的数据,对于返回的每一个16位数据,首先根据公式转换成电压值,然后取所有数据中最大值 */ + /* 公式:vlt * 1.8 * 4 / 4096.0,将内部值转换成电压值 */ + for (i = 0; i < data_len; i++) + { + vlt = s_adc_buf[i]; + float vol = (float)vlt*1.8*4/4096.0; + vlt_max = (vol>vlt_max)?vol:vlt_max; + } + return vlt_max; +} + +/* 采集可燃气体传感器的电压,并返回本阶段采到的最大值 */ +u32 Mq7GatherVoltage(float *val) +{ + u32 ret = 0, i = 0; + u16 data = 0; + float vlt_max = 0; + + memset_s(s_adc_buf, sizeof(s_adc_buf), 0x0, sizeof(s_adc_buf)); + for (u8 em = 0; em < IOT_ADC_EQU_MODEL_BUTT; em++) { + /* 从ADC通道读取可燃气体传感器采集的数据,保存到s_adc_buf,然后获取最大值并返回给vlt_max */ + for(i = 0;i vlt_max)? voltage : vlt_max ; + } + + *val = vlt_max; + return KP_ERR_SUCCESS; +} \ No newline at end of file diff --git a/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_mq7.h b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_mq7.h new file mode 100644 index 0000000000000000000000000000000000000000..97213457b7252e638858cdef57eb64941665b76e --- /dev/null +++ b/EBox_IoT_038_MQ7_Gas_GUE/ebox_gas_mq7.h @@ -0,0 +1,11 @@ +#ifndef __EBOX_GAS_MQ7_H__ +#define __EBOX_GAS_MQ7_H__ + +#include "kp_base_type.h" + + +/* 采集可燃气体传感器的电压,并返回本阶段采到的最大值 */ +u32 Mq7GatherVoltage(float *val); + +#endif + diff --git a/EBox_IoT_038_MQ7_Gas_GUE/kp_base_type.h b/EBox_IoT_038_MQ7_Gas_GUE/kp_base_type.h new file mode 100644 index 0000000000000000000000000000000000000000..90feb1e5db02645405bc0461daba64935d5a4acb --- /dev/null +++ b/EBox_IoT_038_MQ7_Gas_GUE/kp_base_type.h @@ -0,0 +1,65 @@ +#ifndef __KP_BASE_TYPE_H__ +#define __KP_BASE_TYPE_H__ + +#include + +/* 基本数据类型 */ +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef unsigned long ulong; +typedef char s8; +typedef short s16; +typedef int s32; +typedef long long s64; +typedef long slong; + +#undef ERROR +#define ERROR (-1) + +#define KP_ERR_SUCCESS 0 +#define KP_ERR_FAILURE (-1) + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define KP_U8_MAX 0xFF +#define KP_U16_MAX 0xFFFF +#define KP_U32_MAX 0xFFFFFFFF +#define KP_U64_MAX 0xFFFFFFFFFFFFFFFFUL + +#include +#define msleep(x) usleep((x)*1000) + +typedef enum { + GPIO_OUT_LOW = 0, /* 低电平 */ + GPIO_OUT_HIGH = 1 /* 高电平 */ +} gpio_out_value; + +typedef enum { + PWM_PORT_PWM0 = 0, /* PWM0端口 */ + PWM_PORT_PWM1 = 1, /* PWM1端口 */ + PWM_PORT_PWM2 = 2, /* PWM2端口 */ + PWM_PORT_PWM3 = 3, /* PWM3端口 */ + PWM_PORT_PWM4 = 4, /* PWM4端口 */ + PWM_PORT_PWM5 = 5, /* PWM5端口 */ + PWM_PORT_MAX /* 最大值,不可使用 */ +} pwm_port; + +typedef enum { + LED_OFF = 0, + LED_ON = 1, + LED_SPARK = 2 +} led_state; +#define LED_SPARK_INTERVAL_TIME 30 + +#define KP_DEBUG(fmt, args...) do { \ + printf("[KP][%s][%d]", __FILE__, __LINE__); \ + printf(fmt, ##args); \ + printf("\r\n"); \ + } while (0) + + +#endif diff --git a/EBox_IoT_049_OLED_Env_GUE/BUILD.gn b/EBox_IoT_049_OLED_Env_GUE/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bff4df3afd096ec2502f2eb62160d0c1f64d3010 --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/BUILD.gn @@ -0,0 +1,27 @@ +static_library("Env_oled_sample") { + sources = [ + #"ebox_env_module.c", + "ebox_env_oled.c", + "ebox_env_oled_api.c", + "ebox_env_oled_GME12864.c", + "ebox_env_oled_gui.c", + ] + + + include_dirs = [ + "//base/iot_hardware/interfaces/kits/wifiiot_lite", + "//base/iot_hardware/peripheral/interfaces/kits", + "//foundation/communication/interfaces/kits/wifi_lite/wifiservice", + "//foundation/communication/wifi_lite/interfaces/wifiservice", + "../../third_party/iot_link/inc", + "../../third_party/iot_link/oc_mqtt/oc_mqtt_al", + "../../third_party/iot_link/oc_mqtt/oc_mqtt_profile_v5", + "//third_party/cJSON", + "../../iot_hardware_hals/include", + "include", + ] + + deps = [ + "//device/board/isoftstone/qihang/third_party/iot_link:iot_link", + ] +} diff --git a/EBox_IoT_049_OLED_Env_GUE/README.md b/EBox_IoT_049_OLED_Env_GUE/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a4608f9849db8a99533b708cbe69df7d39cc8c99 --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/README.md @@ -0,0 +1,234 @@ +# 启航KP_IOT OLED显示模块 +本示例将演示如何利用启航KP_IOT主控板和OLED显示模块上进行案例开发。 + +## 概述 +oled模块显示尺寸为1.3寸,配有7个引脚,采用四线制spi通讯方式,驱动IC是SH1106,分辨率为128x64,显示颜色为蓝色。该oled模块采用四线制spi通讯方式,硬件配置4个引脚,CS(片选),DC(命令/数据选择),MOSI(spi写数据),CLK(spi时钟)。按照spi工作时序来控制4个引脚就可以完成spi数据传输。 + +**4线制spi写模式的工作时序:** +*  CSX为从机片选,仅当CSX为低电平时,芯片才会被使能。 +*  D/CX为芯片数据/命令控制引脚,当D/CX为低电平时写命令,高电平时写数据。 +*  SCL为总线时钟,SCL每个上升沿上送1bit数据。   +*  SDA为spi传输的数据,一次传输8bit数据,数据格式高位在前,先传输。 + +**对于spi通信而言,数据传输是有时序的,即时钟相位(CPHA)与时钟极性(CPOL)的组合:** + +*  CPOL的高低决定串行同步时钟空闲状态的电平,CPOL=0,为低电平。 +*  CPHA的高低决定串行同步时钟是在第一个时钟跳变沿还是第二个时钟跳变沿的数据被采集,CPHA=0时,第一个边沿的数据被采集。 + + +## 主要试验步骤 + +* 步骤1 首先是spi的复用属于功能的复用,在app/wifiiot_app/init/app_io_init.c文件中进行复用。 + +* 步骤2 将三个对应的io复用成输出形式 +``` +hi_void oled_gpio_io_init(void) +{ +    hi_u32 ret; +    +    ret = hi_io_set_func(HI_IO_NAME_GPIO_8, HI_IO_FUNC_GPIO_8_GPIO); +    if (ret != HI_ERR_SUCCESS) { +        printf("===== ERROR ===== gpio -> hi_io_set_func ret:%d\r\n", ret); +        return; +    } +    printf("----- io set func success-----\r\n"); + +    ret = hi_gpio_set_dir(HI_GPIO_IDX_8, HI_GPIO_DIR_OUT); +    if (ret != HI_ERR_SUCCESS) { +        printf("===== ERROR ===== gpio -> hi_gpio_set_dir1 ret:%d\r\n", ret); +        return; +    } +    printf("----- gpio set dir success! -----\r\n"); +    ret = hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_GPIO); +    if (ret != HI_ERR_SUCCESS) { +        printf("===== ERROR ===== gpio -> hi_io_set_func ret:%d\r\n", ret); +        return; +    } +    printf("----- io set func success-----\r\n"); +    +    ret = hi_gpio_set_dir(HI_GPIO_IDX_11, HI_GPIO_DIR_OUT); +    if (ret != HI_ERR_SUCCESS) { +        printf("===== ERROR ===== gpio -> hi_gpio_set_dir1 ret:%d\r\n", ret); +        return; +    } +    printf("----- gpio set dir success! -----\r\n"); +    ret = hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_GPIO); +    if (ret != HI_ERR_SUCCESS) { +        printf("===== ERROR ===== gpio -> hi_io_set_func ret:%d\r\n", ret); +        return; +    } +    printf("----- io set func success-----\r\n"); +    ret = hi_gpio_set_dir(HI_GPIO_IDX_12, HI_GPIO_DIR_OUT); +    if (ret != HI_ERR_SUCCESS) { +        printf("===== ERROR ===== gpio -> hi_gpio_set_dir1 ret:%d\r\n", ret); +        return; +    } +    printf("----- gpio set dir success! -----\r\n"); +} +``` + +* 步骤3 io复用完成后开始写显示功能的代码,显示功能的入口是led_screen_main.c中的test_led_screen();,我们在该函数中完成自己想要显示的内容,显示之前需要对oled进行初始化: + +``` +void test_led_screen(void) +{   +    //delay_init();                //延时函数初始化       +    //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);    //设置NVIC中断分组2:2位抢占优先级,2位响应优先级   +    printf("before oled clear \r\n"); +    OLED_Init();                     //初始化OLED   +    OLED_Clear(0);             //清屏(全黑) +    printf("after oled clear \r\n"); +    while(1) +    {   +        +        printf("before main page clear \r\n"); +        +        TEST_BMP();              //BMP单色图片显示测试 +        // TEST_LINE(); +        // TEST_Chinese();          //中文显示测试 +        // printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); +        // OLED_Clear(0); +        +        // TEST_Menu2();            //菜单2显示测试 +        // printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); +        // OLED_Clear(0); + +        printf("main loop ......\r\n"); +    } +} +``` +* 步骤4  oled的初始化主要是复位oled然后初始化SSD1306,SSD1306是oled模块上驱动显示的芯片,初始化完成后我们就可以进行显示了。 + +``` +void OLED_Init(void) +{ +    //OLED_Init_GPIO(); //初始化GPIO +    //printf("%s,%s,%d \r\n",__FILE__,__func__,__LINE__); +    delay_ms(200); +    OLED_Reset();     //复位OLED +    printf("%s,%s,%d \r\n",__FILE__,__func__,__LINE__); + +/**************初始化SSD1306*****************/ +    OLED_WR_Byte(0xAE,OLED_CMD); /*display off*/ +    OLED_WR_Byte(0x00,OLED_CMD); /*set lower column address*/ +    OLED_WR_Byte(0x10,OLED_CMD); /*set higher column address*/ +    OLED_WR_Byte(0x40,OLED_CMD); /*set display start line*/ +    OLED_WR_Byte(0xB0,OLED_CMD); /*set page address*/ +    OLED_WR_Byte(0x81,OLED_CMD); /*contract control*/ +    OLED_WR_Byte(0xFF,OLED_CMD); /*128*/ +    OLED_WR_Byte(0xA1,OLED_CMD); /*set segment remap*/ +    OLED_WR_Byte(0xA6,OLED_CMD); /*normal / reverse*/ +    OLED_WR_Byte(0xA8,OLED_CMD); /*multiplex ratio*/ +    OLED_WR_Byte(0x3F,OLED_CMD); /*duty = 1/64*/ +    OLED_WR_Byte(0xC8,OLED_CMD); /*Com scan direction*/ +    OLED_WR_Byte(0xD3,OLED_CMD); /*set display offset*/ +    OLED_WR_Byte(0x00,OLED_CMD); +    OLED_WR_Byte(0xD5,OLED_CMD); /*set osc division*/ +    OLED_WR_Byte(0x80,OLED_CMD); +    OLED_WR_Byte(0xD9,OLED_CMD); /*set pre-charge period*/ +    OLED_WR_Byte(0XF1,OLED_CMD); +    OLED_WR_Byte(0xDA,OLED_CMD); /*set COM pins*/ +    OLED_WR_Byte(0x12,OLED_CMD); +    OLED_WR_Byte(0xDB,OLED_CMD); /*set vcomh*/ +    OLED_WR_Byte(0x30,OLED_CMD); +    OLED_WR_Byte(0x8D,OLED_CMD); /*set charge pump disable*/ +    OLED_WR_Byte(0x14,OLED_CMD); +    OLED_WR_Byte(0xAF,OLED_CMD); /*display ON* +    printf("%s,%s,%d \r\n",__FILE__,__func__,__LINE__); +}   +``` +oled模块的工作原理其实就是在一个128*64分辨率大小的地方写数据,显示的图片,文字其实都是采用专用工具将图片、文字转换成相应的数组,oled的控制器在这些数组对应的点位上描绘出点就达到了显示图片文字的功能。不过读取图片、文字数组的函数是不同的,这个需要我们来完成。这一部分函数在gui.c文件中声明,该文件中还包括绘点,绘字符串,绘线段,绘长方形等等,我们可以根据自己的需要调用不同的函数来实现我们想要的画面,图片和文字案例参考具体操作文档。 + +* 步骤5 在主函数中调用在led_screen_main.c文件的test_led_screen()中调用图片显示 +``` +void test_led_screen(void) +{   +    //delay_init();                //延时函数初始化       +    //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);    //设置NVIC中断分组2:2位抢占优先级,2位响应优先级   +    printf("before oled clear \r\n"); +    OLED_Init();                     //初始化OLED   +    OLED_Clear(0);             //清屏(全黑) +    printf("after oled clear \r\n"); +    while(1) +    {   +        printf("before main page clear \r\n"); +        TEST_BMP();              //BMP单色图片显示测试 +        // TEST_LINE(); +        // TEST_Chinese();          //中文显示测试 +        // printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); +        // OLED_Clear(0); +        // TEST_Menu2();            //菜单2显示测试 +        // printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); +        // OLED_Clear(0); +        printf("main loop ......\r\n"); +    } +} +``` +* 步骤6  在主函数中调用,图片、文字显示功能都实现之后在oled_module.c文件的oled任务中去调用test_led_screen()即可实现图片、文字的显示。 + +``` +void test_led_screen(void) +{   +    //delay_init();                //延时函数初始化       +    //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);    //设置NVIC中断分组2:2位抢占优先级,2位响应优先级   +    printf("before oled clear \r\n"); +    OLED_Init();                     //初始化OLED   +    OLED_Clear(0);             //清屏(全黑) +    printf("after oled clear \r\n"); +    while(1) +    {   +        +        printf("before main page clear \r\n"); +        +        // TEST_BMP();              //BMP单色图片显示测试 +        // TEST_LINE(); +        TEST_Chinese();          //中文显示测试 +        printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); +        OLED_Clear(0); +        +        // TEST_Menu2();            //菜单2显示测试 +        // printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); +        // OLED_Clear(0); + +        printf("main loop ......\r\n"); +    } +} +``` +* 步骤7  在主函数中调用,图片、文字显示功能都实现之后在oled_module.c文件的oled任务中去调用test_led_screen()即可实现图片、文字的显示。 + +``` +void test_led_screen(void) +{   +    //delay_init();                //延时函数初始化       +    //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);    //设置NVIC中断分组2:2位抢占优先级,2位响应优先级   +    printf("before oled clear \r\n"); +    OLED_Init();                     //初始化OLED   +    OLED_Clear(0);             //清屏(全黑) +    printf("after oled clear \r\n"); +    while(1) +    {   +        +        printf("before main page clear \r\n"); +        +        // TEST_BMP();              //BMP单色图片显示测试 +        // TEST_LINE(); +        TEST_Chinese();          //中文显示测试 +        printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); +        OLED_Clear(0); +        +        // TEST_Menu2();            //菜单2显示测试 +        // printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); +        // OLED_Clear(0); + +        printf("main loop ......\r\n"); +    } +} +``` +* 步骤8  在主函数中调用,图片、文字显示功能都实现之后在oled_module.c文件的oled任务中去调用test_led_screen()即可实现图片、文字的显示。 + +```c +"21_KP_LCD_example:lcd_test", +``` +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,通过屏幕显示结果也可以通过串口助手查看具体日志。 \ No newline at end of file diff --git a/EBox_IoT_049_OLED_Env_GUE/ebox_env_module.c b/EBox_IoT_049_OLED_Env_GUE/ebox_env_module.c new file mode 100644 index 0000000000000000000000000000000000000000..73152ad0a1c39841f3bde1b8464742872b904bfd --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/ebox_env_module.c @@ -0,0 +1,62 @@ +#include +#include +#include "ohos_init.h" +#include "cmsis_os2.h" +#include "iot_gpio.h" +#include "kp_base_type.h" +#include "oled_module.h" + +#define TASK_DELAY 200 + + +/* 温湿度传感器处理任务,周期查询温度和湿度数据 */ +void EnvOledTask(void) +{ + while (1) { + //hi_watchdog_feed(); + /* 在OLED上显示 */ + // TEST_Menu2(); + TEST_Name(); + osDelay(TASK_DELAY); + } + + return; +} + +void EnvModuleSample(void) +{ + /* 各模块初始化 */ + printf(">> OLED_Init_GPIO \r\n"); + /* 初始化OLED */ + OLED_Init_GPIO(); + + OLED_Init(); //初始化OLED + + // osDelay(100); + + /* 清屏(全黑) */ + OLED_Clear(0); + + + /* 设置线程属性 */ + osThreadAttr_t attr; + attr.name = "EnvOledTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = 1024 * 4; + attr.priority = 25; + + /* 创建温湿度处理线程 */ + osThreadId_t threadIDSht = osThreadNew((osThreadFunc_t)EnvOledTask, NULL, &attr); + if (threadIDSht == NULL) + { + printf("Falied to create EnvShtTask!\r\n"); + } else { + printf("success to create EnvShtTask!\r\n"); + } +} + +APP_FEATURE_INIT(EnvModuleSample); + diff --git a/EBox_IoT_049_OLED_Env_GUE/ebox_env_module.h b/EBox_IoT_049_OLED_Env_GUE/ebox_env_module.h new file mode 100644 index 0000000000000000000000000000000000000000..e7434f25c0e28d9a8f67d5dbef6fe57b3c815f52 --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/ebox_env_module.h @@ -0,0 +1,14 @@ +#ifndef __EBOX_ENV_MODULE_H__ +#define __EBOX_ENV_MODULE_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + + +#endif diff --git a/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled.c b/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled.c new file mode 100644 index 0000000000000000000000000000000000000000..b51143fe47f81a26361a6cad60aef35e7844cb3d --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include "iot_spi.h" +#include "oled_module.h" +#include "oled_GME12864.h" +#include "oled_gui.h" + + + + +void OledTask(void) +{ + printf(">> OLED_Init_GPIO \r\n"); + /* 初始化OLED */ + OLED_Init_GPIO(); + + OLED_Init(); //初始化OLED + + osDelay(100); + + /* 清屏(全黑) */ + OLED_Clear(0); + + + + + /* 循环OLED显示并清屏 */ + while(1) + { + printf("start display \r\n"); + /* + TEST_BMP(); //BMP单色图片显示测试 + TEST_LINE(); //绘制线条测试 + TEST_Chinese(); //中文显示测试 + printf("test dbg %s,%s,%d \r\n",__FILE__,__func__,__LINE__); + OLED_Clear(0); + + TEST_Menu2(); //菜单2显示测试 + TEST_MainPage(); + */ + // TEST_Menu2(); //菜单2显示测试 + TEST_Name(); + // OLED_Clear(0); + printf("stop display \r\n"); + } +} + +#if 1 +void oled_module_demo(void) +{ + /* 初始化OLED */ + //OledIoInit(); + + /* 设置线程属性 */ + osThreadAttr_t attr; + attr.name = "OledTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = 1024 * 4; + attr.priority = 20; + + /* 创建按键控制风扇线程 */ + osThreadId_t threadID1 = osThreadNew((osThreadFunc_t)OledTask, NULL, &attr); + if (threadID1 == NULL) + { + printf("Falied to create OledTask!\r\n"); + } +} +APP_FEATURE_INIT(oled_module_demo); +#endif diff --git a/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled_GME12864.c b/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled_GME12864.c new file mode 100644 index 0000000000000000000000000000000000000000..868d4e282d94294d7db9840fa88063caaf07916b --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled_GME12864.c @@ -0,0 +1,325 @@ +#include "oled_GME12864.h" +#include "stdlib.h" +#include "string.h" +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "kp_base_type.h" +#include + +#define OLED_NAME_GPIO_13 13 +#define OLED_NAME_GPIO_14 14 +#define OLED_IIC_IDX_0 0 +#define OLED_IIC_BAUDRATE 400000 + +#define SSD1306_I2C_IDX 0 +#define SSD1306_I2C_ADDR (0x3C <<1) + +#define SSD1306_CTRL_CMD 0x00 +#define SSD1306_CTRL_DATA 0x40 +#define SSD1306_MASK_CONT (0x1<<7) + + + +//定义I2C和SPI的宏 +#define SSD1306_USE_IIC 0 +#define SSD1306_USE_SPI 1 + +/* 配置ssd1306使用的协议*/ +#define SSD1306_TRANS_PROTOCOL SSD1306_USE_IIC + +//OLED显存总共分为8页 +//每页8行,一行128个像素点 +//OLED的显存 +//存放格式如下. +//[0]0 1 2 3 ... 127 (0~7)行 +//[1]0 1 2 3 ... 127 (8~15)行 +//[2]0 1 2 3 ... 127 (16~23)行 +//[3]0 1 2 3 ... 127 (24~31)行 +//[4]0 1 2 3 ... 127 (32~39)行 +//[5]0 1 2 3 ... 127 (40~47)行 +//[6]0 1 2 3 ... 127 (48~55)行 +//[7]0 1 2 3 ... 127 (56~63)行 + +//数组每个bit存储OLED每个像素点的颜色值(1-亮(白色),0-灭(黑色)) +//每个数组元素表示1列8个像素点,一共128列 + +static unsigned char OLED_buffer[1024] = { 0x00 }; + +/* oled IO初始化 */ +void OLED_Init_GPIO(void) +{ + /* 补全功能代码 */ + // 初始化 SDA引脚 + u32 ret = IoTGpioInit(OLED_NAME_GPIO_13); + if(ret != 0){ + printf("IoTGpioInit fail :%#x \r\n",ret); + return; + } + + + + /* 设置复用为IIC功能 */ + ret = IoTGpioSetFunc(OLED_NAME_GPIO_13,IOT_GPIO_FUNC_GPIO_13_I2C0_SDA); + if(ret != 0){ + printf("IoTGpioSetFunc fail :%#x \r\n",ret); + return; + } + + + // 初始化 SCL引脚 + ret = IoTGpioInit(OLED_NAME_GPIO_14); + if(ret != 0){ + printf("IoTGpioInit fail :%#x \r\n",ret); + return; + } + + + /* 设置复用为IIC功能 */ + ret = IoTGpioSetFunc(OLED_NAME_GPIO_14,IOT_GPIO_FUNC_GPIO_14_I2C0_SCL); + if(ret != 0){ + printf("IoTGpioSetFunc fail :%#x \r\n",ret); + return; + } + + /* IIC初始化 */ + ret = IoTI2cInit(OLED_IIC_IDX_0,OLED_IIC_BAUDRATE); + if(ret != 0){ + printf("IoTI2cInit fail :%#x \r\n",ret); + return; + } + + + /* IIC设置波特率 */ + ret = IoTI2cSetBaudrate(OLED_IIC_IDX_0,OLED_IIC_BAUDRATE); + if(ret != 0){ + printf("IoTI2cSetBaudrate fail :%#x \r\n",ret); + return; + } + + printf("----- OLED_Init_GPIO success! -----\r\n"); +} + +void OLED_Reset(void) { + /* for I2C - do nothing */ +} + +void HAL_Delay(uint32_t ms) +{ + uint32_t msPerTick = 1000 / osKernelGetTickFreq(); // 10ms + if (ms >= msPerTick) { + osDelay(ms / msPerTick); + } + + uint32_t restMs = ms % msPerTick; + if (restMs > 0) { + usleep(restMs * 1000); + } +} + +uint32_t HAL_GetTick(void) +{ + uint32_t msPerTick = 1000 / osKernelGetTickFreq(); // 10ms + uint32_t tickMs = osKernelGetTickCount() * msPerTick; + + uint32_t csPerMs = osKernelGetSysTimerFreq() / 1000; // 160K cycle/ms + uint32_t csPerTick = csPerMs * msPerTick; // 1600K cycles/tick + uint32_t restMs = osKernelGetSysTimerCount() % csPerTick / csPerMs; + + return tickMs + restMs; +} + + +// Send data +void OLED_WR_DATA(uint8_t *data,int data_len) +{ + uint8_t buff[WIDTH * 2] = { 0 }; + for (size_t i = 0; i < data_len; i++) { + buff[i*2] = SSD1306_CTRL_DATA | SSD1306_MASK_CONT; + buff[i*2+1] = data[i]; + } + data[(data_len - 1) * 2] = SSD1306_CTRL_DATA; + int ret = IoTI2cWrite(SSD1306_I2C_IDX, SSD1306_I2C_ADDR, buff, sizeof(buff)); + //printf("IoTI2cWrite ret = %d\n",ret); +} + +//Send byte +void OLED_WR_Byte(uint8_t dat,uint8_t cmd) +{ + if(cmd == OLED_DATA)//发送的是数据 + { + // uint8_t data[SSD1306_WIDTH * 2] = {0}; + // for (size_t i = 0; i < buff_size; i++) { + // data[i*2] = SSD1306_CTRL_DATA | SSD1306_MASK_CONT; + // data[i*2+1] = buffer[i]; + + // uint8_t buffer[] = {regAddr, dat}; + // IoTI2cWrite(SSD1306_I2C_IDX, SSD1306_I2C_ADDR, buffer, sizeof(buffer)); + + // } + // data[(buff_size - 1) * 2] = SSD1306_CTRL_DATA; + } + else//发送的是命令 + { + uint8_t buffer[] = {SSD1306_CTRL_CMD, dat}; + int ret = IoTI2cWrite(SSD1306_I2C_IDX, SSD1306_I2C_ADDR, buffer, sizeof(buffer)); + //printf("IoTI2cWrite ret = %d\n",ret); + } +} + +// Screen object +// static SSD1306_t SSD1306; + +/******************************************************************* + * @name :void OLED_Set_Pos(unsigned char x, unsigned char y) + * @date :2018-08-27 + * @function :Set coordinates in the OLED screen + * @parameters :x:x coordinates + y:y coordinates + * @retvalue :None +********************************************************************/ +void OLED_Set_Pos(unsigned char x, unsigned char y) +{ + OLED_WR_Byte(YLevel+y/PAGE_SIZE,OLED_CMD); + OLED_WR_Byte((((x+2)&0xf0)>>4)|0x10,OLED_CMD); + OLED_WR_Byte(((x+2)&0x0f),OLED_CMD); +} + +/******************************************************************* + * @name :void OLED_Display_On(void) + * @date :2018-08-27 + * @function :Turn on OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void OLED_Display_On(void) +{ + OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令 + OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON + OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON +} + +/******************************************************************* + * @name :void OLED_Display_Off(void) + * @date :2018-08-27 + * @function :Turn off OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void OLED_Display_Off(void) +{ + OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令 + OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF + OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF +} + +/******************************************************************* + * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) + * @date :2018-08-27 + * @function :set the value of pixel to RAM + * @parameters :x:the x coordinates of pixel + y:the y coordinates of pixel + color:the color value of the point + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) +{ + if(color) + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x]|= (1<<(y%PAGE_SIZE))&0xff; + } + else + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x]&= ~((1<<(y%PAGE_SIZE))&0xff); + } +} + +/******************************************************************* + * @name :void OLED_Display(void) + * @date :2018-08-27 + * @function :Display in OLED screen + * @parameters :None + * @retvalue :None +********************************************************************/ +void OLED_Display(void) +{ + u8 i,n; + for(i=0;i?@[]\\^_`~{}|",8,1); + GUI_ShowNum(30,16,1234567890,10,8,1); + GUI_Fill(0,HEIGHT/2,WIDTH-1,HEIGHT-1,1); + GUI_ShowString(0,HEIGHT/2+2,"6x8:!\"#$%&'()*+,-./:;<=>?@[]\\^_`~{}|",8,0); + GUI_ShowNum(30,HEIGHT/2+18,1234567890,10,8,0); + msleep(1000); + OLED_Clear(0); + GUI_ShowString(0,0,"8x16:!\"#$%&'()*+,-./:;<=>?@[]\\^_`~{}|",16,1); + GUI_ShowNum(40,32,1234567890,10,16,1); + msleep(1500); + OLED_Clear(0); +} + +/***************************************************************************** + * @name :void TEST_Chinese(void) + * @date :2018-08-27 + * @function :chinese display test + * @parameters :None + * @retvalue :None +******************************************************************************/ +void TEST_Chinese(void) +{ + GUI_ShowCHinese_UTF(32,26,16,"软通动力",1); + GUI_ShowCHinese_UTF(8,48,16,"鸿蒙业务发展部",1); + msleep(1000); + OLED_Clear(0); +} + +/***************************************************************************** + * @name :void TEST_BMP(void) + * @date :2018-08-27 + * @function :BMP monochromatic picture display test + * @parameters :None + * @retvalue :None +******************************************************************************/ +void TEST_BMP(void) +{ + /*GUI_DrawBMP(0,0,128,64, BMP2, 1); + msleep(1000); + GUI_DrawBMP(0,0,128,64, BMP2, 0); + msleep(1000); + GUI_DrawBMP(0,0,128,64, BMP3, 1); + msleep(1000); + GUI_DrawBMP(0,0,128,64, BMP4, 1); + msleep(1000);*/ + GUI_DrawBMP(0,0,124,40, gImage_issedu, 1); + msleep(1000); +} + +/***************************************************************************** + * @name :void TEST_Menu1(void) + * @date :2018-08-27 + * @function :Chinese selection menu display test + * @parameters :None + * @retvalue :None +******************************************************************************/ +void TEST_Menu1(void) +{ + GUI_Fill(0,0,WIDTH-1,15,1); + GUI_ShowCHinese(32,0,16,"系统设置",0); + GUI_DrawCircle(10, 24, 1,6); + GUI_DrawCircle(10, 24, 1,3); + GUI_DrawCircle(10, 40, 1,6); + GUI_DrawCircle(10, 40, 1,3); + GUI_DrawCircle(10, 56, 1,6); + GUI_DrawCircle(10, 56, 1,3); + GUI_ShowString(20,16,"A.",16,1); + GUI_ShowCHinese(36,16,16,"音量设置",1); + GUI_ShowString(20,32,"B.",16,1); + GUI_ShowCHinese(36,32,16,"颜色设置",1); + GUI_ShowString(20,48,"C.",16,1); + GUI_ShowCHinese(36,48,16,"网络设置",1); + GUI_DrawRectangle(0, 0,WIDTH-1,HEIGHT-1,1); + GUI_DrawLine(WIDTH-1-10, 15, WIDTH-1-10, HEIGHT-1,1); + GUI_FillTriangel(WIDTH-1-9,20,WIDTH-1-5,16,WIDTH-1-1,20,1); + GUI_FillTriangel(WIDTH-1-9,HEIGHT-1-5,WIDTH-1-5,HEIGHT-1-1,WIDTH-1-1,HEIGHT-1-5,1); + GUI_FillCircle(10, 24, 1,3); + GUI_Fill(20,16,99,31,1); + GUI_ShowString(20,16,"A.",16,0); + GUI_ShowCHinese(36,16,16,"音量设置",0); + GUI_Fill(WIDTH-1-9,23,WIDTH-1-1,28,1); + msleep(1500); + GUI_FillCircle(10, 24, 0,3); + GUI_DrawCircle(10, 24, 1,3); + GUI_Fill(20,16,99,31,0); + GUI_ShowString(20,16,"A.",16,1); + GUI_ShowCHinese(36,16,16,"音量设置",1); + GUI_Fill(WIDTH-1-9,23,WIDTH-1-1,28,0); + GUI_FillCircle(10, 40, 1,3); + GUI_Fill(20,32,99,47,1); + GUI_ShowString(20,32,"B.",16,0); + GUI_ShowCHinese(36,32,16,"颜色设置",0); + GUI_Fill(WIDTH-1-9,37,WIDTH-1-1,42,1); + msleep(1500); + GUI_FillCircle(10, 40, 0,3); + GUI_DrawCircle(10, 40, 1,3); + GUI_Fill(20,32,99,47,0); + GUI_ShowString(20,32,"B.",16,1); + GUI_ShowCHinese(36,32,16,"颜色设置",1); + GUI_Fill(WIDTH-1-9,37,WIDTH-1-1,42,0); + GUI_FillCircle(10, 56, 1,3); + GUI_Fill(20,48,99,63,1); + GUI_ShowString(20,48,"C.",16,0); + GUI_ShowCHinese(36,48,16,"网络设置",0); + GUI_Fill(WIDTH-1-9,HEIGHT-1-13,WIDTH-1-1,HEIGHT-1-8,1); + msleep(1500); +} + +/***************************************************************************** + * @name :void TEST_Menu2(void) + * @date :2018-08-27 + * @function :English weather interface display test + * @parameters :None + * @retvalue :None +******************************************************************************/ +void TEST_Menu2(void) +{ + u8 i; + srand(123456); + GUI_DrawLine(0, 10, WIDTH-1, 10,1); + GUI_DrawLine(WIDTH/2-1,11,WIDTH/2-1,HEIGHT-1,1); + GUI_DrawLine(WIDTH/2-1,10+(HEIGHT-10)/2-1,WIDTH-1,10+(HEIGHT-10)/2-1,1); + GUI_ShowString(0,1,"2018-08-25",8,1); + GUI_ShowString(78,1,"Saturday",8,1); + GUI_ShowString(14,HEIGHT-1-10,"Cloudy",8,1); + GUI_ShowString(WIDTH/2-1+2,13,"TEMP",8,1); + GUI_DrawCircle(WIDTH-1-19, 25, 1,2); + GUI_ShowString(WIDTH-1-14,20,"C",16,1); + GUI_ShowString(WIDTH/2-1+9,20,"32.5",16,1); + GUI_ShowString(WIDTH/2-1+2,39,"PM2.5",8,1); + GUI_ShowString(WIDTH/2-1+5,46,"90ug/m3",16,1); + GUI_DrawBMP(6,16,51,32, BMP5, 1); + for(i=0;i<15;i++) + { + GUI_ShowNum(WIDTH/2-1+9,20,rand()%4,1,16,1); + GUI_ShowNum(WIDTH/2-1+9+8,20,rand()%10,1,16,1); + GUI_ShowNum(WIDTH/2-1+9+8+16,20,rand()%10,1,16,1); + GUI_ShowNum(WIDTH/2-1+5,46,rand()%10,1,16,1); + GUI_ShowNum(WIDTH/2-1+5+8,46,rand()%10,1,16,1); + msleep(500); + } +} + +void TEST_LINE(void) +{ + GUI_DrawLine(0,34,30,34,1); + GUI_DrawLine(96,34,WIDTH-1,34,1); +} + +void TEST_CURVE(void) +{ + extern int hr_valid; + extern int sp02_valid; + + int a = 0; + int b = 0; + int c = 0; + int d = 0; + int e = 0; + int f = 0; + + a = hr_valid / 100; + b = (hr_valid - a * 100) / 10; + c = hr_valid % 10; + d = sp02_valid / 100; + e = (sp02_valid - d * 100) / 10; + f = sp02_valid % 10; + + GUI_ShowString(14,12,"HR:",16,1); + if(a == 0){ + GUI_ShowNum(40,12,b,1,16,1); + GUI_ShowNum(48,12,c,1,16,1); + }else{ + GUI_ShowNum(40,12,a,1,16,1); + GUI_ShowNum(48,12,b,1,16,1); + GUI_ShowNum(56,12,c,1,16,1); + } + + GUI_ShowString(14,38,"SP02:",16,1); + if(d == 0){ + GUI_ShowNum(56,38,e,1,16,1); + GUI_ShowNum(64,38,f,1,16,1); + }else{ + GUI_ShowNum(56,38,d,1,16,1); + GUI_ShowNum(64,38,e,1,16,1); + GUI_ShowNum(72,38,f,1,16,1); + } + + sleep(1); +} + +/***************************************************************************** + * @name :void TEST_Menu2(void) + * @date :2018-08-27 + * @function :English weather interface display test + * @parameters :None + * @retvalue :None +******************************************************************************/ +void TEST_Menu_Env(int temperature, int humidity) +{ + OLED_Clear(0); + char buf[8] = {0}; + int temp = temperature; + int humi = humidity; + + //printf(">>>> show oled: temp:%d, humi:%d\n", temp, humi); + GUI_DrawLine(0, 10, WIDTH-1, 10,1); + GUI_DrawLine(WIDTH/2-1,11,WIDTH/2-1,HEIGHT-1,1); + GUI_DrawLine(WIDTH/2-1,10+(HEIGHT-10)/2-1,WIDTH-1,10+(HEIGHT-10)/2-1,1); + GUI_ShowString(0,1,"2023-02-17",8,1); + GUI_ShowString(78,1,"Friday",8,1); + GUI_ShowString(14,HEIGHT-1-10,"Cloudy",8,1); + GUI_ShowString(WIDTH/2-1+2,13,"TEMP",8,1); + GUI_DrawCircle(WIDTH-1-19, 25, 1,2); + GUI_ShowString(WIDTH-1-14,20,"C",16,1); + memset(buf, 0x00, sizeof(buf)); + sprintf(buf, "%d", temp); + GUI_ShowString(WIDTH/2-1+9,20,buf,16,1); + GUI_ShowString(WIDTH/2-1+2,39,"Humi",8,1); + memset(buf, 0x00, sizeof(buf)); + sprintf(buf, "%d", humi); + GUI_ShowString(WIDTH/2-1+9,46,buf,16,1); + GUI_DrawBMP(6,16,51,32, BMP5, 1); + //printf(">>>> display oled\n"); + OLED_Display(); +} + +/***************************************************************************** + * @name :void TEST_Name(void) + * @date :2023-06-29 + * @function :display your name + * @parameters :None + * @retvalue :None +******************************************************************************/ +void TEST_Name(void) +{ + /* 补全功能代码 */ + OLED_Clear(0); + // GUI_ShowString(0,0,"2000301532",16,1); + // GUI_ShowCHinese(0,16,16,"梁弦",1); + GUI_ShowCHinese_UTF(0,0,16,"韦长江",1); + GUI_ShowCHinese_UTF(0,16,16,"梁弦彤",1); + GUI_ShowCHinese_UTF(0,32,16,"刘嘉妮",1); + GUI_ShowCHinese_UTF(0,48,16,"王玉洁",1); + GUI_ShowCHinese_UTF(64,0,16,"李恩汉",1); + GUI_ShowCHinese_UTF(64,16,16,"梁坤乐",1); + GUI_ShowCHinese_UTF(64,32,16,"兰晶晶",1); + OLED_Display(); + msleep(60000); + // char name[] = "wcj"; + // GUI_TextBox(10, 10, 100, 20, name); + + + +} diff --git a/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled_gui.c b/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled_gui.c new file mode 100644 index 0000000000000000000000000000000000000000..cab4c8e70acfa227aa38d4a6e3bd2ba8f6d47674 --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/ebox_env_oled_gui.c @@ -0,0 +1,964 @@ +#include "oled_GME12864.h" +#include "string.h" +#include "oled_font.h" +#include "oled_gui.h" + +/******************************************************************* + * @name :void GUI_DrawPoint(u8 x,u8 y,u8 color) + * @date :2018-08-27 + * @function :draw a point in LCD screen + * @parameters :x:the x coordinate of the point + y:the y coordinate of the point + color:the color value of the point + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void GUI_DrawPoint(u8 x,u8 y,u8 color) +{ + OLED_Set_Pixel(x,y,color); + // OLED_Display(); +} + +/******************************************************************* + * @name :void GUI_Fill(u8 sx,u8 sy,u8 ex,u8 ey,u8 color) + * @date :2018-08-27 + * @function :fill the specified area + * @parameters :sx:the bebinning x coordinate of the specified area + sy:the bebinning y coordinate of the specified area + ex:the ending x coordinate of the specified area + ey:the ending y coordinate of the specified area + color:the color value of the the specified area + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void GUI_Fill(u8 sx,u8 sy,u8 ex,u8 ey,u8 color) +{ + u8 i,j; + u8 width=ex-sx+1; //得到填充的宽度 + u8 height=ey-sy+1; //高度 + for(i=0;i0)incx=1; //设置单步方向 + else if(delta_x==0)incx=0;//垂直线 + else {incx=-1;delta_x=-delta_x;} + if(delta_y>0)incy=1; + else if(delta_y==0)incy=0;//水平线 + else{incy=-1;delta_y=-delta_y;} + if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴 + else distance=delta_y; + for(t=0;t<=distance+1;t++ )//画线输出 + { + OLED_Set_Pixel(uRow,uCol,color); + xerr+=delta_x ; + yerr+=delta_y ; + if(xerr>distance) + { + xerr-=distance; + uRow+=incx; + } + if(yerr>distance) + { + yerr-=distance; + uCol+=incy; + } + } + // OLED_Display(); +} + +/***************************************************************************** + * @name :void GUI_DrawRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) + * @date :2018-08-27 + * @function :Draw a rectangle + * @parameters :x1:the bebinning x coordinate of the rectangle + y1:the bebinning y coordinate of the rectangle + x2:the ending x coordinate of the rectangle + y2:the ending y coordinate of the rectangle + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_DrawRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) +{ + /* 补全功能代码 */ + GUI_DrawLine(x1, y1, x1, y2, color); // 画左边界 + GUI_DrawLine(x1, y2, x2, y2, color); // 画下边界 + GUI_DrawLine(x2, y2, x2, y1, color); // 画右边界 + GUI_DrawLine(x2, y1, x1, y1, color); // 画上边界 +} + +/***************************************************************************** + * @name :void GUI_FillRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) + * @date :2018-08-27 + * @function :Filled a rectangle + * @parameters :x1:the bebinning x coordinate of the filled rectangle + y1:the bebinning y coordinate of the filled rectangle + x2:the ending x coordinate of the filled rectangle + y2:the ending y coordinate of the filled rectangle + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_FillRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) +{ + /* 补全功能代码 */ + GUI_Fill(x1,y1,x2,y2,color); +} + +/***************************************************************************** + * @name :static void _draw_circle_8(u8 xc, u8 yc, u8 x, u8 y, u8 color) + * @date :2018-08-27 + * @function :8 symmetry circle drawing algorithm (internal call) + * @parameters :xc:the x coordinate of the Circular center + yc:the y coordinate of the Circular center + x:the x coordinate relative to the Circular center + y:the y coordinate relative to the Circular center + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +static void _draw_circle_8(u8 xc, u8 yc, u8 x, u8 y, u8 color) +{ + OLED_Set_Pixel(xc + x, yc + y, color); + OLED_Set_Pixel(xc - x, yc + y, color); + OLED_Set_Pixel(xc + x, yc - y, color); + OLED_Set_Pixel(xc - x, yc - y, color); + OLED_Set_Pixel(xc + y, yc + x, color); + OLED_Set_Pixel(xc - y, yc + x, color); + OLED_Set_Pixel(xc + y, yc - x, color); + OLED_Set_Pixel(xc - y, yc - x, color); +} + +/***************************************************************************** + * @name :void GUI_DrawCircle(u8 xc, u8 yc, u8 color, u8 r) + * @date :2018-08-27 + * @function :Draw a circle of specified size at a specified location + * @parameters :xc:the x coordinate of the Circular center + yc:the y coordinate of the Circular center + r:Circular radius + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_DrawCircle(u8 xc, u8 yc, u8 color, u8 r) +{ + int x = 0, y = r,d; + d = 3 - 2 * r; + while (x <= y) + { + _draw_circle_8(xc, yc, x, y, color); + if (d < 0) + { + d = d + 4 * x + 6; + } + else + { + d = d + 4 * (x - y) + 10; + y--; + } + x++; + } + // OLED_Display(); +} + +/***************************************************************************** + * @name :void GUI_FillCircle(u8 xc, u8 yc, u8 color, u8 r) + * @date :2018-08-27 + * @function :Fill a circle of specified size at a specified location + * @parameters :xc:the x coordinate of the Circular center + yc:the y coordinate of the Circular center + r:Circular radius + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_FillCircle(u8 xc, u8 yc, u8 color, u8 r) +{ + int x = 0, y = r, yi, d; + d = 3 - 2 * r; + while (x <= y) + { + for (yi = x; yi <= y; yi++) + { + _draw_circle_8(xc, yc, x, yi, color); + } + if (d < 0) + { + d = d + 4 * x + 6; + } + else + { + d = d + 4 * (x - y) + 10; + y--; + } + x++; + } + // OLED_Display(); +} + +/********************************************************************************** + * @name :void GUI_DrawTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color) + * @date :2018-08-27 + * @function :Draw a triangle at a specified position + * @parameters :x0:the bebinning x coordinate of the triangular edge + y0:the bebinning y coordinate of the triangular edge + x1:the vertex x coordinate of the triangular + y1:the vertex y coordinate of the triangular + x2:the ending x coordinate of the triangular edge + y2:the ending y coordinate of the triangular edge + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +***********************************************************************************/ +void GUI_DrawTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color) +{ + /* 补全功能代码 */ + GUI_DrawLine(x0, y0, x1, y1, color); // 画第一条边 + GUI_DrawLine(x1, y1, x2, y2, color); // 画第二条边 + GUI_DrawLine(x2, y2, x0, y0, color); // 画第三条边 +} + +/***************************************************************************** + * @name :static void _swap(u8 *a, u8 *b) + * @date :2018-08-27 + * @function :Exchange two numbers(internal call) + * @parameters :a:the address of the first number + b:the address of the second number + * @retvalue :None +******************************************************************************/ +static void _swap(u8 *a, u8 *b) +{ + u16 tmp; + tmp = *a; + *a = *b; + *b = tmp; +} + +/***************************************************************************** + * @name :static void _draw_h_line(u8 x0,u8 x1,u8 y,u8 color) + * @date :2018-08-27 + * @function :draw a horizontal line in RAM(internal call) + * @parameters :x0:the bebinning x coordinate of the horizontal line + x1:the ending x coordinate of the horizontal line + y:the y coordinate of the horizontal line + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +static void _draw_h_line(u8 x0,u8 x1,u8 y,u8 color) +{ + /* 补全功能代码 */ + u8 min_x = (x0 < x1) ? x0 : x1; + u8 max_x = (x0 > x1) ? x0 : x1; + for (u8 x = min_x; x <= max_x; x++) + { + GUI_DrawPixel(x, y, color); + } +} + +/***************************************************************************** + * @name :void GUI_FillTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color) + * @date :2018-08-27 + * @function :filling a triangle at a specified position + * @parameters :x0:the bebinning x coordinate of the triangular edge + y0:the bebinning y coordinate of the triangular edge + x1:the vertex x coordinate of the triangular + y1:the vertex y coordinate of the triangular + x2:the ending x coordinate of the triangular edge + y2:the ending y coordinate of the triangular edge + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_FillTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color) +{ + u8 a, b, y, last; + int dx01, dy01, dx02, dy02, dx12, dy12; + long sa = 0; + long sb = 0; + if (y0 > y1) + { + _swap(&y0,&y1); + _swap(&x0,&x1); + } + if (y1 > y2) + { + _swap(&y2,&y1); + _swap(&x2,&x1); + } + if (y0 > y1) + { + _swap(&y0,&y1); + _swap(&x0,&x1); + } + if(y0 == y2) + { + a = b = x0; + if(x1 < a) + { + a = x1; + } + else if(x1 > b) + { + b = x1; + } + if(x2 < a) + { + a = x2; + } + else if(x2 > b) + { + b = x2; + } + _draw_h_line(a,b,y0,color); + return; + } + dx01 = x1 - x0; + dy01 = y1 - y0; + dx02 = x2 - x0; + dy02 = y2 - y0; + dx12 = x2 - x1; + dy12 = y2 - y1; + + if(y1 == y2) + { + last = y1; + } + else + { + last = y1-1; + } + for(y=y0; y<=last; y++) + { + a = x0 + sa / dy01; + b = x0 + sb / dy02; + sa += dx01; + sb += dx02; + if(a > b) + { + _swap(&a,&b); + } + _draw_h_line(a,b,y,color); + } + sa = dx12 * (y - y1); + sb = dx02 * (y - y0); + for(; y<=y2; y++) + { + a = x1 + sa / dy12; + b = x0 + sb / dy02; + sa += dx12; + sb += dx02; + if(a > b) + { + _swap(&a,&b); + } + _draw_h_line(a,b,y,color); + } + // OLED_Display(); +} + +/***************************************************************************** + * @name :void GUI_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size,u8 mode) + * @date :2018-08-27 + * @function :Display a single English character + * @parameters :x:the bebinning x coordinate of the Character display position + y:the bebinning y coordinate of the Character display position + chr:the ascii code of display character(0~94) + Char_Size:the size of display character(8,16) + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size,u8 mode) +{ + unsigned char c=0,i=0,tmp,j=0; + c=chr-' ';//得到偏移后的值 + if (x>WIDTH-1) {x=0;y=y+2;} + if(Char_Size ==16) + { + /* 处理16位字符 */ + for(i=0;i<16;i++) + { + if(mode) + { + tmp = F8X16[c*16+i]; + } + else + { + tmp = ~(F8X16[c*16+i]); + } + for(j=0;j<8;j++) + { + /* 设置点阵中点的值 */ + if(tmp&(0x80>>j)) + { + OLED_Set_Pixel(x+j, y+i,1); + } + else + { + OLED_Set_Pixel(x+j, y+i,0); + } + } + } + } + else if(Char_Size==8) + { + /* 处理8位字符 */ + for(i=0;i<8;i++) + { + if(mode) + { + tmp = F6x8[c][i]; + } + else + { + tmp = ~(F6x8[c][i]); + } + for(j=0;j<8;j++) + { + /* 设置点阵中点的值 */ + if(tmp&(0x80>>j)) + { + OLED_Set_Pixel(x+j, y+i,1); + } + else + { + OLED_Set_Pixel(x+j, y+i,0); + } + } + } + } + else + { + return; + } + // OLED_Display(); +} + +/***************************************************************************** + * @name :void GUI_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size,u8 mode) + * @date :2018-08-27 + * @function :Display English string + * @parameters :x:the bebinning x coordinate of the English string + y:the bebinning y coordinate of the English string + chr:the start address of the English string + Char_Size:the size of display character + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size,u8 mode) +{ + unsigned char j=0,csize; + if(Char_Size == 16) + { + csize = Char_Size/2; + } + else if(Char_Size == 8) + { + csize = Char_Size/2+2; + } + else + { + return; + } + while (chr[j]!='\0') + { + GUI_ShowChar(x,y,chr[j],Char_Size,mode); + x+=csize; + if(x>120) + { + x=0; + y+=Char_Size; + } + j++; + } +} + +/***************************************************************************** + * @name :u32 mypow(u8 m,u8 n) + * @date :2018-08-27 + * @function :get the nth power of m (internal call) + * @parameters :m:the multiplier + n:the power + * @retvalue :the nth power of m +******************************************************************************/ +static u32 mypow(u8 m,u8 n) +{ + u32 result=1; + while(n--)result*=m; + return result; +} + +/***************************************************************************** + * @name :void GUI_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 Size,u8 mode) + * @date :2018-08-27 + * @function :Display number + * @parameters :x:the bebinning x coordinate of the number + y:the bebinning y coordinate of the number + num:the number(0~4294967295) + len:the length of the display number + Size:the size of display number + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 Size,u8 mode) +{ + u8 t,temp; + u8 enshow=0,csize; + if(Size == 16) + { + csize = Size/2; + } + else if(Size == 8) + { + csize = Size/2+2; + } + else + { + return; + } + for(t=0;t>k)) + { + OLED_Set_Pixel(x+(j%2)*8+k, y+j/2,1); + } + else + { + OLED_Set_Pixel(x+(j%2)*8+k, y+j/2,0); + } + } + } + break; + } + } + // OLED_Display(); +} + +void GUI_ShowFont16_UTF(u8 x,u8 y,u8 *s,u8 mode) +{ + u8 i,j,k,tmp; + u16 num; + num = sizeof(cfont16_UTF)/sizeof(typFNT_GB16_UTF); + for(i=0;i>k)) + { + OLED_Set_Pixel(x+(j%2)*8+k, y+j/2,1); + } + else + { + OLED_Set_Pixel(x+(j%2)*8+k, y+j/2,0); + } + } + } + break; + } + } + // OLED_Display(); +} + + +/***************************************************************************** + * @name :void GUI_ShowFont24(u8 x,u8 y,u8 *s,u8 mode) + * @date :2018-08-27 + * @function :Display a single 24x24 Chinese character + * @parameters :x:the bebinning x coordinate of the Chinese character + y:the bebinning y coordinate of the Chinese character + s:the start address of the Chinese character + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowFont24(u8 x,u8 y,u8 *s,u8 mode) +{ + u8 i,j,k,tmp; + u16 num; + num = sizeof(cfont24)/sizeof(typFNT_GB24); + for(i=0;i>k)) + { + OLED_Set_Pixel(x+(j%3)*8+k, y+j/3,1); + } + else + { + OLED_Set_Pixel(x+(j%3)*8+k, y+j/3,0); + } + } + } + break; + } + } + // OLED_Display(); +} + +void GUI_ShowFont24_UTF(u8 x,u8 y,u8 *s,u8 mode) +{ + u8 i,j,k,tmp; + u16 num; + num = sizeof(cfont24)/sizeof(typFNT_GB24_UTF); + for(i=0;i>k)) + { + OLED_Set_Pixel(x+(j%3)*8+k, y+j/3,1); + } + else + { + OLED_Set_Pixel(x+(j%3)*8+k, y+j/3,0); + } + } + } + break; + } + } + // OLED_Display(); +} + + +/***************************************************************************** + * @name :void GUI_ShowFont32(u8 x,u8 y,u8 *s,u8 mode) + * @date :2018-08-27 + * @function :Display a single 32x32 Chinese character + * @parameters :x:the bebinning x coordinate of the Chinese character + y:the bebinning y coordinate of the Chinese character + s:the start address of the Chinese character + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowFont32(u8 x,u8 y,u8 *s,u8 mode) +{ + u8 i,j,k,tmp; + u16 num; + num = sizeof(cfont32)/sizeof(typFNT_GB32); + for(i=0;i>k)) + { + OLED_Set_Pixel(x+(j%4)*8+k, y+j/4,1); + } + else + { + OLED_Set_Pixel(x+(j%4)*8+k, y+j/4,0); + } + } + } + break; + } + } + // OLED_Display(); +} + +void GUI_ShowFont32_UTF(u8 x,u8 y,u8 *s,u8 mode) +{ + u8 i,j,k,tmp; + u16 num; + num = sizeof(cfont32)/sizeof(typFNT_GB32); + for(i=0;i>k)) + { + OLED_Set_Pixel(x+(j%4)*8+k, y+j/4,1); + } + else + { + OLED_Set_Pixel(x+(j%4)*8+k, y+j/4,0); + } + } + } + break; + } + } + // OLED_Display(); +} + + +/***************************************************************************** + * @name :void GUI_ShowCHinese(u8 x,u8 y,u8 hsize,u8 *str,u8 mode) + * @date :2018-08-27 + * @function :Display Chinese strings + * @parameters :x:the bebinning x coordinate of the Chinese strings + y:the bebinning y coordinate of the Chinese strings + size:the size of Chinese strings + str:the start address of the Chinese strings + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +static void dump_buf(unsigned char * buf,unsigned int len) +{ + for(int i = 0; i < len; i++) + { + printf("%#x ",buf[i]); + } + putchar('\r'); putchar('\n'); +} + +void GUI_ShowCHinese(u8 x,u8 y,u8 hsize,u8 *str,u8 mode) +{ + dump_buf(str, 16); + while(*str!='\0') + { + if(hsize == 16) + { + GUI_ShowFont16(x,y,str,mode); + } + else if(hsize == 24) + { + GUI_ShowFont24(x,y,str,mode); + } + else if(hsize == 32) + { + GUI_ShowFont32(x,y,str,mode); + } + else + { + return; + } + x+=hsize; + if(x>WIDTH-hsize) + { + x=0; + y+=hsize; + } + str+=2; + } +} + +/* UTF-8编码中文占三个字节 */ +void GUI_ShowCHinese_UTF(u8 x,u8 y,u8 hsize,u8 *str,u8 mode) +{ + dump_buf(str, 16); + while(*str!='\0') + { + if(hsize == 16) + { + GUI_ShowFont16_UTF(x,y,str,mode); + } + else if(hsize == 24) + { + GUI_ShowFont24_UTF(x,y,str,mode); + } + else if(hsize == 32) + { + GUI_ShowFont32_UTF(x,y,str,mode); + } + else + { + return; + } + x+=hsize; + if(x>WIDTH-hsize) + { + x=0; + y+=hsize; + } + str+=3; + } +} + + +/***************************************************************************** + * @name :void GUI_DrawBMP(u8 x,u8 y,u8 width, u8 height, u8 BMP[], u8 mode) + * @date :2018-08-27 + * @function :Display a BMP monochromatic picture + * @parameters :x:the bebinning x coordinate of the BMP monochromatic picture + y:the bebinning y coordinate of the BMP monochromatic picture + width:the width of BMP monochromatic picture + height:the height of BMP monochromatic picture + BMP:the start address of BMP monochromatic picture array + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_DrawBMP(u8 x,u8 y,u8 width, u8 height, u8 BMP[], u8 mode) +{ + u8 i,j,k; + u8 tmp; + for(i=0;i>k)) + { + OLED_Set_Pixel(x+j*8+k, y+i,1); + } + else + { + OLED_Set_Pixel(x+j*8+k, y+i,0); + } + } + } + } +// OLED_Display(); +} diff --git a/EBox_IoT_049_OLED_Env_GUE/include/kp_base_type.h b/EBox_IoT_049_OLED_Env_GUE/include/kp_base_type.h new file mode 100644 index 0000000000000000000000000000000000000000..3913556f34220f973f2977edec0bcae8ce09b4b8 --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/include/kp_base_type.h @@ -0,0 +1,53 @@ +#ifndef __KP_BASE_TYPE_H__ +#define __KP_BASE_TYPE_H__ + +#include + +/* 基本数据类型 */ +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef unsigned long ulong; +typedef char s8; +typedef short s16; +typedef int s32; +typedef long long s64; +typedef long slong; + +#undef ERROR +#define ERROR (-1) + +#define KP_ERR_SUCCESS 0 +#define KP_ERR_FAILURE (-1) + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define KP_U16_MAX 0xFFFF +#define KP_U32_MAX 0xFFFFFFFF +#define KP_U64_MAX 0xFFFFFFFFFFFFFFFFUL + +#include +#define msleep(x) usleep((x)*1000) + +typedef enum { + GPIO_OUT_LOW = 0, /**< Low level.CNcomment:低电平CNend*/ + GPIO_OUT_HIGH /**< High level.CNcomment:高电平CNend*/ +} gpio_out_value; + +typedef enum { + LED_OFF = 0, + LED_ON, + LED_SPARK +} led_state; + +#define KP_DEBUG(fmt, args...) do { \ + printf("[KP][%s][%d]", __FILE__, __LINE__); \ + printf(fmt, ##args); \ + printf("\r\n"); \ + } while (0) + + +#endif \ No newline at end of file diff --git a/EBox_IoT_049_OLED_Env_GUE/include/oled_GME12864.h b/EBox_IoT_049_OLED_Env_GUE/include/oled_GME12864.h new file mode 100644 index 0000000000000000000000000000000000000000..3f9927a2dbeeaf19b7e7e32e0322f0a6e14b04fa --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/include/oled_GME12864.h @@ -0,0 +1,69 @@ +#ifndef __OLED_GME12864_H__ +#define __OLED_GME12864_H__ + +#include +#include +#include +#include +#include +#include "hi_spi.h" +#include "iot_spi.h" +//--------------OLED参数定义--------------------- +#define PAGE_SIZE 8 +#define XLevelL 0x02 //1.3寸XLevelL为0x02 0.9寸XLevelL为0x00 +#define XLevelH 0x10 +#define YLevel 0xB0 +#define Brightness 0xFF +#define WIDTH 128 +#define HEIGHT 64 + +//-------------写命令和数据定义------------------- +#define OLED_CMD 0 //写命令 +#define OLED_DATA 1 //写数据 + +//-----------------OLED端口定义---------------- +#define OLED_CS GPIO_Pin_11 //片选信号 PB11 +#define OLED_DC GPIO_Pin_10 //数据/命令控制信号 PB10 +#define OLED_RST GPIO_Pin_12 //复位信号 PB12 + +//-----------------OLED端口操作定义---------------- +/* +#define OLED_CS_Clr() GPIO_ResetBits(GPIOB,OLED_CS) +#define OLED_CS_Set() GPIO_SetBits(GPIOB,OLED_CS) + +#define OLED_DC_Clr() GPIO_ResetBits(GPIOB,OLED_DC) +#define OLED_DC_Set() GPIO_SetBits(GPIOB,OLED_DC) + +#define OLED_RST_Clr() GPIO_ResetBits(GPIOB,OLED_RST) +#define OLED_RST_Set() GPIO_SetBits(GPIOB,OLED_RST) +*/ + +#define OLED_CS_Clr() hi_gpio_set_ouput_val(HI_GPIO_IDX_12,HI_GPIO_VALUE0); +#define OLED_CS_Set() hi_gpio_set_ouput_val(HI_GPIO_IDX_12,HI_GPIO_VALUE1); + +#define OLED_DC_Clr() hi_gpio_set_ouput_val(HI_GPIO_IDX_11,HI_GPIO_VALUE0); +#define OLED_DC_Set() hi_gpio_set_ouput_val(HI_GPIO_IDX_11,HI_GPIO_VALUE1); + +#define OLED_RST_Clr() hi_gpio_set_ouput_val(HI_GPIO_IDX_8,HI_GPIO_VALUE0); +#define OLED_RST_Set() hi_gpio_set_ouput_val(HI_GPIO_IDX_8,HI_GPIO_VALUE1); + +void OledGpioInit(void); +void OledSpiInit(IotSpiIdx spiId); +void OledIoInit(void); +void SpiWriteData(hi_spi_idx spi_id, unsigned char data); + +#define SPI_WriteByte(SPI2,dat) SpiWriteData(0,dat); + +//OLED控制用函数 +void OLED_WR_Byte(uint8_t dat,uint8_t cmd); +void OLED_Display_On(void); +void OLED_Display_Off(void); +void OLED_Set_Pos(unsigned char x, unsigned char y); +void OLED_Reset(void); +void OLED_Init_GPIO(void); +void OLED_Init(void); +void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color); +void OLED_Display(void); +void OLED_Clear(unsigned dat); +#endif + diff --git a/EBox_IoT_049_OLED_Env_GUE/include/oled_bmp.h b/EBox_IoT_049_OLED_Env_GUE/include/oled_bmp.h new file mode 100644 index 0000000000000000000000000000000000000000..3fffc3afac23da57d2d93faa237c04c21537dbbb --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/include/oled_bmp.h @@ -0,0 +1,385 @@ +#ifndef __BMP_H__ +#define __BMP_H__ + +unsigned char BMP2[] = +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7F,0xE0,0x03,0x91,0x1C,0x38,0x18,0x00,0x70,0x00,0xFF,0xFC,0x00,0x07,0xFF,0xFE, + 0x66,0x60,0x04,0x5B,0x22,0x44,0x14,0x01,0x8C,0x01,0x7F,0xFA,0x00,0x04,0x00,0x02, + 0x36,0xC0,0x08,0x15,0x40,0x80,0x52,0x02,0x02,0x01,0xBF,0xF6,0x00,0x3D,0xB6,0xDA, + 0x1F,0x80,0x88,0x11,0x40,0x80,0x34,0x04,0x71,0x01,0xDF,0xEE,0x00,0x25,0xB6,0xDA, + 0x0F,0x02,0x88,0x11,0x40,0x80,0x18,0x00,0x88,0x01,0xE0,0x1E,0x00,0x25,0xB6,0xDA, + 0x06,0x0A,0x88,0x11,0x40,0x80,0x34,0x01,0x04,0x01,0xDF,0xEE,0x00,0x25,0xB6,0xDA, + 0x06,0x2A,0x88,0x11,0x40,0x80,0x52,0x00,0x20,0x01,0xBF,0xF6,0x00,0x3D,0xB6,0xDA, + 0x06,0xAA,0x84,0x51,0x22,0x44,0x14,0x00,0x70,0x01,0x7F,0xFA,0x00,0x04,0x00,0x02, + 0x06,0xAA,0x83,0x91,0x1C,0x38,0x18,0x00,0x20,0x00,0xFF,0xFC,0x00,0x07,0xFF,0xFE, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x1F,0xFC,0x00,0x3F,0xFC,0x7F,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x07,0x3F,0xFE,0x00,0x7F,0xFC,0xFF,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x1B,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x33,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x63,0x30,0x06,0x18,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xC3,0x30,0x06,0x18,0x7F,0xFC,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x83,0x30,0x06,0x00,0x7F,0xFC,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x18,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x18,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x60,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x60,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x7F,0xFC,0xFF,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x1F,0xFC,0x00,0x3F,0xF8,0x7F,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xF9,0xE3,0x0F,0x00,0xF1,0xE0,0x1E,0x3C,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x01,0x0A,0x15,0x10,0x81,0x0A,0x10,0x21,0x42,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x12,0x11,0x10,0x81,0x0A,0x00,0x21,0x40,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x22,0x11,0x1F,0x81,0x0B,0xE0,0x21,0x7C,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x42,0x11,0x10,0x81,0x0A,0x10,0x21,0x42,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x82,0x11,0x10,0x99,0x0A,0x13,0x21,0x42,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x01,0xF9,0xE7,0xCF,0x18,0xF1,0xE3,0x1E,0x3C,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x1C,0x41,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x7C,0x82, + 0x63,0x22,0x61,0x41,0x00,0x00,0x00,0x00,0xF1,0x00,0x00,0x00,0x00,0xC6,0x82,0xC2, + 0x55,0x41,0x51,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0xAA,0x80,0xA2, + 0x49,0x7E,0x49,0x41,0x00,0x00,0x00,0x00,0xFD,0x00,0x00,0x00,0x00,0x92,0x7C,0x92, + 0x41,0x40,0x45,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x02,0x8A, + 0x41,0x21,0x43,0x22,0x00,0x00,0x00,0x00,0xF1,0x00,0x00,0x00,0x00,0x82,0x82,0x86, + 0x41,0x1E,0x41,0x1C,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x7C,0x82, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +unsigned char BMP3[] = +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0xF8,0x03,0xFF,0xF8,0x03,0xC0,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0xFE,0x03,0xFF,0xF8,0x07,0xF3,0xFC,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x18,0x03,0x03,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x7F,0xC0,0x07,0xFF,0xFC,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x03,0x03,0xFF,0xF0,0x03,0xFF,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x18,0x06,0x03,0x80,0x38,0x01,0xFF,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0xFC,0x03,0x00,0x18,0x00,0x7F,0xC0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x1F,0xFF,0x00,0x00,0x0C,0x00,0x3F,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x01,0x80,0x00,0x0C,0x00,0x0E,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x04,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x10,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x10,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC6,0x00,0x0C,0x1E,0x38,0xCC,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC7,0x00,0x1C,0x11,0x45,0x32,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x80,0x38,0x11,0x45,0x22,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x1F,0xFF,0x01,0xFF,0xF0,0x11,0x45,0x22,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0xFE,0x00,0x7F,0xC0,0x11,0x45,0x22,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x79,0x22,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x22,0x00,0x90,0x04,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x42,0x00,0x90,0x04,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x06,0x40,0x41,0x01,0x08,0x08,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x04,0x20,0x81,0x01,0x08,0x08,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x08,0x20,0x81,0x02,0x04,0x10,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x08,0x20,0x80,0x82,0x04,0x10,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x10,0x21,0x00,0x82,0x02,0x10,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x20,0x11,0x00,0x84,0x02,0x10,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x40,0x12,0x00,0x44,0x02,0x20,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x80,0x12,0x00,0x48,0x01,0x20,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x48,0x01,0x20,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x30,0x01,0x20,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x30,0x00,0xC0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +unsigned char BMP4[] = +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x00,0x0C,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x00,0x0F,0xC0,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x00,0x1F,0xFE,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x00,0x3F,0xFF,0xFF,0x00,0x00,0x10,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x07,0x00,0x7F,0xFF,0xFF,0xFF,0xC0,0x10,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x00,0xFF,0xFF,0xFF,0xFF,0xE0,0x10,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x03,0xFF,0xFF,0xFF,0xFF,0xE0,0x20,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x60,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x3F,0xFF,0xFF,0xFF,0xFF,0xF0,0xC0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x07,0x3C,0x3F,0xFF,0xF8,0x7F,0xF1,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x07,0x3F,0xFF,0xFF,0xFF,0xFF,0xF1,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x3F,0xFF,0xFF,0xFF,0xFF,0xF3,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x20,0x00,0xFF,0x00,0x07,0xF2,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x0F,0xFF,0x7E,0xFF,0xFB,0xE7,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x9F,0x7F,0x81,0xFD,0xFC,0x0F,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0xBE,0x3F,0x9D,0xF8,0xFD,0xFF,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0xDF,0x7F,0xBC,0xFD,0xFB,0xFF,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x67,0xFE,0x7E,0x7F,0xE3,0xFF,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x38,0x01,0xFF,0x80,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x07,0xFE,0x00,0x7F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC7,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0F,0x80,0x00,0x00,0x00,0x01,0x83,0x80,0x61,0xC0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0F,0x80,0xF0,0x00,0x00,0x07,0x82,0xE3,0xE1,0xB0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0F,0x80,0x1C,0x00,0x00,0x0C,0x6C,0x02,0x3F,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0E,0x00,0x03,0x00,0x00,0x00,0xFE,0x00,0x3F,0x80,0x00,0x00,0x00, + 0x00,0x00,0x00,0x06,0x00,0xF1,0x80,0x00,0x0F,0x81,0xF7,0xC0,0x7C,0x00,0x00,0x00, + 0x00,0x00,0x00,0x03,0x80,0x18,0x80,0x00,0x03,0xFF,0x80,0xFF,0xE0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x01,0xC0,0x0C,0x40,0x00,0x02,0x18,0x81,0x8C,0x60,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xE1,0x84,0x40,0x00,0x02,0x18,0x81,0x8C,0x60,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x7F,0xC2,0x40,0x00,0x03,0xFF,0x81,0xFF,0xE0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x3F,0xE2,0x40,0x00,0x02,0x00,0x31,0x80,0x0C,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x03,0xFF,0xF0,0xFF,0xFC,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC0,0x7F,0xF0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +////////////////////////////////////////////////////////////////////////////////// +// +//洢ͼƬݣͼƬСΪ51*32 +//ʽ˳򣨸λǰ +// +///////////////////////////////////////////////////////////////////////////////// +unsigned char BMP5[] = +{ + 0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00, + 0x0E,0x00,0x00,0x00,0x00,0x01,0x80,0x0E,0x00,0x20,0x00,0x00,0x01,0xC0,0x00,0x00, + 0x70,0x00,0x00,0x00,0xC0,0x00,0x00,0xE0,0x00,0x00,0x00,0xE0,0x3F,0x81,0xC0,0x00, + 0x00,0x00,0x61,0xFF,0xF0,0x80,0x00,0x00,0x00,0x03,0xC0,0xF8,0x00,0x00,0x00,0x00, + 0x07,0x00,0x1C,0x00,0x00,0x00,0x00,0x1E,0x00,0x0F,0x00,0x00,0x00,0x7C,0x1C,0x00, + 0x03,0x1F,0x80,0x00,0x7C,0x1C,0x07,0xFF,0x1F,0x80,0x00,0x7C,0x1C,0x1F,0xFF,0x9F, + 0x80,0x00,0x00,0x1C,0x7C,0x03,0xF8,0x00,0x00,0x00,0x0F,0xF0,0x00,0x7C,0x00,0x00, + 0x03,0xFF,0x00,0x00,0x0F,0xE0,0x00,0x0F,0xF2,0x00,0x00,0x07,0xFE,0x00,0x1F,0x80, + 0x00,0x00,0x00,0x7F,0x80,0x3C,0x00,0x00,0x00,0x00,0x03,0x80,0x7C,0x00,0x00,0x00, + 0x00,0x03,0xC0,0x70,0x00,0x00,0x00,0x00,0x01,0xC0,0x70,0x00,0x00,0x00,0x00,0x01, + 0xC0,0x78,0x00,0x00,0x00,0x00,0x01,0xC0,0x7C,0x00,0x00,0x00,0x00,0x03,0xC0,0x3C, + 0x00,0x00,0x00,0x00,0x07,0x80,0x3E,0x00,0x00,0x00,0x00,0x3F,0x80,0x0F,0xE1,0xC0, + 0x00,0x1F,0xFC,0x00,0x03,0xFF,0xFC,0x03,0xFF,0xF0,0x00,0x00,0xFF,0xFF,0xFF,0xFF, + 0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x00, +}; +const unsigned char gImage_isoftstone[608] = { /* 0X00,0X01,0X80,0X00,0X26,0X00, */ +0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, +0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0X3C,0X02,0X00,0X00,0X00,0X00,0X00,0XE0,0X10,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0X1E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, +0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, +0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, +0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X7F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, +0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XE0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, +0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X1C,0XFD,0XE3,0XFF, +0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, +0XFF,0X00,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, +0XFF,0X10,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, +0XFF,0X1C,0X0F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0X78,0XF0,0X78,0X3C,0XE7,0XE3,0X80, +0XFF,0X1F,0XFE,0X3E,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7C,0XF8,0XE3,0XE3,0X80, +0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, +0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE3,0XE3,0XFF, +0XFC,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X0F,0XC0,0XE1,0XE3,0XFF, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X20,0X02,0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X3B,0XC3,0X0C,0X3F,0XE3,0XFC,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X26,0X43,0XFC,0X01,0XE0,0X84,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X39,0X03,0XD4,0X3D,0X60,0X84,0X00,0X00,0X00,0X00,0X00, +0XFF,0XFF,0XFF,0XFF,0XFC,0X39,0X83,0XFC,0X11,0X61,0X84,0X3F,0XFF,0XFF,0XFF,0XFF, +0X00,0X00,0X00,0X00,0X00,0X1B,0X83,0XFC,0X15,0X61,0X84,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X3A,0X83,0XDC,0X15,0X61,0X04,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X1A,0XC3,0X00,0X35,0X61,0X04,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X16,0X42,0XFC,0X3D,0X43,0X3C,0X00,0X00,0X00,0X00,0X00, +}; + +const unsigned char gImage_isoftstone2[608] = { /* 0X00,0X01,0X80,0X00,0X26,0X00, */ +0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, +0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0X3C,0X02,0X00,0X00,0X00,0X00,0X00,0XE0,0X10,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0X1E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, +0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, +0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, +0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X7F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, +0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XE0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, +0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X1C,0XFD,0XE3,0XFF, +0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, +0XFF,0X00,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, +0XFF,0X10,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, +0XFF,0X1C,0X0F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0X78,0XF0,0X78,0X3C,0XE7,0XE3,0X80, +0XFF,0X1F,0XFE,0X3E,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7C,0XF8,0XE3,0XE3,0X80, +0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, +0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE3,0XE3,0XFF, +0XFC,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X0F,0XC0,0XE1,0XE3,0XFF, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X20,0X02,0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X3B,0XC3,0X0C,0X3F,0XE3,0XFC,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X26,0X43,0XFC,0X01,0XE0,0X84,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X39,0X03,0XD4,0X3D,0X60,0X84,0X00,0X00,0X00,0X00,0X00, +0XFF,0XFF,0XFF,0XFF,0XFC,0X39,0X83,0XFC,0X11,0X61,0X84,0X3F,0XFF,0XFF,0XFF,0XFF, +0X00,0X00,0X00,0X00,0X00,0X1B,0X83,0XFC,0X15,0X61,0X84,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X3A,0X83,0XDC,0X15,0X61,0X04,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X1A,0XC3,0X00,0X35,0X61,0X04,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X16,0X42,0XFC,0X3D,0X43,0X3C,0X00,0X00,0X00,0X00,0X00, +}; + +const unsigned char gImage_isoftstone3[416] = { /* 0X00,0X01,0X80,0X00,0X1A,0X00, */ +0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, +0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0X3C,0X02,0X7F,0X80,0X7F,0XE7,0XFD,0XE0,0X17,0XFE,0XFF,0X00,0XE1,0XE3,0XFF, +0X7F,0X3E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, +0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, +0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, +0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X3F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, +0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XF0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, +0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X3C,0XFD,0XE3,0XFF, +0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, +0XFF,0X10,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, +0XFF,0X18,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0XC0,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, +0XFF,0X1C,0X1F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0XF8,0XF0,0X78,0X3C,0XE7,0XE3,0X80, +0XFF,0X1F,0XFE,0X3F,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7E,0XF8,0XE3,0XE3,0X80, +0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, +0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE1,0XE3,0XFF, +0XF8,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X07,0XC0,0XE1,0XE3,0XFF, +}; + +const unsigned char gImage_issedu[] = { + 0x00,0x18,0xFF,0x8C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x27,0xFF,0xF3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0xDF,0x80,0xFC,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x01,0x3D,0xFF,0xCE,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x02,0xF7,0xFF,0xF3,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x05,0xDF,0xFF,0xFD,0xD0,0x01,0x83,0x80,0xF7,0xFF,0x80,0xC1,0xC0,0x00,0xC0,0x00, + 0x0B,0xBF,0xFF,0xFE,0xE8,0x0E,0x74,0x7D,0x00,0x00,0x4F,0x3E,0x3E,0xFF,0x3F,0xC0, + 0x17,0x7F,0xFF,0xFF,0xF4,0x11,0xC3,0x82,0xF7,0xFF,0xB0,0xC1,0xC0,0x00,0xC0,0x00, + 0x16,0xFF,0xFF,0xFF,0xFA,0x2F,0xFB,0xFC,0xFF,0xFF,0xCF,0xFD,0xFF,0xFF,0xFF,0xE0, + 0x2D,0xFF,0xC0,0xFF,0xDA,0x2F,0xFB,0xFE,0xFF,0xFF,0xCF,0xFD,0xFE,0xFF,0xFF,0xE0, + 0x5F,0xFE,0x04,0x3F,0xED,0x2F,0xFF,0xFE,0x0B,0x83,0xCF,0xFF,0xFE,0xFF,0xFF,0xD0, + 0x5B,0xFD,0xFB,0xCF,0xFD,0x13,0x8F,0x0E,0xE7,0xFF,0xD0,0xDF,0x9C,0xEF,0xFD,0xD0, + 0xBF,0xFB,0xFF,0xC7,0xF6,0x97,0xEE,0xFE,0xF7,0xFF,0xEF,0xFF,0x5C,0xFF,0xFF,0xD0, + 0xB7,0xF7,0xF3,0xD7,0xFE,0x97,0xED,0xDC,0xFF,0xBB,0xEF,0xFD,0xDD,0x7F,0xFF,0x90, + 0xB7,0xEF,0xEB,0xDB,0xF7,0x57,0xE1,0xF3,0x7F,0xFF,0xE7,0xF1,0xDD,0x7F,0xFF,0xA0, + 0x7B,0x8F,0xD9,0xD4,0xEF,0x57,0xF9,0xF5,0x7F,0xFF,0xEF,0xFD,0xDC,0xFF,0xFF,0xD0, + 0x7E,0xEF,0xC7,0xEB,0x9F,0x57,0xF9,0xF5,0x7F,0xBB,0xEF,0xFD,0xDC,0xFF,0xFF,0xD0, + 0x7F,0xEF,0x9F,0xF5,0xFF,0x4B,0xFD,0xF3,0x7F,0xFF,0xEC,0x3C,0xFA,0xFF,0xFF,0xD0, + 0x7A,0xDF,0xBD,0xF5,0xEF,0x50,0xE5,0xFB,0x7F,0xFF,0xEF,0xFE,0xFA,0xFF,0xFF,0xD0, + 0x7F,0xDF,0x63,0xF9,0xFF,0x6F,0xFB,0xBB,0x7F,0xBB,0xEF,0xFD,0xFA,0xFF,0xFF,0xD0, + 0x7F,0xDF,0x57,0xF9,0xFF,0x6F,0xFB,0xBD,0x7E,0xBB,0xCF,0xFC,0x72,0xFF,0xFF,0xD0, + 0x7F,0xDF,0x67,0xFD,0xFF,0x4F,0xF7,0x5E,0x76,0x3B,0x90,0x71,0xFC,0xFF,0xFF,0xD0, + 0x7B,0xDF,0x15,0xFD,0xFF,0x40,0xEF,0x6E,0xFF,0xFF,0xE7,0xFB,0xFE,0xE0,0x03,0xD0, + 0x7F,0xFF,0xFB,0xFB,0xFF,0x4E,0xEE,0xA6,0xFF,0xFF,0xE7,0xEB,0x8E,0xE8,0x0B,0xD0, + 0x3F,0xFF,0xF7,0xFB,0xEF,0x44,0xE9,0xF2,0xCF,0xFF,0xE7,0xD2,0x76,0xFF,0xFB,0x20, + 0xBF,0xFF,0xFF,0xC7,0xFE,0x42,0x12,0x01,0x20,0x00,0x08,0x0C,0xB1,0x00,0x90,0x40, + 0xBF,0xF7,0xFF,0xB7,0xDE,0x85,0xCC,0xFE,0xFD,0xD7,0xF7,0xF2,0x4E,0xBF,0x65,0xC0, + 0x5E,0xFB,0xFF,0x4F,0xFE,0x97,0xDF,0xFF,0xFF,0xFB,0xF7,0xFE,0xFE,0xFF,0xF6,0xD0, + 0x5A,0xFE,0xF0,0xBF,0xBD,0x17,0xB3,0xEF,0xDB,0x7F,0xF7,0x6E,0xF5,0xCB,0x9F,0xD0, + 0x2F,0x7F,0x80,0xFD,0xFD,0x17,0xF3,0xED,0xFB,0x3F,0xF7,0xEE,0x71,0xEB,0x9F,0xD0, + 0x2F,0xFF,0xFF,0xFF,0xDA,0x17,0xFF,0x8D,0x7B,0xFF,0xF7,0x7F,0xFF,0xEB,0xFD,0xD0, + 0x16,0xDF,0xFF,0xFF,0xB4,0x07,0xDF,0xAD,0xF9,0xFB,0xF7,0xFB,0xDF,0x3B,0xF6,0xD0, + 0x0B,0x77,0xFB,0xFB,0x64,0x00,0x20,0x52,0x04,0x04,0x08,0x04,0x20,0xC4,0x09,0x20, + 0x0D,0xBF,0xFF,0xEE,0xC8,0x07,0xDE,0x8D,0xE9,0xFB,0xF7,0xFB,0xDF,0x2B,0xF4,0xC0, + 0x06,0xFF,0x7B,0xFF,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x03,0x7F,0xFF,0xFF,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0xBF,0xFF,0xFE,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x4F,0xFF,0xF9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x31,0xFF,0xE6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x0C,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif + diff --git a/EBox_IoT_049_OLED_Env_GUE/include/oled_font.h b/EBox_IoT_049_OLED_Env_GUE/include/oled_font.h new file mode 100644 index 0000000000000000000000000000000000000000..4be722d0dc0341554b851383df1d9eeee6148b94 --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/include/oled_font.h @@ -0,0 +1,627 @@ +#ifndef __OLED_FONT_H__ +#define __OLED_FONT_H__ + +//常用ASCII表 +//偏移量32 +//ASCII字符集 +//偏移量32 +//大小:6*8 +//逐行式,顺向(高位在前) +/************************************6*8的点阵************************************/ +const unsigned char F6x8[][8] = +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // sp + 0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x00, // ! + 0x28,0x28,0x28,0x00,0x00,0x00,0x00,0x00, // " + 0x28,0x28,0x7C,0x28,0x7C,0x28,0x28,0x00, // # + 0x10,0x3C,0x50,0x38,0x14,0x78,0x10,0x00, // $ + 0x00,0x4C,0x2C,0x10,0x08,0x60,0x60,0x00, // % + 0x30,0x48,0x50,0x20,0x54,0x48,0x34,0x00, // & + 0x30,0x10,0x20,0x00,0x00,0x00,0x00,0x00, // ' + 0x08,0x10,0x20,0x20,0x20,0x10,0x08,0x00, // ( + 0x20,0x10,0x08,0x08,0x08,0x10,0x20,0x00, // ) + 0x00,0x10,0x54,0x38,0x54,0x10,0x00,0x00, // * + 0x00,0x10,0x10,0x7C,0x10,0x10,0x00,0x00, // + + 0x00,0x00,0x00,0x00,0x00,0x18,0x08,0x10, // , + 0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00, // - + 0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00, // . + 0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00, // / + 0x38,0x44,0x4C,0x54,0x64,0x44,0x38,0x00, // 0 + 0x10,0x30,0x10,0x10,0x10,0x10,0x38,0x00, // 1 + 0x38,0x44,0x04,0x08,0x10,0x20,0x7C,0x00, // 2 + 0x7C,0x08,0x10,0x08,0x04,0x44,0x38,0x00, // 3 + 0x08,0x18,0x28,0x48,0x7C,0x08,0x08,0x00, // 4 + 0x7C,0x40,0x78,0x04,0x04,0x44,0x38,0x00, // 5 + 0x18,0x20,0x40,0x78,0x44,0x44,0x38,0x00, // 6 + 0x7C,0x04,0x08,0x10,0x20,0x20,0x20,0x00, // 7 + 0x38,0x44,0x44,0x38,0x44,0x44,0x38,0x00, // 8 + 0x38,0x44,0x44,0x3C,0x04,0x08,0x30,0x00, // 9 + 0x00,0x30,0x30,0x00,0x30,0x30,0x00,0x00, // : + 0x00,0x30,0x30,0x00,0x30,0x10,0x20,0x00, // ; + 0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00, // < + 0x00,0x00,0x7C,0x00,0x7C,0x00,0x00,0x00, // = + 0x20,0x10,0x08,0x04,0x08,0x10,0x20,0x00, // > + 0x38,0x44,0x04,0x08,0x10,0x00,0x10,0x00, // ? + 0x38,0x44,0x04,0x34,0x5C,0x44,0x38,0x00, // @ + 0x10,0x28,0x44,0x44,0x7C,0x44,0x44,0x00, // A + 0x78,0x44,0x44,0x78,0x44,0x44,0x78,0x00, // B + 0x38,0x44,0x40,0x40,0x40,0x44,0x38,0x00, // C + 0x70,0x48,0x44,0x44,0x44,0x48,0x70,0x00, // D + 0x7C,0x40,0x40,0x78,0x40,0x40,0x7C,0x00, // E + 0x7C,0x40,0x40,0x78,0x40,0x40,0x40,0x00, // F + 0x38,0x44,0x40,0x5C,0x44,0x44,0x3C,0x00, // G + 0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x00, // H + 0x38,0x10,0x10,0x10,0x10,0x10,0x38,0x00, // I + 0x1C,0x08,0x08,0x08,0x08,0x48,0x30,0x00, // J + 0x44,0x48,0x50,0x60,0x50,0x48,0x44,0x00, // K + 0x40,0x40,0x40,0x40,0x40,0x40,0x7C,0x00, // L + 0x44,0x6C,0x54,0x54,0x44,0x44,0x44,0x00, // M + 0x44,0x44,0x64,0x54,0x4C,0x44,0x44,0x00, // N + 0x38,0x44,0x44,0x44,0x44,0x44,0x38,0x00, // O + 0x78,0x44,0x44,0x78,0x40,0x40,0x40,0x00, // P + 0x38,0x44,0x44,0x44,0x54,0x48,0x34,0x00, // Q + 0x78,0x44,0x44,0x78,0x50,0x48,0x44,0x00, // R + 0x3C,0x40,0x40,0x38,0x04,0x04,0x78,0x00, // S + 0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x00, // T + 0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x00, // U + 0x44,0x44,0x44,0x44,0x44,0x28,0x10,0x00, // V + 0x44,0x44,0x44,0x54,0x54,0x54,0x28,0x00, // W + 0x44,0x44,0x28,0x10,0x28,0x44,0x44,0x00, // X + 0x44,0x44,0x44,0x28,0x10,0x10,0x10,0x00, // Y + 0x7C,0x04,0x08,0x10,0x20,0x40,0x7C,0x00, // Z + 0x38,0x20,0x20,0x20,0x20,0x20,0x38,0x00, // [ + 0x00,0x40,0x20,0x10,0x08,0x04,0x00,0x00, // '\' + 0x38,0x08,0x08,0x08,0x08,0x08,0x38,0x00, // ] + 0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00, // ^ + 0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00, // _ + 0x20,0x10,0x08,0x00,0x00,0x00,0x00,0x00, // ' + 0x00,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00, // a + 0x40,0x40,0x58,0x64,0x44,0x44,0x78,0x00, // b + 0x00,0x00,0x38,0x40,0x40,0x44,0x38,0x00, // c + 0x04,0x04,0x34,0x4C,0x44,0x44,0x3C,0x00, // d + 0x00,0x00,0x38,0x44,0x7C,0x40,0x38,0x00, // e + 0x38,0x24,0x20,0x70,0x20,0x20,0x20,0x00, // f + 0x00,0x00,0x3C,0x44,0x44,0x3C,0x04,0x38, // g + 0x40,0x40,0x58,0x64,0x44,0x44,0x44,0x00, // h + 0x10,0x00,0x30,0x10,0x10,0x10,0x38,0x00, // i + 0x08,0x00,0x18,0x08,0x08,0x08,0x48,0x30, // j + 0x40,0x40,0x48,0x50,0x60,0x50,0x48,0x00, // k + 0x30,0x10,0x10,0x10,0x10,0x10,0x38,0x00, // l + 0x00,0x00,0x68,0x54,0x54,0x44,0x44,0x00, // m + 0x00,0x00,0x58,0x64,0x44,0x44,0x44,0x00, // n + 0x00,0x00,0x38,0x44,0x44,0x44,0x38,0x00, // o + 0x00,0x00,0x58,0x64,0x64,0x58,0x40,0x40, // p + 0x00,0x00,0x34,0x4C,0x4C,0x34,0x04,0x04, // q + 0x00,0x00,0x58,0x64,0x40,0x40,0x40,0x00, // r + 0x00,0x00,0x3C,0x40,0x38,0x04,0x78,0x00, // s + 0x20,0x20,0x70,0x20,0x20,0x24,0x18,0x00, // t + 0x00,0x00,0x44,0x44,0x44,0x4C,0x34,0x00, // u + 0x00,0x00,0x44,0x44,0x44,0x28,0x10,0x00, // v + 0x00,0x00,0x44,0x44,0x54,0x54,0x28,0x00, // w + 0x00,0x00,0x44,0x28,0x10,0x28,0x44,0x00, // x + 0x00,0x00,0x44,0x44,0x44,0x3C,0x04,0x38, // y + 0x00,0x00,0x7C,0x08,0x10,0x20,0x7C,0x00, // z + 0x10,0x20,0x20,0x40,0x20,0x20,0x10,0x00, // { + 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00, // | + 0x20,0x10,0x10,0x08,0x10,0x10,0x20,0x00, // } + 0x00,0x00,0x00,0x20,0x54,0x08,0x00,0x00, // ~ +}; + +//常用ASCII表 +//偏移量32 +//ASCII字符集 +//偏移量32 +//大小:8*16 +//逐行式,顺向(高位在前) +/****************************************8*16的点阵************************************/ +const unsigned char F8X16[]= +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 + 0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x18,0x18,0x00,0x00,//! 1 + 0x00,0x12,0x36,0x24,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2 + 0x00,0x00,0x00,0x24,0x24,0x24,0xFE,0x48,0x48,0x48,0xFE,0x48,0x48,0x48,0x00,0x00,//# 3 + 0x00,0x00,0x10,0x38,0x54,0x54,0x50,0x30,0x1C,0x14,0x14,0x54,0x54,0x38,0x10,0x10,//$ 4 + 0x00,0x00,0x00,0x44,0xA4,0xA8,0xA8,0xA8,0x54,0x1A,0x2A,0x2A,0x2A,0x44,0x00,0x00,//% 5 + 0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x50,0x6E,0xA4,0x94,0x88,0x89,0x76,0x00,0x00,//& 6 + 0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7 + 0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00,//( 8 + 0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00,//) 9 + 0x00,0x00,0x00,0x00,0x10,0x10,0xD6,0x38,0x38,0xD6,0x10,0x10,0x00,0x00,0x00,0x00,//* 10 + 0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0x00,0x00,0x00,//+ 11 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x20,0xC0,//, 12 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//- 13 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,//. 14 + 0x00,0x00,0x01,0x02,0x02,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x40,0x00,/// 15 + 0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,//0 16 + 0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,//1 17 + 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,//2 18 + 0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00,//3 19 + 0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00,//4 20 + 0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00,//5 21 + 0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00,//6 22 + 0x00,0x00,0x00,0x7E,0x42,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,//7 23 + 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,//8 24 + 0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00,//9 25 + 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,//: 26 + 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x08,0x30,0x00,//; 27 + 0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00,//< 28 + 0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,//= 29 + 0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00,//> 30 + 0x00,0x00,0x00,0x3C,0x42,0x42,0x62,0x02,0x04,0x08,0x08,0x00,0x18,0x18,0x00,0x00,//? 31 + 0x00,0x00,0x00,0x38,0x44,0x5A,0xAA,0xAA,0xAA,0xAA,0xB4,0x42,0x44,0x38,0x00,0x00,//@ 32 + 0x00,0x00,0x00,0x10,0x10,0x18,0x28,0x28,0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00,//A 33 + 0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78,0x44,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,//B 34 + 0x00,0x00,0x00,0x3E,0x42,0x42,0x80,0x80,0x80,0x80,0x80,0x42,0x44,0x38,0x00,0x00,//C 35 + 0x00,0x00,0x00,0xF8,0x44,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,//D 36 + 0x00,0x00,0x00,0xFE,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x42,0x42,0xFE,0x00,0x00,//E 37 + 0x00,0x00,0x00,0xFE,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x40,0x40,0xE0,0x00,0x00,//F 38 + 0x00,0x00,0x00,0x3C,0x44,0x44,0x80,0x80,0x80,0x8E,0x84,0x44,0x44,0x38,0x00,0x00,//G 39 + 0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,//H 40 + 0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,//I 41 + 0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x88,0xF0,//J 42 + 0x00,0x00,0x00,0xEE,0x44,0x48,0x50,0x70,0x50,0x48,0x48,0x44,0x44,0xEE,0x00,0x00,//K 43 + 0x00,0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x42,0xFE,0x00,0x00,//L 44 + 0x00,0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x6C,0x54,0x54,0x54,0x54,0x54,0xD6,0x00,0x00,//M 45 + 0x00,0x00,0x00,0xC7,0x62,0x62,0x52,0x52,0x4A,0x4A,0x4A,0x46,0x46,0xE2,0x00,0x00,//N 46 + 0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x44,0x38,0x00,0x00,//O 47 + 0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x42,0x7C,0x40,0x40,0x40,0x40,0xE0,0x00,0x00,//P 48 + 0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0xB2,0xCA,0x4C,0x38,0x06,0x00,//Q 49 + 0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78,0x48,0x48,0x44,0x44,0x42,0xE3,0x00,0x00,//R 50 + 0x00,0x00,0x00,0x3E,0x42,0x42,0x40,0x20,0x18,0x04,0x02,0x42,0x42,0x7C,0x00,0x00,//S 51 + 0x00,0x00,0x00,0xFE,0x92,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,//T 52 + 0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,//U 53 + 0x00,0x00,0x00,0xE7,0x42,0x42,0x44,0x24,0x24,0x28,0x28,0x18,0x10,0x10,0x00,0x00,//V 54 + 0x00,0x00,0x00,0xD6,0x92,0x92,0x92,0x92,0xAA,0xAA,0x6C,0x44,0x44,0x44,0x00,0x00,//W 55 + 0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00,//X 56 + 0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,//Y 57 + 0x00,0x00,0x00,0x7E,0x84,0x04,0x08,0x08,0x10,0x20,0x20,0x42,0x42,0xFC,0x00,0x00,//Z 58 + 0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00,//[ 59 + 0x00,0x00,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x04,0x04,0x02,0x02,0x02,0x01,0x01,//\ 60 + 0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00,//] 61 + 0x00,0x08,0x14,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,//_ 63 + 0x00,0x60,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x1E,0x22,0x42,0x42,0x3F,0x00,0x00,//a 65 + 0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x64,0x58,0x00,0x00,//b 66 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x40,0x40,0x40,0x22,0x1C,0x00,0x00,//c 67 + 0x00,0x00,0x00,0x06,0x02,0x02,0x02,0x1E,0x22,0x42,0x42,0x42,0x26,0x1B,0x00,0x00,//d 68 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x40,0x40,0x42,0x3C,0x00,0x00,//e 69 + 0x00,0x00,0x00,0x0F,0x11,0x10,0x10,0x7E,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,//f 70 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x44,0x44,0x38,0x40,0x3C,0x42,0x42,0x3C,//g 71 + 0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,//h 72 + 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,//i 73 + 0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x04,0x44,0x78,//j 74 + 0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x4E,0x48,0x50,0x68,0x48,0x44,0xEE,0x00,0x00,//k 75 + 0x00,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,//l 76 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF6,0x49,0x49,0x49,0x49,0x49,0xED,0x00,0x00,//m 77 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,//n 78 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,//o 79 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD8,0x64,0x42,0x42,0x42,0x64,0x58,0x40,0xE0,//p 80 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x22,0x42,0x42,0x42,0x26,0x1A,0x02,0x07,//q 81 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x32,0x20,0x20,0x20,0x20,0xF8,0x00,0x00,//r 82 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x40,0x3C,0x02,0x42,0x7C,0x00,0x00,//s 83 + 0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x7C,0x10,0x10,0x10,0x10,0x10,0x0C,0x00,0x00,//t 84 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC6,0x42,0x42,0x42,0x42,0x46,0x3B,0x00,0x00,//u 85 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x10,0x10,0x00,0x00,//v 86 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD7,0x92,0x92,0xAA,0xAA,0x44,0x44,0x00,0x00,//w 87 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6E,0x24,0x18,0x18,0x18,0x24,0x76,0x00,0x00,//x 88 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x18,0x10,0x10,0xE0,//y 89 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x44,0x08,0x10,0x10,0x22,0x7E,0x00,0x00,//z 90 + 0x00,0x03,0x04,0x04,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x04,0x04,0x03,0x00,//{ 91 + 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,//| 92 + 0x00,0x60,0x10,0x10,0x10,0x10,0x10,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x60,0x00,//} 93 + 0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x52,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94 +}; +#if 0 +typedef struct +{ + unsigned char Index[2]; + char Msk[16]; +}typFNT_GB8; + +//宋体 +//8*8大小 +//逐行式,顺向(高位在前) +const typFNT_GB8 cfont8[] = +{ +#if 1 + "鸿",0x00,0x10,0x80,0x20,0x40,0x7C,0x1F,0x44,0x84,0x64,0x44,0x54,0x44,0x44,0x04,0x4C, + 0x24,0x40,0x44,0x7E,0xC4,0x02,0x47,0x02,0x5C,0x7A,0x48,0x02,0x40,0x0A,0x00,0x04,/*"鸿",0*/ + "蒙",0x08,0x20,0xFF,0xFE,0x08,0x20,0x7F,0xFE,0x40,0x02,0x8F,0xE4,0x00,0x00,0x7F,0xFC, + 0x06,0x00,0x3B,0x08,0x04,0xB0,0x19,0xC0,0x62,0xA0,0x0C,0x98,0x72,0x86,0x01,0x00,/*"蒙",1*/ + + "九",0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x7F,0xE0,0x04,0x20,0x04,0x20,0x04,0x20, + 0x08,0x20,0x08,0x20,0x08,0x20,0x10,0x22,0x10,0x22,0x20,0x22,0x40,0x1E,0x80,0x00,/*"九",0*/ + "队",0x00,0x40,0x7C,0x40,0x44,0x40,0x48,0x40,0x48,0x40,0x50,0x40,0x48,0x40,0x48,0x40, + 0x44,0xA0,0x44,0xA0,0x44,0xA0,0x69,0x10,0x51,0x10,0x42,0x08,0x44,0x04,0x48,0x02,/*"队",1*/ +#endif +}; +#endif + +typedef struct +{ + unsigned char Index[2]; + char Msk[32]; +}typFNT_GB16; + +typedef struct +{ + unsigned char Index[3]; + char Msk[32]; +}typFNT_GB16_UTF; + +//宋体 +//16*16大小 +//逐行式,顺向(高位在前) +const typFNT_GB16 cfont16[] = +{ +#if 0 + "全",0x01,0x00,0x01,0x00,0x02,0x80,0x04,0x40,0x08,0x20,0x10,0x10,0x2F,0xE8,0xC1,0x06, + 0x01,0x00,0x01,0x00,0x1F,0xF0,0x01,0x00,0x01,0x00,0x01,0x00,0x7F,0xFC,0x00,0x00,/*"全",0*/ + "动",0x00,0x40,0x00,0x40,0x7C,0x40,0x00,0x40,0x01,0xFC,0x00,0x44,0xFE,0x44,0x20,0x44, + 0x20,0x44,0x20,0x84,0x48,0x84,0x44,0x84,0xFD,0x04,0x45,0x04,0x02,0x28,0x04,0x10,/*"动",1*/ + "电",0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8, + 0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x0A,0x01,0x02,0x01,0x02,0x00,0xFE,/*"电",0*/ + "子",0x00,0x00,0x7F,0xF8,0x00,0x10,0x00,0x20,0x00,0x40,0x01,0x80,0x01,0x00,0xFF,0xFE, + 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,/*"子",1*/ + "技",0x10,0x20,0x10,0x20,0x10,0x20,0x13,0xFE,0xFC,0x20,0x10,0x20,0x10,0x20,0x15,0xFC, + 0x18,0x84,0x30,0x88,0xD0,0x48,0x10,0x50,0x10,0x20,0x10,0x50,0x51,0x88,0x26,0x06,/*"技",2*/ + "术",0x01,0x00,0x01,0x20,0x01,0x10,0x01,0x10,0x7F,0xFC,0x03,0x80,0x05,0x40,0x05,0x40, + 0x09,0x20,0x11,0x10,0x21,0x08,0x41,0x04,0x81,0x02,0x01,0x00,0x01,0x00,0x01,0x00,/*"术",3*/ + "系",0x00,0xF8,0x3F,0x00,0x04,0x00,0x08,0x20,0x10,0x40,0x3F,0x80,0x01,0x00,0x06,0x10, + 0x18,0x08,0x7F,0xFC,0x01,0x04,0x09,0x20,0x11,0x10,0x21,0x08,0x45,0x04,0x02,0x00,/*"系",0*/ + "统",0x10,0x40,0x10,0x20,0x20,0x20,0x23,0xFE,0x48,0x40,0xF8,0x88,0x11,0x04,0x23,0xFE, + 0x40,0x92,0xF8,0x90,0x40,0x90,0x00,0x90,0x19,0x12,0xE1,0x12,0x42,0x0E,0x04,0x00,/*"统",1*/ + "设",0x00,0x00,0x21,0xF0,0x11,0x10,0x11,0x10,0x01,0x10,0x02,0x0E,0xF4,0x00,0x13,0xF8, + 0x11,0x08,0x11,0x10,0x10,0x90,0x14,0xA0,0x18,0x40,0x10,0xA0,0x03,0x18,0x0C,0x06,/*"设",2*/ + "置",0x7F,0xFC,0x44,0x44,0x7F,0xFC,0x01,0x00,0x7F,0xFC,0x01,0x00,0x1F,0xF0,0x10,0x10, + 0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0xFF,0xFE,0x00,0x00,/*"置",3*/ + "音",0x02,0x00,0x01,0x00,0x3F,0xF8,0x00,0x00,0x08,0x20,0x04,0x40,0xFF,0xFE,0x00,0x00, + 0x1F,0xF0,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,/*"音",4*/ + "量",0x00,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0xFF,0xFE,0x00,0x00,0x1F,0xF0, + 0x11,0x10,0x1F,0xF0,0x11,0x10,0x1F,0xF0,0x01,0x00,0x1F,0xF0,0x01,0x00,0x7F,0xFC,/*"量",5*/ + "颜",0x10,0x00,0x08,0xFE,0x7F,0x10,0x22,0x20,0x14,0x7C,0x7F,0x44,0x44,0x54,0x48,0x54, + 0x52,0x54,0x44,0x54,0x48,0x54,0x51,0x54,0x42,0x28,0x44,0x24,0x88,0x42,0x30,0x82,/*"颜",6*/ + "色",0x08,0x00,0x08,0x00,0x1F,0xE0,0x20,0x20,0x40,0x40,0xBF,0xF8,0x21,0x08,0x21,0x08, + 0x21,0x08,0x3F,0xF8,0x20,0x00,0x20,0x02,0x20,0x02,0x20,0x02,0x1F,0xFE,0x00,0x00,/*"色",7*/ + "网",0x00,0x00,0x7F,0xFC,0x40,0x04,0x40,0x04,0x42,0x14,0x52,0x94,0x4A,0x54,0x44,0x24, + 0x44,0x24,0x4A,0x54,0x4A,0x54,0x52,0x94,0x61,0x04,0x40,0x04,0x40,0x14,0x40,0x08,/*"网",8*/ + "络",0x10,0x80,0x10,0x80,0x20,0xF8,0x21,0x08,0x4B,0x10,0xFC,0xA0,0x10,0x40,0x20,0xA0, + 0x41,0x18,0xFA,0x06,0x45,0xF8,0x01,0x08,0x19,0x08,0xE1,0x08,0x41,0xF8,0x01,0x08,/*"络",9*/ + +#endif +#if 1 + "鸿",0x00,0x10,0x80,0x20,0x40,0x7C,0x1F,0x44,0x84,0x64,0x44,0x54,0x44,0x44,0x04,0x4C, + 0x24,0x40,0x44,0x7E,0xC4,0x02,0x47,0x02,0x5C,0x7A,0x48,0x02,0x40,0x0A,0x00,0x04,/*"鸿",0*/ + "蒙",0x08,0x20,0xFF,0xFE,0x08,0x20,0x7F,0xFE,0x40,0x02,0x8F,0xE4,0x00,0x00,0x7F,0xFC, + 0x06,0x00,0x3B,0x08,0x04,0xB0,0x19,0xC0,0x62,0xA0,0x0C,0x98,0x72,0x86,0x01,0x00,/*"蒙",1*/ + + "九",0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x7F,0xE0,0x04,0x20,0x04,0x20,0x04,0x20, + 0x08,0x20,0x08,0x20,0x08,0x20,0x10,0x22,0x10,0x22,0x20,0x22,0x40,0x1E,0x80,0x00,/*"九",0*/ + "队",0x00,0x40,0x7C,0x40,0x44,0x40,0x48,0x40,0x48,0x40,0x50,0x40,0x48,0x40,0x48,0x40, + 0x44,0xA0,0x44,0xA0,0x44,0xA0,0x69,0x10,0x51,0x10,0x42,0x08,0x44,0x04,0x48,0x02,/*"队",1*/ + + "软",0x00,0x00,0x18,0x60,0x10,0x40,0x7E,0x40,0x10,0xFE,0x20,0x84,0x29,0xB4,0x68,0x20, + 0x7F,0x20,0x08,0x30,0x08,0x30,0x7F,0x70,0x48,0x48,0x08,0x8C,0x0B,0x86,0x09,0x00,/*"软",0*/ + "通",0x00,0x00,0x27,0xFC,0x20,0x18,0x30,0xB0,0x00,0x60,0x07,0xFC,0x74,0x44,0x77,0xFC, + 0x34,0x44,0x34,0x44,0x37,0xFC,0x34,0x44,0x34,0x4C,0x38,0x00,0x47,0xFE,0x00,0x00,/*"通",1*/ + "动",0x00,0x00,0x00,0x30,0x00,0x30,0x3E,0x30,0x00,0x30,0x00,0xFE,0x7F,0x32,0x7F,0x22, + 0x10,0x22,0x16,0x22,0x22,0x22,0x23,0x62,0x7D,0x46,0x00,0xC6,0x01,0x9C,0x00,0x00,/*"动",2*/ + "力",0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xFE,0x01,0x04,0x01,0x04, + 0x03,0x04,0x03,0x04,0x02,0x04,0x06,0x04,0x0C,0x04,0x18,0x0C,0x70,0x38,0x20,0x00,/*"力",3*/ + + "鸿",0x00,0x10,0x80,0x20,0x40,0x7C,0x1F,0x44,0x84,0x64,0x44,0x54,0x44,0x44,0x04,0x4C, + 0x24,0x40,0x44,0x7E,0xC4,0x02,0x47,0x02,0x5C,0x7A,0x48,0x02,0x40,0x0A,0x00,0x04,/*"鸿",0*/ + "蒙",0x08,0x20,0xFF,0xFE,0x08,0x20,0x7F,0xFE,0x40,0x02,0x8F,0xE4,0x00,0x00,0x7F,0xFC, + 0x06,0x00,0x3B,0x08,0x04,0xB0,0x19,0xC0,0x62,0xA0,0x0C,0x98,0x72,0x86,0x01,0x00,/*"蒙",1*/ + "业",0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x40,0x44,0x44,0x24,0x44,0x24,0x48,0x14,0x48, + 0x14,0x50,0x14,0x60,0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x40,0xFF,0xFE,0x00,0x00,/*"业",2*/ + "务",0x04,0x00,0x04,0x00,0x0F,0xF0,0x18,0x20,0x24,0xC0,0x03,0x00,0x0C,0xC0,0x32,0x30, + 0xC2,0x0E,0x1F,0xF0,0x02,0x10,0x04,0x10,0x04,0x10,0x08,0x10,0x10,0xA0,0x20,0x40,/*"务",3*/ + "发",0x01,0x00,0x11,0x10,0x11,0x08,0x22,0x00,0x3F,0xFC,0x02,0x00,0x04,0x00,0x07,0xF8, + 0x0A,0x08,0x09,0x08,0x11,0x10,0x10,0xA0,0x20,0x40,0x40,0xA0,0x03,0x18,0x1C,0x06,/*"发",4*/ + "展",0x00,0x00,0x3F,0xFC,0x20,0x04,0x20,0x04,0x3F,0xFC,0x22,0x20,0x22,0x20,0x2F,0xF8, + 0x22,0x20,0x22,0x20,0x3F,0xFE,0x24,0x88,0x24,0x50,0x45,0x30,0x46,0x0E,0x84,0x00,/*"展",5*/ + "部",0x10,0x00,0x08,0x3E,0x7F,0xA2,0x00,0x24,0x21,0x24,0x12,0x28,0xFF,0xE4,0x00,0x24, + 0x00,0x22,0x3F,0x22,0x21,0x22,0x21,0x34,0x21,0x28,0x3F,0x20,0x21,0x20,0x00,0x20,/*"部",6*/ + +/*---------------韦----------------*/ +"韦",0x01,0x00,0x01,0x00,0x01,0x00,0x7F,0xFE,0x01,0x00,0x01,0x00,0x3F,0xF8,0x01,0x00, +0x01,0x00,0x7F,0xFC,0x01,0x04,0x01,0x04,0x01,0x04,0x01,0x28,0x01,0x10,0x01,0x00, +/*---------------长----------------*/ +"长",0x08,0x00,0x08,0x10,0x08,0x20,0x08,0x40,0x08,0x80,0x09,0x00,0x08,0x00,0xFF,0xFE, +0x0A,0x00,0x09,0x00,0x08,0x80,0x08,0x40,0x09,0x20,0x0A,0x18,0x0C,0x06,0x08,0x00, +/*---------------江----------------*/ +"江",0x00,0x00,0x20,0x00,0x17,0xFC,0x10,0x40,0x80,0x40,0x40,0x40,0x48,0x40,0x08,0x40, +0x10,0x40,0x10,0x40,0xE0,0x40,0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x00,0x00,0x00, +/*---------------梁----------------*/ +"梁",0x00,0x00,0x08,0x08,0x05,0xF8,0x30,0xF8,0x1B,0x58,0x07,0xD6,0x0E,0xD2,0x39,0xB0, +0x1A,0xA0,0x07,0xFE,0x1F,0xC0,0x06,0xA0,0x0C,0x90,0x18,0x9E,0x61,0x80,0x00,0x00, +/*---------------弦----------------*/ +"弦",0x00,0x00,0x00,0x40,0x3E,0x60,0x06,0x30,0x04,0x3E,0x3F,0xF8,0x38,0x60,0x30,0x48, +0x3E,0xD8,0x37,0xF0,0x04,0xA0,0x04,0x78,0x24,0xCC,0x1D,0xFE,0x1D,0xE6,0x08,0x00, +"彤",/*---------------彤----------------*/ +0x00,0x00,0x08,0x84,0x0F,0x8C,0x08,0x98,0x0A,0x90,0x0A,0xA6,0x0A,0x8C,0x3F,0xF8, +0x3C,0xB2,0x08,0xE6,0x18,0x84,0x18,0x88,0x13,0x98,0x31,0xB0,0x60,0xC0,0x00,0x80, +/*---------------覃----------------*/ +"覃",0xFF,0xFE,0x04,0x40,0x3F,0xF8,0x24,0x48,0x3F,0xF8,0x00,0x00,0x1F,0xF0,0x10,0x10, +0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00, + +/*---------------春----------------*/ +"春",0x01,0x00,0x01,0x00,0x7F,0xFC,0x01,0x00,0x3F,0xF8,0x02,0x00,0xFF,0xFE,0x08,0x20, +0x10,0x10,0x2F,0xE8,0xC8,0x26,0x08,0x20,0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0, + +/*---------------辉----------------*/ +"辉",0x10,0x00,0x13,0xFE,0x92,0x02,0x54,0x44,0x58,0x40,0x13,0xFC,0xFC,0x80,0x28,0xA0, +0x29,0x20,0x29,0xFC,0x28,0x20,0x28,0x20,0x2B,0xFE,0x4C,0x20,0x48,0x20,0x80,0x20, + + + +#endif +}; + +const typFNT_GB16_UTF cfont16_UTF[] = +{ +#if 1 + "鸿",0x00,0x10,0x80,0x20,0x40,0x7C,0x1F,0x44,0x84,0x64,0x44,0x54,0x44,0x44,0x04,0x4C, + 0x24,0x40,0x44,0x7E,0xC4,0x02,0x47,0x02,0x5C,0x7A,0x48,0x02,0x40,0x0A,0x00,0x04,/*"鸿",0*/ + "蒙",0x08,0x20,0xFF,0xFE,0x08,0x20,0x7F,0xFE,0x40,0x02,0x8F,0xE4,0x00,0x00,0x7F,0xFC, + 0x06,0x00,0x3B,0x08,0x04,0xB0,0x19,0xC0,0x62,0xA0,0x0C,0x98,0x72,0x86,0x01,0x00,/*"蒙",1*/ + + "九",0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x7F,0xE0,0x04,0x20,0x04,0x20,0x04,0x20, + 0x08,0x20,0x08,0x20,0x08,0x20,0x10,0x22,0x10,0x22,0x20,0x22,0x40,0x1E,0x80,0x00,/*"九",0*/ + "队",0x00,0x40,0x7C,0x40,0x44,0x40,0x48,0x40,0x48,0x40,0x50,0x40,0x48,0x40,0x48,0x40, + 0x44,0xA0,0x44,0xA0,0x44,0xA0,0x69,0x10,0x51,0x10,0x42,0x08,0x44,0x04,0x48,0x02,/*"队",1*/ + + "软",0x00,0x00,0x18,0x60,0x10,0x40,0x7E,0x40,0x10,0xFE,0x20,0x84,0x29,0xB4,0x68,0x20, + 0x7F,0x20,0x08,0x30,0x08,0x30,0x7F,0x70,0x48,0x48,0x08,0x8C,0x0B,0x86,0x09,0x00,/*"软",0*/ + "通",0x00,0x00,0x27,0xFC,0x20,0x18,0x30,0xB0,0x00,0x60,0x07,0xFC,0x74,0x44,0x77,0xFC, + 0x34,0x44,0x34,0x44,0x37,0xFC,0x34,0x44,0x34,0x4C,0x38,0x00,0x47,0xFE,0x00,0x00,/*"通",1*/ + "动",0x00,0x00,0x00,0x30,0x00,0x30,0x3E,0x30,0x00,0x30,0x00,0xFE,0x7F,0x32,0x7F,0x22, + 0x10,0x22,0x16,0x22,0x22,0x22,0x23,0x62,0x7D,0x46,0x00,0xC6,0x01,0x9C,0x00,0x00,/*"动",2*/ + "力",0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xFE,0x01,0x04,0x01,0x04, + 0x03,0x04,0x03,0x04,0x02,0x04,0x06,0x04,0x0C,0x04,0x18,0x0C,0x70,0x38,0x20,0x00,/*"力",3*/ + + "鸿",0x00,0x10,0x80,0x20,0x40,0x7C,0x1F,0x44,0x84,0x64,0x44,0x54,0x44,0x44,0x04,0x4C, + 0x24,0x40,0x44,0x7E,0xC4,0x02,0x47,0x02,0x5C,0x7A,0x48,0x02,0x40,0x0A,0x00,0x04,/*"鸿",0*/ + "蒙",0x08,0x20,0xFF,0xFE,0x08,0x20,0x7F,0xFE,0x40,0x02,0x8F,0xE4,0x00,0x00,0x7F,0xFC, + 0x06,0x00,0x3B,0x08,0x04,0xB0,0x19,0xC0,0x62,0xA0,0x0C,0x98,0x72,0x86,0x01,0x00,/*"蒙",1*/ + "业",0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x40,0x44,0x44,0x24,0x44,0x24,0x48,0x14,0x48, + 0x14,0x50,0x14,0x60,0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x40,0xFF,0xFE,0x00,0x00,/*"业",2*/ + "务",0x04,0x00,0x04,0x00,0x0F,0xF0,0x18,0x20,0x24,0xC0,0x03,0x00,0x0C,0xC0,0x32,0x30, + 0xC2,0x0E,0x1F,0xF0,0x02,0x10,0x04,0x10,0x04,0x10,0x08,0x10,0x10,0xA0,0x20,0x40,/*"务",3*/ + "发",0x01,0x00,0x11,0x10,0x11,0x08,0x22,0x00,0x3F,0xFC,0x02,0x00,0x04,0x00,0x07,0xF8, + 0x0A,0x08,0x09,0x08,0x11,0x10,0x10,0xA0,0x20,0x40,0x40,0xA0,0x03,0x18,0x1C,0x06,/*"发",4*/ + "展",0x00,0x00,0x3F,0xFC,0x20,0x04,0x20,0x04,0x3F,0xFC,0x22,0x20,0x22,0x20,0x2F,0xF8, + 0x22,0x20,0x22,0x20,0x3F,0xFE,0x24,0x88,0x24,0x50,0x45,0x30,0x46,0x0E,0x84,0x00,/*"展",5*/ + "部",0x10,0x00,0x08,0x3E,0x7F,0xA2,0x00,0x24,0x21,0x24,0x12,0x28,0xFF,0xE4,0x00,0x24, + 0x00,0x22,0x3F,0x22,0x21,0x22,0x21,0x34,0x21,0x28,0x3F,0x20,0x21,0x20,0x00,0x20,/*"部",6*/ + /*---------------韦----------------*/ +"韦",0x01,0x00,0x01,0x00,0x01,0x00,0x7F,0xFE,0x01,0x00,0x01,0x00,0x3F,0xF8,0x01,0x00, +0x01,0x00,0x7F,0xFC,0x01,0x04,0x01,0x04,0x01,0x04,0x01,0x28,0x01,0x10,0x01,0x00, +/*---------------长----------------*/ +"长",0x08,0x00,0x08,0x10,0x08,0x20,0x08,0x40,0x08,0x80,0x09,0x00,0x08,0x00,0xFF,0xFE, +0x0A,0x00,0x09,0x00,0x08,0x80,0x08,0x40,0x09,0x20,0x0A,0x18,0x0C,0x06,0x08,0x00, +/*---------------江----------------*/ +"江",0x00,0x00,0x20,0x00,0x17,0xFC,0x10,0x40,0x80,0x40,0x40,0x40,0x48,0x40,0x08,0x40, +0x10,0x40,0x10,0x40,0xE0,0x40,0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x00,0x00,0x00, +/*---------------梁----------------*/ +"梁",0x00,0x00,0x08,0x08,0x05,0xF8,0x30,0xF8,0x1B,0x58,0x07,0xD6,0x0E,0xD2,0x39,0xB0, +0x1A,0xA0,0x07,0xFE,0x1F,0xC0,0x06,0xA0,0x0C,0x90,0x18,0x9E,0x61,0x80,0x00,0x00, +/*---------------弦----------------*/ +"弦",0x00,0x00,0x00,0x40,0x3E,0x60,0x06,0x30,0x04,0x3E,0x3F,0xF8,0x38,0x60,0x30,0x48, +0x3E,0xD8,0x37,0xF0,0x04,0xA0,0x04,0x78,0x24,0xCC,0x1D,0xFE,0x1D,0xE6,0x08,0x00, +"彤",/*---------------彤----------------*/ +0x00,0x00,0x08,0x84,0x0F,0x8C,0x08,0x98,0x0A,0x90,0x0A,0xA6,0x0A,0x8C,0x3F,0xF8, +0x3C,0xB2,0x08,0xE6,0x18,0x84,0x18,0x88,0x13,0x98,0x31,0xB0,0x60,0xC0,0x00,0x80, +/*---------------覃----------------*/ +"覃",0xFF,0xFE,0x04,0x40,0x3F,0xF8,0x24,0x48,0x3F,0xF8,0x00,0x00,0x1F,0xF0,0x10,0x10, +0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00, + +/*---------------春----------------*/ +"春",0x01,0x00,0x01,0x00,0x7F,0xFC,0x01,0x00,0x3F,0xF8,0x02,0x00,0xFF,0xFE,0x08,0x20, +0x10,0x10,0x2F,0xE8,0xC8,0x26,0x08,0x20,0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0, + +/*---------------辉----------------*/ +"辉",0x10,0x00,0x13,0xFE,0x92,0x02,0x54,0x44,0x58,0x40,0x13,0xFC,0xFC,0x80,0x28,0xA0, +0x29,0x20,0x29,0xFC,0x28,0x20,0x28,0x20,0x2B,0xFE,0x4C,0x20,0x48,0x20,0x80,0x20, +/*---------------王----------------*/ +"王",0x00,0x00,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8, +0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00, + +/*---------------玉----------------*/ +"玉",0x00,0x00,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8, +0x01,0x00,0x01,0x00,0x01,0x20,0x01,0x10,0x01,0x10,0x01,0x00,0xFF,0xFE,0x00,0x00, + +/*---------------洁----------------*/ +"洁",0x00,0x40,0x40,0x40,0x20,0x40,0x2F,0xFE,0x00,0x40,0x80,0x40,0x47,0xFC,0x50,0x00, +0x10,0x00,0x23,0xF8,0xE2,0x08,0x22,0x08,0x22,0x08,0x22,0x08,0x23,0xF8,0x02,0x08, + + "梁",0x00,0x00,0x23,0xF0,0x10,0x90,0x82,0x94,0x52,0x92,0x24,0x92,0xE1,0x10,0x22,0x50, + 0x25,0x20,0x01,0x00,0xFF,0xFE,0x05,0x40,0x09,0x20,0x31,0x18,0xC1,0x06,0x01,0x00,/*"梁",0*/ + "坤",0x10,0x20,0x10,0x20,0x10,0x20,0x11,0xFC,0x11,0x24,0xFD,0x24,0x11,0x24,0x11,0xFC, + 0x11,0x24,0x11,0x24,0x11,0x24,0x1D,0xFC,0xE1,0x24,0x40,0x20,0x00,0x20,0x00,0x20,/*"坤",1*/ + "乐",0x00,0x20,0x00,0xF0,0x1F,0x00,0x10,0x00,0x11,0x00,0x21,0x00,0x21,0x00,0x3F,0xFC, + 0x01,0x00,0x09,0x20,0x09,0x10,0x11,0x08,0x21,0x04,0x41,0x04,0x05,0x00,0x02,0x00,/*"乐",2*/ + /*---------------李----------------*/ +"李",0x01,0x00,0x01,0x00,0x7F,0xFC,0x03,0x80,0x05,0x40,0x09,0x20,0x31,0x18,0xC1,0x06, +0x0F,0xE0,0x00,0x40,0x00,0x80,0xFF,0xFE,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00, + +/*---------------恩----------------*/ +"恩",0x00,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x2F,0xE8,0x21,0x08,0x22,0x88,0x24,0x48, +0x28,0x28,0x3F,0xF8,0x01,0x00,0x08,0x84,0x48,0x92,0x48,0x12,0x87,0xF0,0x00,0x00, + +/*---------------汉----------------*/ +"汉",0x00,0x00,0x27,0xF8,0x12,0x08,0x12,0x08,0x82,0x08,0x41,0x10,0x49,0x10,0x09,0x10, +0x10,0xA0,0x10,0xA0,0xE0,0x40,0x20,0x40,0x20,0xA0,0x21,0x10,0x22,0x08,0x0C,0x06, + +/*---------------兰----------------*/ +"兰",0x10,0x10,0x08,0x10,0x04,0x20,0x04,0x40,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00, +0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00, + +/*---------------晶----------------*/ +"晶",0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0,0x00,0x00, +0x7E,0xFC,0x42,0x84,0x42,0x84,0x7E,0xFC,0x42,0x84,0x42,0x84,0x7E,0xFC,0x42,0x84, + +/*---------------晶----------------*/ +"晶",0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0,0x00,0x00, +0x7E,0xFC,0x42,0x84,0x42,0x84,0x7E,0xFC,0x42,0x84,0x42,0x84,0x7E,0xFC,0x42,0x84, + +/*---------------刘----------------*/ +"刘",0x10,0x04,0x08,0x04,0x08,0x04,0xFF,0xA4,0x02,0x24,0x42,0x24,0x22,0x24,0x14,0x24, +0x14,0x24,0x08,0x24,0x08,0x24,0x14,0x24,0x24,0x04,0x42,0x04,0x82,0x14,0x00,0x08, + +/*---------------嘉----------------*/ +"嘉",0x01,0x00,0xFF,0xFE,0x01,0x00,0x3F,0xF8,0x00,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0, +0x08,0x20,0xFF,0xFE,0x10,0x00,0x7F,0x7C,0x11,0x44,0x21,0x44,0x45,0x7C,0x82,0x44, + +/*---------------妮----------------*/ +"妮",0x10,0x00,0x11,0xFC,0x11,0x04,0x11,0x04,0xFD,0x04,0x25,0xFC,0x25,0x00,0x25,0x40, +0x25,0x44,0x49,0x48,0x29,0x70,0x11,0x40,0x29,0x42,0x46,0x42,0x82,0x3E,0x04,0x00, + + +#endif +}; + + +typedef struct +{ + unsigned char Index[2]; + char Msk[72]; +}typFNT_GB24; + +typedef struct +{ + unsigned char Index[3]; + char Msk[72]; +}typFNT_GB24_UTF; + +//宋体 +//24*24大小 +//逐行式,顺向(高位在前) +const typFNT_GB24 cfont24[] = +{ + "全",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x30,0x00,0x00,0x68,0x00,0x00, + 0x44,0x00,0x00,0xC2,0x00,0x01,0x81,0x00,0x03,0x00,0xC0,0x06,0x00,0x70,0x0F,0xFF, + 0xFE,0x10,0x18,0x08,0x60,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x60, + 0x03,0xFF,0x80,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x08,0x1F, + 0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,/*"全",0*/ + "动",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x01,0x00,0x00,0x61,0x00,0x3F, + 0x81,0x00,0x00,0x01,0x00,0x00,0x01,0x0C,0x00,0x07,0xFC,0x00,0x31,0x0C,0x3F,0xC1, + 0x0C,0x06,0x01,0x0C,0x04,0x01,0x0C,0x0C,0x81,0x08,0x08,0x43,0x08,0x10,0x62,0x08, + 0x10,0x22,0x08,0x2F,0xF4,0x08,0x38,0x14,0x08,0x00,0x08,0x08,0x00,0x11,0x18,0x00, + 0x20,0xF8,0x00,0x40,0x30,0x00,0x00,0x00,/*"动",1*/ + "电",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00, + 0x10,0x00,0x0F,0xFF,0xF0,0x08,0x10,0x20,0x08,0x10,0x20,0x08,0x10,0x20,0x08,0x10, + 0x20,0x0F,0xFF,0xE0,0x08,0x10,0x20,0x08,0x10,0x20,0x08,0x10,0x20,0x08,0x10,0x20, + 0x0F,0xFF,0xE0,0x08,0x10,0x00,0x00,0x10,0x08,0x00,0x10,0x08,0x00,0x10,0x04,0x00, + 0x18,0x0C,0x00,0x0F,0xF8,0x00,0x00,0x00,/*"电",2*/ + "子",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x0F,0xFF,0xF0,0x00,0x00,0x60,0x00, + 0x00,0x80,0x00,0x03,0x00,0x00,0x14,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18, + 0x0C,0x7F,0xFF,0xFE,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00, + 0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00, + 0xF8,0x00,0x00,0x30,0x00,0x00,0x00,0x00,/*"子",3*/ + "技",0x00,0x00,0x00,0x04,0x00,0x00,0x07,0x01,0x80,0x06,0x01,0x00,0x06,0x01,0x00,0x06, + 0x01,0x00,0x06,0xC1,0x0C,0x3F,0x3F,0xF0,0x06,0x01,0x00,0x06,0x01,0x00,0x06,0x01, + 0x00,0x06,0xFF,0xF8,0x07,0x08,0x10,0x3E,0x08,0x30,0x26,0x04,0x20,0x06,0x04,0x60, + 0x06,0x02,0x40,0x06,0x02,0xC0,0x06,0x01,0x80,0x06,0x03,0x80,0x06,0x0C,0x60,0x1E, + 0x10,0x3E,0x0C,0xE0,0x0C,0x00,0x00,0x00,/*"技",4*/ + "术",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x19,0x80,0x00,0x18,0xE0,0x00, + 0x18,0x60,0x00,0x18,0x28,0x00,0x18,0x1C,0x3F,0xFF,0xE0,0x00,0x3C,0x00,0x00,0x7C, + 0x00,0x00,0x5A,0x00,0x00,0xDA,0x00,0x00,0x99,0x00,0x01,0x19,0x80,0x03,0x18,0xC0, + 0x06,0x18,0x60,0x04,0x18,0x38,0x08,0x18,0x1E,0x30,0x18,0x08,0x40,0x18,0x00,0x00, + 0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,/*"术",5*/ + + "鸿",0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80,0x1C,0x01,0x80,0x0E,0x07,0xFC,0x04, + 0x06,0x0C,0x03,0xF6,0x4C,0x00,0xC6,0xCC,0x20,0xC6,0xCC,0x38,0xC6,0x48,0x1C,0xC6, + 0x08,0x00,0xC6,0x78,0x00,0xC6,0x20,0x00,0xC6,0x00,0x0C,0xC7,0xFE,0x0C,0xF0,0x06, + 0x1B,0xE0,0x06,0x1B,0x9F,0xE6,0x32,0x1F,0xE6,0x30,0x00,0x04,0x60,0x00,0x04,0x00, + 0x00,0x7C,0x00,0x00,0x3C,0x00,0x00,0x00,/*"鸿",0*/ + "蒙",0x00,0x00,0x00,0x00,0xC3,0x00,0x00,0xC3,0x00,0x3F,0xFF,0xFE,0x3F,0xFF,0xFE,0x00, + 0xC3,0x00,0x3F,0xFF,0xFC,0x3F,0xFF,0xFC,0x30,0x00,0x0C,0x37,0xFF,0xCC,0x00,0x00, + 0x00,0x00,0x00,0x00,0x1F,0xFF,0xFC,0x00,0x70,0x20,0x01,0xF8,0x60,0x1F,0x3D,0xE0, + 0x18,0x67,0x80,0x01,0xCE,0xC0,0x0F,0x1E,0x60,0x1C,0x72,0x70,0x01,0xE6,0x3E,0x0F, + 0x86,0x0C,0x3C,0x1E,0x00,0x00,0x10,0x00,/*"蒙",1*/ + + "九",0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00, + 0xE0,0x00,0x00,0xE0,0x00,0x1F,0xFF,0x80,0x1F,0xFF,0x80,0x00,0xC1,0x80,0x00,0xC1, + 0x80,0x00,0xC1,0x80,0x00,0xC1,0x80,0x01,0xC1,0x80,0x01,0x81,0x80,0x01,0x81,0x80, + 0x03,0x01,0x80,0x03,0x01,0x84,0x06,0x01,0x86,0x0E,0x01,0x8E,0x1C,0x01,0x8C,0x38, + 0x01,0xFC,0x10,0x00,0xF8,0x00,0x00,0x00,/*"九",0*/ + "队",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x3F,0xC3,0x00,0x30,0xC3,0x00,0x30, + 0x83,0x00,0x31,0x83,0x00,0x31,0x83,0x00,0x31,0x03,0x00,0x33,0x03,0x00,0x33,0x03, + 0x00,0x31,0x83,0x80,0x31,0x87,0x80,0x30,0xC6,0x80,0x30,0xC6,0xC0,0x30,0xCC,0xC0, + 0x30,0xCC,0x60,0x37,0xD8,0x60,0x37,0x98,0x30,0x30,0x30,0x18,0x30,0x70,0x1C,0x30, + 0xE0,0x0E,0x30,0xC0,0x04,0x00,0x00,0x00,/*"队",1*/ + +}; + +typedef struct +{ + unsigned char Index[2]; + char Msk[128]; +}typFNT_GB32; + +typedef struct +{ + unsigned char Index[2]; + char Msk[128]; +}typFNT_GB32_UTF; + +//宋体 +//32*32大小 +//逐行式,顺向(高位在前) +const typFNT_GB32 cfont32[] = +{ + "全",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x80,0x00, + 0x00,0x07,0x80,0x00,0x00,0x06,0x80,0x00,0x00,0x0C,0x40,0x00,0x00,0x1C,0x20,0x00, + 0x00,0x18,0x30,0x00,0x00,0x30,0x18,0x00,0x00,0x60,0x0C,0x00,0x00,0xC0,0x07,0x00, + 0x01,0x80,0x03,0xC0,0x03,0x00,0x02,0xF8,0x07,0xFF,0xFF,0x7C,0x08,0x01,0x80,0x90, + 0x30,0x01,0x80,0x00,0x40,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x81,0x00, + 0x00,0x01,0x83,0x80,0x01,0xFF,0xFF,0xC0,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00, + 0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x10, + 0x00,0x01,0x80,0x38,0x1F,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"全",0*/ + "动",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x0E,0x00, + 0x00,0x00,0x0C,0x00,0x00,0x0C,0x0C,0x00,0x3F,0xFE,0x0C,0x00,0x10,0x00,0x0C,0x00, + 0x00,0x00,0x0C,0x00,0x00,0x00,0x0C,0x18,0x00,0x00,0xFF,0xFC,0x00,0x02,0x0C,0x18, + 0x00,0x07,0x0C,0x18,0x3F,0xFF,0x8C,0x18,0x01,0xC0,0x0C,0x18,0x01,0xC0,0x0C,0x18, + 0x01,0x80,0x08,0x18,0x03,0x00,0x08,0x18,0x02,0x10,0x18,0x18,0x06,0x08,0x18,0x18, + 0x04,0x0C,0x10,0x18,0x08,0x06,0x10,0x18,0x10,0x06,0x30,0x10,0x2F,0xFB,0x20,0x10, + 0x3E,0x03,0x60,0x10,0x10,0x02,0xC0,0x30,0x00,0x00,0x80,0x30,0x00,0x01,0x0C,0x30, + 0x00,0x02,0x03,0xE0,0x00,0x0C,0x01,0xE0,0x00,0x10,0x00,0x80,0x00,0x00,0x00,0x00,/*"动",1*/ + "电",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x80,0x00, + 0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00, + 0x07,0xFF,0xFF,0xC0,0x06,0x03,0x00,0xC0,0x06,0x03,0x00,0xC0,0x06,0x03,0x00,0xC0, + 0x06,0x03,0x00,0xC0,0x06,0x03,0x00,0xC0,0x06,0x03,0x00,0xC0,0x07,0xFF,0xFF,0xC0, + 0x06,0x03,0x00,0xC0,0x06,0x03,0x00,0xC0,0x06,0x03,0x00,0xC0,0x06,0x03,0x00,0xC0, + 0x06,0x03,0x00,0xC0,0x07,0xFF,0xFF,0xC0,0x06,0x03,0x00,0x80,0x06,0x03,0x00,0x00, + 0x00,0x03,0x00,0x10,0x00,0x03,0x00,0x08,0x00,0x03,0x00,0x08,0x00,0x03,0x00,0x18, + 0x00,0x03,0x80,0x1C,0x00,0x01,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"电",2*/ + "子",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0, + 0x03,0xFF,0xFF,0xE0,0x00,0x00,0x01,0xE0,0x00,0x00,0x03,0x00,0x00,0x00,0x06,0x00, + 0x00,0x00,0x18,0x00,0x00,0x00,0x30,0x00,0x00,0x01,0xC0,0x00,0x00,0x01,0xC0,0x00, + 0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x10,0x00,0x01,0x80,0x38,0x3F,0xFF,0xFF,0xFC, + 0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00, + 0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00, + 0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00, + 0x00,0x3F,0x80,0x00,0x00,0x07,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,/*"子",3*/ + "技",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x08,0x00,0x01,0xC0,0x0E,0x00, + 0x01,0x80,0x0C,0x00,0x01,0x80,0x0C,0x00,0x01,0x80,0x0C,0x00,0x01,0x80,0x0C,0x00, + 0x01,0x98,0x0C,0x18,0x3F,0xFF,0xFF,0xFC,0x01,0x80,0x0C,0x00,0x01,0x80,0x0C,0x00, + 0x01,0x80,0x0C,0x00,0x01,0x80,0x0C,0x00,0x01,0x8C,0x0C,0x20,0x01,0xB3,0xFF,0xF0, + 0x01,0xC0,0x80,0x60,0x0F,0x80,0x80,0x60,0x3D,0x80,0x40,0xC0,0x31,0x80,0x40,0xC0, + 0x01,0x80,0x21,0x80,0x01,0x80,0x21,0x80,0x01,0x80,0x33,0x00,0x01,0x80,0x1E,0x00, + 0x01,0x80,0x0C,0x00,0x01,0x80,0x1E,0x00,0x01,0x80,0x37,0x00,0x01,0x80,0xE3,0xC0, + 0x1F,0x83,0x80,0xF8,0x07,0x8E,0x00,0x7C,0x02,0x30,0x00,0x00,0x00,0x00,0x00,0x00,/*"技",4*/ + "术",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0xC0,0x00, + 0x00,0x01,0x8C,0x00,0x00,0x01,0x87,0x00,0x00,0x01,0x83,0x80,0x00,0x01,0x81,0x80, + 0x00,0x01,0x80,0x80,0x00,0x01,0x80,0x30,0x3F,0xFF,0xFF,0xF8,0x10,0x03,0xC0,0x00, + 0x00,0x07,0xC0,0x00,0x00,0x07,0xA0,0x00,0x00,0x0D,0xA0,0x00,0x00,0x0D,0x90,0x00, + 0x00,0x19,0x90,0x00,0x00,0x19,0x98,0x00,0x00,0x31,0x8C,0x00,0x00,0x61,0x86,0x00, + 0x00,0xC1,0x87,0x00,0x00,0x81,0x83,0x80,0x01,0x81,0x81,0xC0,0x03,0x01,0x80,0xF0, + 0x04,0x01,0x80,0x7C,0x08,0x01,0x80,0x38,0x10,0x01,0x80,0x10,0x60,0x01,0x80,0x00, + 0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,/*"术",5*/ +}; + +#endif + diff --git a/EBox_IoT_049_OLED_Env_GUE/include/oled_gui.h b/EBox_IoT_049_OLED_Env_GUE/include/oled_gui.h new file mode 100644 index 0000000000000000000000000000000000000000..b35063d2e37c6736ecb4b239ce1cee59cf7f2a02 --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/include/oled_gui.h @@ -0,0 +1,28 @@ +#ifndef __OLED_GUI_H__ +#define __OLED_GUI_H__ + +#include "kp_base_type.h" + +void GUI_DrawPoint(u8 x, u8 y, u8 color); +void GUI_Fill(u8 sx,u8 sy,u8 ex,u8 ey,u8 color); +void GUI_DrawLine(u8 x1, u8 y1, u8 x2, u8 y2,u8 color); +void GUI_DrawRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color); +void GUI_FillRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color); +void GUI_DrawCircle(u8 xc, u8 yc, u8 color, u8 r); +void GUI_FillCircle(u8 xc, u8 yc, u8 color, u8 r); +void GUI_DrawTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color); +void GUI_FillTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color); +void GUI_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size,u8 mode); +void GUI_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 Size,u8 mode); +void GUI_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size,u8 mode); +void GUI_ShowFont16(u8 x,u8 y,u8 *s,u8 mode); +void GUI_ShowFont16_UTF(u8 x,u8 y,u8 *s,u8 mode); +void GUI_ShowFont24(u8 x,u8 y,u8 *s,u8 mode); +void GUI_ShowFont24_UTF(u8 x,u8 y,u8 *s,u8 mode); +void GUI_ShowFont32(u8 x,u8 y,u8 *s,u8 mode); +void GUI_ShowFont32_UTF(u8 x,u8 y,u8 *s,u8 mode); +void GUI_ShowCHinese(u8 x,u8 y,u8 hsize,u8 *str,u8 mode); +void GUI_ShowCHinese_UTF(u8 x,u8 y,u8 hsize,u8 *str,u8 mode); +void GUI_DrawBMP(u8 x,u8 y,u8 width, u8 height, u8 BMP[], u8 mode); + +#endif diff --git a/EBox_IoT_049_OLED_Env_GUE/include/oled_module.h b/EBox_IoT_049_OLED_Env_GUE/include/oled_module.h new file mode 100644 index 0000000000000000000000000000000000000000..861d077c8b5ba7f8d6f6a29efb50d4d7c12000ea --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/include/oled_module.h @@ -0,0 +1,10 @@ +#ifndef __OLED_MODULE_H__ +#define __OLED_MODULE_H__ + +#include +#include + +void SpiOledTask(void); + + +#endif diff --git a/EBox_IoT_049_OLED_Env_GUE/include/test.h b/EBox_IoT_049_OLED_Env_GUE/include/test.h new file mode 100644 index 0000000000000000000000000000000000000000..31a4fb901c33b43a6ee6b7a4b1e36830b945188f --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/include/test.h @@ -0,0 +1,15 @@ +#ifndef __TEST_H__ +#define __TEST_H__ +void TEST_MainPage(void); +void Test_Color(void); +void Test_Rectangular(void); +void Test_Circle(void); +void Test_Triangle(void); +void TEST_English(void); +void TEST_Number_Character(void); +void TEST_Chinese(void); +void TEST_BMP(void); +void TEST_Menu1(void); +void TEST_Menu2(void); +void TEST_Menu_Env(int temperature, int humidity); +#endif diff --git a/EBox_IoT_049_OLED_Env_GUE/kp_base_type.h b/EBox_IoT_049_OLED_Env_GUE/kp_base_type.h new file mode 100644 index 0000000000000000000000000000000000000000..7064a85a7f7c7a26a245e31edf1bfa142cb4a8a7 --- /dev/null +++ b/EBox_IoT_049_OLED_Env_GUE/kp_base_type.h @@ -0,0 +1,54 @@ +#ifndef __KP_BASE_TYPE_H__ +#define __KP_BASE_TYPE_H__ + +#include + +/* 基本数据类型 */ +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef unsigned long ulong; +typedef char s8; +typedef short s16; +typedef int s32; +typedef long long s64; +typedef long slong; + +#undef ERROR +#define ERROR (-1) + +#define KP_ERR_SUCCESS 0 +#define KP_ERR_FAILURE (-1) + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define KP_U16_MAX 0xFFFF +#define KP_U32_MAX 0xFFFFFFFF +#define KP_U64_MAX 0xFFFFFFFFFFFFFFFFUL + +#include +#define msleep(x) usleep((x)*1000) + +typedef enum { + GPIO_OUT_LOW = 0, /**< Low level.CNcomment:低电平CNend*/ + GPIO_OUT_HIGH /**< High level.CNcomment:高电平CNend*/ +} gpio_out_value; + +typedef enum { + LED_OFF = 0, + LED_ON, + LED_SPARK +} led_state; +#define LED_SPARK_INTERVAL_TIME 30 + +#define KP_DEBUG(fmt, args...) do { \ + printf("[KP][%s][%d]", __FILE__, __LINE__); \ + printf(fmt, ##args); \ + printf("\r\n"); \ + } while (0) + + +#endif \ No newline at end of file diff --git a/common/communicationkit/js_api/BUILD.gn b/common/communicationkit/js_api/BUILD.gn index 6d9bc116de719f0bd3afd64cd0e790524d56e95a..2ba3a0802913315cbf2b38f049f4d71161e8681a 100644 --- a/common/communicationkit/js_api/BUILD.gn +++ b/common/communicationkit/js_api/BUILD.gn @@ -1,25 +1,25 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//build/ohos/notice/notice.gni") -import("//build/templates/metadata/module_info.gni") - -ohos_copy("communicationkit_api") { - sources = [ - "@system.communicationkit.d.ts", - ] - outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] - module_source_dir = target_out_dir + "/$target_name" - module_install_name = "" +# Copyright (c) 2021 Huawei Device Co., Ltd. +# 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. + +import("//build/ohos.gni") +import("//build/ohos/notice/notice.gni") +import("//build/templates/metadata/module_info.gni") + +ohos_copy("communicationkit_api") { + sources = [ + "@system.communicationkit.d.ts", + ] + outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" } \ No newline at end of file diff --git a/common/communicationkit/native_utils/include/nativeapi_communication_kit.h b/common/communicationkit/native_utils/include/nativeapi_communication_kit.h index 627e9dd807175c75a7a4e9af9e76d3fa0f83d6a2..a70987b4ecd1802aa61f0cd98108143bd253209c 100644 --- a/common/communicationkit/native_utils/include/nativeapi_communication_kit.h +++ b/common/communicationkit/native_utils/include/nativeapi_communication_kit.h @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2020 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef JS_NATIVE_API_COMMUNICATION_KIT_H -#define JS_NATIVE_API_COMMUNICATION_KIT_H - -#include "jsi/jsi.h" - -namespace OHOS { -namespace ACELite { -class NativeapiCommunicationKit { -public: - NativeapiCommunicationKit() = default; - ~NativeapiCommunicationKit() = default; - - static JSIValue Get(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum); - static JSIValue Set(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum); - -}; -} // ACELite -} // OHOS +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef JS_NATIVE_API_COMMUNICATION_KIT_H +#define JS_NATIVE_API_COMMUNICATION_KIT_H + +#include "jsi/jsi.h" + +namespace OHOS { +namespace ACELite { +class NativeapiCommunicationKit { +public: + NativeapiCommunicationKit() = default; + ~NativeapiCommunicationKit() = default; + + static JSIValue Get(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum); + static JSIValue Set(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum); + +}; +} // ACELite +} // OHOS #endif // JS_NATIVE_API_COMMUNICATION_KIT_H \ No newline at end of file diff --git a/common/communicationkit/native_utils/include/nativeapi_communication_kit_impl.h b/common/communicationkit/native_utils/include/nativeapi_communication_kit_impl.h index fda8f3d6864d7f63c0efb0aed7da52ba30f716a8..6c8c8cdff233273d9da3ff0d3e470cb79761b20b 100644 --- a/common/communicationkit/native_utils/include/nativeapi_communication_kit_impl.h +++ b/common/communicationkit/native_utils/include/nativeapi_communication_kit_impl.h @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2020 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef JS_FS_COMMUNICATION_KIT_IMPL_API_H -#define JS_FS_COMMUNICATION_KIT_IMPL_API_H - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -#define KEY_MAX_LEN 32 -#define VALUE_MAX_LEN 128 - - -#define LOG_TAG "COMMUNICATION_KIT" -#include "hilog/hiview_log.h" - -#define LOG_E(fmt, ...) HILOG_ERROR(HILOG_MODULE_APP, fmt, ##__VA_ARGS__) -#define LOG_I(fmt, ...) HILOG_INFO(HILOG_MODULE_APP, fmt, ##__VA_ARGS__) - - -typedef int (*JsCallClangFunctionDef)(const char *key, char *value); - -void JsGetClangFuncationRegister(JsCallClangFunctionDef jsGetClang); -void JsSetClangFuncationRegister(JsCallClangFunctionDef jsSetClang); -void JsGetClangFuncationUnregister(void); -void JsSetClangFuncationUnregister(void); - -int GetCommunicationKitValue(const char* key, char* value); -int SetCommunicationKitValue(const char* key, const char* value); - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef JS_FS_COMMUNICATION_KIT_IMPL_API_H +#define JS_FS_COMMUNICATION_KIT_IMPL_API_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define KEY_MAX_LEN 32 +#define VALUE_MAX_LEN 128 + + +#define LOG_TAG "COMMUNICATION_KIT" +#include "hilog/hiview_log.h" + +#define LOG_E(fmt, ...) HILOG_ERROR(HILOG_MODULE_APP, fmt, ##__VA_ARGS__) +#define LOG_I(fmt, ...) HILOG_INFO(HILOG_MODULE_APP, fmt, ##__VA_ARGS__) + + +typedef int (*JsCallClangFunctionDef)(const char *key, char *value); + +void JsGetClangFuncationRegister(JsCallClangFunctionDef jsGetClang); +void JsSetClangFuncationRegister(JsCallClangFunctionDef jsSetClang); +void JsGetClangFuncationUnregister(void); +void JsSetClangFuncationUnregister(void); + +int GetCommunicationKitValue(const char* key, char* value); +int SetCommunicationKitValue(const char* key, const char* value); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + #endif /* JS_FS_COMMUNICATION_KIT_IMPL_API_H */ \ No newline at end of file diff --git a/common/communicationkit/native_utils/src/nativeapi_communication_kit.cpp b/common/communicationkit/native_utils/src/nativeapi_communication_kit.cpp index 0cec06cdc4792ec97f64a0fb435a65c7ec89b556..aeabd504be2c0a24f612701cdc8e8c44dbe52447 100644 --- a/common/communicationkit/native_utils/src/nativeapi_communication_kit.cpp +++ b/common/communicationkit/native_utils/src/nativeapi_communication_kit.cpp @@ -1,159 +1,159 @@ -/* - * Copyright (c) 2020 Huawei Device Co., Ltd. - * 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 "nativeapi_communication_kit.h" -#include "nativeapi_communication_kit_impl.h" - -#include -#include "ability_env.h" -#include "js_async_work.h" -#include "nativeapi_common.h" -#include "nativeapi_config.h" - - -namespace OHOS { -namespace ACELite { -namespace { -char g_kvFullPath[FILE_NAME_MAX_LEN + 1] = {0}; - -bool IsValidKey(const char* key) -{ - if (key == nullptr) { - return false; - } - size_t keyLen = strnlen(key, KEY_MAX_LEN + 1); - if ((keyLen == 0) || (keyLen > KEY_MAX_LEN)) { - return false; - } - if (strpbrk(key, "/\\\"*+,:;<=>\?[]|\x7F")) { - return false; - } - return true; -} - -JSIValue ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, - uint8_t argsNum, AsyncWorkHandler ExecuteFunc, bool flag) -{ - JSIValue undefValue = JSI::CreateUndefined(); - if (!NativeapiCommon::IsValidJSIValue(args, argsNum)) { - return undefValue; - } - FuncParams* params = new FuncParams(); - if (params == nullptr) { - return undefValue; - } - params->thisVal = JSI::AcquireValue(thisVal); - params->args = JSI::AcquireValue(args[0]); - params->flag = flag; - JsAsyncWork::DispatchAsyncWork(ExecuteFunc, reinterpret_cast(params)); - return undefValue; -} - -void ExecuteGet(void* data) -{ - FuncParams* params = reinterpret_cast(data); - if (params == nullptr) { - return; - } - - JSIValue args = params->args; - JSIValue thisVal = params->thisVal; - char* key = JSI::GetStringProperty(args, KV_KEY); - const char* dataPath = GetDataPath(); - JSIValue result = JSI::CreateUndefined(); - int ret = ERROR_CODE_GENERAL; - char* value = reinterpret_cast(malloc(VALUE_MAX_LEN + 1)); - if (value == nullptr) { - NativeapiCommon::FailCallBack(thisVal, args, ret); - goto EXIT; - } - - ret = GetCommunicationKitValue(key, value); - - if (ret == ERROR_FR_NO_FILE) { - // GetDefault(thisVal, args); - goto EXIT; - } - if (ret != NATIVE_SUCCESS) { - NativeapiCommon::FailCallBack(thisVal, args, ret); - goto EXIT; - } - result = JSI::CreateString(value); - NativeapiCommon::SuccessCallBack(thisVal, args, result); -EXIT: - free(value); - JSI::ReleaseString(key); - JSI::ReleaseValueList(args, thisVal, result, ARGS_END); - delete params; -} - -void ExecuteSet(void* data) -{ - FuncParams* params = reinterpret_cast(data); - if (params == nullptr) { - return; - } - - JSIValue args = params->args; - JSIValue thisVal = params->thisVal; - int ret = ERROR_CODE_GENERAL; - - char* key = JSI::GetStringProperty(args, KV_KEY); - char* value = JSI::GetStringProperty(args, KV_VALUE); - - LOG_I("JsSet:ExecuteSet::key=%s,value=%s\r\n",key,value); - - if ((key == nullptr) || !strlen(key)) { - NativeapiCommon::FailCallBack(thisVal, args, ERROR_CODE_PARAM); - goto EXIT; - } - if ((value == nullptr) || !strlen(value)) { - NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined()); - goto EXIT; - } - ret = SetCommunicationKitValue(key, value); - if (ret != NATIVE_SUCCESS) { - NativeapiCommon::FailCallBack(thisVal, args, ret); - goto EXIT; - } - NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined()); - -EXIT: - JSI::ReleaseString(key); - JSI::ReleaseString(value); - JSI::ReleaseValueList(args, thisVal, ARGS_END); - delete params; -} - -} - -void InitNativeApiCommunicationKit(JSIValue exports) -{ - JSI::SetModuleAPI(exports, "get", NativeapiCommunicationKit::Get); - JSI::SetModuleAPI(exports, "set", NativeapiCommunicationKit::Set); -} - -JSIValue NativeapiCommunicationKit::Get(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum) -{ - return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGet, false); -} - -JSIValue NativeapiCommunicationKit::Set(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum) -{ - return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteSet, false); -} - -} // ACELite -} // OHOS +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * 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 "nativeapi_communication_kit.h" +#include "nativeapi_communication_kit_impl.h" + +#include +#include "ability_env.h" +#include "js_async_work.h" +#include "nativeapi_common.h" +#include "nativeapi_config.h" + + +namespace OHOS { +namespace ACELite { +namespace { +char g_kvFullPath[FILE_NAME_MAX_LEN + 1] = {0}; + +bool IsValidKey(const char* key) +{ + if (key == nullptr) { + return false; + } + size_t keyLen = strnlen(key, KEY_MAX_LEN + 1); + if ((keyLen == 0) || (keyLen > KEY_MAX_LEN)) { + return false; + } + if (strpbrk(key, "/\\\"*+,:;<=>\?[]|\x7F")) { + return false; + } + return true; +} + +JSIValue ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, + uint8_t argsNum, AsyncWorkHandler ExecuteFunc, bool flag) +{ + JSIValue undefValue = JSI::CreateUndefined(); + if (!NativeapiCommon::IsValidJSIValue(args, argsNum)) { + return undefValue; + } + FuncParams* params = new FuncParams(); + if (params == nullptr) { + return undefValue; + } + params->thisVal = JSI::AcquireValue(thisVal); + params->args = JSI::AcquireValue(args[0]); + params->flag = flag; + JsAsyncWork::DispatchAsyncWork(ExecuteFunc, reinterpret_cast(params)); + return undefValue; +} + +void ExecuteGet(void* data) +{ + FuncParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + char* key = JSI::GetStringProperty(args, KV_KEY); + const char* dataPath = GetDataPath(); + JSIValue result = JSI::CreateUndefined(); + int ret = ERROR_CODE_GENERAL; + char* value = reinterpret_cast(malloc(VALUE_MAX_LEN + 1)); + if (value == nullptr) { + NativeapiCommon::FailCallBack(thisVal, args, ret); + goto EXIT; + } + + ret = GetCommunicationKitValue(key, value); + + if (ret == ERROR_FR_NO_FILE) { + // GetDefault(thisVal, args); + goto EXIT; + } + if (ret != NATIVE_SUCCESS) { + NativeapiCommon::FailCallBack(thisVal, args, ret); + goto EXIT; + } + result = JSI::CreateString(value); + NativeapiCommon::SuccessCallBack(thisVal, args, result); +EXIT: + free(value); + JSI::ReleaseString(key); + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + delete params; +} + +void ExecuteSet(void* data) +{ + FuncParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + int ret = ERROR_CODE_GENERAL; + + char* key = JSI::GetStringProperty(args, KV_KEY); + char* value = JSI::GetStringProperty(args, KV_VALUE); + + LOG_I("JsSet:ExecuteSet::key=%s,value=%s\r\n",key,value); + + if ((key == nullptr) || !strlen(key)) { + NativeapiCommon::FailCallBack(thisVal, args, ERROR_CODE_PARAM); + goto EXIT; + } + if ((value == nullptr) || !strlen(value)) { + NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined()); + goto EXIT; + } + ret = SetCommunicationKitValue(key, value); + if (ret != NATIVE_SUCCESS) { + NativeapiCommon::FailCallBack(thisVal, args, ret); + goto EXIT; + } + NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined()); + +EXIT: + JSI::ReleaseString(key); + JSI::ReleaseString(value); + JSI::ReleaseValueList(args, thisVal, ARGS_END); + delete params; +} + +} + +void InitNativeApiCommunicationKit(JSIValue exports) +{ + JSI::SetModuleAPI(exports, "get", NativeapiCommunicationKit::Get); + JSI::SetModuleAPI(exports, "set", NativeapiCommunicationKit::Set); +} + +JSIValue NativeapiCommunicationKit::Get(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGet, false); +} + +JSIValue NativeapiCommunicationKit::Set(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteSet, false); +} + +} // ACELite +} // OHOS diff --git a/common/communicationkit/native_utils/src/nativeapi_communication_kit_impl.c b/common/communicationkit/native_utils/src/nativeapi_communication_kit_impl.c index 57684bc7619701a373e130e952d2168712888058..5fc83556d794704b78d6ff97fcb3517bd0ebb742 100644 --- a/common/communicationkit/native_utils/src/nativeapi_communication_kit_impl.c +++ b/common/communicationkit/native_utils/src/nativeapi_communication_kit_impl.c @@ -1,105 +1,105 @@ -/* - * Copyright (c) 2020 Huawei Device Co., Ltd. - * 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 "nativeapi_communication_kit_impl.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "nativeapi_config.h" -#if (defined _WIN32 || defined _WIN64) -#include "shlwapi.h" -#endif - -static JsCallClangFunctionDef g_jsGetClang = NULL; -static JsCallClangFunctionDef g_jsSetClang = NULL; - -static bool IsValidValue(const char *value) -{ - if (value == NULL) - { - return false; - } - size_t valueLen = strnlen(value, VALUE_MAX_LEN + 1); - if ((valueLen == 0) || (valueLen > VALUE_MAX_LEN)) - { - return false; - } - return true; -} - -int GetCommunicationKitValue(const char *key, char *value) -{ - if ((key == NULL) || (value == NULL)) - { - return ERROR_CODE_PARAM; - } - if (NULL != g_jsGetClang) - { - if (0 != g_jsGetClang(key, value)) - { - LOG_E("g_jsGetClang error!\r\n"); - } - } - else - { - LOG_I("If you want use js get c interface, you should use JsGetClangFuncationRegister function.\r\n"); - } - return NATIVE_SUCCESS; -} - -int SetCommunicationKitValue(const char *key, const char *value) -{ - if ((key == NULL) || (!IsValidValue(value))) - { - return ERROR_CODE_PARAM; - } - if (NULL != g_jsSetClang) - { - if (0 != g_jsSetClang(key, value)) - { - LOG_E("g_jsSetClang error!\r\n"); - } - LOG_I("CommunicationKit:SetJsonValue::entry--key=%s;value=%s.\r\n", key, value); - } - else - { - LOG_I("If you want use js set c interface, you should use JsSetClangFuncationRegister function.\r\n"); - } - return NATIVE_SUCCESS; -} - -void JsGetClangFuncationRegister(JsCallClangFunctionDef jsGetClang) -{ - g_jsGetClang = jsGetClang; -} -void JsSetClangFuncationRegister(JsCallClangFunctionDef jsSetClang) -{ - g_jsSetClang = jsSetClang; -} - -void JsGetClangFuncationUnregister(void) -{ - g_jsGetClang = NULL; -} -void JsSetClangFuncationUnregister(void) -{ - g_jsSetClang = NULL; +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * 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 "nativeapi_communication_kit_impl.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nativeapi_config.h" +#if (defined _WIN32 || defined _WIN64) +#include "shlwapi.h" +#endif + +static JsCallClangFunctionDef g_jsGetClang = NULL; +static JsCallClangFunctionDef g_jsSetClang = NULL; + +static bool IsValidValue(const char *value) +{ + if (value == NULL) + { + return false; + } + size_t valueLen = strnlen(value, VALUE_MAX_LEN + 1); + if ((valueLen == 0) || (valueLen > VALUE_MAX_LEN)) + { + return false; + } + return true; +} + +int GetCommunicationKitValue(const char *key, char *value) +{ + if ((key == NULL) || (value == NULL)) + { + return ERROR_CODE_PARAM; + } + if (NULL != g_jsGetClang) + { + if (0 != g_jsGetClang(key, value)) + { + LOG_E("g_jsGetClang error!\r\n"); + } + } + else + { + LOG_I("If you want use js get c interface, you should use JsGetClangFuncationRegister function.\r\n"); + } + return NATIVE_SUCCESS; +} + +int SetCommunicationKitValue(const char *key, const char *value) +{ + if ((key == NULL) || (!IsValidValue(value))) + { + return ERROR_CODE_PARAM; + } + if (NULL != g_jsSetClang) + { + if (0 != g_jsSetClang(key, value)) + { + LOG_E("g_jsSetClang error!\r\n"); + } + LOG_I("CommunicationKit:SetJsonValue::entry--key=%s;value=%s.\r\n", key, value); + } + else + { + LOG_I("If you want use js set c interface, you should use JsSetClangFuncationRegister function.\r\n"); + } + return NATIVE_SUCCESS; +} + +void JsGetClangFuncationRegister(JsCallClangFunctionDef jsGetClang) +{ + g_jsGetClang = jsGetClang; +} +void JsSetClangFuncationRegister(JsCallClangFunctionDef jsSetClang) +{ + g_jsSetClang = jsSetClang; +} + +void JsGetClangFuncationUnregister(void) +{ + g_jsGetClang = NULL; +} +void JsSetClangFuncationUnregister(void) +{ + g_jsSetClang = NULL; } \ No newline at end of file diff --git a/common/inc/flower.h b/common/inc/flower.h index cc46dbd60695111aa3e3c0ac545270f08698295e..06a7e09a63b4902ae35dfd9d70b9992c12d97c0c 100644 --- a/common/inc/flower.h +++ b/common/inc/flower.h @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef __FLOWER_H__ -#define __FLOWER_H__ - - -int FlowerInit(void); - -int FlowerSetMotorStatus(int status); - -int FlowerGetAirStatus(int *temperature, int *humidity); - -int FlowerGetSoilStatus(int *moisture); - -void FlowerDeinit(void); - -#endif // __FLOWER_H__ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef __FLOWER_H__ +#define __FLOWER_H__ + + +int FlowerInit(void); + +int FlowerSetMotorStatus(int status); + +int FlowerGetAirStatus(int *temperature, int *humidity); + +int FlowerGetSoilStatus(int *moisture); + +void FlowerDeinit(void); + +#endif // __FLOWER_H__ diff --git a/common/inc/iot_adc.h b/common/inc/iot_adc.h index 6a0f383f4f2e816f68654614a95a697119fb4f40..ef908dfe1312db72756c1692daaf16e5d8fb511d 100644 --- a/common/inc/iot_adc.h +++ b/common/inc/iot_adc.h @@ -1,94 +1,94 @@ -/* - * Copyright (c) 2020 Huawei Device Co., Ltd. - * 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. - */ - -/** - * @addtogroup IotHardware - * @{ - * - * @brief Provides APIs for operating devices, - * including flash, GPIO, I2C, PWM, UART,ADC, and watchdog APIs. - * - * - * - * @since 2.2 - * @version 2.2 - */ - -/** - * @file iot_adc.h - * - * @brief Declares the ADC interface functions for you to read data. - * - * @since 1.0 - * @version 1.1.0 - */ - -#ifndef IOT_ADC_H -#define IOT_ADC_H - - -/** - * @brief Enumerates analog power control modes. - */ -typedef enum { - /** Automatic control */ - IOT_ADC_CUR_BAIS_DEFAULT, - /** Automatic control */ - IOT_ADC_CUR_BAIS_AUTO, - /** Manual control (AVDD = 1.8 V) */ - IOT_ADC_CUR_BAIS_1P8V, - /** Manual control (AVDD = 3.3 V) */ - IOT_ADC_CUR_BAIS_3P3V, - /** Button value */ - IOT_ADC_CUR_BAIS_BUTT, -} IotAdcCurBais; - -/** - * @brief Enumerates equation models. - */ -typedef enum { - /** One-equation model */ - IOT_ADC_EQU_MODEL_1, - /** Two-equation model */ - IOT_ADC_EQU_MODEL_2, - /** Four-equation model */ - IOT_ADC_EQU_MODEL_4, - /** Eight-equation model */ - IOT_ADC_EQU_MODEL_8, - /** Button value */ - IOT_ADC_EQU_MODEL_BUTT, -} IotAdcEquModelSel; - -/** - * @brief Reads a piece of sampled data from a specified ADC channel based on the input parameters. - * - * - * - * @param channel Indicates the ADC channel index. - * @param data Indicates the pointer to the address for storing the read data. - * @param equModel Indicates the equation model. - * @param curBais Indicates the analog power control mode. - * @param rstCnt Indicates the count of the time from reset to conversion start. - * One count is equal to 334 ns. The value must range from 0 to 0xFF0. - * @return Returns {@link IOT_SUCCESS} if the PWM signal output is stopped; - * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTAdcRead(unsigned int channel, unsigned short *data, IotAdcEquModelSel equModel, - IotAdcCurBais curBais, unsigned short rstCnt); - -#endif +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * 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. + */ + +/** + * @addtogroup IotHardware + * @{ + * + * @brief Provides APIs for operating devices, + * including flash, GPIO, I2C, PWM, UART,ADC, and watchdog APIs. + * + * + * + * @since 2.2 + * @version 2.2 + */ + +/** + * @file iot_adc.h + * + * @brief Declares the ADC interface functions for you to read data. + * + * @since 1.0 + * @version 1.1.0 + */ + +#ifndef IOT_ADC_H +#define IOT_ADC_H + + +/** + * @brief Enumerates analog power control modes. + */ +typedef enum { + /** Automatic control */ + IOT_ADC_CUR_BAIS_DEFAULT, + /** Automatic control */ + IOT_ADC_CUR_BAIS_AUTO, + /** Manual control (AVDD = 1.8 V) */ + IOT_ADC_CUR_BAIS_1P8V, + /** Manual control (AVDD = 3.3 V) */ + IOT_ADC_CUR_BAIS_3P3V, + /** Button value */ + IOT_ADC_CUR_BAIS_BUTT, +} IotAdcCurBais; + +/** + * @brief Enumerates equation models. + */ +typedef enum { + /** One-equation model */ + IOT_ADC_EQU_MODEL_1, + /** Two-equation model */ + IOT_ADC_EQU_MODEL_2, + /** Four-equation model */ + IOT_ADC_EQU_MODEL_4, + /** Eight-equation model */ + IOT_ADC_EQU_MODEL_8, + /** Button value */ + IOT_ADC_EQU_MODEL_BUTT, +} IotAdcEquModelSel; + +/** + * @brief Reads a piece of sampled data from a specified ADC channel based on the input parameters. + * + * + * + * @param channel Indicates the ADC channel index. + * @param data Indicates the pointer to the address for storing the read data. + * @param equModel Indicates the equation model. + * @param curBais Indicates the analog power control mode. + * @param rstCnt Indicates the count of the time from reset to conversion start. + * One count is equal to 334 ns. The value must range from 0 to 0xFF0. + * @return Returns {@link IOT_SUCCESS} if the PWM signal output is stopped; + * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTAdcRead(unsigned int channel, unsigned short *data, IotAdcEquModelSel equModel, + IotAdcCurBais curBais, unsigned short rstCnt); + +#endif /** @} */ \ No newline at end of file diff --git a/common/inc/iot_gpio_ex.h b/common/inc/iot_gpio_ex.h index 703dcd2aeeb03a88d8bdbfc1c7dafbfa02c8df51..01a40930482639a2fee424e9c9ea469d36ca88c5 100644 --- a/common/inc/iot_gpio_ex.h +++ b/common/inc/iot_gpio_ex.h @@ -1,340 +1,340 @@ -/* - * Copyright (c) 2020 Huawei Device Co., Ltd. - * 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 iot_gpio_ex.h - * - * @brief Declares the extended GPIO interface functions. - * - * These functions are used for settings GPIO pulls and driver strength. \n - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef IOT_GPIO_EX_H -#define IOT_GPIO_EX_H - - -/** - * @brief Enumerates the functions of GPIO hardware pin 0. - */ -typedef enum { - /** GPIO0 function */ - IOT_GPIO_FUNC_GPIO_0_GPIO, - /** Functions of UART1 TXD */ - IOT_GPIO_FUNC_GPIO_0_UART1_TXD = 2, - /** SPI1 CK function */ - IOT_GPIO_FUNC_GPIO_0_SPI1_CK, - /** Functions of JTAG TD0 */ - IOT_GPIO_FUNC_GPIO_0_JTAG_TDO, - /** PWM3 OUT function */ - IOT_GPIO_FUNC_GPIO_0_PWM3_OUT, - /** I2C1 SDA function */ - IOT_GPIO_FUNC_GPIO_0_I2C1_SDA, -} WifiIotIoFuncGpio0; - -/** - * @brief Enumerates the functions of GPIO hardware pin 1. - */ -typedef enum { - /** GPIO1 function */ - IOT_GPIO_FUNC_GPIO_1_GPIO, - /** UART1 RXD function */ - IOT_GPIO_FUNC_GPIO_1_UART1_RXD = 2, - /** SPI1 RXD function */ - IOT_GPIO_FUNC_GPIO_1_SPI1_RXD, - /** JTAG TCKfunction */ - IOT_GPIO_FUNC_GPIO_1_JTAG_TCK, - /** PWM4 OUT function */ - IOT_GPIO_FUNC_GPIO_1_PWM4_OUT, - /** I2C1 SCL function */ - IOT_GPIO_FUNC_GPIO_1_I2C1_SCL, - /** BT FREQ function */ - IOT_GPIO_FUNC_GPIO_1_BT_FREQ, -} WifiiIotIoFuncGpio1; - -/** - * @brief Enumerates the functions of GPIO hardware pin 2. - */ -typedef enum { - /** GPIO2 function */ - IOT_GPIO_FUNC_GPIO_2_GPIO, - /** UART1 RTS function */ - IOT_GPIO_FUNC_GPIO_2_UART1_RTS_N = 2, - /** SPI1 TXD function */ - IOT_GPIO_FUNC_GPIO_2_SPI1_TXD, - /** JTAG TRSTN function */ - IOT_GPIO_FUNC_GPIO_2_JTAG_TRSTN, - /** PWM2 OUT function */ - IOT_GPIO_FUNC_GPIO_2_PWM2_OUT, - /** SSI CLK function */ - IOT_GPIO_FUNC_GPIO_2_SSI_CLK = 7, -} WifiIotIoFuncGpio2; - -/** - * @brief Enumerates the functions of GPIO hardware pin 3. - */ -typedef enum { - /** GPIO3 function */ - IOT_GPIO_FUNC_GPIO_3_GPIO, - /** UART0 TXD function */ - IOT_GPIO_FUNC_GPIO_3_UART0_TXD, - /** UART1 CTS function */ - IOT_GPIO_FUNC_GPIO_3_UART1_CTS_N, - /** SPI CSN function */ - IOT_GPIO_FUNC_GPIO_3_SPI1_CSN, - /** JTAG TDI function */ - IOT_GPIO_FUNC_GPIO_3_JTAG_TDI, - /** PWM5 OUT function */ - IOT_GPIO_FUNC_GPIO_3_PWM5_OUT, - /** I2C1 SDA function */ - IOT_GPIO_FUNC_GPIO_3_I2C1_SDA, - /** SSI DATA function */ - IOT_GPIO_FUNC_GPIO_3_SSI_DATA, -} WifiIotIoFuncGpio3; - -/** - * @brief Enumerates the functions of GPIO hardware pin 4. - */ -typedef enum { - /** GPIO4 function */ - IOT_GPIO_FUNC_GPIO_4_GPIO, - /** UART0 RXD function */ - IOT_GPIO_FUNC_GPIO_4_UART0_RXD = 2, - /** JTAG TMS function */ - IOT_GPIO_FUNC_GPIO_4_JTAG_TMS = 4, - /** PWM1 OUT function */ - IOT_GPIO_FUNC_GPIO_4_PWM1_OUT, - /** I2C1 SCL function */ - IOT_GPIO_FUNC_GPIO_4_I2C1_SCL, -} WifiIotIoFuncGpio4; - -/** - * @brief Enumerates the functions of GPIO hardware pin 5. - */ -typedef enum { - /** GPIO5 function */ - IOT_GPIO_FUNC_GPIO_5_GPIO, - /** UART1 RXD function */ - IOT_GPIO_FUNC_GPIO_5_UART1_RXD = 2, - /** SPI0 CSN function */ - IOT_GPIO_FUNC_GPIO_5_SPI0_CSN, - /** PWM2 OUT function */ - IOT_GPIO_FUNC_GPIO_5_PWM2_OUT = 5, - /** I2C0 MCLK function */ - IOT_GPIO_FUNC_GPIO_5_I2S0_MCLK, - /** BT STATUS function */ - IOT_GPIO_FUNC_GPIO_5_BT_STATUS, -} WifiIotIoFuncGpio5; - -/** - * @brief Enumerates the functions of GPIO hardware pin 6. - */ -typedef enum { - /** GPIO6 function */ - IOT_GPIO_FUNC_GPIO_6_GPIO, - /** UART1 TXD function */ - IOT_GPIO_FUNC_GPIO_6_UART1_TXD = 2, - /** SPI0 CK function */ - IOT_GPIO_FUNC_GPIO_6_SPI0_CK, - /** PWM3 OUT function */ - IOT_GPIO_FUNC_GPIO_6_PWM3_OUT = 5, - /** I2S0 TX function */ - IOT_GPIO_FUNC_GPIO_6_I2S0_TX, - /** COEX switch function */ - IOT_GPIO_FUNC_GPIO_6_COEX_SWITCH, -} WifiIotIoFuncGpio6; - -/** - * @brief Enumerates the functions of GPIO hardware pin 7. - */ -typedef enum { - /** GPIO7 function */ - IOT_GPIO_FUNC_GPIO_7_GPIO, - /** UART1 CTS function */ - IOT_GPIO_FUNC_GPIO_7_UART1_CTS_N = 2, - /** SPI0 RXD function */ - IOT_GPIO_FUNC_GPIO_7_SPI0_RXD, - /** PWM0 OUT function */ - IOT_GPIO_FUNC_GPIO_7_PWM0_OUT = 5, - /** I2S0 BCLK function */ - IOT_GPIO_FUNC_GPIO_7_I2S0_BCLK, - /** BT ACTIVE function */ - IOT_GPIO_FUNC_GPIO_7_BT_ACTIVE, -} WifiIotIoFuncGpio7; - -/** - * @brief Enumerates the functions of GPIO hardware pin 8. - */ -typedef enum { - /** GPIO8 function */ - IOT_GPIO_FUNC_GPIO_8_GPIO, - /** UART1 RTS function */ - IOT_GPIO_FUNC_GPIO_8_UART1_RTS_N = 2, - /** SPI0 TXD function */ - IOT_GPIO_FUNC_GPIO_8_SPI0_TXD, - /** PWM1 OUT function */ - IOT_GPIO_FUNC_GPIO_8_PWM1_OUT = 5, - /** I2S0 WS function */ - IOT_GPIO_FUNC_GPIO_8_I2S0_WS, - /** WLAN ACTIVE function */ - IOT_GPIO_FUNC_GPIO_8_WLAN_ACTIVE, -} WifiIotIoFuncGpio8; - -/** - * @brief Enumerates the functions of GPIO hardware pin 9. - */ -typedef enum { - /** GPIO9 function */ - IOT_GPIO_FUNC_GPIO_9_GPIO, - /** I2C0 SCL function */ - IOT_GPIO_FUNC_GPIO_9_I2C0_SCL, - /** UART2 RTS function */ - IOT_GPIO_FUNC_GPIO_9_UART2_RTS_N, - /** SDIO D2 function */ - IOT_GPIO_FUNC_GPIO_9_SDIO_D2, - /** SPI0 TXD function */ - IOT_GPIO_FUNC_GPIO_9_SPI0_TXD, - /** PWM0 OUT function */ - IOT_GPIO_FUNC_GPIO_9_PWM0_OUT, - /** I2S0 MCLK function */ - IOT_GPIO_FUNC_GPIO_9_I2S0_MCLK = 7, -} WifiIotIoFuncGpio9; - -/** - * @brief Enumerates the functions of GPIO hardware pin 10. - */ -typedef enum { - /** GPIO10 function */ - IOT_GPIO_FUNC_GPIO_10_GPIO, - /** I2C0 SDA function */ - IOT_GPIO_FUNC_GPIO_10_I2C0_SDA, - /** UART2 CTS function */ - IOT_GPIO_FUNC_GPIO_10_UART2_CTS_N, - /** SDIO D3 function */ - IOT_GPIO_FUNC_GPIO_10_SDIO_D3, - /** SPI0 CK function */ - IOT_GPIO_FUNC_GPIO_10_SPI0_CK, - /** PWM1 OUT function */ - IOT_GPIO_FUNC_GPIO_10_PWM1_OUT, - /** I2S0 TX function */ - IOT_GPIO_FUNC_GPIO_10_I2S0_TX = 7, -} WifiIotIoFuncGpio10; - -/** - * @brief Enumerates the functions of GPIO hardware pin 11. - */ -typedef enum { - /** GPIO11 function */ - IOT_GPIO_FUNC_GPIO_11_GPIO, - /** UART2 TXD function */ - IOT_GPIO_FUNC_GPIO_11_UART2_TXD = 2, - /** SDIO CMD function */ - IOT_GPIO_FUNC_GPIO_11_SDIO_CMD, - /** SDIO RXD function */ - IOT_GPIO_FUNC_GPIO_11_SPI0_RXD, - /** PWM2 OUT function */ - IOT_GPIO_FUNC_GPIO_11_PWM2_OUT, - /** RF TX_EN_EXT function */ - IOT_GPIO_FUNC_GPIO_11_RF_TX_EN_EXT, - /** I2S0 RX function */ - IOT_GPIO_FUNC_GPIO_11_I2S0_RX, -} WifiIotIoFuncGpio11; - -/** - * @brief Enumerates the functions of GPIO hardware pin 12. - */ -typedef enum { - /** GPIO12 function */ - IOT_GPIO_FUNC_GPIO_12_GPIO, - /** SUART2 RXD function */ - IOT_GPIO_FUNC_GPIO_12_UART2_RXD = 2, - /** SDIO CLK function */ - IOT_GPIO_FUNC_GPIO_12_SDIO_CLK, - /** SDIO CSN function */ - IOT_GPIO_FUNC_GPIO_12_SPI0_CSN, - /** PWM3 OUT function */ - IOT_GPIO_FUNC_GPIO_12_PWM3_OUT, - /** RF RX_EN_EXT function */ - IOT_GPIO_FUNC_GPIO_12_RF_RX_EN_EXT, - /** I2S0 BCLK function */ - IOT_GPIO_FUNC_GPIO_12_I2S0_BCLK, -} WifiIotIoFuncGpio12; - -/** - * @brief Enumerates the functions of GPIO hardware pin 13. - */ -typedef enum { - /** SSI DATA function */ - IOT_GPIO_FUNC_GPIO_13_SSI_DATA, - /** UART0 TXD function */ - IOT_GPIO_FUNC_GPIO_13_UART0_TXD, - /** UART2 RTS function */ - IOT_GPIO_FUNC_GPIO_13_UART2_RTS_N, - /** SDIO D0 function */ - IOT_GPIO_FUNC_GPIO_13_SDIO_D0, - /** GPIO13 function */ - IOT_GPIO_FUNC_GPIO_13_GPIO, - /** PWM4 OUT function */ - IOT_GPIO_FUNC_GPIO_13_PWM4_OUT, - /** I2C0 SDA function */ - IOT_GPIO_FUNC_GPIO_13_I2C0_SDA, - /** I2S0 WS function */ - IOT_GPIO_FUNC_GPIO_13_I2S0_WS, -} WifiIotIoFuncGpio13; - -/** - * @brief Enumerates the functions of GPIO hardware pin 14. - */ -typedef enum { - /** SSI CLK function */ - IOT_GPIO_FUNC_GPIO_14_SSI_CLK, - /** UART0 RXD function */ - IOT_GPIO_FUNC_GPIO_14_UART0_RXD, - /** UART2 CTS function */ - IOT_GPIO_FUNC_GPIO_14_UART2_CTS_N, - /** SDIO D1 function */ - IOT_GPIO_FUNC_GPIO_14_SDIO_D1, - /** GPIO14 function */ - IOT_GPIO_FUNC_GPIO_14_GPIO, - /** PWM5 OUT function */ - IOT_GPIO_FUNC_GPIO_14_PWM5_OUT, - /** I2C0 SCL function */ - IOT_GPIO_FUNC_GPIO_14_I2C0_SCL, -} WifiIotIoFuncGpio14; - -/** - * @brief Enumerates GPIO pull-up or pull-down settings. - */ -typedef enum { - /** No pull */ - IOT_GPIO_PULL_NONE, - /** Pull-up */ - IOT_GPIO_PULL_UP, - /** Pull-down */ - IOT_GPIO_PULL_DOWN, - /** Maximum value */ - IOT_GPIO_PULL_MAX, -} IotGpioPull; - - -unsigned int IoTGpioSetFunc(unsigned int id, unsigned char val); - -unsigned int IoTGpioSetPull(unsigned int id, IotGpioPull val); - -#endif +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * 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 iot_gpio_ex.h + * + * @brief Declares the extended GPIO interface functions. + * + * These functions are used for settings GPIO pulls and driver strength. \n + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef IOT_GPIO_EX_H +#define IOT_GPIO_EX_H + + +/** + * @brief Enumerates the functions of GPIO hardware pin 0. + */ +typedef enum { + /** GPIO0 function */ + IOT_GPIO_FUNC_GPIO_0_GPIO, + /** Functions of UART1 TXD */ + IOT_GPIO_FUNC_GPIO_0_UART1_TXD = 2, + /** SPI1 CK function */ + IOT_GPIO_FUNC_GPIO_0_SPI1_CK, + /** Functions of JTAG TD0 */ + IOT_GPIO_FUNC_GPIO_0_JTAG_TDO, + /** PWM3 OUT function */ + IOT_GPIO_FUNC_GPIO_0_PWM3_OUT, + /** I2C1 SDA function */ + IOT_GPIO_FUNC_GPIO_0_I2C1_SDA, +} WifiIotIoFuncGpio0; + +/** + * @brief Enumerates the functions of GPIO hardware pin 1. + */ +typedef enum { + /** GPIO1 function */ + IOT_GPIO_FUNC_GPIO_1_GPIO, + /** UART1 RXD function */ + IOT_GPIO_FUNC_GPIO_1_UART1_RXD = 2, + /** SPI1 RXD function */ + IOT_GPIO_FUNC_GPIO_1_SPI1_RXD, + /** JTAG TCKfunction */ + IOT_GPIO_FUNC_GPIO_1_JTAG_TCK, + /** PWM4 OUT function */ + IOT_GPIO_FUNC_GPIO_1_PWM4_OUT, + /** I2C1 SCL function */ + IOT_GPIO_FUNC_GPIO_1_I2C1_SCL, + /** BT FREQ function */ + IOT_GPIO_FUNC_GPIO_1_BT_FREQ, +} WifiiIotIoFuncGpio1; + +/** + * @brief Enumerates the functions of GPIO hardware pin 2. + */ +typedef enum { + /** GPIO2 function */ + IOT_GPIO_FUNC_GPIO_2_GPIO, + /** UART1 RTS function */ + IOT_GPIO_FUNC_GPIO_2_UART1_RTS_N = 2, + /** SPI1 TXD function */ + IOT_GPIO_FUNC_GPIO_2_SPI1_TXD, + /** JTAG TRSTN function */ + IOT_GPIO_FUNC_GPIO_2_JTAG_TRSTN, + /** PWM2 OUT function */ + IOT_GPIO_FUNC_GPIO_2_PWM2_OUT, + /** SSI CLK function */ + IOT_GPIO_FUNC_GPIO_2_SSI_CLK = 7, +} WifiIotIoFuncGpio2; + +/** + * @brief Enumerates the functions of GPIO hardware pin 3. + */ +typedef enum { + /** GPIO3 function */ + IOT_GPIO_FUNC_GPIO_3_GPIO, + /** UART0 TXD function */ + IOT_GPIO_FUNC_GPIO_3_UART0_TXD, + /** UART1 CTS function */ + IOT_GPIO_FUNC_GPIO_3_UART1_CTS_N, + /** SPI CSN function */ + IOT_GPIO_FUNC_GPIO_3_SPI1_CSN, + /** JTAG TDI function */ + IOT_GPIO_FUNC_GPIO_3_JTAG_TDI, + /** PWM5 OUT function */ + IOT_GPIO_FUNC_GPIO_3_PWM5_OUT, + /** I2C1 SDA function */ + IOT_GPIO_FUNC_GPIO_3_I2C1_SDA, + /** SSI DATA function */ + IOT_GPIO_FUNC_GPIO_3_SSI_DATA, +} WifiIotIoFuncGpio3; + +/** + * @brief Enumerates the functions of GPIO hardware pin 4. + */ +typedef enum { + /** GPIO4 function */ + IOT_GPIO_FUNC_GPIO_4_GPIO, + /** UART0 RXD function */ + IOT_GPIO_FUNC_GPIO_4_UART0_RXD = 2, + /** JTAG TMS function */ + IOT_GPIO_FUNC_GPIO_4_JTAG_TMS = 4, + /** PWM1 OUT function */ + IOT_GPIO_FUNC_GPIO_4_PWM1_OUT, + /** I2C1 SCL function */ + IOT_GPIO_FUNC_GPIO_4_I2C1_SCL, +} WifiIotIoFuncGpio4; + +/** + * @brief Enumerates the functions of GPIO hardware pin 5. + */ +typedef enum { + /** GPIO5 function */ + IOT_GPIO_FUNC_GPIO_5_GPIO, + /** UART1 RXD function */ + IOT_GPIO_FUNC_GPIO_5_UART1_RXD = 2, + /** SPI0 CSN function */ + IOT_GPIO_FUNC_GPIO_5_SPI0_CSN, + /** PWM2 OUT function */ + IOT_GPIO_FUNC_GPIO_5_PWM2_OUT = 5, + /** I2C0 MCLK function */ + IOT_GPIO_FUNC_GPIO_5_I2S0_MCLK, + /** BT STATUS function */ + IOT_GPIO_FUNC_GPIO_5_BT_STATUS, +} WifiIotIoFuncGpio5; + +/** + * @brief Enumerates the functions of GPIO hardware pin 6. + */ +typedef enum { + /** GPIO6 function */ + IOT_GPIO_FUNC_GPIO_6_GPIO, + /** UART1 TXD function */ + IOT_GPIO_FUNC_GPIO_6_UART1_TXD = 2, + /** SPI0 CK function */ + IOT_GPIO_FUNC_GPIO_6_SPI0_CK, + /** PWM3 OUT function */ + IOT_GPIO_FUNC_GPIO_6_PWM3_OUT = 5, + /** I2S0 TX function */ + IOT_GPIO_FUNC_GPIO_6_I2S0_TX, + /** COEX switch function */ + IOT_GPIO_FUNC_GPIO_6_COEX_SWITCH, +} WifiIotIoFuncGpio6; + +/** + * @brief Enumerates the functions of GPIO hardware pin 7. + */ +typedef enum { + /** GPIO7 function */ + IOT_GPIO_FUNC_GPIO_7_GPIO, + /** UART1 CTS function */ + IOT_GPIO_FUNC_GPIO_7_UART1_CTS_N = 2, + /** SPI0 RXD function */ + IOT_GPIO_FUNC_GPIO_7_SPI0_RXD, + /** PWM0 OUT function */ + IOT_GPIO_FUNC_GPIO_7_PWM0_OUT = 5, + /** I2S0 BCLK function */ + IOT_GPIO_FUNC_GPIO_7_I2S0_BCLK, + /** BT ACTIVE function */ + IOT_GPIO_FUNC_GPIO_7_BT_ACTIVE, +} WifiIotIoFuncGpio7; + +/** + * @brief Enumerates the functions of GPIO hardware pin 8. + */ +typedef enum { + /** GPIO8 function */ + IOT_GPIO_FUNC_GPIO_8_GPIO, + /** UART1 RTS function */ + IOT_GPIO_FUNC_GPIO_8_UART1_RTS_N = 2, + /** SPI0 TXD function */ + IOT_GPIO_FUNC_GPIO_8_SPI0_TXD, + /** PWM1 OUT function */ + IOT_GPIO_FUNC_GPIO_8_PWM1_OUT = 5, + /** I2S0 WS function */ + IOT_GPIO_FUNC_GPIO_8_I2S0_WS, + /** WLAN ACTIVE function */ + IOT_GPIO_FUNC_GPIO_8_WLAN_ACTIVE, +} WifiIotIoFuncGpio8; + +/** + * @brief Enumerates the functions of GPIO hardware pin 9. + */ +typedef enum { + /** GPIO9 function */ + IOT_GPIO_FUNC_GPIO_9_GPIO, + /** I2C0 SCL function */ + IOT_GPIO_FUNC_GPIO_9_I2C0_SCL, + /** UART2 RTS function */ + IOT_GPIO_FUNC_GPIO_9_UART2_RTS_N, + /** SDIO D2 function */ + IOT_GPIO_FUNC_GPIO_9_SDIO_D2, + /** SPI0 TXD function */ + IOT_GPIO_FUNC_GPIO_9_SPI0_TXD, + /** PWM0 OUT function */ + IOT_GPIO_FUNC_GPIO_9_PWM0_OUT, + /** I2S0 MCLK function */ + IOT_GPIO_FUNC_GPIO_9_I2S0_MCLK = 7, +} WifiIotIoFuncGpio9; + +/** + * @brief Enumerates the functions of GPIO hardware pin 10. + */ +typedef enum { + /** GPIO10 function */ + IOT_GPIO_FUNC_GPIO_10_GPIO, + /** I2C0 SDA function */ + IOT_GPIO_FUNC_GPIO_10_I2C0_SDA, + /** UART2 CTS function */ + IOT_GPIO_FUNC_GPIO_10_UART2_CTS_N, + /** SDIO D3 function */ + IOT_GPIO_FUNC_GPIO_10_SDIO_D3, + /** SPI0 CK function */ + IOT_GPIO_FUNC_GPIO_10_SPI0_CK, + /** PWM1 OUT function */ + IOT_GPIO_FUNC_GPIO_10_PWM1_OUT, + /** I2S0 TX function */ + IOT_GPIO_FUNC_GPIO_10_I2S0_TX = 7, +} WifiIotIoFuncGpio10; + +/** + * @brief Enumerates the functions of GPIO hardware pin 11. + */ +typedef enum { + /** GPIO11 function */ + IOT_GPIO_FUNC_GPIO_11_GPIO, + /** UART2 TXD function */ + IOT_GPIO_FUNC_GPIO_11_UART2_TXD = 2, + /** SDIO CMD function */ + IOT_GPIO_FUNC_GPIO_11_SDIO_CMD, + /** SDIO RXD function */ + IOT_GPIO_FUNC_GPIO_11_SPI0_RXD, + /** PWM2 OUT function */ + IOT_GPIO_FUNC_GPIO_11_PWM2_OUT, + /** RF TX_EN_EXT function */ + IOT_GPIO_FUNC_GPIO_11_RF_TX_EN_EXT, + /** I2S0 RX function */ + IOT_GPIO_FUNC_GPIO_11_I2S0_RX, +} WifiIotIoFuncGpio11; + +/** + * @brief Enumerates the functions of GPIO hardware pin 12. + */ +typedef enum { + /** GPIO12 function */ + IOT_GPIO_FUNC_GPIO_12_GPIO, + /** SUART2 RXD function */ + IOT_GPIO_FUNC_GPIO_12_UART2_RXD = 2, + /** SDIO CLK function */ + IOT_GPIO_FUNC_GPIO_12_SDIO_CLK, + /** SDIO CSN function */ + IOT_GPIO_FUNC_GPIO_12_SPI0_CSN, + /** PWM3 OUT function */ + IOT_GPIO_FUNC_GPIO_12_PWM3_OUT, + /** RF RX_EN_EXT function */ + IOT_GPIO_FUNC_GPIO_12_RF_RX_EN_EXT, + /** I2S0 BCLK function */ + IOT_GPIO_FUNC_GPIO_12_I2S0_BCLK, +} WifiIotIoFuncGpio12; + +/** + * @brief Enumerates the functions of GPIO hardware pin 13. + */ +typedef enum { + /** SSI DATA function */ + IOT_GPIO_FUNC_GPIO_13_SSI_DATA, + /** UART0 TXD function */ + IOT_GPIO_FUNC_GPIO_13_UART0_TXD, + /** UART2 RTS function */ + IOT_GPIO_FUNC_GPIO_13_UART2_RTS_N, + /** SDIO D0 function */ + IOT_GPIO_FUNC_GPIO_13_SDIO_D0, + /** GPIO13 function */ + IOT_GPIO_FUNC_GPIO_13_GPIO, + /** PWM4 OUT function */ + IOT_GPIO_FUNC_GPIO_13_PWM4_OUT, + /** I2C0 SDA function */ + IOT_GPIO_FUNC_GPIO_13_I2C0_SDA, + /** I2S0 WS function */ + IOT_GPIO_FUNC_GPIO_13_I2S0_WS, +} WifiIotIoFuncGpio13; + +/** + * @brief Enumerates the functions of GPIO hardware pin 14. + */ +typedef enum { + /** SSI CLK function */ + IOT_GPIO_FUNC_GPIO_14_SSI_CLK, + /** UART0 RXD function */ + IOT_GPIO_FUNC_GPIO_14_UART0_RXD, + /** UART2 CTS function */ + IOT_GPIO_FUNC_GPIO_14_UART2_CTS_N, + /** SDIO D1 function */ + IOT_GPIO_FUNC_GPIO_14_SDIO_D1, + /** GPIO14 function */ + IOT_GPIO_FUNC_GPIO_14_GPIO, + /** PWM5 OUT function */ + IOT_GPIO_FUNC_GPIO_14_PWM5_OUT, + /** I2C0 SCL function */ + IOT_GPIO_FUNC_GPIO_14_I2C0_SCL, +} WifiIotIoFuncGpio14; + +/** + * @brief Enumerates GPIO pull-up or pull-down settings. + */ +typedef enum { + /** No pull */ + IOT_GPIO_PULL_NONE, + /** Pull-up */ + IOT_GPIO_PULL_UP, + /** Pull-down */ + IOT_GPIO_PULL_DOWN, + /** Maximum value */ + IOT_GPIO_PULL_MAX, +} IotGpioPull; + + +unsigned int IoTGpioSetFunc(unsigned int id, unsigned char val); + +unsigned int IoTGpioSetPull(unsigned int id, IotGpioPull val); + +#endif /** @} */ \ No newline at end of file diff --git a/common/inc/iot_i2c_ex.h b/common/inc/iot_i2c_ex.h index e1f09524d32d09d19e4cc87edf1a3106a25347fc..31737a4633d558cc4fed580974c214141b3167b2 100644 --- a/common/inc/iot_i2c_ex.h +++ b/common/inc/iot_i2c_ex.h @@ -1,78 +1,78 @@ -/* - * Copyright (c) 2020 Huawei Device Co., Ltd. - * 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. - */ - - -/** - * @addtogroup wifiiot - * @{ - * - * @brief Provides dedicated device operation interfaces on the Wi-Fi module, - * including ADC, AT, flash, GPIO, I2C, I2S, partition, PWM, SDIO, UART, and watchdog. - * - * - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file wifiiot_i2c_ex.h - * - * @brief Declares the extended I2C interface functions. - * - * These functions are used for I2C baud rate setting and device exception callback. \n - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef IOT_I2C_EX_H -#define IOT_I2C_EX_H - - -/** - * @brief Defines I2C data transmission attributes. - */ -typedef struct { - /** Pointer to the buffer storing data to send */ - unsigned char *sendBuf; - /** Length of data to send */ - unsigned int sendLen; - /** Pointer to the buffer for storing data to receive */ - unsigned char *receiveBuf; - /** Length of data received */ - unsigned int receiveLen; -} IotI2cData; - - -/** - * @brief Sends data to and receives data responses from an I2C device. - * - * - * - * @param id Indicates the I2C device ID. - * @param deviceAddr Indicates the I2C device address. - * @param i2cData Indicates the pointer to the device descriptor of the data to receive. - * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link wifiiot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTI2cWriteread(unsigned int id, unsigned short deviceAddr, const IotI2cData *i2cData); - - - -#endif -/** @} */ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * 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. + */ + + +/** + * @addtogroup wifiiot + * @{ + * + * @brief Provides dedicated device operation interfaces on the Wi-Fi module, + * including ADC, AT, flash, GPIO, I2C, I2S, partition, PWM, SDIO, UART, and watchdog. + * + * + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file wifiiot_i2c_ex.h + * + * @brief Declares the extended I2C interface functions. + * + * These functions are used for I2C baud rate setting and device exception callback. \n + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef IOT_I2C_EX_H +#define IOT_I2C_EX_H + + +/** + * @brief Defines I2C data transmission attributes. + */ +typedef struct { + /** Pointer to the buffer storing data to send */ + unsigned char *sendBuf; + /** Length of data to send */ + unsigned int sendLen; + /** Pointer to the buffer for storing data to receive */ + unsigned char *receiveBuf; + /** Length of data received */ + unsigned int receiveLen; +} IotI2cData; + + +/** + * @brief Sends data to and receives data responses from an I2C device. + * + * + * + * @param id Indicates the I2C device ID. + * @param deviceAddr Indicates the I2C device address. + * @param i2cData Indicates the pointer to the device descriptor of the data to receive. + * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link wifiiot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTI2cWriteread(unsigned int id, unsigned short deviceAddr, const IotI2cData *i2cData); + + + +#endif +/** @} */ diff --git a/common/inc/iot_list.h b/common/inc/iot_list.h index e5bd8f824c692a37646f1033b9c30315cb8c6439..5e4048b02005799ec78a8599aa063ff0aa6918d1 100644 --- a/common/inc/iot_list.h +++ b/common/inc/iot_list.h @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef __IOT_LIST_H__ -#define __IOT_LIST_H__ - -typedef void* IOT_LIST; - -IOT_LIST IoT_ListCreate(void *data, int size); - -int IoT_ListAppend(IOT_LIST mHandle, void *data, int size); - -int IoT_ListUpdate(IOT_LIST mHandle, int idx, void *data, int size); - -int IoT_ListDelete(IOT_LIST mHandle, void *data); - -int IoT_ListGet(IOT_LIST mHandle, int idx, void *data, int size); - -int IoT_ListGetSize(IOT_LIST mHandle); - -void IoT_ListClear(IOT_LIST mHandle); - -void IoT_ListDestroy(IOT_LIST mHandle); - -#endif /* __IOT_LIST_H__ */ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef __IOT_LIST_H__ +#define __IOT_LIST_H__ + +typedef void* IOT_LIST; + +IOT_LIST IoT_ListCreate(void *data, int size); + +int IoT_ListAppend(IOT_LIST mHandle, void *data, int size); + +int IoT_ListUpdate(IOT_LIST mHandle, int idx, void *data, int size); + +int IoT_ListDelete(IOT_LIST mHandle, void *data); + +int IoT_ListGet(IOT_LIST mHandle, int idx, void *data, int size); + +int IoT_ListGetSize(IOT_LIST mHandle); + +void IoT_ListClear(IOT_LIST mHandle); + +void IoT_ListDestroy(IOT_LIST mHandle); + +#endif /* __IOT_LIST_H__ */ diff --git a/common/inc/iot_spi.h b/common/inc/iot_spi.h index 663c1b8e33071831f1172c38027f2a08535ff3ec..407b4abfd73647aa26955f1b0304d6c30b15f288 100644 --- a/common/inc/iot_spi.h +++ b/common/inc/iot_spi.h @@ -1,368 +1,368 @@ -/* - * Copyright (c) 2020 Huawei Device Co., Ltd. - * 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. - */ - -/** - * @addtogroup IotHardware - * @{ - * - * @brief Provides APIs for operating devices, - * including flash, GPIO, I2C, PWM, UART, and watchdog APIs. - * - * - * - * @since 2.2 - * @version 2.2 - */ - -/** - * @file iot_spi.h - * - * @brief Declares flash functions. - * - * These functions are used to initialize or deinitialize a flash device, - * and read data from or write data to a flash memory. \n - * - * @since 2.2 - * @version 2.2 - */ - -#ifndef IOT_SPI_H -#define IOT_SPI_H - -/** - * @brief Indicates the SPI callback, which is used in {@link SpiRegisterUsrFunc}. - */ -typedef void (*SpiIsrFunc)(void); - -/** - * @brief Enumerates SPI channel IDs. - */ -typedef enum { - /** Channel 0 */ - IOT_SPI_ID_0 = 0, - /** Channel 1 */ - IOT_SPI_ID_1, -} IotSpiIdx; - -/** - * @brief Enumerates communication polarities. - */ -typedef enum { - /** Polarity 0 */ - IOT_SPI_CFG_CLOCK_CPOL_0, - /** Polarity 1 */ - IOT_SPI_CFG_CLOCK_CPOL_1, -}IotSpiCfgClockCpol; - -/** - * @brief Enumerates communication phases. - */ -typedef enum { - /** Phase 0 */ - IOT_SPI_CFG_CLOCK_CPHA_0, - /** Phase 1 */ - IOT_SPI_CFG_CLOCK_CPHA_1, -} IotSpiCfgClockCpha; - -/** - * @brief Enumerates communication protocols. - */ -typedef enum { - /** Motorola protocol */ - IOT_SPI_CFG_FRAM_MODE_MOTOROLA, - /** Texas Instruments protocol */ - IOT_SPI_CFG_FRAM_MODE_TI, - /** Microwire protocol */ - IOT_SPI_CFG_FRAM_MODE_MICROWIRE, -} IotSpiCfgFramMode; - -/** - * @brief Enumerates the communication data width, that is, - * the number of valid bits in each frame. - * - */ -typedef enum { - /** 4 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_4BIT = 0x3, - /** 5 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_5BIT, - /** 6 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_6BIT, - /** 7 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_7BIT, - /** 8 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_8BIT, - /** 9 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_9BIT, - /** 10 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_10BIT, - /** 11 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_11BIT, - /** 12 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_12BIT, - /** 13 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_13BIT, - /** 14 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_14BIT, - /** 15 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_15BIT, - /** 16 bits */ - IOT_SPI_CFG_DATA_WIDTH_E_16BIT, -} IotSpiCfgDataWidth; - -/** - * @brief Enumerates the endian mode of each frame. - */ -typedef enum { - /** Little-endian */ - IOT_SPI_CFG_ENDIAN_LITTLE, - /** Big-endian */ - IOT_SPI_CFG_ENDIAN_BIG, -} IotSpiCfgEndian; - -/** - * @brief Defines data communication parameters. - */ -typedef struct { - /** Communication polarity. For details about available values, - * see {@link IotSpiCfgClockCpol}. - */ - unsigned int cpol : 1; - /** Communication phase. - * For details about available values, see {@link IotSpiCfgClockCpha}. - */ - unsigned int cpha : 1; - /** Communication protocol. - * For details about available values, see {@link IotSpiCfgFramMode}. - */ - unsigned int framMode : 2; - /** Communication data width. - * For details about available values, see {@link IotSpiCfgDataWidth}. - */ - unsigned int dataWidth : 4; - /** Endian mode. For details about available values, see {@link IotSpiCfgEndian}. */ - unsigned int endian : 1; - /** Padding bit */ - unsigned int pad : 23; - /** Communication frequency. The value ranges from 2460 Hz to 40 MHz. */ - unsigned int freq; -} IotSpiCfgBasicInfo; - -/** - * @brief Specifies whether a device is a master or slave device. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** Whether the device is a slave device */ - unsigned int isSlave : 1; - /** Padding bit */ - unsigned int pad : 31; -} IotSpiCfgInitParam; - -/** - * @brief Sends data in SPI slave mode. - * - * In SPI slave mode, this function sends data of the length - * specified by byteLen in writeData through - * the channel specified by spiId within the duration timeOutMs. - * - * @param spiId Indicates the SPI channel ID. - * @param writeData Indicates the pointer to the data to send. - * @param byteLen Indicates the length of the data to send. - * @param timeOutMs Indicates the timeout interval. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiSlaveWrite(IotSpiIdx spiId, char *writeData, unsigned int byteLen, unsigned int timeOutMs); - -/** - * @brief Reads data in SPI slave mode. - * - * In SPI slave mode, this function reads data of the length - * specified by byteLen in readData through the channel - * specified by spiId within the duration timeOutMs. - * - * @param spiId Indicates the SPI channel ID. - * @param readData Indicates the pointer to the data to read. - * @param byteLen Indicates the length of the data to read. - * @param timeOutMs Indicates the timeout interval. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiSlaveRead(IotSpiIdx spiId, char *readData, unsigned int byteLen, unsigned int timeOutMs); - -/** - * @brief Sends data in half-duplex SPI master mode. - * - * In SPI master mode, this function sends data of the length - * specified by byteLen in writeData - * through the channel specified by spiId. - * - * @param spiId Indicates the SPI channel ID. - * @param writeData Indicates the pointer to the data to send. - * @param byteLen Indicates the length of the data to send. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiHostWrite(IotSpiIdx spiId, char *writeData, unsigned int byteLen); - -/** - * @brief Reads data in half-duplex SPI master mode. - * - * In SPI master mode, this function reads data of the length - * specified by byteLen in readData - * through the channel specified by spiId. - * - * @param spiId Indicates the SPI channel ID. - * @param readData Indicates the pointer to the data to read. - * @param byteLen Indicates the length of the data to read. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiHostRead(IotSpiIdx spiId, char *readData, unsigned int byteLen); - -/** - * @brief Sends and reads data in full-duplex SPI master mode. - * - * In SPI master mode, this function sends data in writeData and - * reads data of the length specified by byteLen in readData - * both through the channel specified by spiId. - * - * @param spiId Indicates the SPI channel ID. - * @param writeData Indicates the pointer to the data to send. - * @param readData Indicates the pointer to the data to read. - * @param byteLen Indicates the length of the data to read. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiHostWriteread(IotSpiIdx spiId, char *writeData, char *readData, unsigned int byteLen); - -/** - * @brief Sets the SPI channel parameter. - * - * - * - * @param spiId Indicates the SPI channel ID. - * @param param Indicates the pointer to the SPI parameter to set. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiSetBasicInfo(IotSpiIdx spiId, const IotSpiCfgBasicInfo *param); - -/** - * @brief Initializes an SPI device. - * - * This function initializes the device with the channel ID spiId, - * device type initParam, and device parameter param. - * - * @param spiId Indicates the SPI channel ID. - * @param initParam Specifies whether the device is a slave one. - * @param param Indicates the pointer to the SPI device parameter. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiInit(IotSpiIdx spiId, IotSpiCfgInitParam initParam, const IotSpiCfgBasicInfo *param); - -/** - * @brief Deinitializes an SPI device. - * - * @param spiId Indicates the SPI channel ID. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiDeinit(IotSpiIdx spiId); - -/** - * @brief Sets whether to enable the interrupt request (IRQ) mode for an SPI device. - * - * - * - * @param spiId Indicates the SPI channel ID. - * @param irqEn Specifies whether to enable IRQ. - * The value 1 means to enable IRQ, and 0 means to disable IRQ. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiSetIrqMode(IotSpiIdx spiId, unsigned char irqEn); - -/** - * @brief Sets whether to enable DMA to transfer data for an SPI device in slave mode. - * - * - * - * @param spiId Indicates the SPI channel ID. - * @param dmaEn Specifies whether to enable DMA. - * The value 1 means to enable DMA, and 0 means to disable DMA. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiSetDmaMode(IotSpiIdx spiId, unsigned char dmaEn); - -/** - * @brief Registers the data TX preparation/recovery function. - * - * This function registers the functions - * registered by prepareF and restoreF for - * an SPI device with a channel specified by spiId. - * - * @param spiId Indicates the SPI channel ID. - * @param prepareF Indicates the function used for data preparation. - * @param restoreF Indicates the function used for data recovery. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiRegisterUsrFunc(IotSpiIdx spiId, SpiIsrFunc prepareF, SpiIsrFunc restoreF); - -/** - * @brief Sets whether to enable loopback test for an SPI device. - * - * - * - * @param spiId Indicates the SPI channel ID. - * @param lbEn Specifies whether to enable loopback test. The value 1 - * means to enable loopback test, and 0 means to disable loopback test. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link iot_errno.h} otherwise. - * @since 1.0 - * @version 1.0 - */ -unsigned int IoTSpiSetLoopBackMode(IotSpiIdx spiId, unsigned char lbEn); - -#endif -/** @} */ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * 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. + */ + +/** + * @addtogroup IotHardware + * @{ + * + * @brief Provides APIs for operating devices, + * including flash, GPIO, I2C, PWM, UART, and watchdog APIs. + * + * + * + * @since 2.2 + * @version 2.2 + */ + +/** + * @file iot_spi.h + * + * @brief Declares flash functions. + * + * These functions are used to initialize or deinitialize a flash device, + * and read data from or write data to a flash memory. \n + * + * @since 2.2 + * @version 2.2 + */ + +#ifndef IOT_SPI_H +#define IOT_SPI_H + +/** + * @brief Indicates the SPI callback, which is used in {@link SpiRegisterUsrFunc}. + */ +typedef void (*SpiIsrFunc)(void); + +/** + * @brief Enumerates SPI channel IDs. + */ +typedef enum { + /** Channel 0 */ + IOT_SPI_ID_0 = 0, + /** Channel 1 */ + IOT_SPI_ID_1, +} IotSpiIdx; + +/** + * @brief Enumerates communication polarities. + */ +typedef enum { + /** Polarity 0 */ + IOT_SPI_CFG_CLOCK_CPOL_0, + /** Polarity 1 */ + IOT_SPI_CFG_CLOCK_CPOL_1, +}IotSpiCfgClockCpol; + +/** + * @brief Enumerates communication phases. + */ +typedef enum { + /** Phase 0 */ + IOT_SPI_CFG_CLOCK_CPHA_0, + /** Phase 1 */ + IOT_SPI_CFG_CLOCK_CPHA_1, +} IotSpiCfgClockCpha; + +/** + * @brief Enumerates communication protocols. + */ +typedef enum { + /** Motorola protocol */ + IOT_SPI_CFG_FRAM_MODE_MOTOROLA, + /** Texas Instruments protocol */ + IOT_SPI_CFG_FRAM_MODE_TI, + /** Microwire protocol */ + IOT_SPI_CFG_FRAM_MODE_MICROWIRE, +} IotSpiCfgFramMode; + +/** + * @brief Enumerates the communication data width, that is, + * the number of valid bits in each frame. + * + */ +typedef enum { + /** 4 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_4BIT = 0x3, + /** 5 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_5BIT, + /** 6 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_6BIT, + /** 7 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_7BIT, + /** 8 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_8BIT, + /** 9 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_9BIT, + /** 10 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_10BIT, + /** 11 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_11BIT, + /** 12 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_12BIT, + /** 13 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_13BIT, + /** 14 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_14BIT, + /** 15 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_15BIT, + /** 16 bits */ + IOT_SPI_CFG_DATA_WIDTH_E_16BIT, +} IotSpiCfgDataWidth; + +/** + * @brief Enumerates the endian mode of each frame. + */ +typedef enum { + /** Little-endian */ + IOT_SPI_CFG_ENDIAN_LITTLE, + /** Big-endian */ + IOT_SPI_CFG_ENDIAN_BIG, +} IotSpiCfgEndian; + +/** + * @brief Defines data communication parameters. + */ +typedef struct { + /** Communication polarity. For details about available values, + * see {@link IotSpiCfgClockCpol}. + */ + unsigned int cpol : 1; + /** Communication phase. + * For details about available values, see {@link IotSpiCfgClockCpha}. + */ + unsigned int cpha : 1; + /** Communication protocol. + * For details about available values, see {@link IotSpiCfgFramMode}. + */ + unsigned int framMode : 2; + /** Communication data width. + * For details about available values, see {@link IotSpiCfgDataWidth}. + */ + unsigned int dataWidth : 4; + /** Endian mode. For details about available values, see {@link IotSpiCfgEndian}. */ + unsigned int endian : 1; + /** Padding bit */ + unsigned int pad : 23; + /** Communication frequency. The value ranges from 2460 Hz to 40 MHz. */ + unsigned int freq; +} IotSpiCfgBasicInfo; + +/** + * @brief Specifies whether a device is a master or slave device. + * + * @since 1.0 + * @version 1.0 + */ +typedef struct { + /** Whether the device is a slave device */ + unsigned int isSlave : 1; + /** Padding bit */ + unsigned int pad : 31; +} IotSpiCfgInitParam; + +/** + * @brief Sends data in SPI slave mode. + * + * In SPI slave mode, this function sends data of the length + * specified by byteLen in writeData through + * the channel specified by spiId within the duration timeOutMs. + * + * @param spiId Indicates the SPI channel ID. + * @param writeData Indicates the pointer to the data to send. + * @param byteLen Indicates the length of the data to send. + * @param timeOutMs Indicates the timeout interval. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiSlaveWrite(IotSpiIdx spiId, char *writeData, unsigned int byteLen, unsigned int timeOutMs); + +/** + * @brief Reads data in SPI slave mode. + * + * In SPI slave mode, this function reads data of the length + * specified by byteLen in readData through the channel + * specified by spiId within the duration timeOutMs. + * + * @param spiId Indicates the SPI channel ID. + * @param readData Indicates the pointer to the data to read. + * @param byteLen Indicates the length of the data to read. + * @param timeOutMs Indicates the timeout interval. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiSlaveRead(IotSpiIdx spiId, char *readData, unsigned int byteLen, unsigned int timeOutMs); + +/** + * @brief Sends data in half-duplex SPI master mode. + * + * In SPI master mode, this function sends data of the length + * specified by byteLen in writeData + * through the channel specified by spiId. + * + * @param spiId Indicates the SPI channel ID. + * @param writeData Indicates the pointer to the data to send. + * @param byteLen Indicates the length of the data to send. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiHostWrite(IotSpiIdx spiId, char *writeData, unsigned int byteLen); + +/** + * @brief Reads data in half-duplex SPI master mode. + * + * In SPI master mode, this function reads data of the length + * specified by byteLen in readData + * through the channel specified by spiId. + * + * @param spiId Indicates the SPI channel ID. + * @param readData Indicates the pointer to the data to read. + * @param byteLen Indicates the length of the data to read. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiHostRead(IotSpiIdx spiId, char *readData, unsigned int byteLen); + +/** + * @brief Sends and reads data in full-duplex SPI master mode. + * + * In SPI master mode, this function sends data in writeData and + * reads data of the length specified by byteLen in readData + * both through the channel specified by spiId. + * + * @param spiId Indicates the SPI channel ID. + * @param writeData Indicates the pointer to the data to send. + * @param readData Indicates the pointer to the data to read. + * @param byteLen Indicates the length of the data to read. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiHostWriteread(IotSpiIdx spiId, char *writeData, char *readData, unsigned int byteLen); + +/** + * @brief Sets the SPI channel parameter. + * + * + * + * @param spiId Indicates the SPI channel ID. + * @param param Indicates the pointer to the SPI parameter to set. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiSetBasicInfo(IotSpiIdx spiId, const IotSpiCfgBasicInfo *param); + +/** + * @brief Initializes an SPI device. + * + * This function initializes the device with the channel ID spiId, + * device type initParam, and device parameter param. + * + * @param spiId Indicates the SPI channel ID. + * @param initParam Specifies whether the device is a slave one. + * @param param Indicates the pointer to the SPI device parameter. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiInit(IotSpiIdx spiId, IotSpiCfgInitParam initParam, const IotSpiCfgBasicInfo *param); + +/** + * @brief Deinitializes an SPI device. + * + * @param spiId Indicates the SPI channel ID. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiDeinit(IotSpiIdx spiId); + +/** + * @brief Sets whether to enable the interrupt request (IRQ) mode for an SPI device. + * + * + * + * @param spiId Indicates the SPI channel ID. + * @param irqEn Specifies whether to enable IRQ. + * The value 1 means to enable IRQ, and 0 means to disable IRQ. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiSetIrqMode(IotSpiIdx spiId, unsigned char irqEn); + +/** + * @brief Sets whether to enable DMA to transfer data for an SPI device in slave mode. + * + * + * + * @param spiId Indicates the SPI channel ID. + * @param dmaEn Specifies whether to enable DMA. + * The value 1 means to enable DMA, and 0 means to disable DMA. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiSetDmaMode(IotSpiIdx spiId, unsigned char dmaEn); + +/** + * @brief Registers the data TX preparation/recovery function. + * + * This function registers the functions + * registered by prepareF and restoreF for + * an SPI device with a channel specified by spiId. + * + * @param spiId Indicates the SPI channel ID. + * @param prepareF Indicates the function used for data preparation. + * @param restoreF Indicates the function used for data recovery. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiRegisterUsrFunc(IotSpiIdx spiId, SpiIsrFunc prepareF, SpiIsrFunc restoreF); + +/** + * @brief Sets whether to enable loopback test for an SPI device. + * + * + * + * @param spiId Indicates the SPI channel ID. + * @param lbEn Specifies whether to enable loopback test. The value 1 + * means to enable loopback test, and 0 means to disable loopback test. + * @return Returns {@link IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link iot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int IoTSpiSetLoopBackMode(IotSpiIdx spiId, unsigned char lbEn); + +#endif +/** @} */ diff --git a/common/inc/iot_store_manager.h b/common/inc/iot_store_manager.h index 447da36ab55df65ebd635035635d01ae914d44f2..793415209e5cb75927531ba84d2a20ed645d7bcf 100644 --- a/common/inc/iot_store_manager.h +++ b/common/inc/iot_store_manager.h @@ -1,38 +1,38 @@ - -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef __IOT_STORE_MANAGER_H__ -#define __IOT_STORE_MANAGER_H__ - -#define USER_KV_STORE 1 -#if (USER_KV_STORE) -int StoreManagerAddData(const char *data, int length); - -int StoreManagerUpdateData(int idx, const char *data, int length); - -int StoreManagerDeleteDataWithId(int idx); - -int StoreManagerDeleteData(const char *data); - -int StoreManagerGetTotal(void); - -int StoreManagerGetData(char *data, int size, int idx); - -void StoreManagerDelete(void); - -#endif - -#endif /* __IOT_STORE_MANAGER_H__ */ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef __IOT_STORE_MANAGER_H__ +#define __IOT_STORE_MANAGER_H__ + +#define USER_KV_STORE 1 +#if (USER_KV_STORE) +int StoreManagerAddData(const char *data, int length); + +int StoreManagerUpdateData(int idx, const char *data, int length); + +int StoreManagerDeleteDataWithId(int idx); + +int StoreManagerDeleteData(const char *data); + +int StoreManagerGetTotal(void); + +int StoreManagerGetData(char *data, int size, int idx); + +void StoreManagerDelete(void); + +#endif + +#endif /* __IOT_STORE_MANAGER_H__ */ diff --git a/common/iot_gpio_interface/iot_gpio_func.c b/common/iot_gpio_interface/iot_gpio_func.c index 457400c4d438489c55147b489011ff6bc97ada8d..22430598f12bfed31d75fe0bb4247c5408711419 100644 --- a/common/iot_gpio_interface/iot_gpio_func.c +++ b/common/iot_gpio_interface/iot_gpio_func.c @@ -1,315 +1,315 @@ -#include "wifiiot_gpio.h" -#include "iot_gpio_ex.h" -#include "iot_uart.h" -#include "iot_spi.h" -#include "iot_pwm.h" -#include "iot_i2c.h" -#include "iot_gpio_func.h" - - -/* 通过GPIO引脚号获取GPIO功能编号 */ -u32 Gpio2Gpio(u32 gpio, u8 *func) -{ - u32 ret = KP_ERR_SUCCESS; - - /* 根据引脚号确定引脚GPIO功能编号 */ - switch (gpio) - { - case WIFI_IOT_GPIO_IDX_0: - func = IOT_GPIO_FUNC_GPIO_0_GPIO; - break; - case WIFI_IOT_GPIO_IDX_1: - func = IOT_GPIO_FUNC_GPIO_1_GPIO; - break; - case WIFI_IOT_GPIO_IDX_2: - func = IOT_GPIO_FUNC_GPIO_2_GPIO; - break; - case WIFI_IOT_GPIO_IDX_3: - func = IOT_GPIO_FUNC_GPIO_3_GPIO; - break; - case WIFI_IOT_GPIO_IDX_4: - func = IOT_GPIO_FUNC_GPIO_4_GPIO; - break; - case WIFI_IOT_GPIO_IDX_5: - func = IOT_GPIO_FUNC_GPIO_5_GPIO; - break; - case WIFI_IOT_GPIO_IDX_6: - func = IOT_GPIO_FUNC_GPIO_6_GPIO; - break; - case WIFI_IOT_GPIO_IDX_7: - func = IOT_GPIO_FUNC_GPIO_7_GPIO; - break; - case WIFI_IOT_GPIO_IDX_8: - func = IOT_GPIO_FUNC_GPIO_8_GPIO; - break; - case WIFI_IOT_GPIO_IDX_9: - func = IOT_GPIO_FUNC_GPIO_9_GPIO; - break; - case WIFI_IOT_GPIO_IDX_10: - func = IOT_GPIO_FUNC_GPIO_10_GPIO; - break; - case WIFI_IOT_GPIO_IDX_11: - func = IOT_GPIO_FUNC_GPIO_11_GPIO; - break; - case WIFI_IOT_GPIO_IDX_12: - func = IOT_GPIO_FUNC_GPIO_12_GPIO; - break; - case WIFI_IOT_GPIO_IDX_13: - func = IOT_GPIO_FUNC_GPIO_13_GPIO; - break; - case WIFI_IOT_GPIO_IDX_14: - func = IOT_GPIO_FUNC_GPIO_14_GPIO; - break; - default: - IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); - return KP_ERR_FAILURE; - } - - return KP_ERR_SUCCESS; -} - -/* 通过GPIO引脚号获取GPIO功能编号 */ -u32 Gpio2Uart(u32 gpio, u8 *func, u32 *uartId) -{ - u32 ret = KP_ERR_SUCCESS; - - /* 根据引脚号确定引脚GPIO功能编号 */ - switch (gpio) - { - case WIFI_IOT_GPIO_IDX_0: - func = IOT_GPIO_FUNC_GPIO_0_UART1_TXD; - uartId = IOT_UART_IDX_1; - break; - case WIFI_IOT_GPIO_IDX_1: - func = IOT_GPIO_FUNC_GPIO_1_UART1_RXD; - uartId = IOT_UART_IDX_1; - break; - case WIFI_IOT_GPIO_IDX_3: - func = IOT_GPIO_FUNC_GPIO_3_UART0_TXD; - uartId = IOT_UART_IDX_0; - break; - case WIFI_IOT_GPIO_IDX_4: - func = IOT_GPIO_FUNC_GPIO_4_UART0_RXD; - uartId = IOT_UART_IDX_0; - break; - case WIFI_IOT_GPIO_IDX_5: - func = IOT_GPIO_FUNC_GPIO_5_UART1_RXD; - uartId = IOT_UART_IDX_1; - break; - case WIFI_IOT_GPIO_IDX_6: - func = IOT_GPIO_FUNC_GPIO_6_UART1_TXD; - uartId = IOT_UART_IDX_1; - break; - case WIFI_IOT_GPIO_IDX_11: - func = IOT_GPIO_FUNC_GPIO_11_UART2_TXD; - uartId = IOT_UART_IDX_2; - break; - case WIFI_IOT_GPIO_IDX_12: - func = IOT_GPIO_FUNC_GPIO_12_UART2_RXD; - uartId = IOT_UART_IDX_2; - break; - case WIFI_IOT_GPIO_IDX_13: - func = IOT_GPIO_FUNC_GPIO_13_UART0_TXD; - uartId = IOT_UART_IDX_0; - break; - case WIFI_IOT_GPIO_IDX_14: - func = IOT_GPIO_FUNC_GPIO_14_UART0_RXD; - uartId = IOT_UART_IDX_0; - break; - default: - IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); - return KP_ERR_FAILURE; - } - - return KP_ERR_SUCCESS; -} - -/* 通过GPIO引脚号获取SPI功能编号 */ -u32 Gpio2Spi(u32 gpio, u8 *func, u32 *spiId) -{ - u32 ret = KP_ERR_SUCCESS; - - /* 根据引脚号确定引脚GPIO功能编号 */ - switch (gpio) - { - case WIFI_IOT_GPIO_IDX_0: - func = IOT_GPIO_FUNC_GPIO_0_SPI1_CK; - spiId = IOT_SPI_ID_1; - break; - case WIFI_IOT_GPIO_IDX_1: - func = IOT_GPIO_FUNC_GPIO_1_SPI1_RXD; - spiId = IOT_SPI_ID_1; - break; - case WIFI_IOT_GPIO_IDX_2: - func = IOT_GPIO_FUNC_GPIO_2_SPI1_TXD; - spiId = IOT_SPI_ID_1; - break; - case WIFI_IOT_GPIO_IDX_3: - func = IOT_GPIO_FUNC_GPIO_3_SPI1_CSN; - spiId = IOT_SPI_ID_1; - break; - case WIFI_IOT_GPIO_IDX_5: - func = IOT_GPIO_FUNC_GPIO_5_SPI0_CSN; - spiId = IOT_SPI_ID_0; - break; - case WIFI_IOT_GPIO_IDX_6: - func = IOT_GPIO_FUNC_GPIO_6_SPI0_CK; - spiId = IOT_SPI_ID_0; - break; - case WIFI_IOT_GPIO_IDX_7: - func = IOT_GPIO_FUNC_GPIO_7_SPI0_RXD; - spiId = IOT_SPI_ID_0; - break; - case WIFI_IOT_GPIO_IDX_8: - func = IOT_GPIO_FUNC_GPIO_8_SPI0_TXD; - spiId = IOT_SPI_ID_0; - break; - case WIFI_IOT_GPIO_IDX_9: - func = IOT_GPIO_FUNC_GPIO_9_SPI0_TXD; - spiId = IOT_SPI_ID_0; - break; - case WIFI_IOT_GPIO_IDX_10: - func = IOT_GPIO_FUNC_GPIO_10_SPI0_CK; - spiId = IOT_SPI_ID_0; - break; - case WIFI_IOT_GPIO_IDX_11: - func = IOT_GPIO_FUNC_GPIO_11_SPI0_RXD; - spiId = IOT_SPI_ID_0; - break; - case WIFI_IOT_GPIO_IDX_12: - func = IOT_GPIO_FUNC_GPIO_12_SPI0_CSN; - spiId = IOT_SPI_ID_0; - break; - default: - IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); - return KP_ERR_FAILURE; - } - - return KP_ERR_SUCCESS; -} - -/* 通过GPIO引脚号获取PWM功能编号 */ -u32 Gpio2Pwm(u32 gpio, u8 *func, u32 *pwmId) -{ - u32 ret = KP_ERR_SUCCESS; - - /* 根据引脚号确定引脚GPIO功能编号 */ - switch (gpio) - { - case WIFI_IOT_GPIO_IDX_0: - func = IOT_GPIO_FUNC_GPIO_0_PWM3_OUT; - pwmId = PWM_PORT_PWM3; - break; - case WIFI_IOT_GPIO_IDX_1: - func = IOT_GPIO_FUNC_GPIO_1_PWM4_OUT; - pwmId = PWM_PORT_PWM4; - break; - case WIFI_IOT_GPIO_IDX_2: - func = IOT_GPIO_FUNC_GPIO_2_PWM2_OUT; - pwmId = PWM_PORT_PWM2; - break; - case WIFI_IOT_GPIO_IDX_3: - func = IOT_GPIO_FUNC_GPIO_3_PWM5_OUT; - pwmId = PWM_PORT_PWM5; - break; - case WIFI_IOT_GPIO_IDX_4: - func = IOT_GPIO_FUNC_GPIO_4_PWM1_OUT; - pwmId = PWM_PORT_PWM1; - break; - case WIFI_IOT_GPIO_IDX_5: - func = IOT_GPIO_FUNC_GPIO_5_PWM2_OUT; - pwmId = PWM_PORT_PWM2; - break; - case WIFI_IOT_GPIO_IDX_6: - func = IOT_GPIO_FUNC_GPIO_6_PWM3_OUT; - pwmId = PWM_PORT_PWM3; - break; - case WIFI_IOT_GPIO_IDX_7: - func = IOT_GPIO_FUNC_GPIO_7_PWM0_OUT; - pwmId = PWM_PORT_PWM0; - break; - case WIFI_IOT_GPIO_IDX_8: - func = IOT_GPIO_FUNC_GPIO_8_PWM1_OUT; - pwmId = PWM_PORT_PWM1; - break; - case WIFI_IOT_GPIO_IDX_9: - func = IOT_GPIO_FUNC_GPIO_9_PWM0_OUT; - pwmId = PWM_PORT_PWM0; - break; - case WIFI_IOT_GPIO_IDX_10: - func = IOT_GPIO_FUNC_GPIO_10_PWM1_OUT; - pwmId = PWM_PORT_PWM1; - break; - case WIFI_IOT_GPIO_IDX_11: - func = IOT_GPIO_FUNC_GPIO_11_PWM2_OUT; - pwmId = PWM_PORT_PWM2; - break; - case WIFI_IOT_GPIO_IDX_12: - func = IOT_GPIO_FUNC_GPIO_12_PWM3_OUT; - pwmId = PWM_PORT_PWM3; - break; - case WIFI_IOT_GPIO_IDX_13: - func = IOT_GPIO_FUNC_GPIO_13_PWM4_OUT; - pwmId = PWM_PORT_PWM4; - break; - case WIFI_IOT_GPIO_IDX_14: - func = IOT_GPIO_FUNC_GPIO_14_PWM5_OUT; - pwmId = PWM_PORT_PWM5; - break; - default: - IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); - return KP_ERR_FAILURE; - } - - return KP_ERR_SUCCESS; -} - -/* 通过GPIO引脚号获取IIC功能编号 */ -u32 Gpio2IIC(u32 gpio, u8 *func, u32 *i2cId) -{ - u32 ret = KP_ERR_SUCCESS; - - /* 根据引脚号确定引脚GPIO功能编号 */ - switch (gpio) - { - case WIFI_IOT_GPIO_IDX_0: - func = IOT_GPIO_FUNC_GPIO_0_I2C1_SDA; - i2cId = IOT_I2C_IDX_1; - break; - case WIFI_IOT_GPIO_IDX_1: - func = IOT_GPIO_FUNC_GPIO_1_I2C1_SCL; - i2cId = IOT_I2C_IDX_1; - break; - case WIFI_IOT_GPIO_IDX_3: - func = IOT_GPIO_FUNC_GPIO_3_I2C1_SDA; - i2cId = IOT_I2C_IDX_1; - break; - case WIFI_IOT_GPIO_IDX_4: - func = IOT_GPIO_FUNC_GPIO_4_I2C1_SCL; - i2cId = IOT_I2C_IDX_1; - break; - case WIFI_IOT_GPIO_IDX_9: - func = IOT_GPIO_FUNC_GPIO_9_I2C0_SCL; - i2cId = IOT_I2C_IDX_0; - break; - case WIFI_IOT_GPIO_IDX_10: - func = IOT_GPIO_FUNC_GPIO_10_I2C0_SDA; - i2cId = IOT_I2C_IDX_0; - break; - case WIFI_IOT_GPIO_IDX_13: - func = IOT_GPIO_FUNC_GPIO_13_I2C0_SDA; - i2cId = IOT_I2C_IDX_0; - break; - case WIFI_IOT_GPIO_IDX_14: - func = IOT_GPIO_FUNC_GPIO_14_I2C0_SCL; - i2cId = IOT_I2C_IDX_0; - break; - default: - IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); - return KP_ERR_FAILURE; - } - - return KP_ERR_SUCCESS; -} - - +#include "wifiiot_gpio.h" +#include "iot_gpio_ex.h" +#include "iot_uart.h" +#include "iot_spi.h" +#include "iot_pwm.h" +#include "iot_i2c.h" +#include "iot_gpio_func.h" + + +/* 通过GPIO引脚号获取GPIO功能编号 */ +u32 Gpio2Gpio(u32 gpio, u8 *func) +{ + u32 ret = KP_ERR_SUCCESS; + + /* 根据引脚号确定引脚GPIO功能编号 */ + switch (gpio) + { + case WIFI_IOT_GPIO_IDX_0: + func = IOT_GPIO_FUNC_GPIO_0_GPIO; + break; + case WIFI_IOT_GPIO_IDX_1: + func = IOT_GPIO_FUNC_GPIO_1_GPIO; + break; + case WIFI_IOT_GPIO_IDX_2: + func = IOT_GPIO_FUNC_GPIO_2_GPIO; + break; + case WIFI_IOT_GPIO_IDX_3: + func = IOT_GPIO_FUNC_GPIO_3_GPIO; + break; + case WIFI_IOT_GPIO_IDX_4: + func = IOT_GPIO_FUNC_GPIO_4_GPIO; + break; + case WIFI_IOT_GPIO_IDX_5: + func = IOT_GPIO_FUNC_GPIO_5_GPIO; + break; + case WIFI_IOT_GPIO_IDX_6: + func = IOT_GPIO_FUNC_GPIO_6_GPIO; + break; + case WIFI_IOT_GPIO_IDX_7: + func = IOT_GPIO_FUNC_GPIO_7_GPIO; + break; + case WIFI_IOT_GPIO_IDX_8: + func = IOT_GPIO_FUNC_GPIO_8_GPIO; + break; + case WIFI_IOT_GPIO_IDX_9: + func = IOT_GPIO_FUNC_GPIO_9_GPIO; + break; + case WIFI_IOT_GPIO_IDX_10: + func = IOT_GPIO_FUNC_GPIO_10_GPIO; + break; + case WIFI_IOT_GPIO_IDX_11: + func = IOT_GPIO_FUNC_GPIO_11_GPIO; + break; + case WIFI_IOT_GPIO_IDX_12: + func = IOT_GPIO_FUNC_GPIO_12_GPIO; + break; + case WIFI_IOT_GPIO_IDX_13: + func = IOT_GPIO_FUNC_GPIO_13_GPIO; + break; + case WIFI_IOT_GPIO_IDX_14: + func = IOT_GPIO_FUNC_GPIO_14_GPIO; + break; + default: + IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); + return KP_ERR_FAILURE; + } + + return KP_ERR_SUCCESS; +} + +/* 通过GPIO引脚号获取GPIO功能编号 */ +u32 Gpio2Uart(u32 gpio, u8 *func, u32 *uartId) +{ + u32 ret = KP_ERR_SUCCESS; + + /* 根据引脚号确定引脚GPIO功能编号 */ + switch (gpio) + { + case WIFI_IOT_GPIO_IDX_0: + func = IOT_GPIO_FUNC_GPIO_0_UART1_TXD; + uartId = IOT_UART_IDX_1; + break; + case WIFI_IOT_GPIO_IDX_1: + func = IOT_GPIO_FUNC_GPIO_1_UART1_RXD; + uartId = IOT_UART_IDX_1; + break; + case WIFI_IOT_GPIO_IDX_3: + func = IOT_GPIO_FUNC_GPIO_3_UART0_TXD; + uartId = IOT_UART_IDX_0; + break; + case WIFI_IOT_GPIO_IDX_4: + func = IOT_GPIO_FUNC_GPIO_4_UART0_RXD; + uartId = IOT_UART_IDX_0; + break; + case WIFI_IOT_GPIO_IDX_5: + func = IOT_GPIO_FUNC_GPIO_5_UART1_RXD; + uartId = IOT_UART_IDX_1; + break; + case WIFI_IOT_GPIO_IDX_6: + func = IOT_GPIO_FUNC_GPIO_6_UART1_TXD; + uartId = IOT_UART_IDX_1; + break; + case WIFI_IOT_GPIO_IDX_11: + func = IOT_GPIO_FUNC_GPIO_11_UART2_TXD; + uartId = IOT_UART_IDX_2; + break; + case WIFI_IOT_GPIO_IDX_12: + func = IOT_GPIO_FUNC_GPIO_12_UART2_RXD; + uartId = IOT_UART_IDX_2; + break; + case WIFI_IOT_GPIO_IDX_13: + func = IOT_GPIO_FUNC_GPIO_13_UART0_TXD; + uartId = IOT_UART_IDX_0; + break; + case WIFI_IOT_GPIO_IDX_14: + func = IOT_GPIO_FUNC_GPIO_14_UART0_RXD; + uartId = IOT_UART_IDX_0; + break; + default: + IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); + return KP_ERR_FAILURE; + } + + return KP_ERR_SUCCESS; +} + +/* 通过GPIO引脚号获取SPI功能编号 */ +u32 Gpio2Spi(u32 gpio, u8 *func, u32 *spiId) +{ + u32 ret = KP_ERR_SUCCESS; + + /* 根据引脚号确定引脚GPIO功能编号 */ + switch (gpio) + { + case WIFI_IOT_GPIO_IDX_0: + func = IOT_GPIO_FUNC_GPIO_0_SPI1_CK; + spiId = IOT_SPI_ID_1; + break; + case WIFI_IOT_GPIO_IDX_1: + func = IOT_GPIO_FUNC_GPIO_1_SPI1_RXD; + spiId = IOT_SPI_ID_1; + break; + case WIFI_IOT_GPIO_IDX_2: + func = IOT_GPIO_FUNC_GPIO_2_SPI1_TXD; + spiId = IOT_SPI_ID_1; + break; + case WIFI_IOT_GPIO_IDX_3: + func = IOT_GPIO_FUNC_GPIO_3_SPI1_CSN; + spiId = IOT_SPI_ID_1; + break; + case WIFI_IOT_GPIO_IDX_5: + func = IOT_GPIO_FUNC_GPIO_5_SPI0_CSN; + spiId = IOT_SPI_ID_0; + break; + case WIFI_IOT_GPIO_IDX_6: + func = IOT_GPIO_FUNC_GPIO_6_SPI0_CK; + spiId = IOT_SPI_ID_0; + break; + case WIFI_IOT_GPIO_IDX_7: + func = IOT_GPIO_FUNC_GPIO_7_SPI0_RXD; + spiId = IOT_SPI_ID_0; + break; + case WIFI_IOT_GPIO_IDX_8: + func = IOT_GPIO_FUNC_GPIO_8_SPI0_TXD; + spiId = IOT_SPI_ID_0; + break; + case WIFI_IOT_GPIO_IDX_9: + func = IOT_GPIO_FUNC_GPIO_9_SPI0_TXD; + spiId = IOT_SPI_ID_0; + break; + case WIFI_IOT_GPIO_IDX_10: + func = IOT_GPIO_FUNC_GPIO_10_SPI0_CK; + spiId = IOT_SPI_ID_0; + break; + case WIFI_IOT_GPIO_IDX_11: + func = IOT_GPIO_FUNC_GPIO_11_SPI0_RXD; + spiId = IOT_SPI_ID_0; + break; + case WIFI_IOT_GPIO_IDX_12: + func = IOT_GPIO_FUNC_GPIO_12_SPI0_CSN; + spiId = IOT_SPI_ID_0; + break; + default: + IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); + return KP_ERR_FAILURE; + } + + return KP_ERR_SUCCESS; +} + +/* 通过GPIO引脚号获取PWM功能编号 */ +u32 Gpio2Pwm(u32 gpio, u8 *func, u32 *pwmId) +{ + u32 ret = KP_ERR_SUCCESS; + + /* 根据引脚号确定引脚GPIO功能编号 */ + switch (gpio) + { + case WIFI_IOT_GPIO_IDX_0: + func = IOT_GPIO_FUNC_GPIO_0_PWM3_OUT; + pwmId = PWM_PORT_PWM3; + break; + case WIFI_IOT_GPIO_IDX_1: + func = IOT_GPIO_FUNC_GPIO_1_PWM4_OUT; + pwmId = PWM_PORT_PWM4; + break; + case WIFI_IOT_GPIO_IDX_2: + func = IOT_GPIO_FUNC_GPIO_2_PWM2_OUT; + pwmId = PWM_PORT_PWM2; + break; + case WIFI_IOT_GPIO_IDX_3: + func = IOT_GPIO_FUNC_GPIO_3_PWM5_OUT; + pwmId = PWM_PORT_PWM5; + break; + case WIFI_IOT_GPIO_IDX_4: + func = IOT_GPIO_FUNC_GPIO_4_PWM1_OUT; + pwmId = PWM_PORT_PWM1; + break; + case WIFI_IOT_GPIO_IDX_5: + func = IOT_GPIO_FUNC_GPIO_5_PWM2_OUT; + pwmId = PWM_PORT_PWM2; + break; + case WIFI_IOT_GPIO_IDX_6: + func = IOT_GPIO_FUNC_GPIO_6_PWM3_OUT; + pwmId = PWM_PORT_PWM3; + break; + case WIFI_IOT_GPIO_IDX_7: + func = IOT_GPIO_FUNC_GPIO_7_PWM0_OUT; + pwmId = PWM_PORT_PWM0; + break; + case WIFI_IOT_GPIO_IDX_8: + func = IOT_GPIO_FUNC_GPIO_8_PWM1_OUT; + pwmId = PWM_PORT_PWM1; + break; + case WIFI_IOT_GPIO_IDX_9: + func = IOT_GPIO_FUNC_GPIO_9_PWM0_OUT; + pwmId = PWM_PORT_PWM0; + break; + case WIFI_IOT_GPIO_IDX_10: + func = IOT_GPIO_FUNC_GPIO_10_PWM1_OUT; + pwmId = PWM_PORT_PWM1; + break; + case WIFI_IOT_GPIO_IDX_11: + func = IOT_GPIO_FUNC_GPIO_11_PWM2_OUT; + pwmId = PWM_PORT_PWM2; + break; + case WIFI_IOT_GPIO_IDX_12: + func = IOT_GPIO_FUNC_GPIO_12_PWM3_OUT; + pwmId = PWM_PORT_PWM3; + break; + case WIFI_IOT_GPIO_IDX_13: + func = IOT_GPIO_FUNC_GPIO_13_PWM4_OUT; + pwmId = PWM_PORT_PWM4; + break; + case WIFI_IOT_GPIO_IDX_14: + func = IOT_GPIO_FUNC_GPIO_14_PWM5_OUT; + pwmId = PWM_PORT_PWM5; + break; + default: + IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); + return KP_ERR_FAILURE; + } + + return KP_ERR_SUCCESS; +} + +/* 通过GPIO引脚号获取IIC功能编号 */ +u32 Gpio2IIC(u32 gpio, u8 *func, u32 *i2cId) +{ + u32 ret = KP_ERR_SUCCESS; + + /* 根据引脚号确定引脚GPIO功能编号 */ + switch (gpio) + { + case WIFI_IOT_GPIO_IDX_0: + func = IOT_GPIO_FUNC_GPIO_0_I2C1_SDA; + i2cId = IOT_I2C_IDX_1; + break; + case WIFI_IOT_GPIO_IDX_1: + func = IOT_GPIO_FUNC_GPIO_1_I2C1_SCL; + i2cId = IOT_I2C_IDX_1; + break; + case WIFI_IOT_GPIO_IDX_3: + func = IOT_GPIO_FUNC_GPIO_3_I2C1_SDA; + i2cId = IOT_I2C_IDX_1; + break; + case WIFI_IOT_GPIO_IDX_4: + func = IOT_GPIO_FUNC_GPIO_4_I2C1_SCL; + i2cId = IOT_I2C_IDX_1; + break; + case WIFI_IOT_GPIO_IDX_9: + func = IOT_GPIO_FUNC_GPIO_9_I2C0_SCL; + i2cId = IOT_I2C_IDX_0; + break; + case WIFI_IOT_GPIO_IDX_10: + func = IOT_GPIO_FUNC_GPIO_10_I2C0_SDA; + i2cId = IOT_I2C_IDX_0; + break; + case WIFI_IOT_GPIO_IDX_13: + func = IOT_GPIO_FUNC_GPIO_13_I2C0_SDA; + i2cId = IOT_I2C_IDX_0; + break; + case WIFI_IOT_GPIO_IDX_14: + func = IOT_GPIO_FUNC_GPIO_14_I2C0_SCL; + i2cId = IOT_I2C_IDX_0; + break; + default: + IOT_PRINTF_FUNC("Invalid gpio :%d \r\n", gpio); + return KP_ERR_FAILURE; + } + + return KP_ERR_SUCCESS; +} + + diff --git a/common/iot_gpio_interface/iot_gpio_i2c.c b/common/iot_gpio_interface/iot_gpio_i2c.c index d93e96c6b97add4b672c1eb2287ea517112eb513..1d488536bd7000d2fe3473ce85441c75110f3f4a 100644 --- a/common/iot_gpio_interface/iot_gpio_i2c.c +++ b/common/iot_gpio_interface/iot_gpio_i2c.c @@ -1,66 +1,66 @@ -#include "wifiiot_gpio.h" -#include "iot_gpio.h" -#include "iot_gpio_ex.h" -#include "iot_i2c.h" -#include "iot_gpio_i2c.h" -#include "iot_gpio_func.h" - - -/* GPIO初始化复用为IIC功能 */ -u32 GpioInitIIC(u32 pinSDA, u32 pinSCL, u32 baud) -{ - /* 根据输入参数GPIO引脚号初始化 */ - u32 ret = IoTGpioInit(pinSDA); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTGpioInit failed :%#x \r\n", ret); - return ret; - } - - /* 根据引脚号确定引脚IIC功能配置值及IIC端口号 */ - u8 sdaFunc = 0; - u32 i2cPort = 0; - ret = Gpio2IIC(pinSDA, &sdaFunc, &i2cPort); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("Gpio2IIC failed :%#x \r\n", ret); +#include "wifiiot_gpio.h" +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "iot_i2c.h" +#include "iot_gpio_i2c.h" +#include "iot_gpio_func.h" + + +/* GPIO初始化复用为IIC功能 */ +u32 GpioInitIIC(u32 pinSDA, u32 pinSCL, u32 baud) +{ + /* 根据输入参数GPIO引脚号初始化 */ + u32 ret = IoTGpioInit(pinSDA); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTGpioInit failed :%#x \r\n", ret); + return ret; + } + + /* 根据引脚号确定引脚IIC功能配置值及IIC端口号 */ + u8 sdaFunc = 0; + u32 i2cPort = 0; + ret = Gpio2IIC(pinSDA, &sdaFunc, &i2cPort); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("Gpio2IIC failed :%#x \r\n", ret); return ret; - } - - /* 设置复用为IIC功能 */ - ret = IoTGpioSetFunc(pinSDA, sdaFunc); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTGpioSetFunc failed :%#x \r\n", ret); + } + + /* 设置复用为IIC功能 */ + ret = IoTGpioSetFunc(pinSDA, sdaFunc); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTGpioSetFunc failed :%#x \r\n", ret); + return ret; + } + + /* 根据引脚号确定引脚IIC功能配置值及IIC端口号 */ + u8 sclFunc = 0; + ret = Gpio2IIC(pinSCL, &sclFunc, &i2cPort); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("Gpio2IIC failed :%#x \r\n", ret); return ret; - } - - /* 根据引脚号确定引脚IIC功能配置值及IIC端口号 */ - u8 sclFunc = 0; - ret = Gpio2IIC(pinSCL, &sclFunc, &i2cPort); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("Gpio2IIC failed :%#x \r\n", ret); - return ret; - } - + } + /* 设置复用为IIC功能 */ - ret = IoTGpioSetFunc(pinSCL, sclFunc); + ret = IoTGpioSetFunc(pinSCL, sclFunc); if(ret != 0){ - IOT_PRINTF_FUNC("IoTGpioSetFunc failed :%#x \r\n", ret); - return ret; + IOT_PRINTF_FUNC("IoTGpioSetFunc failed :%#x \r\n", ret); + return ret; } /* IIC初始化 */ - ret = IoTI2cInit(i2cPort, baud); - if (ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("IoTI2cInit failed :%#x \r\n", ret); - return ret; + ret = IoTI2cInit(i2cPort, baud); + if (ret != KP_ERR_SUCCESS) { + IOT_PRINTF_FUNC("IoTI2cInit failed :%#x \r\n", ret); + return ret; } /* IIC设置波特率 */ - ret = IoTI2cSetBaudrate(i2cPort, baud); - if (ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("IoTI2cSetBaudrate failed :%#x \r\n", ret); - return ret; - } - - return KP_ERR_SUCCESS; -} - + ret = IoTI2cSetBaudrate(i2cPort, baud); + if (ret != KP_ERR_SUCCESS) { + IOT_PRINTF_FUNC("IoTI2cSetBaudrate failed :%#x \r\n", ret); + return ret; + } + + return KP_ERR_SUCCESS; +} + diff --git a/common/iot_gpio_interface/iot_gpio_i2c.h b/common/iot_gpio_interface/iot_gpio_i2c.h index cdc7e77843e5f5fc4cecbc569b7415a6401f2243..aabba670a8a653ae4ac7abe2e1401ddf84fc9454 100644 --- a/common/iot_gpio_interface/iot_gpio_i2c.h +++ b/common/iot_gpio_interface/iot_gpio_i2c.h @@ -1,13 +1,13 @@ -#ifndef __IOT_GPIO_IIC_H__ -#define __IOT_GPIO_IIC_H__ - -#include "iot_base_type.h" - - -/* GPIO初始化复用为IIC功能 */ -u32 GpioInitIIC(u32 pinSDA, u32 pinSCL, u32 baud); - - - -#endif - +#ifndef __IOT_GPIO_IIC_H__ +#define __IOT_GPIO_IIC_H__ + +#include "iot_base_type.h" + + +/* GPIO初始化复用为IIC功能 */ +u32 GpioInitIIC(u32 pinSDA, u32 pinSCL, u32 baud); + + + +#endif + diff --git a/common/iot_gpio_interface/iot_gpio_pwm.c b/common/iot_gpio_interface/iot_gpio_pwm.c index a17732e594d1a15d2af2447a842dec7ca9928c45..55625b83c71f27e97ee40f81c932e5d68761cb58 100644 --- a/common/iot_gpio_interface/iot_gpio_pwm.c +++ b/common/iot_gpio_interface/iot_gpio_pwm.c @@ -1,86 +1,86 @@ -#include "wifiiot_gpio.h" -#include "iot_gpio.h" -#include "iot_gpio_ex.h" -#include "iot_pwm.h" -#include "iot_gpio_pwm.h" -#include "iot_gpio_func.h" - - -/* GPIO初始化复用为PWM功能 */ -u32 GpioInitPwm(u32 pin) -{ - /* 根据输入参数GPIO引脚号初始化 */ - u32 ret = IoTGpioInit(pin); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTGpioInit failed :%#x \r\n", ret); +#include "wifiiot_gpio.h" +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "iot_pwm.h" +#include "iot_gpio_pwm.h" +#include "iot_gpio_func.h" + + +/* GPIO初始化复用为PWM功能 */ +u32 GpioInitPwm(u32 pin) +{ + /* 根据输入参数GPIO引脚号初始化 */ + u32 ret = IoTGpioInit(pin); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTGpioInit failed :%#x \r\n", ret); + return ret; + } + + /* 根据引脚号确定引脚PWM功能配置值及PWM端口号 */ + u8 pwmFunc = 0; + u32 pwmPort = 0; + ret = Gpio2Pwm(pin, &pwmFunc, &pwmPort); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("Gpio2Pwm failed :%#x \r\n", ret); return ret; - } - - /* 根据引脚号确定引脚PWM功能配置值及PWM端口号 */ - u8 pwmFunc = 0; - u32 pwmPort = 0; - ret = Gpio2Pwm(pin, &pwmFunc, &pwmPort); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("Gpio2Pwm failed :%#x \r\n", ret); - return ret; - } - - /* 设置复用为PWM功能 */ - ret = IoTGpioSetFunc(pin, pwmFunc); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTGpioSetFunc failed :%#x \r\n", ret); - return ret; - } - - /* PWM初始化 */ - ret = IoTPwmDeinit(pwmPort); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTPwmDeinit failed :%#x \r\n", ret); - return ret; - } - - ret = IoTPwmInit(pwmPort); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTPwmInit failed :%#x \r\n", ret); - return ret; - } - - return KP_ERR_SUCCESS; -} - -/* PWM控制 */ -u32 GpioCtrlPwm(u32 pwmPort, u32 state, u16 duty, u32 freq) -{ - u32 ret = KP_ERR_SUCCESS; - - switch (state) { - case PWM_OUT_START: - { - /* PWM控制启动 */ - ret = IoTPwmStart(pwmPort, duty, freq); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTPwmStart failed :%#x \r\n", ret); - return ret; - } - break; - } - case PWM_OUT_STOP: - { - /* PWM控制停止 */ - ret = IoTPwmStop(pwmPort); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTPwmStop failed :%#x \r\n", ret); - return ret; - } - break; - } - default: - { - IOT_PRINTF_FUNC("Invalid state :%d \r\n", state); - return KP_ERR_FAILURE; - } - } - - return KP_ERR_SUCCESS; -} - + } + + /* 设置复用为PWM功能 */ + ret = IoTGpioSetFunc(pin, pwmFunc); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTGpioSetFunc failed :%#x \r\n", ret); + return ret; + } + + /* PWM初始化 */ + ret = IoTPwmDeinit(pwmPort); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTPwmDeinit failed :%#x \r\n", ret); + return ret; + } + + ret = IoTPwmInit(pwmPort); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTPwmInit failed :%#x \r\n", ret); + return ret; + } + + return KP_ERR_SUCCESS; +} + +/* PWM控制 */ +u32 GpioCtrlPwm(u32 pwmPort, u32 state, u16 duty, u32 freq) +{ + u32 ret = KP_ERR_SUCCESS; + + switch (state) { + case PWM_OUT_START: + { + /* PWM控制启动 */ + ret = IoTPwmStart(pwmPort, duty, freq); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTPwmStart failed :%#x \r\n", ret); + return ret; + } + break; + } + case PWM_OUT_STOP: + { + /* PWM控制停止 */ + ret = IoTPwmStop(pwmPort); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTPwmStop failed :%#x \r\n", ret); + return ret; + } + break; + } + default: + { + IOT_PRINTF_FUNC("Invalid state :%d \r\n", state); + return KP_ERR_FAILURE; + } + } + + return KP_ERR_SUCCESS; +} + diff --git a/common/iot_gpio_interface/iot_gpio_pwm.h b/common/iot_gpio_interface/iot_gpio_pwm.h index 41ae1dcc5e21089a701e1c25d7f7b272bb5297fb..95002cc2ac06df9c18e498f47bd89407560980dd 100644 --- a/common/iot_gpio_interface/iot_gpio_pwm.h +++ b/common/iot_gpio_interface/iot_gpio_pwm.h @@ -1,16 +1,16 @@ -#ifndef __IOT_GPIO_PWM_H__ -#define __IOT_GPIO_PWM_H__ - -#include "iot_base_type.h" - - -/* GPIO初始化复用为PWM功能 */ -u32 GpioInitPwm(u32 pin); - -/* PWM控制 */ -u32 GpioCtrlPwm(u32 pwmPort, u32 state, u16 duty, u32 freq); - - - -#endif - +#ifndef __IOT_GPIO_PWM_H__ +#define __IOT_GPIO_PWM_H__ + +#include "iot_base_type.h" + + +/* GPIO初始化复用为PWM功能 */ +u32 GpioInitPwm(u32 pin); + +/* PWM控制 */ +u32 GpioCtrlPwm(u32 pwmPort, u32 state, u16 duty, u32 freq); + + + +#endif + diff --git a/common/iot_led/led_pwm.c b/common/iot_led/led_pwm.c index 40c0008051e58fae23b936b1c7d084de6b5f72eb..1613699cbfa769290cc31b90187314da011c7870 100644 --- a/common/iot_led/led_pwm.c +++ b/common/iot_led/led_pwm.c @@ -1,137 +1,137 @@ -#include -#include "ohos_init.h" -#include "cmsis_os2.h" -#include "iot_pwm.h" -#include "wifiiot_gpio.h" -#include "iot_gpio.h" -#include "iot_gpio_ex.h" -#include "led_pwm.h" - -#define LED_FREQ 64000 -#define LED_DUTY 100 - -static unsigned int spwmPort = 0; - - -/* 初始化LED模块 */ -u32 LedPwmInit(u32 pin) -{ - /* LED灯根据输入参数GPIO引脚初始化 */ - u32 ret = IoTGpioInit(pin); - if(ret != 0){ - printf("IoTGpioInit failed :%#x \r\n",ret); - return ret; - } - - /* 根据引脚号确定引脚PWM功能配置值及PWM端口号 */ - u8 pinFunc = 0; - switch (pin) - { - case WIFI_IOT_GPIO_IDX_0: - pinFunc = IOT_GPIO_FUNC_GPIO_0_PWM3_OUT; - spwmPort = PWM_PORT_PWM3; - break; - case WIFI_IOT_GPIO_IDX_1: - pinFunc = IOT_GPIO_FUNC_GPIO_1_PWM4_OUT; - spwmPort = PWM_PORT_PWM4; - break; - case WIFI_IOT_GPIO_IDX_2: - pinFunc = IOT_GPIO_FUNC_GPIO_2_PWM2_OUT; - spwmPort = PWM_PORT_PWM2; - break; - case WIFI_IOT_GPIO_IDX_3: - pinFunc = IOT_GPIO_FUNC_GPIO_3_PWM5_OUT; - spwmPort = PWM_PORT_PWM5; - break; - case WIFI_IOT_GPIO_IDX_4: - pinFunc = IOT_GPIO_FUNC_GPIO_4_PWM1_OUT; - spwmPort = PWM_PORT_PWM1; - break; - case WIFI_IOT_GPIO_IDX_5: - pinFunc = IOT_GPIO_FUNC_GPIO_5_PWM2_OUT; - spwmPort = PWM_PORT_PWM2; - break; - case WIFI_IOT_GPIO_IDX_6: - pinFunc = IOT_GPIO_FUNC_GPIO_6_PWM3_OUT; - spwmPort = PWM_PORT_PWM3; - break; - case WIFI_IOT_GPIO_IDX_7: - pinFunc = IOT_GPIO_FUNC_GPIO_7_PWM0_OUT; - spwmPort = PWM_PORT_PWM0; - break; - case WIFI_IOT_GPIO_IDX_8: - pinFunc = IOT_GPIO_FUNC_GPIO_8_PWM1_OUT; - spwmPort = PWM_PORT_PWM1; - break; - case WIFI_IOT_GPIO_IDX_9: - pinFunc = IOT_GPIO_FUNC_GPIO_9_PWM0_OUT; - spwmPort = PWM_PORT_PWM0; - break; - case WIFI_IOT_GPIO_IDX_10: - pinFunc = IOT_GPIO_FUNC_GPIO_10_PWM1_OUT; - spwmPort = PWM_PORT_PWM1; - break; - case WIFI_IOT_GPIO_IDX_11: - pinFunc = IOT_GPIO_FUNC_GPIO_11_PWM2_OUT; - spwmPort = PWM_PORT_PWM2; - break; - case WIFI_IOT_GPIO_IDX_12: - pinFunc = IOT_GPIO_FUNC_GPIO_12_PWM3_OUT; - spwmPort = PWM_PORT_PWM3; - break; - case WIFI_IOT_GPIO_IDX_13: - pinFunc = IOT_GPIO_FUNC_GPIO_13_PWM4_OUT; - spwmPort = PWM_PORT_PWM4; - break; - case WIFI_IOT_GPIO_IDX_14: - pinFunc = IOT_GPIO_FUNC_GPIO_14_PWM5_OUT; - spwmPort = PWM_PORT_PWM5; - break; - default: - return KP_ERR_FAILURE; - } - - /* 设置复用为PWM功能 */ - ret = IoTGpioSetFunc(pin, pinFunc); - if(ret != 0){ - printf("IoTGpioSetFunc failed :%#x \r\n",ret); - return ret; - } - - /* PWM初始化 */ - ret = IoTPwmDeinit(spwmPort); - if(ret != 0){ - printf("IoTPwmDeinit failed :%#x \r\n",ret); - return ret; - } - - ret = IoTPwmInit(spwmPort); - if(ret != 0){ - printf("IoTPwmInit failed :%#x \r\n",ret); - return ret; - } -} - -void LedPwmCtrl(unsigned int status) -{ - switch (status) { - case LED_ON: - IoTPwmStart(spwmPort, LED_DUTY, LED_FREQ); - break; - case LED_OFF: - IoTPwmStop(spwmPort); - break; - case LED_SPARK: - IoTPwmStart(spwmPort, LED_DUTY, LED_FREQ); - osDelay(LED_SPARK_INTERVAL_TIME); - IoTPwmStop(spwmPort); - osDelay(LED_SPARK_INTERVAL_TIME); - break; - default: - osDelay(LED_SPARK_INTERVAL_TIME); - break; - } - - return; -} - +#include +#include "ohos_init.h" +#include "cmsis_os2.h" +#include "iot_pwm.h" +#include "wifiiot_gpio.h" +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "led_pwm.h" + +#define LED_FREQ 64000 +#define LED_DUTY 100 + +static unsigned int spwmPort = 0; + + +/* 初始化LED模块 */ +u32 LedPwmInit(u32 pin) +{ + /* LED灯根据输入参数GPIO引脚初始化 */ + u32 ret = IoTGpioInit(pin); + if(ret != 0){ + printf("IoTGpioInit failed :%#x \r\n",ret); + return ret; + } + + /* 根据引脚号确定引脚PWM功能配置值及PWM端口号 */ + u8 pinFunc = 0; + switch (pin) + { + case WIFI_IOT_GPIO_IDX_0: + pinFunc = IOT_GPIO_FUNC_GPIO_0_PWM3_OUT; + spwmPort = PWM_PORT_PWM3; + break; + case WIFI_IOT_GPIO_IDX_1: + pinFunc = IOT_GPIO_FUNC_GPIO_1_PWM4_OUT; + spwmPort = PWM_PORT_PWM4; + break; + case WIFI_IOT_GPIO_IDX_2: + pinFunc = IOT_GPIO_FUNC_GPIO_2_PWM2_OUT; + spwmPort = PWM_PORT_PWM2; + break; + case WIFI_IOT_GPIO_IDX_3: + pinFunc = IOT_GPIO_FUNC_GPIO_3_PWM5_OUT; + spwmPort = PWM_PORT_PWM5; + break; + case WIFI_IOT_GPIO_IDX_4: + pinFunc = IOT_GPIO_FUNC_GPIO_4_PWM1_OUT; + spwmPort = PWM_PORT_PWM1; + break; + case WIFI_IOT_GPIO_IDX_5: + pinFunc = IOT_GPIO_FUNC_GPIO_5_PWM2_OUT; + spwmPort = PWM_PORT_PWM2; + break; + case WIFI_IOT_GPIO_IDX_6: + pinFunc = IOT_GPIO_FUNC_GPIO_6_PWM3_OUT; + spwmPort = PWM_PORT_PWM3; + break; + case WIFI_IOT_GPIO_IDX_7: + pinFunc = IOT_GPIO_FUNC_GPIO_7_PWM0_OUT; + spwmPort = PWM_PORT_PWM0; + break; + case WIFI_IOT_GPIO_IDX_8: + pinFunc = IOT_GPIO_FUNC_GPIO_8_PWM1_OUT; + spwmPort = PWM_PORT_PWM1; + break; + case WIFI_IOT_GPIO_IDX_9: + pinFunc = IOT_GPIO_FUNC_GPIO_9_PWM0_OUT; + spwmPort = PWM_PORT_PWM0; + break; + case WIFI_IOT_GPIO_IDX_10: + pinFunc = IOT_GPIO_FUNC_GPIO_10_PWM1_OUT; + spwmPort = PWM_PORT_PWM1; + break; + case WIFI_IOT_GPIO_IDX_11: + pinFunc = IOT_GPIO_FUNC_GPIO_11_PWM2_OUT; + spwmPort = PWM_PORT_PWM2; + break; + case WIFI_IOT_GPIO_IDX_12: + pinFunc = IOT_GPIO_FUNC_GPIO_12_PWM3_OUT; + spwmPort = PWM_PORT_PWM3; + break; + case WIFI_IOT_GPIO_IDX_13: + pinFunc = IOT_GPIO_FUNC_GPIO_13_PWM4_OUT; + spwmPort = PWM_PORT_PWM4; + break; + case WIFI_IOT_GPIO_IDX_14: + pinFunc = IOT_GPIO_FUNC_GPIO_14_PWM5_OUT; + spwmPort = PWM_PORT_PWM5; + break; + default: + return KP_ERR_FAILURE; + } + + /* 设置复用为PWM功能 */ + ret = IoTGpioSetFunc(pin, pinFunc); + if(ret != 0){ + printf("IoTGpioSetFunc failed :%#x \r\n",ret); + return ret; + } + + /* PWM初始化 */ + ret = IoTPwmDeinit(spwmPort); + if(ret != 0){ + printf("IoTPwmDeinit failed :%#x \r\n",ret); + return ret; + } + + ret = IoTPwmInit(spwmPort); + if(ret != 0){ + printf("IoTPwmInit failed :%#x \r\n",ret); + return ret; + } +} + +void LedPwmCtrl(unsigned int status) +{ + switch (status) { + case LED_ON: + IoTPwmStart(spwmPort, LED_DUTY, LED_FREQ); + break; + case LED_OFF: + IoTPwmStop(spwmPort); + break; + case LED_SPARK: + IoTPwmStart(spwmPort, LED_DUTY, LED_FREQ); + osDelay(LED_SPARK_INTERVAL_TIME); + IoTPwmStop(spwmPort); + osDelay(LED_SPARK_INTERVAL_TIME); + break; + default: + osDelay(LED_SPARK_INTERVAL_TIME); + break; + } + + return; +} + diff --git a/common/iot_led/led_pwm.h b/common/iot_led/led_pwm.h index 7b7a3dc8b3d8afdb434b82a4bcf53425940f023d..39216ce4d9688bf96cf8f8e2af33245cbe67d53b 100644 --- a/common/iot_led/led_pwm.h +++ b/common/iot_led/led_pwm.h @@ -1,11 +1,11 @@ -#ifndef __LED_PWM_H__ -#define __LED_PWM_H__ - -#include "iot_base_type.h" - -/* 初始化LED模块 */ -u32 LedPwmInit(u32 pin); -void LedPwmCtrl(unsigned int status); - -#endif - +#ifndef __LED_PWM_H__ +#define __LED_PWM_H__ + +#include "iot_base_type.h" + +/* 初始化LED模块 */ +u32 LedPwmInit(u32 pin); +void LedPwmCtrl(unsigned int status); + +#endif + diff --git a/common/iot_list/iot_list.c b/common/iot_list/iot_list.c index a3d60399e2c18af84d070142a5e95d04cfdf83e3..800c5587724d758a8e59fe3a97b9289102454629 100644 --- a/common/iot_list/iot_list.c +++ b/common/iot_list/iot_list.c @@ -1,286 +1,286 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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 "iot_list.h" - -#define LIST_DEBUG -#ifdef LIST_DEBUG -#define LST_DBG(fmt, args...) printf("[LIST_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) -#define LST_ERR(fmt, args...) printf("[LIST_ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) -#else -#define LST_DBG(fmt, args...) do {} while (0) -#define LST_ERR(fmt, args...) do {} while (0) -#endif - -typedef struct __ListNode { - void *data; - int size; - struct __ListNode *prev; - struct __ListNode *next; -} ListNode; - -typedef struct { - ListNode *head, *tail; - int total; -} DLinkList; - -static ListNode *ListNodeCreate(void *data, int size) -{ - ListNode *pNode = NULL; - if (data == NULL || size <= 0) { - LST_ERR("NULL POINT!\n"); - return pNode; - } - - pNode = (ListNode *)malloc(sizeof(ListNode)); - if (pNode == NULL) { - LST_ERR("OOM!\n"); - return NULL; - } - - pNode->data = malloc(size); - if (pNode->data == NULL) { - LST_ERR("OOM!\n"); - free(pNode); - return NULL; - } - - memcpy(pNode->data, data, size); - pNode->size = size; - pNode->prev = NULL; - pNode->next = NULL; - - return pNode; -} - -static void ListNodeDestroy(ListNode *pNode) -{ - if (pNode == NULL) { - return; - } - if (pNode->data) { - free(pNode->data); - pNode->data = NULL; - } - free(pNode); -} - -static ListNode *ListNodeSearch(ListNode *head, int idx) -{ - ListNode *pNode = head; - for (int i = 0; i < idx; i++) { - if (pNode == NULL) { - break; - } - pNode = pNode->next; - } - - return pNode; -} - -static ListNode *ListNodeSearchData(ListNode *head, void *data) -{ - ListNode *pNode = head; - - while (pNode != NULL) { - if (memcmp(pNode->data, data, pNode->size) == 0) { - break; - } - pNode = pNode->next; - } - - return pNode; -} - -IOT_LIST IoT_ListCreate(void *data, int size) -{ - ListNode *pNode = NULL; - DLinkList *list = (DLinkList *)malloc(sizeof(DLinkList)); - if (list == NULL) { - LST_ERR("OOM!\n"); - return NULL; - } - - pNode = ListNodeCreate(data, size); - if (pNode != NULL) { - list->total = 1; - } else { - list->total = 0; - } - list->head = list->tail = pNode; - - return (DLinkList *)list; -} - -int IoT_ListAppend(IOT_LIST mHandle, void *data, int size) -{ - ListNode *pNode = NULL; - DLinkList *list = (DLinkList *)mHandle; - if (list == NULL) { - LST_ERR("NULL POINT! \n"); - return -1; - } - - pNode = ListNodeCreate(data, size); - if (pNode == NULL) { - LST_ERR("ListNodeCreate failed! \n"); - return -1; - } - - if (list->head == NULL) { - list->head = list->tail = pNode; - } else { - list->tail->next = pNode; - pNode->prev = list->tail; - list->tail = pNode; - } - - list->total++; - - return 0; -} - -int IoT_ListUpdate(IOT_LIST mHandle, int idx, void *data, int size) -{ - int retval = 0; - ListNode *pNode = NULL; - DLinkList *list = (DLinkList *)mHandle; - if (list == NULL || data == NULL) { - LST_ERR("NULL POINT! \n"); - return -1; - } - - pNode = ListNodeSearch(list->head, idx); - if (pNode != NULL) { - if (size != pNode->size) { - pNode->data = realloc(pNode->data, size); - pNode->size = size; - } - memcpy(pNode->data, data, size); - } else { - retval = IoT_ListAppend(mHandle, data, size); - } - - return retval; -} - -int IoT_ListDelete(IOT_LIST mHandle, void *data) -{ - ListNode *pNode = NULL; - ListNode *prev = NULL; - ListNode *next = NULL; - DLinkList *list = (DLinkList *)mHandle; - if (list == NULL || data == NULL) { - LST_ERR("NULL POINT! \n"); - return -1; - } - - pNode = ListNodeSearchData(list->head, data); - if (pNode == NULL) { - return -1; - } - prev = pNode->prev; - next = pNode->next; - - if (prev != NULL && next != NULL){ - prev->next = next; - next->prev = prev; - } else if (prev == NULL && next != NULL) { - next->prev = NULL; - list->head = next; - } else if (prev != NULL && next == NULL) { - prev->next = NULL; - list->tail = prev; - } else { - list->head = list->tail = NULL; - } - pNode->next = NULL; - pNode->prev = NULL; - list->total--; - - ListNodeDestroy(pNode); - pNode = NULL; - - return 0; -} - -int IoT_ListGet(IOT_LIST mHandle, int idx, void *data, int size) -{ - ListNode *pNode; - DLinkList *list = (DLinkList *)mHandle; - if (list == NULL) { - LST_ERR("NULL POINT! \n"); - return -1; - } - - pNode = ListNodeSearch(list->head, idx); - if (pNode == NULL || pNode->data == NULL || data == NULL || size < pNode->size) { - LST_ERR("no such node(%d) \n", idx); - return -1; - } - - memcpy(data, pNode->data, pNode->size); - - return 0; -} - -int IoT_ListGetSize(IOT_LIST mHandle) -{ - if (mHandle == NULL) { - return -1; - } - - return ((DLinkList *)mHandle)->total; -} - -void IoT_ListClear(IOT_LIST mHandle) -{ - DLinkList *list = (DLinkList *)mHandle; - if (list == NULL) { - return; - } - while (list->head) { - ListNode *pNode = list->head; - list->head = pNode->next; - pNode->next = NULL; - list->head->prev = NULL; - - ListNodeDestroy(pNode); - } - list->total = 0; -} - -void IoT_ListDestroy(IOT_LIST mHandle) -{ - DLinkList *list = (DLinkList *)mHandle; - if (list == NULL) { - return; - } - while (list->head) { - ListNode *pNode = list->head; - list->head = pNode->next; - pNode->next = NULL; - list->head->prev = NULL; - - ListNodeDestroy(pNode); - } - list->total = 0; - - free(list); - list = NULL; -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 "iot_list.h" + +#define LIST_DEBUG +#ifdef LIST_DEBUG +#define LST_DBG(fmt, args...) printf("[LIST_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) +#define LST_ERR(fmt, args...) printf("[LIST_ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) +#else +#define LST_DBG(fmt, args...) do {} while (0) +#define LST_ERR(fmt, args...) do {} while (0) +#endif + +typedef struct __ListNode { + void *data; + int size; + struct __ListNode *prev; + struct __ListNode *next; +} ListNode; + +typedef struct { + ListNode *head, *tail; + int total; +} DLinkList; + +static ListNode *ListNodeCreate(void *data, int size) +{ + ListNode *pNode = NULL; + if (data == NULL || size <= 0) { + LST_ERR("NULL POINT!\n"); + return pNode; + } + + pNode = (ListNode *)malloc(sizeof(ListNode)); + if (pNode == NULL) { + LST_ERR("OOM!\n"); + return NULL; + } + + pNode->data = malloc(size); + if (pNode->data == NULL) { + LST_ERR("OOM!\n"); + free(pNode); + return NULL; + } + + memcpy(pNode->data, data, size); + pNode->size = size; + pNode->prev = NULL; + pNode->next = NULL; + + return pNode; +} + +static void ListNodeDestroy(ListNode *pNode) +{ + if (pNode == NULL) { + return; + } + if (pNode->data) { + free(pNode->data); + pNode->data = NULL; + } + free(pNode); +} + +static ListNode *ListNodeSearch(ListNode *head, int idx) +{ + ListNode *pNode = head; + for (int i = 0; i < idx; i++) { + if (pNode == NULL) { + break; + } + pNode = pNode->next; + } + + return pNode; +} + +static ListNode *ListNodeSearchData(ListNode *head, void *data) +{ + ListNode *pNode = head; + + while (pNode != NULL) { + if (memcmp(pNode->data, data, pNode->size) == 0) { + break; + } + pNode = pNode->next; + } + + return pNode; +} + +IOT_LIST IoT_ListCreate(void *data, int size) +{ + ListNode *pNode = NULL; + DLinkList *list = (DLinkList *)malloc(sizeof(DLinkList)); + if (list == NULL) { + LST_ERR("OOM!\n"); + return NULL; + } + + pNode = ListNodeCreate(data, size); + if (pNode != NULL) { + list->total = 1; + } else { + list->total = 0; + } + list->head = list->tail = pNode; + + return (DLinkList *)list; +} + +int IoT_ListAppend(IOT_LIST mHandle, void *data, int size) +{ + ListNode *pNode = NULL; + DLinkList *list = (DLinkList *)mHandle; + if (list == NULL) { + LST_ERR("NULL POINT! \n"); + return -1; + } + + pNode = ListNodeCreate(data, size); + if (pNode == NULL) { + LST_ERR("ListNodeCreate failed! \n"); + return -1; + } + + if (list->head == NULL) { + list->head = list->tail = pNode; + } else { + list->tail->next = pNode; + pNode->prev = list->tail; + list->tail = pNode; + } + + list->total++; + + return 0; +} + +int IoT_ListUpdate(IOT_LIST mHandle, int idx, void *data, int size) +{ + int retval = 0; + ListNode *pNode = NULL; + DLinkList *list = (DLinkList *)mHandle; + if (list == NULL || data == NULL) { + LST_ERR("NULL POINT! \n"); + return -1; + } + + pNode = ListNodeSearch(list->head, idx); + if (pNode != NULL) { + if (size != pNode->size) { + pNode->data = realloc(pNode->data, size); + pNode->size = size; + } + memcpy(pNode->data, data, size); + } else { + retval = IoT_ListAppend(mHandle, data, size); + } + + return retval; +} + +int IoT_ListDelete(IOT_LIST mHandle, void *data) +{ + ListNode *pNode = NULL; + ListNode *prev = NULL; + ListNode *next = NULL; + DLinkList *list = (DLinkList *)mHandle; + if (list == NULL || data == NULL) { + LST_ERR("NULL POINT! \n"); + return -1; + } + + pNode = ListNodeSearchData(list->head, data); + if (pNode == NULL) { + return -1; + } + prev = pNode->prev; + next = pNode->next; + + if (prev != NULL && next != NULL){ + prev->next = next; + next->prev = prev; + } else if (prev == NULL && next != NULL) { + next->prev = NULL; + list->head = next; + } else if (prev != NULL && next == NULL) { + prev->next = NULL; + list->tail = prev; + } else { + list->head = list->tail = NULL; + } + pNode->next = NULL; + pNode->prev = NULL; + list->total--; + + ListNodeDestroy(pNode); + pNode = NULL; + + return 0; +} + +int IoT_ListGet(IOT_LIST mHandle, int idx, void *data, int size) +{ + ListNode *pNode; + DLinkList *list = (DLinkList *)mHandle; + if (list == NULL) { + LST_ERR("NULL POINT! \n"); + return -1; + } + + pNode = ListNodeSearch(list->head, idx); + if (pNode == NULL || pNode->data == NULL || data == NULL || size < pNode->size) { + LST_ERR("no such node(%d) \n", idx); + return -1; + } + + memcpy(data, pNode->data, pNode->size); + + return 0; +} + +int IoT_ListGetSize(IOT_LIST mHandle) +{ + if (mHandle == NULL) { + return -1; + } + + return ((DLinkList *)mHandle)->total; +} + +void IoT_ListClear(IOT_LIST mHandle) +{ + DLinkList *list = (DLinkList *)mHandle; + if (list == NULL) { + return; + } + while (list->head) { + ListNode *pNode = list->head; + list->head = pNode->next; + pNode->next = NULL; + list->head->prev = NULL; + + ListNodeDestroy(pNode); + } + list->total = 0; +} + +void IoT_ListDestroy(IOT_LIST mHandle) +{ + DLinkList *list = (DLinkList *)mHandle; + if (list == NULL) { + return; + } + while (list->head) { + ListNode *pNode = list->head; + list->head = pNode->next; + pNode->next = NULL; + list->head->prev = NULL; + + ListNodeDestroy(pNode); + } + list->total = 0; + + free(list); + list = NULL; +} diff --git a/common/iot_list/iot_store_manager.c b/common/iot_list/iot_store_manager.c index 110511ce7b6c76948cf7e47c13cb6d07026a07c3..9c56ca248cb19de026a35422625a22f6b1496509 100644 --- a/common/iot_list/iot_store_manager.c +++ b/common/iot_list/iot_store_manager.c @@ -1,530 +1,530 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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 -#include -#include -#include -#include - -#include "ohos_errno.h" -#include "ohos_types.h" -#include "utils_config.h" -#include "utils_file.h" - -#include "iot_store_manager.h" - -#if (USER_KV_STORE) -#define INDX_KEY "//offset.idx" -#define INDX_TMP "//offset.tmp" -#define DATA_KEY "//data.info" -#define DATA_TMP "//data.tmp" - -#define TEMP_KEY "//tmp.idx" - -#define STORE_DEBUG -#ifdef STORE_DEBUG -#define STORE_DBG(fmt, args...) printf("[%s|%d][STORE_DEBUG]" fmt, __func__, __LINE__, ##args) -#define STORE_ERR(fmt, args...) printf("[%s|%d][STORE_ERROR]" fmt, __func__, __LINE__, ##args) -#else -#define STORE_DBG(fmt, args...) do {} while (0) -#define STORE_ERR(fmt, args...) do {} while (0) -#endif - -#define UTILS_CLOSE(fdx, idx) ({ \ - if ((fdx) != -1) { \ - close((fdx)); \ - (fdx) = -1; \ - } \ - if ((idx) != -1) { \ - close((idx)); \ - (idx) = -1; \ - } \ - }) - -static int GetFileSize(const char *filename) -{ - int offset = 0; - struct stat fileStat; - if (stat(filename, &fileStat) == 0) { - offset = fileStat.st_size; - } - - return offset; -} - -int StoreManagerAddData(const char *data, int length) -{ - int total = 0; - int offset = 0; - int ret = 0; - int fd = -1; - int fidx = -1; - - offset = GetFileSize(DATA_KEY); - - if (data == NULL || length <= 0) { - STORE_ERR("NULL POINT! \n"); - return -1; - } - - fidx = open(INDX_KEY, O_RDWR | O_CREAT | O_APPEND, 0); - if (fidx < 0) { - STORE_ERR("UtilsFileOpen %s failed! \n", INDX_KEY); - return -1; - } - - fd = open(DATA_KEY, O_RDWR | O_CREAT | O_APPEND, 0); - if (fd < 0) { - ret = -1; - STORE_ERR("UtilsFileOpen %s failed! \n", DATA_KEY); - goto ADD_EXIT; - } - - lseek(fidx, 0, SEEK_SET); - - if (read(fidx, &total, sizeof(int)) < 0) { - ret = -1; - STORE_ERR("UtilsFileRead total failed! \n"); - goto ADD_EXIT; - } - total += 1; - printf("save total = %d! \n", total); - - lseek(fidx, 0, SEEK_SET); - - if (write(fidx, &total, sizeof(int)) < 0) { - ret = -1; - STORE_ERR("UtilsFileWrite total failed! \n"); - goto ADD_EXIT; - } - lseek(fidx, 0, SEEK_END); - - if (write(fidx, &offset, sizeof(int)) < 0) { - ret = -1; - STORE_ERR("UtilsFileWrite offset failed! \n"); - goto ADD_EXIT; - } - lseek(fd, 0, SEEK_END); - write(fd, &length, sizeof(int)); - - if (write(fd, data, length) < 0) { - ret = -1; - STORE_ERR("UtilsFileWrite data failed! \n"); - goto ADD_EXIT; - } - STORE_DBG("save data[%d|%s]->%d success! \n", length, data, offset); -ADD_EXIT: - - UTILS_CLOSE(fd, fidx); - - return ret; -} - -int StoreManagerUpdateData(int idx, const char *data, int length) -{ - int fd = -1; - int fidx = -1; - int tmp = -1; - int tmpidx = -1; - int total = 0; - - fidx = open(INDX_KEY, O_RDWR, 0); - if (fidx < 0) { - printf("UtilsFileOpen INDX_KEY failed! \n"); - return -1; - } - - lseek(fidx, 0, SEEK_SET); - if (read(fidx, (char *)&total, sizeof(int)) < 0) { - printf("UtilsFileRead failed! \n"); - goto ERR_UPDATE; - } - if (total <= 0) { - printf("total is 0! \n"); - goto ERR_UPDATE; - } - - if (idx >= total) { - printf("idx(%d) > total(%d) \n", idx, total); - goto ERR_UPDATE; - } - - fd = open(DATA_KEY, O_RDWR, 0); - if (fd < 0) { - printf("UtilsFileOpen DATA_KEY failed! \n"); - goto ERR_UPDATE; - } - - tmp = open(DATA_TMP, O_CREAT | O_RDWR, 0); - if (tmp < 0) { - printf("UtilsFileOpen DATA_TMP failed! \n"); - goto ERR_UPDATE; - } - tmpidx = open(INDX_TMP, O_CREAT | O_RDWR, 0); - if (tmpidx < 0) { - printf("UtilsFileOpen INDX_TMP failed! \n"); - goto ERR_UPDATE; - } - - if (write(tmpidx, &total, sizeof(int)) < 0) { - printf("UtilsFileWrite tmpidx failed! \n"); - goto ERR_UPDATE; - } - - for (int i = 0; i <= total; i++) { - void *pdata = NULL; - int offset = 0; - int psize = 0; - - if (read(fidx, (void *)&offset, sizeof(int)) < 0) { - printf("UtilsFileRead fidx offset failed! \n"); - goto ERR_UPDATE; - } - if (i == idx) { - offset = GetFileSize(DATA_TMP); - write(tmp, data, length); - write(tmpidx, (void *)&offset, sizeof(int)); - continue; - } - - lseek(fd, offset, SEEK_SET); - if (read(fd, &psize, sizeof(int)) < 0) { - printf("UtilsFileRead fd psize failed! \n"); - goto ERR_UPDATE; - } - if (psize <= 0) { - goto ERR_UPDATE; - } - pdata = malloc(psize); - if (read(fd, pdata, psize) < 0) { - free(pdata); - goto ERR_UPDATE; - } - offset = GetFileSize(DATA_TMP); - write(tmp, psize, sizeof(int)); - write(tmp, pdata, psize); - write(tmpidx, &offset, sizeof(int)); - - free(pdata); - } - - UTILS_CLOSE(fd, fidx); - UTILS_CLOSE(tmp, tmpidx); - - unlink(INDX_KEY); - unlink(DATA_KEY); - - rename(DATA_TMP, DATA_KEY); - rename(INDX_TMP, INDX_KEY); - - return 0; -ERR_UPDATE: - - UTILS_CLOSE(fd, fidx); - UTILS_CLOSE(tmp, tmpidx); - - return -1; -} - -int StoreManagerDeleteDataWithId(int idx) -{ - int fd = -1; - int fidx = -1; - int tmp = -1; - int tmpidx = -1; - int total = 0; - - fidx = open(INDX_KEY, O_RDWR, 0); - if (fidx < 0) { - return -1; - } - - lseek(fidx, 0, SEEK_SET); - if (read(fidx, &total, sizeof(int)) < 0) { - goto ERR_DELETE_ID; - } - if (total <= 0) { - goto ERR_DELETE_ID; - } - - if (idx >= total) { - goto ERR_DELETE_ID; - } - - if (total == 1) { - close(fidx); - unlink(INDX_KEY); - unlink(DATA_KEY); - return 0; - } - - total -= 1; - fd = open(DATA_KEY, O_RDWR, 0); - if (fd < 0) { - goto ERR_DELETE_ID; - } - - tmp = open(DATA_TMP, O_CREAT | O_RDWR, 0); - if (tmp < 0) { - goto ERR_DELETE_ID; - } - tmpidx = open(INDX_TMP, O_CREAT | O_RDWR, 0); - if (tmpidx < 0) { - goto ERR_DELETE_ID; - } - - if (write(tmpidx, &total, sizeof(int)) < 0) { - goto ERR_DELETE_ID; - } - - for (int i = 0; i <= total; i++) { - void *data = NULL; - int offset = 0; - int size = 0; - - if (read(fidx, &offset, sizeof(int)) < 0) { - goto ERR_DELETE_ID; - } - if (i == idx) { - continue; - } - - lseek(fd, offset, SEEK_SET); - if (read(fd, &size, sizeof(int)) < 0) { - goto ERR_DELETE_ID; - } - if (size <= 0) { - goto ERR_DELETE_ID; - } - data = malloc(size); - if (read(fd, data, size) < 0) { - free(data); - goto ERR_DELETE_ID; - } - offset = GetFileSize(DATA_TMP); - write(tmp, size, sizeof(int)); - write(tmp, data, size); - write(tmpidx, &offset, sizeof(int)); - - free(data); - } - - UTILS_CLOSE(fd, fidx); - UTILS_CLOSE(tmp, tmpidx); - - unlink(INDX_KEY); - unlink(DATA_KEY); - - rename(DATA_TMP, DATA_KEY); - rename(INDX_TMP, INDX_KEY); - - return 0; - -ERR_DELETE_ID: - - UTILS_CLOSE(fd, fidx); - UTILS_CLOSE(tmp, tmpidx); - - return -1; -} - -int StoreManagerDeleteData(const char *data) -{ - int fd = -1; - int fidx = -1; - int tmp = -1; - int tmpidx = -1; - int total = 0; - - fidx = open(INDX_KEY, O_RDWR, 0); - if (fidx < 0) { - return -1; - } - - lseek(fidx, 0, SEEK_SET); - if (read(fidx, &total, sizeof(int)) < 0) { - goto ERR_DELETE_DATA; - } - if (total <= 0) { - goto ERR_DELETE_DATA; - } - - fd = open(DATA_KEY, O_RDWR, 0); - if (fd < 0) { - goto ERR_DELETE_DATA; - } - - tmp = open(DATA_TMP, O_CREAT | O_RDWR, 0); - if (tmp < 0) { - goto ERR_DELETE_DATA; - } - tmpidx = open(INDX_TMP, O_CREAT | O_RDWR, 0); - if (tmpidx < 0) { - goto ERR_DELETE_DATA; - } - - if (write(tmpidx, &total, sizeof(int)) < 0) { - goto ERR_DELETE_DATA; - } - - for (int i = 0; i <= total; i++) { - void *pdata = NULL; - int offset = 0; - int psize = 0; - - if (read(fidx, &offset, sizeof(int)) < 0) { - goto ERR_DELETE_DATA; - } - - lseek(fd, offset, SEEK_SET); - if (read(fd, &psize, sizeof(int)) < 0) { - goto ERR_DELETE_DATA; - } - if (psize <= 0) { - goto ERR_DELETE_DATA; - } - pdata = malloc(psize); - if (read(fd, pdata, psize) < 0) { - free(pdata); - goto ERR_DELETE_DATA; - } - - if (memcmp(pdata, data, psize) != 0) { - offset = GetFileSize(DATA_TMP); - write(tmp, psize, sizeof(int)); - write(tmp, pdata, psize); - write(tmpidx, &offset, sizeof(int)); - } - - free(pdata); - } - - UTILS_CLOSE(fd, fidx); - UTILS_CLOSE(tmp, tmpidx); - - unlink(INDX_KEY); - unlink(DATA_KEY); - - rename(DATA_TMP, DATA_KEY); - rename(INDX_TMP, INDX_KEY); - - return 0; -ERR_DELETE_DATA: - - UTILS_CLOSE(fd, fidx); - UTILS_CLOSE(tmp, tmpidx); - - return -1; -} - -int StoreManagerGetTotal(void) -{ - int total = 0; - int fd = open(INDX_KEY, O_RDWR, 0); - - if (fd < 0) { - STORE_ERR("open INDX_KEY failed! \n"); - return -1; - } - - lseek(fd, 0, SEEK_SET); - - if (read(fd, &total, sizeof(int)) < 0) { - STORE_ERR("read total failed! \n"); - total = -1; - } else { - STORE_ERR("read total =%d \n", total); - } - - close(fd); - - return total; -} - -int StoreManagerGetData(char *data, int size, int idx) -{ - int fd = -1; - int fidx = -1; - unsigned int total = 0; - unsigned int offset = 0; - unsigned int psize = 0; - - fidx = open(INDX_KEY, O_RDWR, 0); - if (fidx < 0) { - return -1; - } - - fd = open(DATA_KEY, O_RDWR, 0); - if (fd < 0) { - UTILS_CLOSE(fd, fidx); - return -1; - } - lseek(fidx, 0, SEEK_SET); - - if (read(fidx, &total, sizeof(int)) < 0) { - UTILS_CLOSE(fd, fidx); - return -1; - } - - if (idx >= total) { - UTILS_CLOSE(fd, fidx); - return -1; - } - - if (lseek(fidx, (idx + 1) * sizeof(int), SEEK_SET) < 0) { - UTILS_CLOSE(fd, fidx); - return -1; - } - - if (read(fidx, &offset, sizeof(int)) < 0) { - UTILS_CLOSE(fd, fidx); - return -1; - } - - if (lseek(fd, offset, SEEK_SET) < 0) { - UTILS_CLOSE(fd, fidx); - return -1; - } - - if (read(fd, &psize, sizeof(int)) < 0) { - UTILS_CLOSE(fd, fidx); - return -1; - } - - if (size < psize) { - UTILS_CLOSE(fd, fidx); - return -1; - } - - if (read(fd, data, psize) < 0) { - UTILS_CLOSE(fd, fidx); - return -1; - } - - UTILS_CLOSE(fd, fidx); - - return 0; -} - -void StoreManagerDelete(void) -{ - unlink(DATA_KEY); - unlink(INDX_KEY); -} - -#endif +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 +#include +#include +#include +#include + +#include "ohos_errno.h" +#include "ohos_types.h" +#include "utils_config.h" +#include "utils_file.h" + +#include "iot_store_manager.h" + +#if (USER_KV_STORE) +#define INDX_KEY "//offset.idx" +#define INDX_TMP "//offset.tmp" +#define DATA_KEY "//data.info" +#define DATA_TMP "//data.tmp" + +#define TEMP_KEY "//tmp.idx" + +#define STORE_DEBUG +#ifdef STORE_DEBUG +#define STORE_DBG(fmt, args...) printf("[%s|%d][STORE_DEBUG]" fmt, __func__, __LINE__, ##args) +#define STORE_ERR(fmt, args...) printf("[%s|%d][STORE_ERROR]" fmt, __func__, __LINE__, ##args) +#else +#define STORE_DBG(fmt, args...) do {} while (0) +#define STORE_ERR(fmt, args...) do {} while (0) +#endif + +#define UTILS_CLOSE(fdx, idx) ({ \ + if ((fdx) != -1) { \ + close((fdx)); \ + (fdx) = -1; \ + } \ + if ((idx) != -1) { \ + close((idx)); \ + (idx) = -1; \ + } \ + }) + +static int GetFileSize(const char *filename) +{ + int offset = 0; + struct stat fileStat; + if (stat(filename, &fileStat) == 0) { + offset = fileStat.st_size; + } + + return offset; +} + +int StoreManagerAddData(const char *data, int length) +{ + int total = 0; + int offset = 0; + int ret = 0; + int fd = -1; + int fidx = -1; + + offset = GetFileSize(DATA_KEY); + + if (data == NULL || length <= 0) { + STORE_ERR("NULL POINT! \n"); + return -1; + } + + fidx = open(INDX_KEY, O_RDWR | O_CREAT | O_APPEND, 0); + if (fidx < 0) { + STORE_ERR("UtilsFileOpen %s failed! \n", INDX_KEY); + return -1; + } + + fd = open(DATA_KEY, O_RDWR | O_CREAT | O_APPEND, 0); + if (fd < 0) { + ret = -1; + STORE_ERR("UtilsFileOpen %s failed! \n", DATA_KEY); + goto ADD_EXIT; + } + + lseek(fidx, 0, SEEK_SET); + + if (read(fidx, &total, sizeof(int)) < 0) { + ret = -1; + STORE_ERR("UtilsFileRead total failed! \n"); + goto ADD_EXIT; + } + total += 1; + printf("save total = %d! \n", total); + + lseek(fidx, 0, SEEK_SET); + + if (write(fidx, &total, sizeof(int)) < 0) { + ret = -1; + STORE_ERR("UtilsFileWrite total failed! \n"); + goto ADD_EXIT; + } + lseek(fidx, 0, SEEK_END); + + if (write(fidx, &offset, sizeof(int)) < 0) { + ret = -1; + STORE_ERR("UtilsFileWrite offset failed! \n"); + goto ADD_EXIT; + } + lseek(fd, 0, SEEK_END); + write(fd, &length, sizeof(int)); + + if (write(fd, data, length) < 0) { + ret = -1; + STORE_ERR("UtilsFileWrite data failed! \n"); + goto ADD_EXIT; + } + STORE_DBG("save data[%d|%s]->%d success! \n", length, data, offset); +ADD_EXIT: + + UTILS_CLOSE(fd, fidx); + + return ret; +} + +int StoreManagerUpdateData(int idx, const char *data, int length) +{ + int fd = -1; + int fidx = -1; + int tmp = -1; + int tmpidx = -1; + int total = 0; + + fidx = open(INDX_KEY, O_RDWR, 0); + if (fidx < 0) { + printf("UtilsFileOpen INDX_KEY failed! \n"); + return -1; + } + + lseek(fidx, 0, SEEK_SET); + if (read(fidx, (char *)&total, sizeof(int)) < 0) { + printf("UtilsFileRead failed! \n"); + goto ERR_UPDATE; + } + if (total <= 0) { + printf("total is 0! \n"); + goto ERR_UPDATE; + } + + if (idx >= total) { + printf("idx(%d) > total(%d) \n", idx, total); + goto ERR_UPDATE; + } + + fd = open(DATA_KEY, O_RDWR, 0); + if (fd < 0) { + printf("UtilsFileOpen DATA_KEY failed! \n"); + goto ERR_UPDATE; + } + + tmp = open(DATA_TMP, O_CREAT | O_RDWR, 0); + if (tmp < 0) { + printf("UtilsFileOpen DATA_TMP failed! \n"); + goto ERR_UPDATE; + } + tmpidx = open(INDX_TMP, O_CREAT | O_RDWR, 0); + if (tmpidx < 0) { + printf("UtilsFileOpen INDX_TMP failed! \n"); + goto ERR_UPDATE; + } + + if (write(tmpidx, &total, sizeof(int)) < 0) { + printf("UtilsFileWrite tmpidx failed! \n"); + goto ERR_UPDATE; + } + + for (int i = 0; i <= total; i++) { + void *pdata = NULL; + int offset = 0; + int psize = 0; + + if (read(fidx, (void *)&offset, sizeof(int)) < 0) { + printf("UtilsFileRead fidx offset failed! \n"); + goto ERR_UPDATE; + } + if (i == idx) { + offset = GetFileSize(DATA_TMP); + write(tmp, data, length); + write(tmpidx, (void *)&offset, sizeof(int)); + continue; + } + + lseek(fd, offset, SEEK_SET); + if (read(fd, &psize, sizeof(int)) < 0) { + printf("UtilsFileRead fd psize failed! \n"); + goto ERR_UPDATE; + } + if (psize <= 0) { + goto ERR_UPDATE; + } + pdata = malloc(psize); + if (read(fd, pdata, psize) < 0) { + free(pdata); + goto ERR_UPDATE; + } + offset = GetFileSize(DATA_TMP); + write(tmp, psize, sizeof(int)); + write(tmp, pdata, psize); + write(tmpidx, &offset, sizeof(int)); + + free(pdata); + } + + UTILS_CLOSE(fd, fidx); + UTILS_CLOSE(tmp, tmpidx); + + unlink(INDX_KEY); + unlink(DATA_KEY); + + rename(DATA_TMP, DATA_KEY); + rename(INDX_TMP, INDX_KEY); + + return 0; +ERR_UPDATE: + + UTILS_CLOSE(fd, fidx); + UTILS_CLOSE(tmp, tmpidx); + + return -1; +} + +int StoreManagerDeleteDataWithId(int idx) +{ + int fd = -1; + int fidx = -1; + int tmp = -1; + int tmpidx = -1; + int total = 0; + + fidx = open(INDX_KEY, O_RDWR, 0); + if (fidx < 0) { + return -1; + } + + lseek(fidx, 0, SEEK_SET); + if (read(fidx, &total, sizeof(int)) < 0) { + goto ERR_DELETE_ID; + } + if (total <= 0) { + goto ERR_DELETE_ID; + } + + if (idx >= total) { + goto ERR_DELETE_ID; + } + + if (total == 1) { + close(fidx); + unlink(INDX_KEY); + unlink(DATA_KEY); + return 0; + } + + total -= 1; + fd = open(DATA_KEY, O_RDWR, 0); + if (fd < 0) { + goto ERR_DELETE_ID; + } + + tmp = open(DATA_TMP, O_CREAT | O_RDWR, 0); + if (tmp < 0) { + goto ERR_DELETE_ID; + } + tmpidx = open(INDX_TMP, O_CREAT | O_RDWR, 0); + if (tmpidx < 0) { + goto ERR_DELETE_ID; + } + + if (write(tmpidx, &total, sizeof(int)) < 0) { + goto ERR_DELETE_ID; + } + + for (int i = 0; i <= total; i++) { + void *data = NULL; + int offset = 0; + int size = 0; + + if (read(fidx, &offset, sizeof(int)) < 0) { + goto ERR_DELETE_ID; + } + if (i == idx) { + continue; + } + + lseek(fd, offset, SEEK_SET); + if (read(fd, &size, sizeof(int)) < 0) { + goto ERR_DELETE_ID; + } + if (size <= 0) { + goto ERR_DELETE_ID; + } + data = malloc(size); + if (read(fd, data, size) < 0) { + free(data); + goto ERR_DELETE_ID; + } + offset = GetFileSize(DATA_TMP); + write(tmp, size, sizeof(int)); + write(tmp, data, size); + write(tmpidx, &offset, sizeof(int)); + + free(data); + } + + UTILS_CLOSE(fd, fidx); + UTILS_CLOSE(tmp, tmpidx); + + unlink(INDX_KEY); + unlink(DATA_KEY); + + rename(DATA_TMP, DATA_KEY); + rename(INDX_TMP, INDX_KEY); + + return 0; + +ERR_DELETE_ID: + + UTILS_CLOSE(fd, fidx); + UTILS_CLOSE(tmp, tmpidx); + + return -1; +} + +int StoreManagerDeleteData(const char *data) +{ + int fd = -1; + int fidx = -1; + int tmp = -1; + int tmpidx = -1; + int total = 0; + + fidx = open(INDX_KEY, O_RDWR, 0); + if (fidx < 0) { + return -1; + } + + lseek(fidx, 0, SEEK_SET); + if (read(fidx, &total, sizeof(int)) < 0) { + goto ERR_DELETE_DATA; + } + if (total <= 0) { + goto ERR_DELETE_DATA; + } + + fd = open(DATA_KEY, O_RDWR, 0); + if (fd < 0) { + goto ERR_DELETE_DATA; + } + + tmp = open(DATA_TMP, O_CREAT | O_RDWR, 0); + if (tmp < 0) { + goto ERR_DELETE_DATA; + } + tmpidx = open(INDX_TMP, O_CREAT | O_RDWR, 0); + if (tmpidx < 0) { + goto ERR_DELETE_DATA; + } + + if (write(tmpidx, &total, sizeof(int)) < 0) { + goto ERR_DELETE_DATA; + } + + for (int i = 0; i <= total; i++) { + void *pdata = NULL; + int offset = 0; + int psize = 0; + + if (read(fidx, &offset, sizeof(int)) < 0) { + goto ERR_DELETE_DATA; + } + + lseek(fd, offset, SEEK_SET); + if (read(fd, &psize, sizeof(int)) < 0) { + goto ERR_DELETE_DATA; + } + if (psize <= 0) { + goto ERR_DELETE_DATA; + } + pdata = malloc(psize); + if (read(fd, pdata, psize) < 0) { + free(pdata); + goto ERR_DELETE_DATA; + } + + if (memcmp(pdata, data, psize) != 0) { + offset = GetFileSize(DATA_TMP); + write(tmp, psize, sizeof(int)); + write(tmp, pdata, psize); + write(tmpidx, &offset, sizeof(int)); + } + + free(pdata); + } + + UTILS_CLOSE(fd, fidx); + UTILS_CLOSE(tmp, tmpidx); + + unlink(INDX_KEY); + unlink(DATA_KEY); + + rename(DATA_TMP, DATA_KEY); + rename(INDX_TMP, INDX_KEY); + + return 0; +ERR_DELETE_DATA: + + UTILS_CLOSE(fd, fidx); + UTILS_CLOSE(tmp, tmpidx); + + return -1; +} + +int StoreManagerGetTotal(void) +{ + int total = 0; + int fd = open(INDX_KEY, O_RDWR, 0); + + if (fd < 0) { + STORE_ERR("open INDX_KEY failed! \n"); + return -1; + } + + lseek(fd, 0, SEEK_SET); + + if (read(fd, &total, sizeof(int)) < 0) { + STORE_ERR("read total failed! \n"); + total = -1; + } else { + STORE_ERR("read total =%d \n", total); + } + + close(fd); + + return total; +} + +int StoreManagerGetData(char *data, int size, int idx) +{ + int fd = -1; + int fidx = -1; + unsigned int total = 0; + unsigned int offset = 0; + unsigned int psize = 0; + + fidx = open(INDX_KEY, O_RDWR, 0); + if (fidx < 0) { + return -1; + } + + fd = open(DATA_KEY, O_RDWR, 0); + if (fd < 0) { + UTILS_CLOSE(fd, fidx); + return -1; + } + lseek(fidx, 0, SEEK_SET); + + if (read(fidx, &total, sizeof(int)) < 0) { + UTILS_CLOSE(fd, fidx); + return -1; + } + + if (idx >= total) { + UTILS_CLOSE(fd, fidx); + return -1; + } + + if (lseek(fidx, (idx + 1) * sizeof(int), SEEK_SET) < 0) { + UTILS_CLOSE(fd, fidx); + return -1; + } + + if (read(fidx, &offset, sizeof(int)) < 0) { + UTILS_CLOSE(fd, fidx); + return -1; + } + + if (lseek(fd, offset, SEEK_SET) < 0) { + UTILS_CLOSE(fd, fidx); + return -1; + } + + if (read(fd, &psize, sizeof(int)) < 0) { + UTILS_CLOSE(fd, fidx); + return -1; + } + + if (size < psize) { + UTILS_CLOSE(fd, fidx); + return -1; + } + + if (read(fd, data, psize) < 0) { + UTILS_CLOSE(fd, fidx); + return -1; + } + + UTILS_CLOSE(fd, fidx); + + return 0; +} + +void StoreManagerDelete(void) +{ + unlink(DATA_KEY); + unlink(INDX_KEY); +} + +#endif diff --git a/common/iot_nfc/nfc_app.c b/common/iot_nfc/nfc_app.c index 848f548116674d17f1b2f21084f8974279e00cf7..f2c0826135dd9b2c878c2dc9d4c11e4a61b70fb5 100644 --- a/common/iot_nfc/nfc_app.c +++ b/common/iot_nfc/nfc_app.c @@ -1,189 +1,189 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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 "nfc_app.h" -#include "NT3H.h" -#include "iot_nfc.h" -#include -#include -#include -#include - -#define HI_IO_FUNC_GPIO_1_I2C1_SCL_6 6 -#define I2C_IDX_BAUDRATE (400000) - -#define CONST_2 2 -#define CONST_3 3 -#define CONST_4 4 -#define CONST_8 8 -#define CONST_9 9 -#define CONST_10 10 -#define CONST_15 15 -#define CONST_16 16 -#define CONST_32 32 -#define CONST_35 35 -#define CONST_48 48 -#define CONST_64 64 -#define CONST_65 65 -#define CONST_96 96 -#define CONST_97 97 -#define CONST_126 126 -#define CONST_512 512 - -char product[50], wifissid[50], wifipwd[50], deviceid[50], devicepwd[50], nodeid[20]; - -/** - * @brief NFC JSON数据中,获取WiFi的ssid和密钥及设备DevicesID和密钥 - * - * @return uint8_t - */ -uint8_t nfc_get_devived_data(void) { - uint8_t memary_buf[CONST_16 * CONST_15]; - cJSON *json, *jsonTemp; // *jsonArray, - uint8_t jsonbuf[CONST_512 * CONST_2] = {0}; - char jsonbuf_string[CONST_512 * CONST_2] = {0}; - uint8_t payload_len = 0; - uint8_t json_len = 0; - - NT3H1101_Read_Userpages(CONST_15, memary_buf); - - payload_len = memary_buf[CONST_4]; - json_len = payload_len - CONST_3; - - printf("payload_len: %d", payload_len); - //取出真实的json数据包,往后再偏移3位 - for (uint8_t i = 0; i < json_len; i++) { - jsonbuf[i] = memary_buf[CONST_9 + i]; - } - memset(jsonbuf_string, 0x00, sizeof(jsonbuf_string)); - sprintf(jsonbuf_string, "%s", jsonbuf); - - printf("nfc data: %s", jsonbuf_string); - //解析json数据 - json = cJSON_Parse(jsonbuf_string); - if (!json) { - printf("Error before: [%s]\n", cJSON_GetErrorPtr()); - return -1; - } else { - jsonTemp = cJSON_GetObjectItem(json, "product"); - memset(product, 0, sizeof(product)); - snprintf(product, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); - jsonTemp = cJSON_GetObjectItem(json, "device_id"); - memset(deviceid, 0, sizeof(deviceid)); - snprintf(deviceid, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); - jsonTemp = cJSON_GetObjectItem(json, "secret"); - memset(devicepwd, 0, sizeof(devicepwd)); - snprintf(devicepwd, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); - jsonTemp = cJSON_GetObjectItem(json, "ssid"); - memset(wifissid, 0, sizeof(wifissid)); - snprintf(wifissid, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); - jsonTemp = cJSON_GetObjectItem(json, "pwd"); - memset(wifipwd, 0, sizeof(wifipwd)); - snprintf(wifipwd, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); - - cJSON_Delete(json); - free(json); // isequal - } - return 0; -} - -char byte2char(uint8_t num) { - char ch; - if (num >= CONST_32 && num <= CONST_64) { - ch = '0' + (num - CONST_48); - } else if (num >= CONST_65 && num <= CONST_96) { - ch = 'A' + (num - CONST_65); - } else if (num >= CONST_97 && num <= CONST_126) { - ch = 'a' + (num - CONST_97); - } else { - ch = '0'; - } - return ch; -} - -/** - * @brief Get the nfc device data object - * - * @return uint8_t - */ -uint8_t get_nfc_device_data(void) { - uint8_t memary_buf[16 * 15] = {0}; - uint8_t payload_len = 0; - uint8_t start_index = 0; // 取值开始位置 - uint8_t count = 0; // 取值数量 - NT3H1101_Read_Userpages(CONST_15, memary_buf); - // 符号SOH+NUL 和 表示1的正文开始,如果不符合,不进行读取 - if (!(memary_buf[CONST_8] == 1 && memary_buf[CONST_9] == 0 && byte2char(memary_buf[CONST_35 + 1]) == '1')) { - return -1; - } - payload_len = memary_buf[CONST_35]; // 十进制的有效数据总长度 - start_index = CONST_35 + CONST_4; // 表示长度的位置+4为数据位置 - count = (memary_buf[CONST_35 + CONST_2] - CONST_48) * CONST_10 + (memary_buf[CONST_35 + CONST_3] - CONST_48); - - // 03 9B D2 02 96 68 77 20 01 00 48 00 39 41 34 39 00 81 07 00 07 20 06 85 14 91 14 06 00 00 00 00 00 00 91 6B 31 32 34 36 33 31 35 63 39 33 63 36 36 34 63 36 66 37 39 33 38 64 63 32 30 38 37 32 30 38 4C 61 6D 70 5F 30 30 32 33 32 36 31 32 33 34 35 36 41 42 43 44 45 46 47 31 32 33 34 35 36 41 42 43 44 45 46 47 34 30 31 31 35 31 30 74 65 61 6D 58 2D 4C 61 6D 70 36 32 30 56 56 56 56 56 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 8B 0C 12 51 C2 6D 52 32 84 34 A1 82 65 9C FE - // 124 6315c93c664c6f7938dc2087 208 Lamp_002 326 123456ABCDEFG123456ABCDEFG 401 1 510 teamX-Lamp 620 VVVVVXXXXXXXXXXXXXXX - // product_id+_+node_id,pwd - - for (int i = 0; i < count; i++) { - product[i] = byte2char(memary_buf[start_index + i]); - } - printf("product_id=%s\n", product); - // 下一个起始位置和长度 - start_index += count + CONST_3; - count = (memary_buf[start_index - CONST_2] - CONST_48) * CONST_10 + (memary_buf[start_index - 1] - CONST_48); - for (int i = 0; i < count; i++) { - nodeid[i] = byte2char(memary_buf[start_index + i]); - } - printf("node_id=%s\n", nodeid); - // 下一个起始位置和长度 - start_index += count + CONST_3; - count = (memary_buf[start_index - CONST_2] - CONST_48) * CONST_10 + (memary_buf[start_index - 1] - CONST_48); - for (int i = 0; i < count; i++) { - devicepwd[i] = byte2char(memary_buf[start_index + i]); - } - - sprintf(deviceid, "%s_%s", product, nodeid); - - printf("device_id=%s,secret=%s\n", deviceid, devicepwd); - - return 0; -} -int BOARD_InitNfc(void) { - // GPIO_1复用为I2C1_SCL - IoTGpioSetFunc(1, HI_IO_FUNC_GPIO_1_I2C1_SCL_6); - // baudrate: 400kbps - IoTI2cInit(1, I2C_IDX_BAUDRATE); - return 0; -} - -int BOARD_GetNfcInfo(NfcInfo *info) { - int ret = -1; - if (info == NULL) { - return ret; - } - - if (nfc_get_devived_data() == 0) { - info->deviceID = (const char *)deviceid; - info->devicePWD = (const char *)devicepwd; - info->wifiSSID = (const char *)wifissid; - info->wifiPWD = (const char *)wifipwd; - ret = 0; - } else if (get_nfc_device_data() == 0) { - info->deviceID = (const char *)deviceid; - info->devicePWD = (const char *)devicepwd; - ret = 0; - } - return ret; -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 "nfc_app.h" +#include "NT3H.h" +#include "iot_nfc.h" +#include +#include +#include +#include + +#define HI_IO_FUNC_GPIO_1_I2C1_SCL_6 6 +#define I2C_IDX_BAUDRATE (400000) + +#define CONST_2 2 +#define CONST_3 3 +#define CONST_4 4 +#define CONST_8 8 +#define CONST_9 9 +#define CONST_10 10 +#define CONST_15 15 +#define CONST_16 16 +#define CONST_32 32 +#define CONST_35 35 +#define CONST_48 48 +#define CONST_64 64 +#define CONST_65 65 +#define CONST_96 96 +#define CONST_97 97 +#define CONST_126 126 +#define CONST_512 512 + +char product[50], wifissid[50], wifipwd[50], deviceid[50], devicepwd[50], nodeid[20]; + +/** + * @brief NFC JSON数据中,获取WiFi的ssid和密钥及设备DevicesID和密钥 + * + * @return uint8_t + */ +uint8_t nfc_get_devived_data(void) { + uint8_t memary_buf[CONST_16 * CONST_15]; + cJSON *json, *jsonTemp; // *jsonArray, + uint8_t jsonbuf[CONST_512 * CONST_2] = {0}; + char jsonbuf_string[CONST_512 * CONST_2] = {0}; + uint8_t payload_len = 0; + uint8_t json_len = 0; + + NT3H1101_Read_Userpages(CONST_15, memary_buf); + + payload_len = memary_buf[CONST_4]; + json_len = payload_len - CONST_3; + + printf("payload_len: %d", payload_len); + //取出真实的json数据包,往后再偏移3位 + for (uint8_t i = 0; i < json_len; i++) { + jsonbuf[i] = memary_buf[CONST_9 + i]; + } + memset(jsonbuf_string, 0x00, sizeof(jsonbuf_string)); + sprintf(jsonbuf_string, "%s", jsonbuf); + + printf("nfc data: %s", jsonbuf_string); + //解析json数据 + json = cJSON_Parse(jsonbuf_string); + if (!json) { + printf("Error before: [%s]\n", cJSON_GetErrorPtr()); + return -1; + } else { + jsonTemp = cJSON_GetObjectItem(json, "product"); + memset(product, 0, sizeof(product)); + snprintf(product, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); + jsonTemp = cJSON_GetObjectItem(json, "device_id"); + memset(deviceid, 0, sizeof(deviceid)); + snprintf(deviceid, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); + jsonTemp = cJSON_GetObjectItem(json, "secret"); + memset(devicepwd, 0, sizeof(devicepwd)); + snprintf(devicepwd, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); + jsonTemp = cJSON_GetObjectItem(json, "ssid"); + memset(wifissid, 0, sizeof(wifissid)); + snprintf(wifissid, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); + jsonTemp = cJSON_GetObjectItem(json, "pwd"); + memset(wifipwd, 0, sizeof(wifipwd)); + snprintf(wifipwd, strlen(jsonTemp->valuestring) + 1, "%s", jsonTemp->valuestring); + + cJSON_Delete(json); + free(json); // isequal + } + return 0; +} + +char byte2char(uint8_t num) { + char ch; + if (num >= CONST_32 && num <= CONST_64) { + ch = '0' + (num - CONST_48); + } else if (num >= CONST_65 && num <= CONST_96) { + ch = 'A' + (num - CONST_65); + } else if (num >= CONST_97 && num <= CONST_126) { + ch = 'a' + (num - CONST_97); + } else { + ch = '0'; + } + return ch; +} + +/** + * @brief Get the nfc device data object + * + * @return uint8_t + */ +uint8_t get_nfc_device_data(void) { + uint8_t memary_buf[16 * 15] = {0}; + uint8_t payload_len = 0; + uint8_t start_index = 0; // 取值开始位置 + uint8_t count = 0; // 取值数量 + NT3H1101_Read_Userpages(CONST_15, memary_buf); + // 符号SOH+NUL 和 表示1的正文开始,如果不符合,不进行读取 + if (!(memary_buf[CONST_8] == 1 && memary_buf[CONST_9] == 0 && byte2char(memary_buf[CONST_35 + 1]) == '1')) { + return -1; + } + payload_len = memary_buf[CONST_35]; // 十进制的有效数据总长度 + start_index = CONST_35 + CONST_4; // 表示长度的位置+4为数据位置 + count = (memary_buf[CONST_35 + CONST_2] - CONST_48) * CONST_10 + (memary_buf[CONST_35 + CONST_3] - CONST_48); + + // 03 9B D2 02 96 68 77 20 01 00 48 00 39 41 34 39 00 81 07 00 07 20 06 85 14 91 14 06 00 00 00 00 00 00 91 6B 31 32 34 36 33 31 35 63 39 33 63 36 36 34 63 36 66 37 39 33 38 64 63 32 30 38 37 32 30 38 4C 61 6D 70 5F 30 30 32 33 32 36 31 32 33 34 35 36 41 42 43 44 45 46 47 31 32 33 34 35 36 41 42 43 44 45 46 47 34 30 31 31 35 31 30 74 65 61 6D 58 2D 4C 61 6D 70 36 32 30 56 56 56 56 56 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 8B 0C 12 51 C2 6D 52 32 84 34 A1 82 65 9C FE + // 124 6315c93c664c6f7938dc2087 208 Lamp_002 326 123456ABCDEFG123456ABCDEFG 401 1 510 teamX-Lamp 620 VVVVVXXXXXXXXXXXXXXX + // product_id+_+node_id,pwd + + for (int i = 0; i < count; i++) { + product[i] = byte2char(memary_buf[start_index + i]); + } + printf("product_id=%s\n", product); + // 下一个起始位置和长度 + start_index += count + CONST_3; + count = (memary_buf[start_index - CONST_2] - CONST_48) * CONST_10 + (memary_buf[start_index - 1] - CONST_48); + for (int i = 0; i < count; i++) { + nodeid[i] = byte2char(memary_buf[start_index + i]); + } + printf("node_id=%s\n", nodeid); + // 下一个起始位置和长度 + start_index += count + CONST_3; + count = (memary_buf[start_index - CONST_2] - CONST_48) * CONST_10 + (memary_buf[start_index - 1] - CONST_48); + for (int i = 0; i < count; i++) { + devicepwd[i] = byte2char(memary_buf[start_index + i]); + } + + sprintf(deviceid, "%s_%s", product, nodeid); + + printf("device_id=%s,secret=%s\n", deviceid, devicepwd); + + return 0; +} +int BOARD_InitNfc(void) { + // GPIO_1复用为I2C1_SCL + IoTGpioSetFunc(1, HI_IO_FUNC_GPIO_1_I2C1_SCL_6); + // baudrate: 400kbps + IoTI2cInit(1, I2C_IDX_BAUDRATE); + return 0; +} + +int BOARD_GetNfcInfo(NfcInfo *info) { + int ret = -1; + if (info == NULL) { + return ret; + } + + if (nfc_get_devived_data() == 0) { + info->deviceID = (const char *)deviceid; + info->devicePWD = (const char *)devicepwd; + info->wifiSSID = (const char *)wifissid; + info->wifiPWD = (const char *)wifipwd; + ret = 0; + } else if (get_nfc_device_data() == 0) { + info->deviceID = (const char *)deviceid; + info->devicePWD = (const char *)devicepwd; + ret = 0; + } + return ret; +} diff --git a/common/iot_nfc/nfc_app.h b/common/iot_nfc/nfc_app.h index 78088819598f7e322c68b1c938133eee7d93644b..e3da3176e5ae6da782643eb5010cbe36571157d2 100644 --- a/common/iot_nfc/nfc_app.h +++ b/common/iot_nfc/nfc_app.h @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef __NFC_APP_H__ -#define __NFC_APP_H__ - -#include "nfc.h" - -uint8_t nfc_get_devived_data(void); -/** - * @brief 数字管家NFC数据 - * - * @return uint8_t 0 成功 - */ -uint8_t get_nfc_device_data(void); -/** - * @brief 初始化NFC板卡 - * - * @return int - */ -int BOARD_InitNfc(void); +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef __NFC_APP_H__ +#define __NFC_APP_H__ + +#include "nfc.h" + +uint8_t nfc_get_devived_data(void); +/** + * @brief 数字管家NFC数据 + * + * @return uint8_t 0 成功 + */ +uint8_t get_nfc_device_data(void); +/** + * @brief 初始化NFC板卡 + * + * @return int + */ +int BOARD_InitNfc(void); #endif \ No newline at end of file diff --git a/common/iot_socket/socket_client.c b/common/iot_socket/socket_client.c index 6a847426b3dbd4d2e3a7fccb9a494a4772510bcf..8d09699cefd953b49262b81f9e4c27b99b91a3d9 100644 --- a/common/iot_socket/socket_client.c +++ b/common/iot_socket/socket_client.c @@ -1,304 +1,304 @@ - -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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 "socket_client.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ohos_types.h" - -#define SOCKET_TASK_STACK (1024 * 8) -#define SOCKET_TASK_PERIOD 27 - -#define UDP_DEF_PORT 9090 -#define TCP_DEF_PORT 8989 - -#define MSG_DATE_BUF_LEN 24 -#define PROTOCOL_HEADER "HM" -#define DATA_DEVICE_NAME "TD" -#define DATA_SWITCH "TA" -#define DATA_MSG_ON "on" -#define DATA_MSG_OFF "off" - -#ifndef ARRAYSIZE -#define ARRAYSIZE(a) (sizeof((a)) / sizeof((a[0]))) -#endif -#ifndef bool -#define bool unsigned char -#endif -#ifndef true -#define true 1 -#endif -#ifndef false -#define false 0 -#endif - -#define SOCKET_CLIENT_DEBUG -#ifdef SOCKET_CLIENT_DEBUG -#define SCK_ERR(fmt, args...) printf("[SOCKET_ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) -#define SCK_DBG(fmt, args...) printf("[SOCKET_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) -#define SCK_INFO(fmt, args...) printf("[SOCKET_INFO][%s|%d]" fmt, __func__, __LINE__, ##args) -#else -#define SCK_ERR(fmt, args...) do {} while(0) -#define SCK_DBG(fmt, args...) do {} while(0) -#define SCK_INFO(fmt, args...) do {} while(0) -#endif - -static void ResolveDevName(SocketEventCallback callback, char *value); -static void ResolveSwitch(SocketEventCallback callback, char *value); - -typedef union { - char msg[MSG_DATE_BUF_LEN]; - struct { - char head[2]; - char cmd[2]; - char buff[20]; - } msg_info; -} MsgInfo; - -typedef struct { - char cmd[MSG_DATE_BUF_LEN]; - void (*func)(SocketEventCallback callback, char *value); -} MsgData; - -static MsgData g_msgData[] = { - {DATA_DEVICE_NAME, ResolveDevName}, - {DATA_SWITCH, ResolveSwitch} -}; - -static bool g_threadRunning = false; - -// ********************************************************************************************************************************** // -static bool IsEqualTo(const char *msg1, const char *msg2, int length) -{ - if (msg1 == NULL || msg2 == NULL || length <= 0) { - SCK_ERR("NULL POINT! \n"); - return false; - } - - return (strncasecmp(msg1, msg2, length) == 0); -} - -static void ResolveDevName(SocketEventCallback callback, char *value) -{ - SCK_INFO(" ########### value : %s ################ \n", value); -} - -static void ResolveSwitch(SocketEventCallback callback, char *value) -{ - SCK_INFO(" ########### value : %s ################ \n", value); - if (callback != NULL) { - callback(SOCKET_SET_CMD, value); - } -} - -static int SocketClientResolveData(const char *data, int len, SocketEventCallback callback) -{ - MsgInfo msgInfo = {0}; - if (data == NULL || len <= 0) { - SCK_ERR("NULL POINT!\n"); - return -1; - } - - if (len > MSG_DATE_BUF_LEN) { - len = MSG_DATE_BUF_LEN; - } - - memcpy(msgInfo.msg, data, len); - SCK_DBG("head:%s\n", msgInfo.msg_info.head); - for (int i = 0; i < ARRAYSIZE(g_msgData); i++) { - if (IsEqualTo(msgInfo.msg_info.cmd, g_msgData[i].cmd, strlen(g_msgData[i].cmd))) { - g_msgData[i].func(callback, msgInfo.msg_info.buff); - SCK_INFO(" cmd %s is match! \n", g_msgData[i].cmd); - break; - } - } - - return 0; -} - -static int SocketOpen(const char *ip, int port) -{ - int sockfd; - struct sockaddr_in recvAddr; - if (ip == NULL || port <= 0) { - return -1; - } - - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) { - SCK_ERR("socket failed! errno=%d\n", errno); - return -1; - } - - memset(&recvAddr, 0x00, sizeof(recvAddr)); - recvAddr.sin_family = AF_INET; - recvAddr.sin_port = htons(port); - recvAddr.sin_addr.s_addr = inet_addr(ip); - - if (connect(sockfd, (struct sockaddr *)&recvAddr, sizeof(recvAddr)) < 0) { - SCK_ERR("connect failed! errno=%d\n", errno); - close(sockfd); - return -1; - } - - return sockfd; -} - -static int GetServerIp(char *ip, int size) -{ - char recMsg[256] = {0}; - char sockfd; - char *tmp = NULL; - struct sockaddr_in localAddr, serverAddr; - int sockaddr_len = sizeof(serverAddr); - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd < 0) { - SCK_ERR("socket failed!\n"); - return -1; - } - - memset(&localAddr, 0x00, sizeof(localAddr)); - localAddr.sin_family = AF_INET; - localAddr.sin_port = htons(UDP_DEF_PORT); - localAddr.sin_addr.s_addr = inet_addr(INADDR_ANY); - - if (bind(sockfd, (struct sockaddr *)&localAddr, sizeof(localAddr)) < 0) { - SCK_ERR("bind failed! errno : %d(%s)\n", errno, strerror(errno)); - close(sockfd); - return -1; - } - - if (recvfrom(sockfd, recMsg, sizeof(recMsg), 0, (struct sockaddr *)&serverAddr, &sockaddr_len) < 0) { - SCK_ERR("recvfrom failed! \n"); - close(sockfd); - return -1; - } - - tmp = inet_ntoa(serverAddr.sin_addr); - SCK_INFO("the server ip is %s \n", tmp); - if (ip == NULL || size < strlen(tmp)) { - SCK_ERR("params is invalid!! \n"); - close(sockfd); - return -1; - } - - strncpy(ip, tmp, strlen(tmp)); - - close(sockfd); - - return 0; -} - -static void SocketClientProcess(void *arg) -{ - int sockfd = -1; - char ipBuf[256] = {0}; - char sendBuf[256] = {0}; - char mDeviceName[256] = {0}; - - SocketCallback *mCallback = (SocketCallback *)arg; - if (mCallback == NULL) { - SCK_ERR("socket callback is NULL! \n"); - return; - } - - if (GetServerIp(ipBuf, sizeof(ipBuf)) < 0) { - SCK_ERR("get server ip failed! \n"); - g_threadRunning = false; - return; - } - - sockfd = SocketOpen((const char *)ipBuf, TCP_DEF_PORT); - if (sockfd < 0) { - SCK_ERR("socket open failed! \n"); - g_threadRunning = false; - return; - } - - if (mCallback->socketEvent != NULL) { - mCallback->socketEvent(SOCKET_CONNECTTED, NULL); - } - - if (mCallback->socketGetDeviceName != NULL) { - mCallback->socketGetDeviceName(mDeviceName, sizeof(mDeviceName)); - sprintf(sendBuf, "%s%s%s", PROTOCOL_HEADER, DATA_DEVICE_NAME, mDeviceName); - if (send(sockfd, sendBuf, strlen(sendBuf), 0) < 0) { - SCK_ERR("send %s failed! \n", sendBuf); - goto EXIT; - } - } - - while (g_threadRunning) { - char recvBuf[1024] = {0}; - int recvBytes = recv(sockfd, recvBuf, sizeof(recvBuf), 0); - if (recvBytes <= 0) { - break; - } - SCK_INFO("recvMsg[%d] : %s \n", recvBytes, recvBuf); - if (SocketClientResolveData((const char *)recvBuf, recvBytes, mCallback->socketEvent) < 0) { - break; - } - } - -EXIT: - close(sockfd); - sockfd = -1; - if (mCallback->socketEvent != NULL) { - mCallback->socketEvent(SOCKET_DISCONNECT, NULL); - } - g_threadRunning = false; -} - -int SocketClientStart(SocketCallback *gCallback) -{ - osThreadAttr_t attr; - - attr.name = "SocketClientTask"; - attr.attr_bits = 0U; - attr.cb_mem = NULL; - attr.cb_size = 0U; - attr.stack_mem = NULL; - attr.stack_size = SOCKET_TASK_STACK; - attr.priority = SOCKET_TASK_PERIOD; - - g_threadRunning = true; - - if (osThreadNew(SocketClientProcess, (void *)gCallback, &attr) == NULL) { - SCK_ERR("Falied to create ClientTask!\n"); - return -1; - } - - return 0; -} - -void SocketClientStop(void) -{ - if (g_threadRunning) { - g_threadRunning = false; - } -} + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 "socket_client.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ohos_types.h" + +#define SOCKET_TASK_STACK (1024 * 8) +#define SOCKET_TASK_PERIOD 27 + +#define UDP_DEF_PORT 9090 +#define TCP_DEF_PORT 8989 + +#define MSG_DATE_BUF_LEN 24 +#define PROTOCOL_HEADER "HM" +#define DATA_DEVICE_NAME "TD" +#define DATA_SWITCH "TA" +#define DATA_MSG_ON "on" +#define DATA_MSG_OFF "off" + +#ifndef ARRAYSIZE +#define ARRAYSIZE(a) (sizeof((a)) / sizeof((a[0]))) +#endif +#ifndef bool +#define bool unsigned char +#endif +#ifndef true +#define true 1 +#endif +#ifndef false +#define false 0 +#endif + +#define SOCKET_CLIENT_DEBUG +#ifdef SOCKET_CLIENT_DEBUG +#define SCK_ERR(fmt, args...) printf("[SOCKET_ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) +#define SCK_DBG(fmt, args...) printf("[SOCKET_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) +#define SCK_INFO(fmt, args...) printf("[SOCKET_INFO][%s|%d]" fmt, __func__, __LINE__, ##args) +#else +#define SCK_ERR(fmt, args...) do {} while(0) +#define SCK_DBG(fmt, args...) do {} while(0) +#define SCK_INFO(fmt, args...) do {} while(0) +#endif + +static void ResolveDevName(SocketEventCallback callback, char *value); +static void ResolveSwitch(SocketEventCallback callback, char *value); + +typedef union { + char msg[MSG_DATE_BUF_LEN]; + struct { + char head[2]; + char cmd[2]; + char buff[20]; + } msg_info; +} MsgInfo; + +typedef struct { + char cmd[MSG_DATE_BUF_LEN]; + void (*func)(SocketEventCallback callback, char *value); +} MsgData; + +static MsgData g_msgData[] = { + {DATA_DEVICE_NAME, ResolveDevName}, + {DATA_SWITCH, ResolveSwitch} +}; + +static bool g_threadRunning = false; + +// ********************************************************************************************************************************** // +static bool IsEqualTo(const char *msg1, const char *msg2, int length) +{ + if (msg1 == NULL || msg2 == NULL || length <= 0) { + SCK_ERR("NULL POINT! \n"); + return false; + } + + return (strncasecmp(msg1, msg2, length) == 0); +} + +static void ResolveDevName(SocketEventCallback callback, char *value) +{ + SCK_INFO(" ########### value : %s ################ \n", value); +} + +static void ResolveSwitch(SocketEventCallback callback, char *value) +{ + SCK_INFO(" ########### value : %s ################ \n", value); + if (callback != NULL) { + callback(SOCKET_SET_CMD, value); + } +} + +static int SocketClientResolveData(const char *data, int len, SocketEventCallback callback) +{ + MsgInfo msgInfo = {0}; + if (data == NULL || len <= 0) { + SCK_ERR("NULL POINT!\n"); + return -1; + } + + if (len > MSG_DATE_BUF_LEN) { + len = MSG_DATE_BUF_LEN; + } + + memcpy(msgInfo.msg, data, len); + SCK_DBG("head:%s\n", msgInfo.msg_info.head); + for (int i = 0; i < ARRAYSIZE(g_msgData); i++) { + if (IsEqualTo(msgInfo.msg_info.cmd, g_msgData[i].cmd, strlen(g_msgData[i].cmd))) { + g_msgData[i].func(callback, msgInfo.msg_info.buff); + SCK_INFO(" cmd %s is match! \n", g_msgData[i].cmd); + break; + } + } + + return 0; +} + +static int SocketOpen(const char *ip, int port) +{ + int sockfd; + struct sockaddr_in recvAddr; + if (ip == NULL || port <= 0) { + return -1; + } + + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { + SCK_ERR("socket failed! errno=%d\n", errno); + return -1; + } + + memset(&recvAddr, 0x00, sizeof(recvAddr)); + recvAddr.sin_family = AF_INET; + recvAddr.sin_port = htons(port); + recvAddr.sin_addr.s_addr = inet_addr(ip); + + if (connect(sockfd, (struct sockaddr *)&recvAddr, sizeof(recvAddr)) < 0) { + SCK_ERR("connect failed! errno=%d\n", errno); + close(sockfd); + return -1; + } + + return sockfd; +} + +static int GetServerIp(char *ip, int size) +{ + char recMsg[256] = {0}; + char sockfd; + char *tmp = NULL; + struct sockaddr_in localAddr, serverAddr; + int sockaddr_len = sizeof(serverAddr); + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) { + SCK_ERR("socket failed!\n"); + return -1; + } + + memset(&localAddr, 0x00, sizeof(localAddr)); + localAddr.sin_family = AF_INET; + localAddr.sin_port = htons(UDP_DEF_PORT); + localAddr.sin_addr.s_addr = inet_addr(INADDR_ANY); + + if (bind(sockfd, (struct sockaddr *)&localAddr, sizeof(localAddr)) < 0) { + SCK_ERR("bind failed! errno : %d(%s)\n", errno, strerror(errno)); + close(sockfd); + return -1; + } + + if (recvfrom(sockfd, recMsg, sizeof(recMsg), 0, (struct sockaddr *)&serverAddr, &sockaddr_len) < 0) { + SCK_ERR("recvfrom failed! \n"); + close(sockfd); + return -1; + } + + tmp = inet_ntoa(serverAddr.sin_addr); + SCK_INFO("the server ip is %s \n", tmp); + if (ip == NULL || size < strlen(tmp)) { + SCK_ERR("params is invalid!! \n"); + close(sockfd); + return -1; + } + + strncpy(ip, tmp, strlen(tmp)); + + close(sockfd); + + return 0; +} + +static void SocketClientProcess(void *arg) +{ + int sockfd = -1; + char ipBuf[256] = {0}; + char sendBuf[256] = {0}; + char mDeviceName[256] = {0}; + + SocketCallback *mCallback = (SocketCallback *)arg; + if (mCallback == NULL) { + SCK_ERR("socket callback is NULL! \n"); + return; + } + + if (GetServerIp(ipBuf, sizeof(ipBuf)) < 0) { + SCK_ERR("get server ip failed! \n"); + g_threadRunning = false; + return; + } + + sockfd = SocketOpen((const char *)ipBuf, TCP_DEF_PORT); + if (sockfd < 0) { + SCK_ERR("socket open failed! \n"); + g_threadRunning = false; + return; + } + + if (mCallback->socketEvent != NULL) { + mCallback->socketEvent(SOCKET_CONNECTTED, NULL); + } + + if (mCallback->socketGetDeviceName != NULL) { + mCallback->socketGetDeviceName(mDeviceName, sizeof(mDeviceName)); + sprintf(sendBuf, "%s%s%s", PROTOCOL_HEADER, DATA_DEVICE_NAME, mDeviceName); + if (send(sockfd, sendBuf, strlen(sendBuf), 0) < 0) { + SCK_ERR("send %s failed! \n", sendBuf); + goto EXIT; + } + } + + while (g_threadRunning) { + char recvBuf[1024] = {0}; + int recvBytes = recv(sockfd, recvBuf, sizeof(recvBuf), 0); + if (recvBytes <= 0) { + break; + } + SCK_INFO("recvMsg[%d] : %s \n", recvBytes, recvBuf); + if (SocketClientResolveData((const char *)recvBuf, recvBytes, mCallback->socketEvent) < 0) { + break; + } + } + +EXIT: + close(sockfd); + sockfd = -1; + if (mCallback->socketEvent != NULL) { + mCallback->socketEvent(SOCKET_DISCONNECT, NULL); + } + g_threadRunning = false; +} + +int SocketClientStart(SocketCallback *gCallback) +{ + osThreadAttr_t attr; + + attr.name = "SocketClientTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = SOCKET_TASK_STACK; + attr.priority = SOCKET_TASK_PERIOD; + + g_threadRunning = true; + + if (osThreadNew(SocketClientProcess, (void *)gCallback, &attr) == NULL) { + SCK_ERR("Falied to create ClientTask!\n"); + return -1; + } + + return 0; +} + +void SocketClientStop(void) +{ + if (g_threadRunning) { + g_threadRunning = false; + } +} diff --git a/common/iot_socket/socket_client.h b/common/iot_socket/socket_client.h index c1ba420cf5ee6d32b04fdc4b6e6c5c69aca47274..a656b137ee86f228fb8d372b0cae871f30b2dedc 100644 --- a/common/iot_socket/socket_client.h +++ b/common/iot_socket/socket_client.h @@ -1,39 +1,39 @@ - -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef __SOCKET_CLIENT_H__ -#define __SOCKET_CLIENT_H__ - -typedef enum { - SOCKET_CONNECTTED = 1, - SOCKET_DISCONNECT, - SOCKET_SET_CMD -} SOCKET_EVENT; - -typedef int (*SocketGetDeviceName)(char *buf, int size); - -typedef int (*SocketEventCallback)(SOCKET_EVENT event, void *value); - -typedef struct { - SocketGetDeviceName socketGetDeviceName; - SocketEventCallback socketEvent; -} SocketCallback; - -int SocketClientStart(SocketCallback *gCallback); - -void SocketClientStop(void); - -#endif /* __SOCKET_CLIENT_H__ */ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef __SOCKET_CLIENT_H__ +#define __SOCKET_CLIENT_H__ + +typedef enum { + SOCKET_CONNECTTED = 1, + SOCKET_DISCONNECT, + SOCKET_SET_CMD +} SOCKET_EVENT; + +typedef int (*SocketGetDeviceName)(char *buf, int size); + +typedef int (*SocketEventCallback)(SOCKET_EVENT event, void *value); + +typedef struct { + SocketGetDeviceName socketGetDeviceName; + SocketEventCallback socketEvent; +} SocketCallback; + +int SocketClientStart(SocketCallback *gCallback); + +void SocketClientStop(void); + +#endif /* __SOCKET_CLIENT_H__ */ diff --git a/common/iot_wifi_bes2600/iot_bes2600_debug.h b/common/iot_wifi_bes2600/iot_bes2600_debug.h index a5e615d145030139be29798d3e10bf095eae3392..f16a74a411c94ca1a140fa586b040e4b914c5a81 100644 --- a/common/iot_wifi_bes2600/iot_bes2600_debug.h +++ b/common/iot_wifi_bes2600/iot_bes2600_debug.h @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ -#ifndef IOT_BES2600_DEBUG_H_ -#define IOT_BES2600_DEBUG_H_ - - -#define LOG_TAG "BES2600_WIFI" -#include "hilog/hiview_log.h" - -#define LOG_E(fmt, ...) HILOG_ERROR(HILOG_MODULE_APP, fmt, ##__VA_ARGS__) -#define LOG_I(fmt, ...) HILOG_INFO(HILOG_MODULE_APP, fmt, ##__VA_ARGS__) - - +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ +#ifndef IOT_BES2600_DEBUG_H_ +#define IOT_BES2600_DEBUG_H_ + + +#define LOG_TAG "BES2600_WIFI" +#include "hilog/hiview_log.h" + +#define LOG_E(fmt, ...) HILOG_ERROR(HILOG_MODULE_APP, fmt, ##__VA_ARGS__) +#define LOG_I(fmt, ...) HILOG_INFO(HILOG_MODULE_APP, fmt, ##__VA_ARGS__) + + #endif /* __IOT_SCHEDULE_H__ */ \ No newline at end of file diff --git a/common/oled_api/oled_bmp.h b/common/oled_api/oled_bmp.h index 7a8e25e076479a360dcdef5f07de444a3e633158..3fffc3afac23da57d2d93faa237c04c21537dbbb 100644 --- a/common/oled_api/oled_bmp.h +++ b/common/oled_api/oled_bmp.h @@ -1,385 +1,385 @@ -#ifndef __BMP_H__ -#define __BMP_H__ - -unsigned char BMP2[] = -{ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x7F,0xE0,0x03,0x91,0x1C,0x38,0x18,0x00,0x70,0x00,0xFF,0xFC,0x00,0x07,0xFF,0xFE, - 0x66,0x60,0x04,0x5B,0x22,0x44,0x14,0x01,0x8C,0x01,0x7F,0xFA,0x00,0x04,0x00,0x02, - 0x36,0xC0,0x08,0x15,0x40,0x80,0x52,0x02,0x02,0x01,0xBF,0xF6,0x00,0x3D,0xB6,0xDA, - 0x1F,0x80,0x88,0x11,0x40,0x80,0x34,0x04,0x71,0x01,0xDF,0xEE,0x00,0x25,0xB6,0xDA, - 0x0F,0x02,0x88,0x11,0x40,0x80,0x18,0x00,0x88,0x01,0xE0,0x1E,0x00,0x25,0xB6,0xDA, - 0x06,0x0A,0x88,0x11,0x40,0x80,0x34,0x01,0x04,0x01,0xDF,0xEE,0x00,0x25,0xB6,0xDA, - 0x06,0x2A,0x88,0x11,0x40,0x80,0x52,0x00,0x20,0x01,0xBF,0xF6,0x00,0x3D,0xB6,0xDA, - 0x06,0xAA,0x84,0x51,0x22,0x44,0x14,0x00,0x70,0x01,0x7F,0xFA,0x00,0x04,0x00,0x02, - 0x06,0xAA,0x83,0x91,0x1C,0x38,0x18,0x00,0x20,0x00,0xFF,0xFC,0x00,0x07,0xFF,0xFE, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x1F,0xFC,0x00,0x3F,0xFC,0x7F,0xF0,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x07,0x3F,0xFE,0x00,0x7F,0xFC,0xFF,0xF8,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x0F,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x1B,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x33,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x63,0x30,0x06,0x18,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0xC3,0x30,0x06,0x18,0x7F,0xFC,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x83,0x30,0x06,0x00,0x7F,0xFC,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x18,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x18,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x60,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x60,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x7F,0xFC,0xFF,0xF8,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x1F,0xFC,0x00,0x3F,0xF8,0x7F,0xF0,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0xF9,0xE3,0x0F,0x00,0xF1,0xE0,0x1E,0x3C,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x01,0x0A,0x15,0x10,0x81,0x0A,0x10,0x21,0x42,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x12,0x11,0x10,0x81,0x0A,0x00,0x21,0x40,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x22,0x11,0x1F,0x81,0x0B,0xE0,0x21,0x7C,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x42,0x11,0x10,0x81,0x0A,0x10,0x21,0x42,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x82,0x11,0x10,0x99,0x0A,0x13,0x21,0x42,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x01,0xF9,0xE7,0xCF,0x18,0xF1,0xE3,0x1E,0x3C,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x41,0x1C,0x41,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x7C,0x82, - 0x63,0x22,0x61,0x41,0x00,0x00,0x00,0x00,0xF1,0x00,0x00,0x00,0x00,0xC6,0x82,0xC2, - 0x55,0x41,0x51,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0xAA,0x80,0xA2, - 0x49,0x7E,0x49,0x41,0x00,0x00,0x00,0x00,0xFD,0x00,0x00,0x00,0x00,0x92,0x7C,0x92, - 0x41,0x40,0x45,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x02,0x8A, - 0x41,0x21,0x43,0x22,0x00,0x00,0x00,0x00,0xF1,0x00,0x00,0x00,0x00,0x82,0x82,0x86, - 0x41,0x1E,0x41,0x1C,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x7C,0x82, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -}; - -unsigned char BMP3[] = -{ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0xF8,0x03,0xFF,0xF8,0x03,0xC0,0xF0,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x0F,0xFE,0x03,0xFF,0xF8,0x07,0xF3,0xFC,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x18,0x03,0x03,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x7F,0xC0,0x07,0xFF,0xFC,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x30,0x03,0x03,0xFF,0xF0,0x03,0xFF,0xF8,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x18,0x06,0x03,0x80,0x38,0x01,0xFF,0xF0,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x0F,0xFC,0x03,0x00,0x18,0x00,0x7F,0xC0,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x1F,0xFF,0x00,0x00,0x0C,0x00,0x3F,0x80,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x30,0x01,0x80,0x00,0x0C,0x00,0x0E,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x04,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x10,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x10,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC6,0x00,0x0C,0x1E,0x38,0xCC,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x60,0x00,0xC7,0x00,0x1C,0x11,0x45,0x32,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x80,0x38,0x11,0x45,0x22,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x1F,0xFF,0x01,0xFF,0xF0,0x11,0x45,0x22,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x0F,0xFE,0x00,0x7F,0xC0,0x11,0x45,0x22,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x79,0x22,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x22,0x00,0x90,0x04,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x42,0x00,0x90,0x04,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x06,0x40,0x41,0x01,0x08,0x08,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x04,0x20,0x81,0x01,0x08,0x08,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x08,0x20,0x81,0x02,0x04,0x10,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x08,0x20,0x80,0x82,0x04,0x10,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x10,0x21,0x00,0x82,0x02,0x10,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x20,0x11,0x00,0x84,0x02,0x10,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x40,0x12,0x00,0x44,0x02,0x20,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x80,0x12,0x00,0x48,0x01,0x20,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x48,0x01,0x20,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x30,0x01,0x20,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x30,0x00,0xC0,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -}; - -unsigned char BMP4[] = -{ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x01,0x00,0x0C,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x01,0x00,0x0F,0xC0,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x00,0x1F,0xFE,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x00,0x3F,0xFF,0xFF,0x00,0x00,0x10,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x07,0x00,0x7F,0xFF,0xFF,0xFF,0xC0,0x10,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x06,0x00,0xFF,0xFF,0xFF,0xFF,0xE0,0x10,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x06,0x03,0xFF,0xFF,0xFF,0xFF,0xE0,0x20,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x06,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x60,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x06,0x3F,0xFF,0xFF,0xFF,0xFF,0xF0,0xC0,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x07,0x3C,0x3F,0xFF,0xF8,0x7F,0xF1,0x80,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x07,0x3F,0xFF,0xFF,0xFF,0xFF,0xF1,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x3F,0xFF,0xFF,0xFF,0xFF,0xF3,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x03,0x20,0x00,0xFF,0x00,0x07,0xF2,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x01,0x0F,0xFF,0x7E,0xFF,0xFB,0xE7,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x01,0x9F,0x7F,0x81,0xFD,0xFC,0x0F,0x80,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x01,0xBE,0x3F,0x9D,0xF8,0xFD,0xFF,0x80,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0xDF,0x7F,0xBC,0xFD,0xFB,0xFF,0x80,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x67,0xFE,0x7E,0x7F,0xE3,0xFF,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x38,0x01,0xFF,0x80,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x07,0xFE,0x00,0x7F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC7,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x0F,0x80,0x00,0x00,0x00,0x01,0x83,0x80,0x61,0xC0,0x00,0x00,0x00, - 0x00,0x00,0x00,0x0F,0x80,0xF0,0x00,0x00,0x07,0x82,0xE3,0xE1,0xB0,0x00,0x00,0x00, - 0x00,0x00,0x00,0x0F,0x80,0x1C,0x00,0x00,0x0C,0x6C,0x02,0x3F,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x0E,0x00,0x03,0x00,0x00,0x00,0xFE,0x00,0x3F,0x80,0x00,0x00,0x00, - 0x00,0x00,0x00,0x06,0x00,0xF1,0x80,0x00,0x0F,0x81,0xF7,0xC0,0x7C,0x00,0x00,0x00, - 0x00,0x00,0x00,0x03,0x80,0x18,0x80,0x00,0x03,0xFF,0x80,0xFF,0xE0,0x00,0x00,0x00, - 0x00,0x00,0x00,0x01,0xC0,0x0C,0x40,0x00,0x02,0x18,0x81,0x8C,0x60,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0xE1,0x84,0x40,0x00,0x02,0x18,0x81,0x8C,0x60,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x7F,0xC2,0x40,0x00,0x03,0xFF,0x81,0xFF,0xE0,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x3F,0xE2,0x40,0x00,0x02,0x00,0x31,0x80,0x0C,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x03,0xFF,0xF0,0xFF,0xFC,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC0,0x7F,0xF0,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -}; - -////////////////////////////////////////////////////////////////////////////////// -// -//洢ͼƬݣͼƬСΪ51*32 -//ʽ˳򣨸λǰ -// -///////////////////////////////////////////////////////////////////////////////// -unsigned char BMP5[] = -{ - 0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00, - 0x0E,0x00,0x00,0x00,0x00,0x01,0x80,0x0E,0x00,0x20,0x00,0x00,0x01,0xC0,0x00,0x00, - 0x70,0x00,0x00,0x00,0xC0,0x00,0x00,0xE0,0x00,0x00,0x00,0xE0,0x3F,0x81,0xC0,0x00, - 0x00,0x00,0x61,0xFF,0xF0,0x80,0x00,0x00,0x00,0x03,0xC0,0xF8,0x00,0x00,0x00,0x00, - 0x07,0x00,0x1C,0x00,0x00,0x00,0x00,0x1E,0x00,0x0F,0x00,0x00,0x00,0x7C,0x1C,0x00, - 0x03,0x1F,0x80,0x00,0x7C,0x1C,0x07,0xFF,0x1F,0x80,0x00,0x7C,0x1C,0x1F,0xFF,0x9F, - 0x80,0x00,0x00,0x1C,0x7C,0x03,0xF8,0x00,0x00,0x00,0x0F,0xF0,0x00,0x7C,0x00,0x00, - 0x03,0xFF,0x00,0x00,0x0F,0xE0,0x00,0x0F,0xF2,0x00,0x00,0x07,0xFE,0x00,0x1F,0x80, - 0x00,0x00,0x00,0x7F,0x80,0x3C,0x00,0x00,0x00,0x00,0x03,0x80,0x7C,0x00,0x00,0x00, - 0x00,0x03,0xC0,0x70,0x00,0x00,0x00,0x00,0x01,0xC0,0x70,0x00,0x00,0x00,0x00,0x01, - 0xC0,0x78,0x00,0x00,0x00,0x00,0x01,0xC0,0x7C,0x00,0x00,0x00,0x00,0x03,0xC0,0x3C, - 0x00,0x00,0x00,0x00,0x07,0x80,0x3E,0x00,0x00,0x00,0x00,0x3F,0x80,0x0F,0xE1,0xC0, - 0x00,0x1F,0xFC,0x00,0x03,0xFF,0xFC,0x03,0xFF,0xF0,0x00,0x00,0xFF,0xFF,0xFF,0xFF, - 0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x00, -}; -const unsigned char gImage_isoftstone[608] = { /* 0X00,0X01,0X80,0X00,0X26,0X00, */ -0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, -0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, -0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, -0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, -0X3F,0X3C,0X02,0X00,0X00,0X00,0X00,0X00,0XE0,0X10,0X00,0X00,0X00,0X00,0X00,0X00, -0X7F,0X1E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, -0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, -0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, -0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X7F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, -0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XE0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, -0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X1C,0XFD,0XE3,0XFF, -0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, -0XFF,0X00,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, -0XFF,0X10,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, -0XFF,0X1C,0X0F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0X78,0XF0,0X78,0X3C,0XE7,0XE3,0X80, -0XFF,0X1F,0XFE,0X3E,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7C,0XF8,0XE3,0XE3,0X80, -0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, -0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE3,0XE3,0XFF, -0XFC,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X0F,0XC0,0XE1,0XE3,0XFF, -0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X20,0X02,0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X3B,0XC3,0X0C,0X3F,0XE3,0XFC,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X26,0X43,0XFC,0X01,0XE0,0X84,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X39,0X03,0XD4,0X3D,0X60,0X84,0X00,0X00,0X00,0X00,0X00, -0XFF,0XFF,0XFF,0XFF,0XFC,0X39,0X83,0XFC,0X11,0X61,0X84,0X3F,0XFF,0XFF,0XFF,0XFF, -0X00,0X00,0X00,0X00,0X00,0X1B,0X83,0XFC,0X15,0X61,0X84,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X3A,0X83,0XDC,0X15,0X61,0X04,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X1A,0XC3,0X00,0X35,0X61,0X04,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X16,0X42,0XFC,0X3D,0X43,0X3C,0X00,0X00,0X00,0X00,0X00, -}; - -const unsigned char gImage_isoftstone2[608] = { /* 0X00,0X01,0X80,0X00,0X26,0X00, */ -0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, -0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, -0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, -0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, -0X3F,0X3C,0X02,0X00,0X00,0X00,0X00,0X00,0XE0,0X10,0X00,0X00,0X00,0X00,0X00,0X00, -0X7F,0X1E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, -0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, -0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, -0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X7F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, -0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XE0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, -0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X1C,0XFD,0XE3,0XFF, -0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, -0XFF,0X00,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, -0XFF,0X10,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, -0XFF,0X1C,0X0F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0X78,0XF0,0X78,0X3C,0XE7,0XE3,0X80, -0XFF,0X1F,0XFE,0X3E,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7C,0XF8,0XE3,0XE3,0X80, -0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, -0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE3,0XE3,0XFF, -0XFC,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X0F,0XC0,0XE1,0XE3,0XFF, -0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X20,0X02,0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X3B,0XC3,0X0C,0X3F,0XE3,0XFC,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X26,0X43,0XFC,0X01,0XE0,0X84,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X39,0X03,0XD4,0X3D,0X60,0X84,0X00,0X00,0X00,0X00,0X00, -0XFF,0XFF,0XFF,0XFF,0XFC,0X39,0X83,0XFC,0X11,0X61,0X84,0X3F,0XFF,0XFF,0XFF,0XFF, -0X00,0X00,0X00,0X00,0X00,0X1B,0X83,0XFC,0X15,0X61,0X84,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X3A,0X83,0XDC,0X15,0X61,0X04,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X1A,0XC3,0X00,0X35,0X61,0X04,0X00,0X00,0X00,0X00,0X00, -0X00,0X00,0X00,0X00,0X00,0X16,0X42,0XFC,0X3D,0X43,0X3C,0X00,0X00,0X00,0X00,0X00, -}; - -const unsigned char gImage_isoftstone3[416] = { /* 0X00,0X01,0X80,0X00,0X1A,0X00, */ -0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, -0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, -0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, -0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, -0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, -0X3F,0X3C,0X02,0X7F,0X80,0X7F,0XE7,0XFD,0XE0,0X17,0XFE,0XFF,0X00,0XE1,0XE3,0XFF, -0X7F,0X3E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, -0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, -0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, -0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X3F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, -0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XF0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, -0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X3C,0XFD,0XE3,0XFF, -0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, -0XFF,0X10,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, -0XFF,0X18,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0XC0,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, -0XFF,0X1C,0X1F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0XF8,0XF0,0X78,0X3C,0XE7,0XE3,0X80, -0XFF,0X1F,0XFE,0X3F,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7E,0XF8,0XE3,0XE3,0X80, -0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, -0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE1,0XE3,0XFF, -0XF8,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X07,0XC0,0XE1,0XE3,0XFF, -}; - -const unsigned char gImage_issedu[] = { - 0x00,0x18,0xFF,0x8C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x27,0xFF,0xF3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0xDF,0x80,0xFC,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x3D,0xFF,0xCE,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x02,0xF7,0xFF,0xF3,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x05,0xDF,0xFF,0xFD,0xD0,0x01,0x83,0x80,0xF7,0xFF,0x80,0xC1,0xC0,0x00,0xC0,0x00, - 0x0B,0xBF,0xFF,0xFE,0xE8,0x0E,0x74,0x7D,0x00,0x00,0x4F,0x3E,0x3E,0xFF,0x3F,0xC0, - 0x17,0x7F,0xFF,0xFF,0xF4,0x11,0xC3,0x82,0xF7,0xFF,0xB0,0xC1,0xC0,0x00,0xC0,0x00, - 0x16,0xFF,0xFF,0xFF,0xFA,0x2F,0xFB,0xFC,0xFF,0xFF,0xCF,0xFD,0xFF,0xFF,0xFF,0xE0, - 0x2D,0xFF,0xC0,0xFF,0xDA,0x2F,0xFB,0xFE,0xFF,0xFF,0xCF,0xFD,0xFE,0xFF,0xFF,0xE0, - 0x5F,0xFE,0x04,0x3F,0xED,0x2F,0xFF,0xFE,0x0B,0x83,0xCF,0xFF,0xFE,0xFF,0xFF,0xD0, - 0x5B,0xFD,0xFB,0xCF,0xFD,0x13,0x8F,0x0E,0xE7,0xFF,0xD0,0xDF,0x9C,0xEF,0xFD,0xD0, - 0xBF,0xFB,0xFF,0xC7,0xF6,0x97,0xEE,0xFE,0xF7,0xFF,0xEF,0xFF,0x5C,0xFF,0xFF,0xD0, - 0xB7,0xF7,0xF3,0xD7,0xFE,0x97,0xED,0xDC,0xFF,0xBB,0xEF,0xFD,0xDD,0x7F,0xFF,0x90, - 0xB7,0xEF,0xEB,0xDB,0xF7,0x57,0xE1,0xF3,0x7F,0xFF,0xE7,0xF1,0xDD,0x7F,0xFF,0xA0, - 0x7B,0x8F,0xD9,0xD4,0xEF,0x57,0xF9,0xF5,0x7F,0xFF,0xEF,0xFD,0xDC,0xFF,0xFF,0xD0, - 0x7E,0xEF,0xC7,0xEB,0x9F,0x57,0xF9,0xF5,0x7F,0xBB,0xEF,0xFD,0xDC,0xFF,0xFF,0xD0, - 0x7F,0xEF,0x9F,0xF5,0xFF,0x4B,0xFD,0xF3,0x7F,0xFF,0xEC,0x3C,0xFA,0xFF,0xFF,0xD0, - 0x7A,0xDF,0xBD,0xF5,0xEF,0x50,0xE5,0xFB,0x7F,0xFF,0xEF,0xFE,0xFA,0xFF,0xFF,0xD0, - 0x7F,0xDF,0x63,0xF9,0xFF,0x6F,0xFB,0xBB,0x7F,0xBB,0xEF,0xFD,0xFA,0xFF,0xFF,0xD0, - 0x7F,0xDF,0x57,0xF9,0xFF,0x6F,0xFB,0xBD,0x7E,0xBB,0xCF,0xFC,0x72,0xFF,0xFF,0xD0, - 0x7F,0xDF,0x67,0xFD,0xFF,0x4F,0xF7,0x5E,0x76,0x3B,0x90,0x71,0xFC,0xFF,0xFF,0xD0, - 0x7B,0xDF,0x15,0xFD,0xFF,0x40,0xEF,0x6E,0xFF,0xFF,0xE7,0xFB,0xFE,0xE0,0x03,0xD0, - 0x7F,0xFF,0xFB,0xFB,0xFF,0x4E,0xEE,0xA6,0xFF,0xFF,0xE7,0xEB,0x8E,0xE8,0x0B,0xD0, - 0x3F,0xFF,0xF7,0xFB,0xEF,0x44,0xE9,0xF2,0xCF,0xFF,0xE7,0xD2,0x76,0xFF,0xFB,0x20, - 0xBF,0xFF,0xFF,0xC7,0xFE,0x42,0x12,0x01,0x20,0x00,0x08,0x0C,0xB1,0x00,0x90,0x40, - 0xBF,0xF7,0xFF,0xB7,0xDE,0x85,0xCC,0xFE,0xFD,0xD7,0xF7,0xF2,0x4E,0xBF,0x65,0xC0, - 0x5E,0xFB,0xFF,0x4F,0xFE,0x97,0xDF,0xFF,0xFF,0xFB,0xF7,0xFE,0xFE,0xFF,0xF6,0xD0, - 0x5A,0xFE,0xF0,0xBF,0xBD,0x17,0xB3,0xEF,0xDB,0x7F,0xF7,0x6E,0xF5,0xCB,0x9F,0xD0, - 0x2F,0x7F,0x80,0xFD,0xFD,0x17,0xF3,0xED,0xFB,0x3F,0xF7,0xEE,0x71,0xEB,0x9F,0xD0, - 0x2F,0xFF,0xFF,0xFF,0xDA,0x17,0xFF,0x8D,0x7B,0xFF,0xF7,0x7F,0xFF,0xEB,0xFD,0xD0, - 0x16,0xDF,0xFF,0xFF,0xB4,0x07,0xDF,0xAD,0xF9,0xFB,0xF7,0xFB,0xDF,0x3B,0xF6,0xD0, - 0x0B,0x77,0xFB,0xFB,0x64,0x00,0x20,0x52,0x04,0x04,0x08,0x04,0x20,0xC4,0x09,0x20, - 0x0D,0xBF,0xFF,0xEE,0xC8,0x07,0xDE,0x8D,0xE9,0xFB,0xF7,0xFB,0xDF,0x2B,0xF4,0xC0, - 0x06,0xFF,0x7B,0xFF,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x03,0x7F,0xFF,0xFF,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0xBF,0xFF,0xFE,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x4F,0xFF,0xF9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x31,0xFF,0xE6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x0C,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -}; -#endif - +#ifndef __BMP_H__ +#define __BMP_H__ + +unsigned char BMP2[] = +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7F,0xE0,0x03,0x91,0x1C,0x38,0x18,0x00,0x70,0x00,0xFF,0xFC,0x00,0x07,0xFF,0xFE, + 0x66,0x60,0x04,0x5B,0x22,0x44,0x14,0x01,0x8C,0x01,0x7F,0xFA,0x00,0x04,0x00,0x02, + 0x36,0xC0,0x08,0x15,0x40,0x80,0x52,0x02,0x02,0x01,0xBF,0xF6,0x00,0x3D,0xB6,0xDA, + 0x1F,0x80,0x88,0x11,0x40,0x80,0x34,0x04,0x71,0x01,0xDF,0xEE,0x00,0x25,0xB6,0xDA, + 0x0F,0x02,0x88,0x11,0x40,0x80,0x18,0x00,0x88,0x01,0xE0,0x1E,0x00,0x25,0xB6,0xDA, + 0x06,0x0A,0x88,0x11,0x40,0x80,0x34,0x01,0x04,0x01,0xDF,0xEE,0x00,0x25,0xB6,0xDA, + 0x06,0x2A,0x88,0x11,0x40,0x80,0x52,0x00,0x20,0x01,0xBF,0xF6,0x00,0x3D,0xB6,0xDA, + 0x06,0xAA,0x84,0x51,0x22,0x44,0x14,0x00,0x70,0x01,0x7F,0xFA,0x00,0x04,0x00,0x02, + 0x06,0xAA,0x83,0x91,0x1C,0x38,0x18,0x00,0x20,0x00,0xFF,0xFC,0x00,0x07,0xFF,0xFE, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x1F,0xFC,0x00,0x3F,0xFC,0x7F,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x07,0x3F,0xFE,0x00,0x7F,0xFC,0xFF,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x1B,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x33,0x30,0x06,0x00,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x63,0x30,0x06,0x18,0x60,0x00,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xC3,0x30,0x06,0x18,0x7F,0xFC,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x83,0x30,0x06,0x00,0x7F,0xFC,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x18,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x18,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x00,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x60,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x30,0x06,0x00,0x60,0x0C,0xC0,0x18,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x00,0x7F,0xFC,0xFF,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x1F,0xFC,0x00,0x3F,0xF8,0x7F,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xF9,0xE3,0x0F,0x00,0xF1,0xE0,0x1E,0x3C,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x01,0x0A,0x15,0x10,0x81,0x0A,0x10,0x21,0x42,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x12,0x11,0x10,0x81,0x0A,0x00,0x21,0x40,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x22,0x11,0x1F,0x81,0x0B,0xE0,0x21,0x7C,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x42,0x11,0x10,0x81,0x0A,0x10,0x21,0x42,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x82,0x11,0x10,0x99,0x0A,0x13,0x21,0x42,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x01,0xF9,0xE7,0xCF,0x18,0xF1,0xE3,0x1E,0x3C,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x1C,0x41,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x7C,0x82, + 0x63,0x22,0x61,0x41,0x00,0x00,0x00,0x00,0xF1,0x00,0x00,0x00,0x00,0xC6,0x82,0xC2, + 0x55,0x41,0x51,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0xAA,0x80,0xA2, + 0x49,0x7E,0x49,0x41,0x00,0x00,0x00,0x00,0xFD,0x00,0x00,0x00,0x00,0x92,0x7C,0x92, + 0x41,0x40,0x45,0x41,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x02,0x8A, + 0x41,0x21,0x43,0x22,0x00,0x00,0x00,0x00,0xF1,0x00,0x00,0x00,0x00,0x82,0x82,0x86, + 0x41,0x1E,0x41,0x1C,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x82,0x7C,0x82, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +unsigned char BMP3[] = +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0xF8,0x03,0xFF,0xF8,0x03,0xC0,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0xFE,0x03,0xFF,0xF8,0x07,0xF3,0xFC,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x18,0x03,0x03,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC3,0x00,0x00,0x0F,0xFF,0xFE,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x7F,0xC0,0x07,0xFF,0xFC,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x03,0x03,0xFF,0xF0,0x03,0xFF,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x18,0x06,0x03,0x80,0x38,0x01,0xFF,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0xFC,0x03,0x00,0x18,0x00,0x7F,0xC0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x1F,0xFF,0x00,0x00,0x0C,0x00,0x3F,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x01,0x80,0x00,0x0C,0x00,0x0E,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x04,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x10,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC0,0x00,0x0C,0x10,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC6,0x00,0x0C,0x1E,0x38,0xCC,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0xC7,0x00,0x1C,0x11,0x45,0x32,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x30,0x01,0x83,0x80,0x38,0x11,0x45,0x22,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x1F,0xFF,0x01,0xFF,0xF0,0x11,0x45,0x22,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0xFE,0x00,0x7F,0xC0,0x11,0x45,0x22,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x79,0x22,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x22,0x00,0x90,0x04,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x42,0x00,0x90,0x04,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x06,0x40,0x41,0x01,0x08,0x08,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x04,0x20,0x81,0x01,0x08,0x08,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x08,0x20,0x81,0x02,0x04,0x10,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x08,0x20,0x80,0x82,0x04,0x10,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x10,0x21,0x00,0x82,0x02,0x10,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x20,0x11,0x00,0x84,0x02,0x10,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x40,0x12,0x00,0x44,0x02,0x20,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x80,0x12,0x00,0x48,0x01,0x20,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x48,0x01,0x20,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x30,0x01,0x20,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x30,0x00,0xC0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +unsigned char BMP4[] = +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x00,0x0C,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x00,0x0F,0xC0,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x00,0x1F,0xFE,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x00,0x3F,0xFF,0xFF,0x00,0x00,0x10,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x07,0x00,0x7F,0xFF,0xFF,0xFF,0xC0,0x10,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x00,0xFF,0xFF,0xFF,0xFF,0xE0,0x10,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x03,0xFF,0xFF,0xFF,0xFF,0xE0,0x20,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x60,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x06,0x3F,0xFF,0xFF,0xFF,0xFF,0xF0,0xC0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x07,0x3C,0x3F,0xFF,0xF8,0x7F,0xF1,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x07,0x3F,0xFF,0xFF,0xFF,0xFF,0xF1,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x3F,0xFF,0xFF,0xFF,0xFF,0xF3,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x03,0x20,0x00,0xFF,0x00,0x07,0xF2,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x0F,0xFF,0x7E,0xFF,0xFB,0xE7,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x9F,0x7F,0x81,0xFD,0xFC,0x0F,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0xBE,0x3F,0x9D,0xF8,0xFD,0xFF,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0xDF,0x7F,0xBC,0xFD,0xFB,0xFF,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x67,0xFE,0x7E,0x7F,0xE3,0xFF,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x38,0x01,0xFF,0x80,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x07,0xFE,0x00,0x7F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC7,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0F,0x80,0x00,0x00,0x00,0x01,0x83,0x80,0x61,0xC0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0F,0x80,0xF0,0x00,0x00,0x07,0x82,0xE3,0xE1,0xB0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0F,0x80,0x1C,0x00,0x00,0x0C,0x6C,0x02,0x3F,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0E,0x00,0x03,0x00,0x00,0x00,0xFE,0x00,0x3F,0x80,0x00,0x00,0x00, + 0x00,0x00,0x00,0x06,0x00,0xF1,0x80,0x00,0x0F,0x81,0xF7,0xC0,0x7C,0x00,0x00,0x00, + 0x00,0x00,0x00,0x03,0x80,0x18,0x80,0x00,0x03,0xFF,0x80,0xFF,0xE0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x01,0xC0,0x0C,0x40,0x00,0x02,0x18,0x81,0x8C,0x60,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xE1,0x84,0x40,0x00,0x02,0x18,0x81,0x8C,0x60,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x7F,0xC2,0x40,0x00,0x03,0xFF,0x81,0xFF,0xE0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x3F,0xE2,0x40,0x00,0x02,0x00,0x31,0x80,0x0C,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x03,0xFF,0xF0,0xFF,0xFC,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC0,0x7F,0xF0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +////////////////////////////////////////////////////////////////////////////////// +// +//洢ͼƬݣͼƬСΪ51*32 +//ʽ˳򣨸λǰ +// +///////////////////////////////////////////////////////////////////////////////// +unsigned char BMP5[] = +{ + 0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00, + 0x0E,0x00,0x00,0x00,0x00,0x01,0x80,0x0E,0x00,0x20,0x00,0x00,0x01,0xC0,0x00,0x00, + 0x70,0x00,0x00,0x00,0xC0,0x00,0x00,0xE0,0x00,0x00,0x00,0xE0,0x3F,0x81,0xC0,0x00, + 0x00,0x00,0x61,0xFF,0xF0,0x80,0x00,0x00,0x00,0x03,0xC0,0xF8,0x00,0x00,0x00,0x00, + 0x07,0x00,0x1C,0x00,0x00,0x00,0x00,0x1E,0x00,0x0F,0x00,0x00,0x00,0x7C,0x1C,0x00, + 0x03,0x1F,0x80,0x00,0x7C,0x1C,0x07,0xFF,0x1F,0x80,0x00,0x7C,0x1C,0x1F,0xFF,0x9F, + 0x80,0x00,0x00,0x1C,0x7C,0x03,0xF8,0x00,0x00,0x00,0x0F,0xF0,0x00,0x7C,0x00,0x00, + 0x03,0xFF,0x00,0x00,0x0F,0xE0,0x00,0x0F,0xF2,0x00,0x00,0x07,0xFE,0x00,0x1F,0x80, + 0x00,0x00,0x00,0x7F,0x80,0x3C,0x00,0x00,0x00,0x00,0x03,0x80,0x7C,0x00,0x00,0x00, + 0x00,0x03,0xC0,0x70,0x00,0x00,0x00,0x00,0x01,0xC0,0x70,0x00,0x00,0x00,0x00,0x01, + 0xC0,0x78,0x00,0x00,0x00,0x00,0x01,0xC0,0x7C,0x00,0x00,0x00,0x00,0x03,0xC0,0x3C, + 0x00,0x00,0x00,0x00,0x07,0x80,0x3E,0x00,0x00,0x00,0x00,0x3F,0x80,0x0F,0xE1,0xC0, + 0x00,0x1F,0xFC,0x00,0x03,0xFF,0xFC,0x03,0xFF,0xF0,0x00,0x00,0xFF,0xFF,0xFF,0xFF, + 0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x00, +}; +const unsigned char gImage_isoftstone[608] = { /* 0X00,0X01,0X80,0X00,0X26,0X00, */ +0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, +0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0X3C,0X02,0X00,0X00,0X00,0X00,0X00,0XE0,0X10,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0X1E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, +0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, +0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, +0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X7F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, +0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XE0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, +0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X1C,0XFD,0XE3,0XFF, +0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, +0XFF,0X00,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, +0XFF,0X10,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, +0XFF,0X1C,0X0F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0X78,0XF0,0X78,0X3C,0XE7,0XE3,0X80, +0XFF,0X1F,0XFE,0X3E,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7C,0XF8,0XE3,0XE3,0X80, +0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, +0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE3,0XE3,0XFF, +0XFC,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X0F,0XC0,0XE1,0XE3,0XFF, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X20,0X02,0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X3B,0XC3,0X0C,0X3F,0XE3,0XFC,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X26,0X43,0XFC,0X01,0XE0,0X84,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X39,0X03,0XD4,0X3D,0X60,0X84,0X00,0X00,0X00,0X00,0X00, +0XFF,0XFF,0XFF,0XFF,0XFC,0X39,0X83,0XFC,0X11,0X61,0X84,0X3F,0XFF,0XFF,0XFF,0XFF, +0X00,0X00,0X00,0X00,0X00,0X1B,0X83,0XFC,0X15,0X61,0X84,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X3A,0X83,0XDC,0X15,0X61,0X04,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X1A,0XC3,0X00,0X35,0X61,0X04,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X16,0X42,0XFC,0X3D,0X43,0X3C,0X00,0X00,0X00,0X00,0X00, +}; + +const unsigned char gImage_isoftstone2[608] = { /* 0X00,0X01,0X80,0X00,0X26,0X00, */ +0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, +0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0X3C,0X02,0X00,0X00,0X00,0X00,0X00,0XE0,0X10,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0X1E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, +0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, +0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, +0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X7F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, +0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XE0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, +0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X1C,0XFD,0XE3,0XFF, +0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, +0XFF,0X00,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, +0XFF,0X10,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, +0XFF,0X1C,0X0F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0X78,0XF0,0X78,0X3C,0XE7,0XE3,0X80, +0XFF,0X1F,0XFE,0X3E,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7C,0XF8,0XE3,0XE3,0X80, +0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, +0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE3,0XE3,0XFF, +0XFC,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X0F,0XC0,0XE1,0XE3,0XFF, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X20,0X02,0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X3B,0XC3,0X0C,0X3F,0XE3,0XFC,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X26,0X43,0XFC,0X01,0XE0,0X84,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X39,0X03,0XD4,0X3D,0X60,0X84,0X00,0X00,0X00,0X00,0X00, +0XFF,0XFF,0XFF,0XFF,0XFC,0X39,0X83,0XFC,0X11,0X61,0X84,0X3F,0XFF,0XFF,0XFF,0XFF, +0X00,0X00,0X00,0X00,0X00,0X1B,0X83,0XFC,0X15,0X61,0X84,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X3A,0X83,0XDC,0X15,0X61,0X04,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X1A,0XC3,0X00,0X35,0X61,0X04,0X00,0X00,0X00,0X00,0X00, +0X00,0X00,0X00,0X00,0X00,0X16,0X42,0XFC,0X3D,0X43,0X3C,0X00,0X00,0X00,0X00,0X00, +}; + +const unsigned char gImage_isoftstone3[416] = { /* 0X00,0X01,0X80,0X00,0X1A,0X00, */ +0X03,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X1F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00, +0XF0,0X07,0XF8,0X00,0X00,0X00,0X00,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,0X00,0X00, +0XC0,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X80,0X1F,0XFE,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00, +0X0F,0X1E,0X0E,0X00,0X00,0X00,0X00,0X00,0XF0,0X70,0X00,0X00,0X00,0X00,0X00,0X00, +0X3F,0X3C,0X02,0X7F,0X80,0X7F,0XE7,0XFD,0XE0,0X17,0XFE,0XFF,0X00,0XE1,0XE3,0XFF, +0X7F,0X3E,0X00,0X7F,0XF0,0X7F,0XE7,0XFC,0XF0,0X07,0XFE,0XFF,0XE0,0XF1,0XE3,0XFF, +0XFF,0X1F,0X00,0X7F,0XFC,0X7F,0XE7,0XFC,0XF8,0X07,0XFE,0XFF,0XF0,0XF1,0XE3,0XFF, +0XFF,0X1F,0XE0,0X7F,0XFC,0X7F,0XE7,0XFC,0XFF,0X07,0XFE,0XFF,0XF8,0XF9,0XE3,0XFF, +0XFF,0X0F,0XF8,0X7E,0X3E,0X78,0X00,0XE0,0X3F,0XC0,0XF0,0XF8,0X7C,0XF9,0XE3,0X80, +0XFF,0X03,0XFC,0X7C,0X1E,0X78,0X00,0XE0,0X1F,0XF0,0XF0,0XF0,0X3C,0XFD,0XE3,0X80, +0XFF,0X00,0X7E,0X78,0X0E,0X78,0X00,0XE0,0X03,0XF0,0XF0,0XF0,0X3C,0XFD,0XE3,0XFF, +0XFF,0X00,0X1F,0X78,0X0E,0X7F,0XE0,0XE0,0X00,0XF8,0XF0,0XF0,0X1C,0XFF,0XE3,0XFF, +0XFF,0X10,0X0F,0X78,0X0E,0X7F,0XE0,0XE0,0X80,0X78,0XF0,0XF0,0X1C,0XEF,0XE3,0XFF, +0XFF,0X18,0X0F,0X38,0X0E,0X7F,0XE0,0XE0,0XC0,0X78,0XF0,0XF0,0X3C,0XE7,0XE3,0X80, +0XFF,0X1C,0X1F,0X3C,0X1E,0X7F,0XE0,0XE0,0XE0,0XF8,0XF0,0X78,0X3C,0XE7,0XE3,0X80, +0XFF,0X1F,0XFE,0X3F,0X7E,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X7E,0XF8,0XE3,0XE3,0X80, +0XFF,0X1F,0XFE,0X1F,0XFC,0X78,0X00,0XE0,0XFF,0XF0,0XF0,0X3F,0XF8,0XE3,0XE3,0XFF, +0XFE,0X0F,0XFC,0X0F,0XF8,0X78,0X00,0XE0,0X7F,0XE0,0XF0,0X1F,0XF0,0XE1,0XE3,0XFF, +0XF8,0X03,0XF0,0X03,0XE0,0X78,0X00,0XE0,0X1F,0X80,0XF0,0X07,0XC0,0XE1,0XE3,0XFF, +}; + +const unsigned char gImage_issedu[] = { + 0x00,0x18,0xFF,0x8C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x27,0xFF,0xF3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0xDF,0x80,0xFC,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x01,0x3D,0xFF,0xCE,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x02,0xF7,0xFF,0xF3,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x05,0xDF,0xFF,0xFD,0xD0,0x01,0x83,0x80,0xF7,0xFF,0x80,0xC1,0xC0,0x00,0xC0,0x00, + 0x0B,0xBF,0xFF,0xFE,0xE8,0x0E,0x74,0x7D,0x00,0x00,0x4F,0x3E,0x3E,0xFF,0x3F,0xC0, + 0x17,0x7F,0xFF,0xFF,0xF4,0x11,0xC3,0x82,0xF7,0xFF,0xB0,0xC1,0xC0,0x00,0xC0,0x00, + 0x16,0xFF,0xFF,0xFF,0xFA,0x2F,0xFB,0xFC,0xFF,0xFF,0xCF,0xFD,0xFF,0xFF,0xFF,0xE0, + 0x2D,0xFF,0xC0,0xFF,0xDA,0x2F,0xFB,0xFE,0xFF,0xFF,0xCF,0xFD,0xFE,0xFF,0xFF,0xE0, + 0x5F,0xFE,0x04,0x3F,0xED,0x2F,0xFF,0xFE,0x0B,0x83,0xCF,0xFF,0xFE,0xFF,0xFF,0xD0, + 0x5B,0xFD,0xFB,0xCF,0xFD,0x13,0x8F,0x0E,0xE7,0xFF,0xD0,0xDF,0x9C,0xEF,0xFD,0xD0, + 0xBF,0xFB,0xFF,0xC7,0xF6,0x97,0xEE,0xFE,0xF7,0xFF,0xEF,0xFF,0x5C,0xFF,0xFF,0xD0, + 0xB7,0xF7,0xF3,0xD7,0xFE,0x97,0xED,0xDC,0xFF,0xBB,0xEF,0xFD,0xDD,0x7F,0xFF,0x90, + 0xB7,0xEF,0xEB,0xDB,0xF7,0x57,0xE1,0xF3,0x7F,0xFF,0xE7,0xF1,0xDD,0x7F,0xFF,0xA0, + 0x7B,0x8F,0xD9,0xD4,0xEF,0x57,0xF9,0xF5,0x7F,0xFF,0xEF,0xFD,0xDC,0xFF,0xFF,0xD0, + 0x7E,0xEF,0xC7,0xEB,0x9F,0x57,0xF9,0xF5,0x7F,0xBB,0xEF,0xFD,0xDC,0xFF,0xFF,0xD0, + 0x7F,0xEF,0x9F,0xF5,0xFF,0x4B,0xFD,0xF3,0x7F,0xFF,0xEC,0x3C,0xFA,0xFF,0xFF,0xD0, + 0x7A,0xDF,0xBD,0xF5,0xEF,0x50,0xE5,0xFB,0x7F,0xFF,0xEF,0xFE,0xFA,0xFF,0xFF,0xD0, + 0x7F,0xDF,0x63,0xF9,0xFF,0x6F,0xFB,0xBB,0x7F,0xBB,0xEF,0xFD,0xFA,0xFF,0xFF,0xD0, + 0x7F,0xDF,0x57,0xF9,0xFF,0x6F,0xFB,0xBD,0x7E,0xBB,0xCF,0xFC,0x72,0xFF,0xFF,0xD0, + 0x7F,0xDF,0x67,0xFD,0xFF,0x4F,0xF7,0x5E,0x76,0x3B,0x90,0x71,0xFC,0xFF,0xFF,0xD0, + 0x7B,0xDF,0x15,0xFD,0xFF,0x40,0xEF,0x6E,0xFF,0xFF,0xE7,0xFB,0xFE,0xE0,0x03,0xD0, + 0x7F,0xFF,0xFB,0xFB,0xFF,0x4E,0xEE,0xA6,0xFF,0xFF,0xE7,0xEB,0x8E,0xE8,0x0B,0xD0, + 0x3F,0xFF,0xF7,0xFB,0xEF,0x44,0xE9,0xF2,0xCF,0xFF,0xE7,0xD2,0x76,0xFF,0xFB,0x20, + 0xBF,0xFF,0xFF,0xC7,0xFE,0x42,0x12,0x01,0x20,0x00,0x08,0x0C,0xB1,0x00,0x90,0x40, + 0xBF,0xF7,0xFF,0xB7,0xDE,0x85,0xCC,0xFE,0xFD,0xD7,0xF7,0xF2,0x4E,0xBF,0x65,0xC0, + 0x5E,0xFB,0xFF,0x4F,0xFE,0x97,0xDF,0xFF,0xFF,0xFB,0xF7,0xFE,0xFE,0xFF,0xF6,0xD0, + 0x5A,0xFE,0xF0,0xBF,0xBD,0x17,0xB3,0xEF,0xDB,0x7F,0xF7,0x6E,0xF5,0xCB,0x9F,0xD0, + 0x2F,0x7F,0x80,0xFD,0xFD,0x17,0xF3,0xED,0xFB,0x3F,0xF7,0xEE,0x71,0xEB,0x9F,0xD0, + 0x2F,0xFF,0xFF,0xFF,0xDA,0x17,0xFF,0x8D,0x7B,0xFF,0xF7,0x7F,0xFF,0xEB,0xFD,0xD0, + 0x16,0xDF,0xFF,0xFF,0xB4,0x07,0xDF,0xAD,0xF9,0xFB,0xF7,0xFB,0xDF,0x3B,0xF6,0xD0, + 0x0B,0x77,0xFB,0xFB,0x64,0x00,0x20,0x52,0x04,0x04,0x08,0x04,0x20,0xC4,0x09,0x20, + 0x0D,0xBF,0xFF,0xEE,0xC8,0x07,0xDE,0x8D,0xE9,0xFB,0xF7,0xFB,0xDF,0x2B,0xF4,0xC0, + 0x06,0xFF,0x7B,0xFF,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x03,0x7F,0xFF,0xFF,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0xBF,0xFF,0xFE,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x4F,0xFF,0xF9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x31,0xFF,0xE6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x0C,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif + diff --git a/common/ssd1306/ssd1306_drv.c b/common/ssd1306/ssd1306_drv.c index 6b629bdc32d39381206857c3914b4425bb93f915..75bc3bc296e402cad65a17ddaa2f5a80c3c7c9fb 100644 --- a/common/ssd1306/ssd1306_drv.c +++ b/common/ssd1306/ssd1306_drv.c @@ -1,507 +1,507 @@ -#include "hi_spi.h" -#include "iot_spi.h" - -//定义I2C和SPI的宏 -#define SSD1306_USE_IIC 1 -#define SSD1306_USE_SPI 0 - -/* IIC方式控制SSD1306 */ -#if SSD1306_USE_IIC -#include "ssd1306_iic_drv.h" - -#define SSD1306_I2C_ADDR (0x3C <<1) -#define OLED_IIC_BAUDRATE 400000 -#endif - -/* SPI方式控制SSD1306 */ -#if SSD1306_USE_SPI -#include "ssd1306_spi_drv.h" - -#define U8_LEN 1 -#endif - - -//OLED显存总共分为8页 -//每页8行,一行128个像素点 -//OLED的显存 -//存放格式如下. -//[0]0 1 2 3 ... 127 (0~7)行 -//[1]0 1 2 3 ... 127 (8~15)行 -//[2]0 1 2 3 ... 127 (16~23)行 -//[3]0 1 2 3 ... 127 (24~31)行 -//[4]0 1 2 3 ... 127 (32~39)行 -//[5]0 1 2 3 ... 127 (40~47)行 -//[6]0 1 2 3 ... 127 (48~55)行 -//[7]0 1 2 3 ... 127 (56~63)行 - - -static unsigned char SSD1306_buffer[SSD1306_BUFFER_SIZE] = {0x00}; - - -/* IIC方式控制SSD1306 */ -#if SSD1306_USE_IIC -/******************************************************************* - * @name :void SSD1306InitGPIO(void) - * @date :2018-08-27 - * @function :初始化SSD1306的GPIO - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306InitGPIO(void) -{ - return; -} - -/******************************************************************* - * @name :void SSD1306IOInit(u8 i2cId) - * @date :2023-02-24 - * @function :初始化SSD1306的IIC,在此之前必须先初始化SSD1306的GPIO为IIC功能 - 即在调用本函数之前先调用iot_gpio_iic.h中的初始化接口函数 - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306InitIO(u8 i2cId) -{ - u32 ret = KP_ERR_SUCCESS; - - /* IIC初始化 */ - ret = IoTI2cInit(i2cId, OLED_IIC_BAUDRATE); - if (ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("IoTI2cInit failed :%#x \r\n", ret); - return; - } - - /* IIC设置波特率 */ - ret = IoTI2cSetBaudrate(i2cId, OLED_IIC_BAUDRATE); - if (ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("IoTI2cSetBaudrate failed :%#x \r\n", ret); - return; - } - - printf("SSD1306InitIO success \r\n"); -} - -/******************************************************************* - * @name :void OLED_Reset(void) - * @date :2018-08-27 - * @function :Reset OLED screen - * @parameters :dat:0-Display full black - 1-Display full white - * @retvalue :None -********************************************************************/ -void SSD1306Reset(void) -{ - /* for I2C - do nothing */ -} - -u32 SSD1306WriteBuf(u32 iicId, u8 *data, u32 byteLen) -{ - u32 ret = IoTI2cWrite(iicId, SSD1306_I2C_ADDR, data, byteLen); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTI2cWrite failed :%#x \r\n", ret); - return ret; - } - - return KP_ERR_SUCCESS; -} - -u32 SSD1306WriteCmd(u32 iicId, u8 cmd) -{ - u32 ret = KP_ERR_SUCCESS; - - u8 buffer[] = {SSD1306_CTRL_CMD, cmd}; - ret = SSD1306WriteBuf(iicId, SSD1306_I2C_ADDR, buffer, sizeof(buffer)); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("SSD1306WriteBuf failed :%#x \r\n", ret); - return ret; - } - - return KP_ERR_SUCCESS; -} - -/******************************************************************* - * @name :u32 SSD1306WriteData(u32 iicId, u8 *data, u32 byteLen) - * @date :2018-08-27 - * @function :Write a byte of content to the OLED screen - * @parameters :dat:Content to be written - dataType:0-write command - 1-write data - * @retvalue :None -********************************************************************/ -u32 SSD1306WriteData(u32 iicId, u8 *data, u32 byteLen) -{ - u32 ret = KP_ERR_SUCCESS; - u8 buff[byteLen * 2] = {0}; - - for (u32 i = 0; i < byteLen; i++) { - buff[i*2] = SSD1306_CTRL_DATA | SSD1306_MASK_CONT; - buff[i*2+1] = data[i]; - } - buff[(byteLen - 1) * 2] = SSD1306_CTRL_DATA; - ret = SSD1306WriteBuf(iicId, SSD1306_I2C_ADDR, buff, sizeof(buff)); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("SSD1306WriteBuf failed :%#x \r\n", ret); - return ret; - } - - return KP_ERR_SUCCESS; -} - -#endif - - -/* SPI方式控制SSD1306 */ -#if SSD1306_USE_SPI -/******************************************************************* - * @name :void SSD1306InitGPIO(void) - * @date :2018-08-27 - * @function :初始化SSD1306的GPIO - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306InitGPIO(void) -{ - return; -} - -/******************************************************************* - * @name :void SSD1306IOInit(u8 spiId) - * @date :2023-02-24 - * @function :初始化SSD1306的SPI,在此之前必须先初始化SSD1306的GPIO为SPI功能 - 即在调用本函数之前先调用iot_gpio_spi.h中的初始化接口函数 - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306InitIO(u8 spiId) -{ - u32 ret = KP_ERR_SUCCESS; +#include "hi_spi.h" +#include "iot_spi.h" + +//定义I2C和SPI的宏 +#define SSD1306_USE_IIC 1 +#define SSD1306_USE_SPI 0 + +/* IIC方式控制SSD1306 */ +#if SSD1306_USE_IIC +#include "ssd1306_iic_drv.h" + +#define SSD1306_I2C_ADDR (0x3C <<1) +#define OLED_IIC_BAUDRATE 400000 +#endif + +/* SPI方式控制SSD1306 */ +#if SSD1306_USE_SPI +#include "ssd1306_spi_drv.h" + +#define U8_LEN 1 +#endif + + +//OLED显存总共分为8页 +//每页8行,一行128个像素点 +//OLED的显存 +//存放格式如下. +//[0]0 1 2 3 ... 127 (0~7)行 +//[1]0 1 2 3 ... 127 (8~15)行 +//[2]0 1 2 3 ... 127 (16~23)行 +//[3]0 1 2 3 ... 127 (24~31)行 +//[4]0 1 2 3 ... 127 (32~39)行 +//[5]0 1 2 3 ... 127 (40~47)行 +//[6]0 1 2 3 ... 127 (48~55)行 +//[7]0 1 2 3 ... 127 (56~63)行 + + +static unsigned char SSD1306_buffer[SSD1306_BUFFER_SIZE] = {0x00}; + + +/* IIC方式控制SSD1306 */ +#if SSD1306_USE_IIC +/******************************************************************* + * @name :void SSD1306InitGPIO(void) + * @date :2018-08-27 + * @function :初始化SSD1306的GPIO + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306InitGPIO(void) +{ + return; +} + +/******************************************************************* + * @name :void SSD1306IOInit(u8 i2cId) + * @date :2023-02-24 + * @function :初始化SSD1306的IIC,在此之前必须先初始化SSD1306的GPIO为IIC功能 + 即在调用本函数之前先调用iot_gpio_iic.h中的初始化接口函数 + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306InitIO(u8 i2cId) +{ + u32 ret = KP_ERR_SUCCESS; + + /* IIC初始化 */ + ret = IoTI2cInit(i2cId, OLED_IIC_BAUDRATE); + if (ret != KP_ERR_SUCCESS) { + IOT_PRINTF_FUNC("IoTI2cInit failed :%#x \r\n", ret); + return; + } + + /* IIC设置波特率 */ + ret = IoTI2cSetBaudrate(i2cId, OLED_IIC_BAUDRATE); + if (ret != KP_ERR_SUCCESS) { + IOT_PRINTF_FUNC("IoTI2cSetBaudrate failed :%#x \r\n", ret); + return; + } + + printf("SSD1306InitIO success \r\n"); +} + +/******************************************************************* + * @name :void OLED_Reset(void) + * @date :2018-08-27 + * @function :Reset OLED screen + * @parameters :dat:0-Display full black + 1-Display full white + * @retvalue :None +********************************************************************/ +void SSD1306Reset(void) +{ + /* for I2C - do nothing */ +} + +u32 SSD1306WriteBuf(u32 iicId, u8 *data, u32 byteLen) +{ + u32 ret = IoTI2cWrite(iicId, SSD1306_I2C_ADDR, data, byteLen); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTI2cWrite failed :%#x \r\n", ret); + return ret; + } + + return KP_ERR_SUCCESS; +} + +u32 SSD1306WriteCmd(u32 iicId, u8 cmd) +{ + u32 ret = KP_ERR_SUCCESS; + + u8 buffer[] = {SSD1306_CTRL_CMD, cmd}; + ret = SSD1306WriteBuf(iicId, SSD1306_I2C_ADDR, buffer, sizeof(buffer)); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("SSD1306WriteBuf failed :%#x \r\n", ret); + return ret; + } + + return KP_ERR_SUCCESS; +} + +/******************************************************************* + * @name :u32 SSD1306WriteData(u32 iicId, u8 *data, u32 byteLen) + * @date :2018-08-27 + * @function :Write a byte of content to the OLED screen + * @parameters :dat:Content to be written + dataType:0-write command + 1-write data + * @retvalue :None +********************************************************************/ +u32 SSD1306WriteData(u32 iicId, u8 *data, u32 byteLen) +{ + u32 ret = KP_ERR_SUCCESS; + u8 buff[byteLen * 2] = {0}; + + for (u32 i = 0; i < byteLen; i++) { + buff[i*2] = SSD1306_CTRL_DATA | SSD1306_MASK_CONT; + buff[i*2+1] = data[i]; + } + buff[(byteLen - 1) * 2] = SSD1306_CTRL_DATA; + ret = SSD1306WriteBuf(iicId, SSD1306_I2C_ADDR, buff, sizeof(buff)); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("SSD1306WriteBuf failed :%#x \r\n", ret); + return ret; + } + + return KP_ERR_SUCCESS; +} + +#endif + + +/* SPI方式控制SSD1306 */ +#if SSD1306_USE_SPI +/******************************************************************* + * @name :void SSD1306InitGPIO(void) + * @date :2018-08-27 + * @function :初始化SSD1306的GPIO + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306InitGPIO(void) +{ + return; +} + +/******************************************************************* + * @name :void SSD1306IOInit(u8 spiId) + * @date :2023-02-24 + * @function :初始化SSD1306的SPI,在此之前必须先初始化SSD1306的GPIO为SPI功能 + 即在调用本函数之前先调用iot_gpio_spi.h中的初始化接口函数 + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306InitIO(u8 spiId) +{ + u32 ret = KP_ERR_SUCCESS; /* 去初始化SPI */ - ret = IoTSpiDeinit(spiId); - if (ret != KP_ERR_SUCCESS) { - printf("IoTSpiDeinit failed :%#x \r\n", ret); + ret = IoTSpiDeinit(spiId); + if (ret != KP_ERR_SUCCESS) { + printf("IoTSpiDeinit failed :%#x \r\n", ret); return; } - IotSpiCfgInitParam spiInitParam = {0}; - spiInitParam.isSlave = FALSE; - IotSpiCfgBasicInfo spiBasicInfo = {0}; - spiBasicInfo.cpol = HI_SPI_CFG_CLOCK_CPOL_0; - spiBasicInfo.cpha = HI_SPI_CFG_CLOCK_CPHA_0; - spiBasicInfo.framMode = HI_SPI_CFG_FRAM_MODE_MOTOROLA; - spiBasicInfo.dataWidth = HI_SPI_CFG_DATA_WIDTH_E_8BIT; - spiBasicInfo.endian = HI_SPI_CFG_ENDIAN_LITTLE; - spiBasicInfo.freq = 2000000; /* defaul freq 2000000 Hz */ + IotSpiCfgInitParam spiInitParam = {0}; + spiInitParam.isSlave = FALSE; + IotSpiCfgBasicInfo spiBasicInfo = {0}; + spiBasicInfo.cpol = HI_SPI_CFG_CLOCK_CPOL_0; + spiBasicInfo.cpha = HI_SPI_CFG_CLOCK_CPHA_0; + spiBasicInfo.framMode = HI_SPI_CFG_FRAM_MODE_MOTOROLA; + spiBasicInfo.dataWidth = HI_SPI_CFG_DATA_WIDTH_E_8BIT; + spiBasicInfo.endian = HI_SPI_CFG_ENDIAN_LITTLE; + spiBasicInfo.freq = 2000000; /* defaul freq 2000000 Hz */ - //test_spi_printf("app_demo_spi_test_cmd_mw_sr Start"); - - ret = IoTSpiInit(spiId, spiInitParam, &spiBasicInfo); - if (ret != KP_ERR_SUCCESS) { - printf("IoTSpiInit failed :%#x \r\n", ret); + //test_spi_printf("app_demo_spi_test_cmd_mw_sr Start"); + + ret = IoTSpiInit(spiId, spiInitParam, &spiBasicInfo); + if (ret != KP_ERR_SUCCESS) { + printf("IoTSpiInit failed :%#x \r\n", ret); return; } - IoTSpiSetLoopBackMode(spiId, FALSE); - - osDelay(100); - - IoTSpiSetIrqMode(spiId, FALSE); - IoTSpiSetDmaMode(spiId, FALSE); + IoTSpiSetLoopBackMode(spiId, FALSE); - osDelay(100); - - printf("SSD1306InitIO success \r\n"); -} - -/******************************************************************* - * @name :void OLED_Reset(void) - * @date :2018-08-27 - * @function :Reset OLED screen - * @parameters :dat:0-Display full black - 1-Display full white - * @retvalue :None -********************************************************************/ -void SSD1306Reset(void) -{ - SSD1306_RST_Set(); - delay_ms(100); - SSD1306_RST_Clr(); - delay_ms(100); - SSD1306_RST_Set(); - printf("SSD1306 reset \r\n"); -} - -u32 SSD1306WriteBuf(u32 spiId, u8 *data, u32 byteLen) -{ - u32 ret = IoTSpiHostWrite(spiId, data, byteLen); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("IoTSpiHostWrite failed :%#x \r\n", ret); - return ret; - } - - return KP_ERR_SUCCESS; -} - -/******************************************************************* - * @name :u32 SSD1306WriteCmd(u32 spiId, u8 cmd) - * @date :2018-08-27 - * @function :Write a byte of content to the OLED screen - * @parameters :dat:Content to be written - dataType:0-write command - 1-write data - * @retvalue :None -********************************************************************/ -u32 SSD1306WriteCmd(u32 spiId, u8 cmd) -{ - u32 ret = KP_ERR_SUCCESS; + osDelay(100); - // 低电平写命令 - ret = SSD1306_DC_Clr(); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("SSD1306_DC_Clr failed :%#x \r\n", ret); - return ret; - } - - // 低电平片选 - ret = SSD1306_CS_Clr(); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("SSD1306_CS_Clr failed :%#x \r\n", ret); - return ret; - } - - // 写数据 - ret = SSD1306WriteBuf(spiId, cmd, U8_LEN); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("SSD1306WriteBuf failed :%#x \r\n", ret); - return ret; - } - - // 取消片选 - ret = SSD1306_CS_Set(); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("SSD1306_CS_Set failed :%#x \r\n", ret); - return ret; - } - - return KP_ERR_SUCCESS; -} - -/******************************************************************* - * @name :u32 SSD1306WriteByte(u32 spiId, u8 dat, u32 dataType) - * @date :2018-08-27 - * @function :Write a byte of content to the OLED screen - * @parameters :dat:Content to be written - dataType:0-write command - 1-write data - * @retvalue :None -********************************************************************/ -u32 SSD1306WriteData(u32 spiId, u8 *data, u32 byteLen) -{ - u32 ret = KP_ERR_SUCCESS; + IoTSpiSetIrqMode(spiId, FALSE); + IoTSpiSetDmaMode(spiId, FALSE); - // 高电平写数据 - ret = SSD1306_DC_Set(); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("SSD1306_DC_Set failed :%#x \r\n", ret); - return ret; - } - - // 低电平片选 - ret = SSD1306_CS_Clr(); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("SSD1306_CS_Clr failed :%#x \r\n", ret); - return ret; - } - - // 写数据 - ret = SSD1306WriteBuf(spiId, data, byteLen); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("Ssd1306WriteData failed :%#x \r\n", ret); - return ret; - } - - // 取消片选 - ret = SSD1306_CS_Set(); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("SSD1306_CS_Set failed :%#x \r\n", ret); + osDelay(100); + + printf("SSD1306InitIO success \r\n"); +} + +/******************************************************************* + * @name :void OLED_Reset(void) + * @date :2018-08-27 + * @function :Reset OLED screen + * @parameters :dat:0-Display full black + 1-Display full white + * @retvalue :None +********************************************************************/ +void SSD1306Reset(void) +{ + SSD1306_RST_Set(); + delay_ms(100); + SSD1306_RST_Clr(); + delay_ms(100); + SSD1306_RST_Set(); + printf("SSD1306 reset \r\n"); +} + +u32 SSD1306WriteBuf(u32 spiId, u8 *data, u32 byteLen) +{ + u32 ret = IoTSpiHostWrite(spiId, data, byteLen); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("IoTSpiHostWrite failed :%#x \r\n", ret); return ret; - } - - return KP_ERR_SUCCESS; -} -#endif - -/* Fills the Screenbuffer with values from a given buffer of a fixed length */ -u32 SSD1306FillBuffer(u8* buf, u32 len) { - u32 ret = KP_ERR_FAILURE; - if (len <= SSD1306_BUFFER_SIZE) { - memcpy(SSD1306_Buffer, buf, len); - ret = KP_ERR_SUCCESS; - } - - return ret; -} - -/******************************************************************* - * @name :void OLED_Init(void) - * @date :2018-08-27 - * @function :initialise OLED SH1106 control IC - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306Init(void) -{ - //SSD1306InitGPIO(); //初始化GPIO - //delay_ms(200); - SSD1306Reset(); //复位OLED - printf("%s,%s,%d \r\n", __FILE__, __func__, __LINE__); - - // Wait for the screen to boot - osDelay(100); - -/**************初始化SSD1306*****************/ - SSD1306WRCmd(0xAE); /*display off*/ - SSD1306WRCmd(0x00); /*set lower column address*/ - SSD1306WRCmd(0x10); /*set higher column address*/ - SSD1306WRCmd(0x40); /*set display start line*/ - SSD1306WRCmd(0xB0); /*set page address*/ - SSD1306WRCmd(0x81); /*contract control*/ - SSD1306WRCmd(0xFF); /*128*/ - SSD1306WRCmd(0xA1); /*set segment remap*/ - SSD1306WRCmd(0xA6); /*normal / reverse*/ - SSD1306WRCmd(0xA8); /*multiplex ratio*/ - SSD1306WRCmd(0x3F); /*duty = 1/64*/ - SSD1306WRCmd(0xC8); /*Com scan direction*/ - SSD1306WRCmd(0xD3); /*set display offset*/ - SSD1306WRCmd(0x00); - SSD1306WRCmd(0xD5); /*set osc division*/ - SSD1306WRCmd(0x80); - SSD1306WRCmd(0xD9); /*set pre-charge period*/ - SSD1306WRCmd(0XF1); - SSD1306WRCmd(0xDA); /*set COM pins*/ - SSD1306WRCmd(0x12); - SSD1306WRCmd(0xDB); /*set vcomh*/ - SSD1306WRCmd(0x30); - SSD1306WRCmd(0x8D); /*set charge pump disable*/ - SSD1306WRCmd(0x14); - SSD1306WRCmd(0xAF); /*display ON*/ - - printf("%s,%s,%d \r\n", __FILE__, __func__, __LINE__); -} - -/******************************************************************* - * @name :void OLED_Set_Pos(unsigned char x, unsigned char y) - * @date :2018-08-27 - * @function :Set coordinates in the OLED screen - * @parameters :x:x coordinates - y:y coordinates - * @retvalue :None -********************************************************************/ -void SSD1306SetPos(unsigned char x, unsigned char y) -{ - SSD1306WRCmd(YLevel+y/PAGE_SIZE); - SSD1306WRCmd((((x+2)&0xf0)>>4)|0x10); - SSD1306WRCmd(((x+2)&0x0f)); -} - -/******************************************************************* - * @name :void OLED_Display_On(void) - * @date :2018-08-27 - * @function :Turn on OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOn(void) -{ - SSD1306WRCmd(0X8D); //SET DCDC命令 - SSD1306WRCmd(0X14); //DCDC ON - SSD1306WRCmd(0XAF); //DISPLAY ON -} - -/******************************************************************* - * @name :void OLED_Display_Off(void) - * @date :2018-08-27 - * @function :Turn off OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOff(void) -{ - SSD1306WRCmd(0X8D); //SET DCDC命令 - SSD1306WRCmd(0X10); //DCDC OFF - SSD1306WRCmd(0XAE); //DISPLAY OFF -} - -/******************************************************************* - * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) - * @date :2018-08-27 - * @function :set the value of pixel to RAM - * @parameters :x:the x coordinates of pixel - y:the y coordinates of pixel - color:the color value of the point - 1-white - 0-black - * @retvalue :None -********************************************************************/ -void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) -{ - if(x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT) { - // Don't write outside the buffer - return; - } - - if(color) - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; - } - else - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); - } -} - -/******************************************************************* - * @name :void OLED_Display(void) - * @date :2018-08-27 - * @function :Display in OLED screen - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306Display(void) -{ - u8 i,n; - for(i=0; i>4)|0x10); + SSD1306WRCmd(((x+2)&0x0f)); +} + +/******************************************************************* + * @name :void OLED_Display_On(void) + * @date :2018-08-27 + * @function :Turn on OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOn(void) +{ + SSD1306WRCmd(0X8D); //SET DCDC命令 + SSD1306WRCmd(0X14); //DCDC ON + SSD1306WRCmd(0XAF); //DISPLAY ON +} + +/******************************************************************* + * @name :void OLED_Display_Off(void) + * @date :2018-08-27 + * @function :Turn off OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOff(void) +{ + SSD1306WRCmd(0X8D); //SET DCDC命令 + SSD1306WRCmd(0X10); //DCDC OFF + SSD1306WRCmd(0XAE); //DISPLAY OFF +} + +/******************************************************************* + * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) + * @date :2018-08-27 + * @function :set the value of pixel to RAM + * @parameters :x:the x coordinates of pixel + y:the y coordinates of pixel + color:the color value of the point + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) +{ + if(x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT) { + // Don't write outside the buffer + return; + } + + if(color) + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; + } + else + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); + } +} + +/******************************************************************* + * @name :void OLED_Display(void) + * @date :2018-08-27 + * @function :Display in OLED screen + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306Display(void) +{ + u8 i,n; + for(i=0; i 0) - incx = 1; //设置单步方向 - else if (delta_x == 0) - incx = 0; //垂直线 - else { - incx = -1; - delta_x = -delta_x; - } - - if (delta_y > 0) - incy = 1; - else if (delta_y == 0) - incy = 0; //水平线 - else { - incy = -1; - delta_y = -delta_y; - } - - if ( delta_x > delta_y) - distance = delta_x; //选取基本增量坐标轴 - else - distance = delta_y; - - for (t = 0; t <= distance + 1; t++) //画线输出 - { - SSD1306SetPixel(uRow, uCol, color); - xerr += delta_x; - yerr += delta_y; - if (xerr > distance) - { - xerr -= distance; - uRow += incx; - } - if (yerr > distance) - { - yerr -= distance; - uCol += incy; - } - } - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - -/***************************************************************************** - * @name :void GUI_DrawRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) - * @date :2018-08-27 - * @function :Draw a rectangle - * @parameters :x1:the bebinning x coordinate of the rectangle - y1:the bebinning y coordinate of the rectangle - x2:the ending x coordinate of the rectangle - y2:the ending y coordinate of the rectangle - color:the color value of the rectangle - 1-white - 0-black - * @retvalue :None -******************************************************************************/ -void GUI_DrawRectangle(u8 x1, u8 y1, u8 x2, u8 y2, u8 color) -{ - GUI_DrawLine(x1, y1, x2, y1, color); - GUI_DrawLine(x1, y1, x1, y2, color); - GUI_DrawLine(x1, y2, x2, y2, color); - GUI_DrawLine(x2, y1, x2, y2, color); -} - -/***************************************************************************** - * @name :void GUI_FillRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) - * @date :2018-08-27 - * @function :Filled a rectangle - * @parameters :x1:the bebinning x coordinate of the filled rectangle - y1:the bebinning y coordinate of the filled rectangle - x2:the ending x coordinate of the filled rectangle - y2:the ending y coordinate of the filled rectangle - color:the color value of the rectangle - 1-white - 0-black - * @retvalue :None -******************************************************************************/ -void GUI_FillRectangle(u8 x1, u8 y1, u8 x2, u8 y2, u8 color) -{ - GUI_Fill(x1, y1, x2, y2, color); -} - -/***************************************************************************** - * @name :static void _draw_circle_8(u8 xc, u8 yc, u8 x, u8 y, u8 color) - * @date :2018-08-27 - * @function :8 symmetry circle drawing algorithm (internal call) - * @parameters :xc:the x coordinate of the Circular center - yc:the y coordinate of the Circular center - x:the x coordinate relative to the Circular center - y:the y coordinate relative to the Circular center - color:the color value of the rectangle - 1-white - 0-black - * @retvalue :None -******************************************************************************/ -static void _draw_circle_8(u8 xc, u8 yc, u8 x, u8 y, u8 color) -{ - OLED_Set_Pixel(xc + x, yc + y, color); - OLED_Set_Pixel(xc - x, yc + y, color); - OLED_Set_Pixel(xc + x, yc - y, color); - OLED_Set_Pixel(xc - x, yc - y, color); - OLED_Set_Pixel(xc + y, yc + x, color); - OLED_Set_Pixel(xc - y, yc + x, color); - OLED_Set_Pixel(xc + y, yc - x, color); - OLED_Set_Pixel(xc - y, yc - x, color); -} - -/***************************************************************************** - * @name :void GUI_DrawCircle(u8 xc, u8 yc, u8 color, u8 r) - * @date :2018-08-27 - * @function :Draw a circle of specified size at a specified location - * @parameters :xc:the x coordinate of the Circular center - yc:the y coordinate of the Circular center - r:Circular radius - color:the color value of the rectangle - 1-white - 0-black - * @retvalue :None -******************************************************************************/ -void GUI_DrawCircle(u8 xc, u8 yc, u8 color, u8 r) -{ - int x = 0, y = r, d; - d = 3 - 2 * r; - while (x <= y) - { - _draw_circle_8(xc, yc, x, y, color); - if (d < 0) - { - d = d + 4 * x + 6; - } - else - { - d = d + 4 * (x - y) + 10; - y--; - } - x++; - } - - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - -/***************************************************************************** - * @name :void GUI_FillCircle(u8 xc, u8 yc, u8 color, u8 r) - * @date :2018-08-27 - * @function :Fill a circle of specified size at a specified location - * @parameters :xc:the x coordinate of the Circular center - yc:the y coordinate of the Circular center - r:Circular radius - color:the color value of the rectangle - 1-white - 0-black - * @retvalue :None -******************************************************************************/ -void GUI_FillCircle(u8 xc, u8 yc, u8 color, u8 r) -{ - int x = 0, y = r, yi, d; - d = 3 - 2 * r; - while (x <= y) - { - for (yi = x; yi <= y; yi++) - { - _draw_circle_8(xc, yc, x, yi, color); - } - - if (d < 0) - { - d = d + 4 * x + 6; - } - else - { - d = d + 4 * (x - y) + 10; - y--; - } - x++; - } - - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - -/********************************************************************************** - * @name :void GUI_DrawTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color) - * @date :2018-08-27 - * @function :Draw a triangle at a specified position - * @parameters :x0:the bebinning x coordinate of the triangular edge - y0:the bebinning y coordinate of the triangular edge - x1:the vertex x coordinate of the triangular - y1:the vertex y coordinate of the triangular - x2:the ending x coordinate of the triangular edge - y2:the ending y coordinate of the triangular edge - color:the color value of the rectangle - 1-white - 0-black - * @retvalue :None -***********************************************************************************/ -void GUI_DrawTriangel(u8 x0, u8 y0, u8 x1, u8 y1, u8 x2, u8 y2, u8 color) -{ - GUI_DrawLine(x0, y0, x1, y1, color); - GUI_DrawLine(x1, y1, x2, y2, color); - GUI_DrawLine(x2, y2, x0, y0, color); -} - -/***************************************************************************** - * @name :static void _swap(u8 *a, u8 *b) - * @date :2018-08-27 - * @function :Exchange two numbers(internal call) - * @parameters :a:the address of the first number - b:the address of the second number - * @retvalue :None -******************************************************************************/ -static void _swap(u8 *a, u8 *b) -{ - u16 tmp; - tmp = *a; - *a = *b; - *b = tmp; -} - -/***************************************************************************** - * @name :static void _draw_h_line(u8 x0,u8 x1,u8 y,u8 color) - * @date :2018-08-27 - * @function :draw a horizontal line in RAM(internal call) - * @parameters :x0:the bebinning x coordinate of the horizontal line - x1:the ending x coordinate of the horizontal line - y:the y coordinate of the horizontal line - color:the color value of the rectangle - 1-white - 0-black - * @retvalue :None -******************************************************************************/ -static void _draw_h_line(u8 x0, u8 x1, u8 y, u8 color) -{ - u8 i = 0; - for(i = x0; i <= x1; i++) - { - SSD1306SetPixel(i, y, color); - } -} - -/***************************************************************************** - * @name :void GUI_FillTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color) - * @date :2018-08-27 - * @function :filling a triangle at a specified position - * @parameters :x0:the bebinning x coordinate of the triangular edge - y0:the bebinning y coordinate of the triangular edge - x1:the vertex x coordinate of the triangular - y1:the vertex y coordinate of the triangular - x2:the ending x coordinate of the triangular edge - y2:the ending y coordinate of the triangular edge - color:the color value of the rectangle - 1-white - 0-black - * @retvalue :None -******************************************************************************/ -void GUI_FillTriangel(u8 x0, u8 y0, u8 x1, u8 y1, u8 x2, u8 y2, u8 color) -{ - u8 a, b, y, last; - int dx01, dy01, dx02, dy02, dx12, dy12; - long sa = 0; - long sb = 0; - if (y0 > y1) - { - _swap(&y0,&y1); - _swap(&x0,&x1); - } - if (y1 > y2) - { - _swap(&y2,&y1); - _swap(&x2,&x1); - } - if (y0 > y1) - { - _swap(&y0,&y1); - _swap(&x0,&x1); - } - if(y0 == y2) - { - a = b = x0; - if(x1 < a) - { - a = x1; - } - else if(x1 > b) - { - b = x1; - } - if(x2 < a) - { - a = x2; - } - else if(x2 > b) - { - b = x2; - } - _draw_h_line(a, b, y0, color); - return; - } - dx01 = x1 - x0; - dy01 = y1 - y0; - dx02 = x2 - x0; - dy02 = y2 - y0; - dx12 = x2 - x1; - dy12 = y2 - y1; - - if(y1 == y2) - { - last = y1; - } - else - { - last = y1 - 1; - } - for(y = y0; y <= last; y++) - { - a = x0 + sa / dy01; - b = x0 + sb / dy02; - sa += dx01; - sb += dx02; - if(a > b) - { - _swap(&a, &b); - } - _draw_h_line(a, b, y, color); - } - sa = dx12 * (y - y1); - sb = dx02 * (y - y0); - for(; y <= y2; y++) - { - a = x1 + sa / dy12; - b = x0 + sb / dy02; - sa += dx12; - sb += dx02; - if(a > b) - { - _swap(&a, &b); - } - _draw_h_line(a, b, y, color); - } - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - -/***************************************************************************** - * @name :void GUI_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size,u8 mode) - * @date :2018-08-27 - * @function :Display a single English character - * @parameters :x:the bebinning x coordinate of the Character display position - y:the bebinning y coordinate of the Character display position - chr:the ascii code of display character(0~94) - Char_Size:the size of display character(8,16) - mode:0-white background and black character - 1-black background and white character - * @retvalue :None -******************************************************************************/ -void GUI_ShowChar(u8 x, u8 y, u8 chr, u8 Char_Size, u8 mode) -{ - unsigned char c = 0, i = 0, tmp, j = 0; - c = chr - ' '; //得到偏移后的值 - if(x > WIDTH-1) {x = 0; y = y + 2;} - if(Char_Size == 16) - { - /* 处理16位字符 */ - for(i = 0; i < 16; i++) - { - if(mode) - { - tmp = F8X16[c * 16 + i]; - } - else - { - tmp = ~(F8X16[c * 16 + i]); - } - for(j = 0; j < 8; j++) - { - /* 设置点阵中点的值 */ - if(tmp & (0x80 >> j)) - { - SSD1306SetPixel(x + j, y + i, 1); - } - else - { - SSD1306SetPixel(x + j, y + i, 0); - } - } - } - } - else if(Char_Size == 8) - { - /* 处理8位字符 */ - for(i = 0; i < 8; i++) - { - if(mode) - { - tmp = F6x8[c][i]; - } else - { - tmp = ~(F6x8[c][i]); - } - for(j = 0; j < 8; j++) - { - /* 设置点阵中点的值 */ - if(tmp & (0x80 >> j)) - { - SSD1306SetPixel(x + j, y + i, 1); - } - else - { - SSD1306SetPixel(x + j, y + i, 0); - } - } - } - } - else - { - return; - } - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - -/***************************************************************************** - * @name :void GUI_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size,u8 mode) - * @date :2018-08-27 - * @function :Display English string - * @parameters :x:the bebinning x coordinate of the English string - y:the bebinning y coordinate of the English string - chr:the start address of the English string - Char_Size:the size of display character - mode:0-white background and black character - 1-black background and white character - * @retvalue :None -******************************************************************************/ -void GUI_ShowString(u8 x, u8 y, u8 *chr, u8 Char_Size, u8 mode) -{ - unsigned char j = 0, csize; - if(Char_Size == 16) - { - csize = Char_Size / 2; - } - else if(Char_Size == 8) - { - csize = Char_Size / 2 + 2; - } - else - { - return; - } - while (chr[j] != '\0') - { - GUI_ShowChar(x, y, chr[j], Char_Size, mode); - x += csize; - if(x > 120) - { - x = 0; - y += Char_Size; - } - j++; - } -} - -/***************************************************************************** - * @name :u32 mypow(u8 m,u8 n) - * @date :2018-08-27 - * @function :get the nth power of m (internal call) - * @parameters :m:the multiplier - n:the power - * @retvalue :the nth power of m -******************************************************************************/ -static u32 mypow(u8 m, u8 n) -{ - u32 result = 1; - while (n--) result *= m; - return result; -} - -/***************************************************************************** - * @name :void GUI_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 Size,u8 mode) - * @date :2018-08-27 - * @function :Display number - * @parameters :x:the bebinning x coordinate of the number - y:the bebinning y coordinate of the number - num:the number(0~4294967295) - len:the length of the display number - Size:the size of display number - mode:0-white background and black character - 1-black background and white character - * @retvalue :None -******************************************************************************/ -void GUI_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 Size, u8 mode) -{ - u8 t, temp; - u8 enshow = 0, csize; - if(Size == 16) - { - csize = Size / 2; - } - else if(Size == 8) - { - csize = Size / 2 + 2; - } - else - { - return; - } - for(t = 0; t < len; t++) - { - temp=(num / mypow(10, len - t - 1)) % 10; - if(enshow == 0 && t < (len - 1)) - { - if(temp == 0) - { - GUI_ShowChar(x + csize * t, y, ' ', Size, mode); - continue; - } else { - enshow = 1; - } - } - GUI_ShowChar(x + csize * t, y, temp + '0', Size, mode); - } -} - -/***************************************************************************** - * @name :void GUI_ShowFont16(u8 x,u8 y,u8 *s,u8 mode) - * @date :2018-08-27 - * @function :Display a single 16x16 Chinese character - * @parameters :x:the bebinning x coordinate of the Chinese character - y:the bebinning y coordinate of the Chinese character - s:the start address of the Chinese character - mode:0-white background and black character - 1-black background and white character - * @retvalue :None -******************************************************************************/ -void GUI_ShowFont16(u8 x, u8 y, u8 *s, u8 mode) -{ - u8 i, j, k, tmp; - u16 num; - num = sizeof(cfont16) / sizeof(typFNT_GB16); - for(i = 0; i < num; i++) - { - if((cfont16[i].Index[0] == *s) && (cfont16[i].Index[1] == *(s + 1))) - { - for(j = 0; j < 32; j++) - { - if(mode) - { - tmp = cfont16[i].Msk[j]; - } - else - { - tmp = ~(cfont16[i].Msk[j]); - } - for(k = 0; k < 8; k++) - { - if(tmp & (0x80 >> k)) - { - OLED_Set_Pixel(x + (j % 2) * 8 + k, y + j / 2, 1); - } - else - { - OLED_Set_Pixel(x + (j % 2) * 8 + k, y + j / 2, 0); - } - } - } - break; - } - } - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - -void GUI_ShowFont16_UTF(u8 x, u8 y, u8 *s, u8 mode) -{ - u8 i, j, k, tmp; - u16 num; - num = sizeof(cfont16_UTF) / sizeof(typFNT_GB16_UTF); - for(i = 0; i < num; i++) - { - if((cfont16_UTF[i].Index[0] == *s) && (cfont16_UTF[i].Index[1] == *(s + 1)) && (cfont16_UTF[i].Index[2] == *(s + 2))) - { - for(j = 0; j < 32; j++) - { - if(mode) - { - tmp = cfont16_UTF[i].Msk[j]; - } - else - { - tmp = ~(cfont16_UTF[i].Msk[j]); - } - for(k = 0; k < 8; k++) - { - if(tmp & (0x80 >> k)) - { - OLED_Set_Pixel(x + (j % 2) * 8 + k, y + j / 2, 1); - } - else - { - OLED_Set_Pixel(x + (j % 2) * 8 + k, y + j / 2, 0); - } - } - } - break; - } - } - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - - -/***************************************************************************** - * @name :void GUI_ShowFont24(u8 x,u8 y,u8 *s,u8 mode) - * @date :2018-08-27 - * @function :Display a single 24x24 Chinese character - * @parameters :x:the bebinning x coordinate of the Chinese character - y:the bebinning y coordinate of the Chinese character - s:the start address of the Chinese character - mode:0-white background and black character - 1-black background and white character - * @retvalue :None -******************************************************************************/ -void GUI_ShowFont24(u8 x, u8 y, u8 *s, u8 mode) -{ - u8 i, j, k, tmp; - u16 num; - num = sizeof(cfont24) / sizeof(typFNT_GB24); - for(i = 0; i < num; i++) - { - if((cfont24[i].Index[0] == *s) && (cfont24[i].Index[1] == *(s + 1))) - { - for(j = 0; j < 72; j++) - { - if(mode) - { - tmp = cfont24[i].Msk[j]; - } - else - { - tmp = ~(cfont24[i].Msk[j]); - } - for(k = 0; k < 8; k++) - { - if(tmp & (0x80 >> k)) - { - OLED_Set_Pixel(x + (j % 3) * 8 + k, y + j / 3, 1); - } - else - { - OLED_Set_Pixel(x + (j % 3) * 8 + k, y + j / 3, 0); - } - } - } - break; - } - } - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - -/***************************************************************************** - * @name :void GUI_ShowFont32(u8 x,u8 y,u8 *s,u8 mode) - * @date :2018-08-27 - * @function :Display a single 32x32 Chinese character - * @parameters :x:the bebinning x coordinate of the Chinese character - y:the bebinning y coordinate of the Chinese character - s:the start address of the Chinese character - mode:0-white background and black character - 1-black background and white character - * @retvalue :None -******************************************************************************/ -void GUI_ShowFont32(u8 x, u8 y, u8 *s, u8 mode) -{ - u8 i, j, k, tmp; - u16 num; - num = sizeof(cfont32) / sizeof(typFNT_GB32); - for(i = 0; i < num; i++) - { - if((cfont32[i].Index[0] == *s) && (cfont32[i].Index[1] == *(s + 1))) - { - for(j = 0; j < 128; j++) - { - if(mode) - { - tmp = cfont32[i].Msk[j]; - } - else - { - tmp = ~(cfont32[i].Msk[j]); - } - for(k = 0; k < 8; k++) - { - if(tmp & (0x80 >> k)) - { - OLED_Set_Pixel(x + (j % 4) * 8 + k, y + j / 4, 1); - } - else - { - OLED_Set_Pixel(x + (j % 4) * 8 + k, y + j / 4, 0); - } - } - } - break; - } - } - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - -/***************************************************************************** - * @name :void GUI_ShowCHinese(u8 x,u8 y,u8 hsize,u8 *str,u8 mode) - * @date :2018-08-27 - * @function :Display Chinese strings - * @parameters :x:the bebinning x coordinate of the Chinese strings - y:the bebinning y coordinate of the Chinese strings - size:the size of Chinese strings - str:the start address of the Chinese strings - mode:0-white background and black character - 1-black background and white character - * @retvalue :None -******************************************************************************/ -void GUI_ShowChinese(u8 x, u8 y, u8 hsize, u8 *str, u8 mode) -{ - while(*str != '\0') - { - if(hsize == 16) - { - GUI_ShowFont16(x, y, str, mode); - } - else if(hsize == 24) - { - GUI_ShowFont24(x, y, str, mode); - } - else if(hsize == 32) - { - GUI_ShowFont32(x, y, str, mode); - } - else - { - return; - } - x += hsize; - if(x > WIDTH - hsize) - { - x = 0; - y += hsize; - } - str += 2; - } -} - -/***************************************************************************** - * @name :void GUI_DrawBMP(u8 x,u8 y,u8 width, u8 height, u8 BMP[], u8 mode) - * @date :2018-08-27 - * @function :Display a BMP monochromatic picture - * @parameters :x:the bebinning x coordinate of the BMP monochromatic picture - y:the bebinning y coordinate of the BMP monochromatic picture - width:the width of BMP monochromatic picture - height:the height of BMP monochromatic picture - BMP:the start address of BMP monochromatic picture array - mode:0-white background and black character - 1-black background and white character - * @retvalue :None -******************************************************************************/ -void GUI_DrawBMP(u8 x, u8 y, u8 width, u8 height, u8 BMP[], u8 mode) -{ - u8 i, j, k; - u8 tmp; - for(i = 0; i < height; i++) - { - for(j = 0; j < (width + 7) / 8; j++) - { - if(mode) - { - tmp = BMP[i * ((width + 7) / 8) + j]; - } - else - { - tmp = ~BMP[i * ((width + 7) / 8) + j]; - } - for(k = 0; k < 8; k++) - { - if(tmp & (0x80 >> k)) - { - OLED_Set_Pixel(x + j * 8 + k, y + i, 1); - } - else - { - OLED_Set_Pixel(x + j * 8 + k, y + i, 0); - } - } - } - } - //SSD1306Display(); //接口不再刷新,画完后统一刷新 -} - +#include "ssd1306_drv.h" +#include "oled_font.h" +#include "ssd1306_gui.h" +#include "iot_base_type.h" + +/******************************************************************* + * @name :void GUI_DrawPoint(u8 x,u8 y,u8 color) + * @date :2018-08-27 + * @function :draw a point in LCD screen + * @parameters :x:the x coordinate of the point + y:the y coordinate of the point + color:the color value of the point + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void GUI_DrawPoint(u8 x, u8 y, u8 color) +{ + SSD1306SetPixel(x, y, color); + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/******************************************************************* + * @name :void GUI_Fill(u8 sx,u8 sy,u8 ex,u8 ey,u8 color) + * @date :2018-08-27 + * @function :fill the specified area + * @parameters :sx:the bebinning x coordinate of the specified area + sy:the bebinning y coordinate of the specified area + ex:the ending x coordinate of the specified area + ey:the ending y coordinate of the specified area + color:the color value of the the specified area + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void GUI_Fill(u8 sx, u8 sy, u8 ex, u8 ey, u8 color) +{ + u8 i = 0, j = 0; + u8 width = ex - sx + 1; //得到填充的宽度 + u8 height = ey - sy + 1; //高度 + for(i = 0; i < height; i++) + { + for(j = 0; j < width; j++) + { + SSD1306SetPixel(sx + j, sy + i, color); + } + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/******************************************************************* + * @name :void GUI_DrawLine(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) + * @date :2018-08-27 + * @function :Draw a line between two points + * @parameters :x1:the bebinning x coordinate of the line + y1:the bebinning y coordinate of the line + x2:the ending x coordinate of the line + y2:the ending y coordinate of the line + color:the color value of the line + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void GUI_DrawLine(u8 x1, u8 y1, u8 x2, u8 y2, u8 color) +{ + u16 t = 0; + int xerr = 0, yerr = 0, delta_x = 0, delta_y = 0, distance = 0; + int incx = 0, incy = 0, uRow = 0, uCol = 0; + + delta_x = x2 - x1; ////计算坐标增量 + delta_y = y2 - y1; + uRow = x1; + uCol = y1; + if (delta_x > 0) + incx = 1; //设置单步方向 + else if (delta_x == 0) + incx = 0; //垂直线 + else { + incx = -1; + delta_x = -delta_x; + } + + if (delta_y > 0) + incy = 1; + else if (delta_y == 0) + incy = 0; //水平线 + else { + incy = -1; + delta_y = -delta_y; + } + + if ( delta_x > delta_y) + distance = delta_x; //选取基本增量坐标轴 + else + distance = delta_y; + + for (t = 0; t <= distance + 1; t++) //画线输出 + { + SSD1306SetPixel(uRow, uCol, color); + xerr += delta_x; + yerr += delta_y; + if (xerr > distance) + { + xerr -= distance; + uRow += incx; + } + if (yerr > distance) + { + yerr -= distance; + uCol += incy; + } + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/***************************************************************************** + * @name :void GUI_DrawRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) + * @date :2018-08-27 + * @function :Draw a rectangle + * @parameters :x1:the bebinning x coordinate of the rectangle + y1:the bebinning y coordinate of the rectangle + x2:the ending x coordinate of the rectangle + y2:the ending y coordinate of the rectangle + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_DrawRectangle(u8 x1, u8 y1, u8 x2, u8 y2, u8 color) +{ + GUI_DrawLine(x1, y1, x2, y1, color); + GUI_DrawLine(x1, y1, x1, y2, color); + GUI_DrawLine(x1, y2, x2, y2, color); + GUI_DrawLine(x2, y1, x2, y2, color); +} + +/***************************************************************************** + * @name :void GUI_FillRectangle(u8 x1, u8 y1, u8 x2, u8 y2,u8 color) + * @date :2018-08-27 + * @function :Filled a rectangle + * @parameters :x1:the bebinning x coordinate of the filled rectangle + y1:the bebinning y coordinate of the filled rectangle + x2:the ending x coordinate of the filled rectangle + y2:the ending y coordinate of the filled rectangle + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_FillRectangle(u8 x1, u8 y1, u8 x2, u8 y2, u8 color) +{ + GUI_Fill(x1, y1, x2, y2, color); +} + +/***************************************************************************** + * @name :static void _draw_circle_8(u8 xc, u8 yc, u8 x, u8 y, u8 color) + * @date :2018-08-27 + * @function :8 symmetry circle drawing algorithm (internal call) + * @parameters :xc:the x coordinate of the Circular center + yc:the y coordinate of the Circular center + x:the x coordinate relative to the Circular center + y:the y coordinate relative to the Circular center + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +static void _draw_circle_8(u8 xc, u8 yc, u8 x, u8 y, u8 color) +{ + OLED_Set_Pixel(xc + x, yc + y, color); + OLED_Set_Pixel(xc - x, yc + y, color); + OLED_Set_Pixel(xc + x, yc - y, color); + OLED_Set_Pixel(xc - x, yc - y, color); + OLED_Set_Pixel(xc + y, yc + x, color); + OLED_Set_Pixel(xc - y, yc + x, color); + OLED_Set_Pixel(xc + y, yc - x, color); + OLED_Set_Pixel(xc - y, yc - x, color); +} + +/***************************************************************************** + * @name :void GUI_DrawCircle(u8 xc, u8 yc, u8 color, u8 r) + * @date :2018-08-27 + * @function :Draw a circle of specified size at a specified location + * @parameters :xc:the x coordinate of the Circular center + yc:the y coordinate of the Circular center + r:Circular radius + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_DrawCircle(u8 xc, u8 yc, u8 color, u8 r) +{ + int x = 0, y = r, d; + d = 3 - 2 * r; + while (x <= y) + { + _draw_circle_8(xc, yc, x, y, color); + if (d < 0) + { + d = d + 4 * x + 6; + } + else + { + d = d + 4 * (x - y) + 10; + y--; + } + x++; + } + + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/***************************************************************************** + * @name :void GUI_FillCircle(u8 xc, u8 yc, u8 color, u8 r) + * @date :2018-08-27 + * @function :Fill a circle of specified size at a specified location + * @parameters :xc:the x coordinate of the Circular center + yc:the y coordinate of the Circular center + r:Circular radius + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_FillCircle(u8 xc, u8 yc, u8 color, u8 r) +{ + int x = 0, y = r, yi, d; + d = 3 - 2 * r; + while (x <= y) + { + for (yi = x; yi <= y; yi++) + { + _draw_circle_8(xc, yc, x, yi, color); + } + + if (d < 0) + { + d = d + 4 * x + 6; + } + else + { + d = d + 4 * (x - y) + 10; + y--; + } + x++; + } + + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/********************************************************************************** + * @name :void GUI_DrawTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color) + * @date :2018-08-27 + * @function :Draw a triangle at a specified position + * @parameters :x0:the bebinning x coordinate of the triangular edge + y0:the bebinning y coordinate of the triangular edge + x1:the vertex x coordinate of the triangular + y1:the vertex y coordinate of the triangular + x2:the ending x coordinate of the triangular edge + y2:the ending y coordinate of the triangular edge + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +***********************************************************************************/ +void GUI_DrawTriangel(u8 x0, u8 y0, u8 x1, u8 y1, u8 x2, u8 y2, u8 color) +{ + GUI_DrawLine(x0, y0, x1, y1, color); + GUI_DrawLine(x1, y1, x2, y2, color); + GUI_DrawLine(x2, y2, x0, y0, color); +} + +/***************************************************************************** + * @name :static void _swap(u8 *a, u8 *b) + * @date :2018-08-27 + * @function :Exchange two numbers(internal call) + * @parameters :a:the address of the first number + b:the address of the second number + * @retvalue :None +******************************************************************************/ +static void _swap(u8 *a, u8 *b) +{ + u16 tmp; + tmp = *a; + *a = *b; + *b = tmp; +} + +/***************************************************************************** + * @name :static void _draw_h_line(u8 x0,u8 x1,u8 y,u8 color) + * @date :2018-08-27 + * @function :draw a horizontal line in RAM(internal call) + * @parameters :x0:the bebinning x coordinate of the horizontal line + x1:the ending x coordinate of the horizontal line + y:the y coordinate of the horizontal line + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +static void _draw_h_line(u8 x0, u8 x1, u8 y, u8 color) +{ + u8 i = 0; + for(i = x0; i <= x1; i++) + { + SSD1306SetPixel(i, y, color); + } +} + +/***************************************************************************** + * @name :void GUI_FillTriangel(u8 x0,u8 y0,u8 x1,u8 y1,u8 x2,u8 y2,u8 color) + * @date :2018-08-27 + * @function :filling a triangle at a specified position + * @parameters :x0:the bebinning x coordinate of the triangular edge + y0:the bebinning y coordinate of the triangular edge + x1:the vertex x coordinate of the triangular + y1:the vertex y coordinate of the triangular + x2:the ending x coordinate of the triangular edge + y2:the ending y coordinate of the triangular edge + color:the color value of the rectangle + 1-white + 0-black + * @retvalue :None +******************************************************************************/ +void GUI_FillTriangel(u8 x0, u8 y0, u8 x1, u8 y1, u8 x2, u8 y2, u8 color) +{ + u8 a, b, y, last; + int dx01, dy01, dx02, dy02, dx12, dy12; + long sa = 0; + long sb = 0; + if (y0 > y1) + { + _swap(&y0,&y1); + _swap(&x0,&x1); + } + if (y1 > y2) + { + _swap(&y2,&y1); + _swap(&x2,&x1); + } + if (y0 > y1) + { + _swap(&y0,&y1); + _swap(&x0,&x1); + } + if(y0 == y2) + { + a = b = x0; + if(x1 < a) + { + a = x1; + } + else if(x1 > b) + { + b = x1; + } + if(x2 < a) + { + a = x2; + } + else if(x2 > b) + { + b = x2; + } + _draw_h_line(a, b, y0, color); + return; + } + dx01 = x1 - x0; + dy01 = y1 - y0; + dx02 = x2 - x0; + dy02 = y2 - y0; + dx12 = x2 - x1; + dy12 = y2 - y1; + + if(y1 == y2) + { + last = y1; + } + else + { + last = y1 - 1; + } + for(y = y0; y <= last; y++) + { + a = x0 + sa / dy01; + b = x0 + sb / dy02; + sa += dx01; + sb += dx02; + if(a > b) + { + _swap(&a, &b); + } + _draw_h_line(a, b, y, color); + } + sa = dx12 * (y - y1); + sb = dx02 * (y - y0); + for(; y <= y2; y++) + { + a = x1 + sa / dy12; + b = x0 + sb / dy02; + sa += dx12; + sb += dx02; + if(a > b) + { + _swap(&a, &b); + } + _draw_h_line(a, b, y, color); + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/***************************************************************************** + * @name :void GUI_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size,u8 mode) + * @date :2018-08-27 + * @function :Display a single English character + * @parameters :x:the bebinning x coordinate of the Character display position + y:the bebinning y coordinate of the Character display position + chr:the ascii code of display character(0~94) + Char_Size:the size of display character(8,16) + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowChar(u8 x, u8 y, u8 chr, u8 Char_Size, u8 mode) +{ + unsigned char c = 0, i = 0, tmp, j = 0; + c = chr - ' '; //得到偏移后的值 + if(x > WIDTH-1) {x = 0; y = y + 2;} + if(Char_Size == 16) + { + /* 处理16位字符 */ + for(i = 0; i < 16; i++) + { + if(mode) + { + tmp = F8X16[c * 16 + i]; + } + else + { + tmp = ~(F8X16[c * 16 + i]); + } + for(j = 0; j < 8; j++) + { + /* 设置点阵中点的值 */ + if(tmp & (0x80 >> j)) + { + SSD1306SetPixel(x + j, y + i, 1); + } + else + { + SSD1306SetPixel(x + j, y + i, 0); + } + } + } + } + else if(Char_Size == 8) + { + /* 处理8位字符 */ + for(i = 0; i < 8; i++) + { + if(mode) + { + tmp = F6x8[c][i]; + } else + { + tmp = ~(F6x8[c][i]); + } + for(j = 0; j < 8; j++) + { + /* 设置点阵中点的值 */ + if(tmp & (0x80 >> j)) + { + SSD1306SetPixel(x + j, y + i, 1); + } + else + { + SSD1306SetPixel(x + j, y + i, 0); + } + } + } + } + else + { + return; + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/***************************************************************************** + * @name :void GUI_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size,u8 mode) + * @date :2018-08-27 + * @function :Display English string + * @parameters :x:the bebinning x coordinate of the English string + y:the bebinning y coordinate of the English string + chr:the start address of the English string + Char_Size:the size of display character + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowString(u8 x, u8 y, u8 *chr, u8 Char_Size, u8 mode) +{ + unsigned char j = 0, csize; + if(Char_Size == 16) + { + csize = Char_Size / 2; + } + else if(Char_Size == 8) + { + csize = Char_Size / 2 + 2; + } + else + { + return; + } + while (chr[j] != '\0') + { + GUI_ShowChar(x, y, chr[j], Char_Size, mode); + x += csize; + if(x > 120) + { + x = 0; + y += Char_Size; + } + j++; + } +} + +/***************************************************************************** + * @name :u32 mypow(u8 m,u8 n) + * @date :2018-08-27 + * @function :get the nth power of m (internal call) + * @parameters :m:the multiplier + n:the power + * @retvalue :the nth power of m +******************************************************************************/ +static u32 mypow(u8 m, u8 n) +{ + u32 result = 1; + while (n--) result *= m; + return result; +} + +/***************************************************************************** + * @name :void GUI_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 Size,u8 mode) + * @date :2018-08-27 + * @function :Display number + * @parameters :x:the bebinning x coordinate of the number + y:the bebinning y coordinate of the number + num:the number(0~4294967295) + len:the length of the display number + Size:the size of display number + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 Size, u8 mode) +{ + u8 t, temp; + u8 enshow = 0, csize; + if(Size == 16) + { + csize = Size / 2; + } + else if(Size == 8) + { + csize = Size / 2 + 2; + } + else + { + return; + } + for(t = 0; t < len; t++) + { + temp=(num / mypow(10, len - t - 1)) % 10; + if(enshow == 0 && t < (len - 1)) + { + if(temp == 0) + { + GUI_ShowChar(x + csize * t, y, ' ', Size, mode); + continue; + } else { + enshow = 1; + } + } + GUI_ShowChar(x + csize * t, y, temp + '0', Size, mode); + } +} + +/***************************************************************************** + * @name :void GUI_ShowFont16(u8 x,u8 y,u8 *s,u8 mode) + * @date :2018-08-27 + * @function :Display a single 16x16 Chinese character + * @parameters :x:the bebinning x coordinate of the Chinese character + y:the bebinning y coordinate of the Chinese character + s:the start address of the Chinese character + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowFont16(u8 x, u8 y, u8 *s, u8 mode) +{ + u8 i, j, k, tmp; + u16 num; + num = sizeof(cfont16) / sizeof(typFNT_GB16); + for(i = 0; i < num; i++) + { + if((cfont16[i].Index[0] == *s) && (cfont16[i].Index[1] == *(s + 1))) + { + for(j = 0; j < 32; j++) + { + if(mode) + { + tmp = cfont16[i].Msk[j]; + } + else + { + tmp = ~(cfont16[i].Msk[j]); + } + for(k = 0; k < 8; k++) + { + if(tmp & (0x80 >> k)) + { + OLED_Set_Pixel(x + (j % 2) * 8 + k, y + j / 2, 1); + } + else + { + OLED_Set_Pixel(x + (j % 2) * 8 + k, y + j / 2, 0); + } + } + } + break; + } + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +void GUI_ShowFont16_UTF(u8 x, u8 y, u8 *s, u8 mode) +{ + u8 i, j, k, tmp; + u16 num; + num = sizeof(cfont16_UTF) / sizeof(typFNT_GB16_UTF); + for(i = 0; i < num; i++) + { + if((cfont16_UTF[i].Index[0] == *s) && (cfont16_UTF[i].Index[1] == *(s + 1)) && (cfont16_UTF[i].Index[2] == *(s + 2))) + { + for(j = 0; j < 32; j++) + { + if(mode) + { + tmp = cfont16_UTF[i].Msk[j]; + } + else + { + tmp = ~(cfont16_UTF[i].Msk[j]); + } + for(k = 0; k < 8; k++) + { + if(tmp & (0x80 >> k)) + { + OLED_Set_Pixel(x + (j % 2) * 8 + k, y + j / 2, 1); + } + else + { + OLED_Set_Pixel(x + (j % 2) * 8 + k, y + j / 2, 0); + } + } + } + break; + } + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + + +/***************************************************************************** + * @name :void GUI_ShowFont24(u8 x,u8 y,u8 *s,u8 mode) + * @date :2018-08-27 + * @function :Display a single 24x24 Chinese character + * @parameters :x:the bebinning x coordinate of the Chinese character + y:the bebinning y coordinate of the Chinese character + s:the start address of the Chinese character + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowFont24(u8 x, u8 y, u8 *s, u8 mode) +{ + u8 i, j, k, tmp; + u16 num; + num = sizeof(cfont24) / sizeof(typFNT_GB24); + for(i = 0; i < num; i++) + { + if((cfont24[i].Index[0] == *s) && (cfont24[i].Index[1] == *(s + 1))) + { + for(j = 0; j < 72; j++) + { + if(mode) + { + tmp = cfont24[i].Msk[j]; + } + else + { + tmp = ~(cfont24[i].Msk[j]); + } + for(k = 0; k < 8; k++) + { + if(tmp & (0x80 >> k)) + { + OLED_Set_Pixel(x + (j % 3) * 8 + k, y + j / 3, 1); + } + else + { + OLED_Set_Pixel(x + (j % 3) * 8 + k, y + j / 3, 0); + } + } + } + break; + } + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/***************************************************************************** + * @name :void GUI_ShowFont32(u8 x,u8 y,u8 *s,u8 mode) + * @date :2018-08-27 + * @function :Display a single 32x32 Chinese character + * @parameters :x:the bebinning x coordinate of the Chinese character + y:the bebinning y coordinate of the Chinese character + s:the start address of the Chinese character + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowFont32(u8 x, u8 y, u8 *s, u8 mode) +{ + u8 i, j, k, tmp; + u16 num; + num = sizeof(cfont32) / sizeof(typFNT_GB32); + for(i = 0; i < num; i++) + { + if((cfont32[i].Index[0] == *s) && (cfont32[i].Index[1] == *(s + 1))) + { + for(j = 0; j < 128; j++) + { + if(mode) + { + tmp = cfont32[i].Msk[j]; + } + else + { + tmp = ~(cfont32[i].Msk[j]); + } + for(k = 0; k < 8; k++) + { + if(tmp & (0x80 >> k)) + { + OLED_Set_Pixel(x + (j % 4) * 8 + k, y + j / 4, 1); + } + else + { + OLED_Set_Pixel(x + (j % 4) * 8 + k, y + j / 4, 0); + } + } + } + break; + } + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + +/***************************************************************************** + * @name :void GUI_ShowCHinese(u8 x,u8 y,u8 hsize,u8 *str,u8 mode) + * @date :2018-08-27 + * @function :Display Chinese strings + * @parameters :x:the bebinning x coordinate of the Chinese strings + y:the bebinning y coordinate of the Chinese strings + size:the size of Chinese strings + str:the start address of the Chinese strings + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_ShowChinese(u8 x, u8 y, u8 hsize, u8 *str, u8 mode) +{ + while(*str != '\0') + { + if(hsize == 16) + { + GUI_ShowFont16(x, y, str, mode); + } + else if(hsize == 24) + { + GUI_ShowFont24(x, y, str, mode); + } + else if(hsize == 32) + { + GUI_ShowFont32(x, y, str, mode); + } + else + { + return; + } + x += hsize; + if(x > WIDTH - hsize) + { + x = 0; + y += hsize; + } + str += 2; + } +} + +/***************************************************************************** + * @name :void GUI_DrawBMP(u8 x,u8 y,u8 width, u8 height, u8 BMP[], u8 mode) + * @date :2018-08-27 + * @function :Display a BMP monochromatic picture + * @parameters :x:the bebinning x coordinate of the BMP monochromatic picture + y:the bebinning y coordinate of the BMP monochromatic picture + width:the width of BMP monochromatic picture + height:the height of BMP monochromatic picture + BMP:the start address of BMP monochromatic picture array + mode:0-white background and black character + 1-black background and white character + * @retvalue :None +******************************************************************************/ +void GUI_DrawBMP(u8 x, u8 y, u8 width, u8 height, u8 BMP[], u8 mode) +{ + u8 i, j, k; + u8 tmp; + for(i = 0; i < height; i++) + { + for(j = 0; j < (width + 7) / 8; j++) + { + if(mode) + { + tmp = BMP[i * ((width + 7) / 8) + j]; + } + else + { + tmp = ~BMP[i * ((width + 7) / 8) + j]; + } + for(k = 0; k < 8; k++) + { + if(tmp & (0x80 >> k)) + { + OLED_Set_Pixel(x + j * 8 + k, y + i, 1); + } + else + { + OLED_Set_Pixel(x + j * 8 + k, y + i, 0); + } + } + } + } + //SSD1306Display(); //接口不再刷新,画完后统一刷新 +} + diff --git "a/common/ssd1306/ssd1306_iic_drv - \345\211\257\346\234\254.c" "b/common/ssd1306/ssd1306_iic_drv - \345\211\257\346\234\254.c" index 4f7dd47cf67531d2a41214e51845a26787c5e8c4..bd0934a0e7241c8fd7b3012df3cde50fbc3eec6b 100644 --- "a/common/ssd1306/ssd1306_iic_drv - \345\211\257\346\234\254.c" +++ "b/common/ssd1306/ssd1306_iic_drv - \345\211\257\346\234\254.c" @@ -1,307 +1,307 @@ -#include "ssd1306_iic_drv.h" +#include "ssd1306_iic_drv.h" + +#define SSD1306_I2C_ADDR (0x3C <<1) +#define OLED_IIC_BAUDRATE 400000 + + +//定义I2C和SPI的宏 +#define SSD1306_USE_IIC 1 +#define SSD1306_USE_SPI 0 + + +//OLED显存总共分为8页 +//每页8行,一行128个像素点 +//OLED的显存 +//存放格式如下. +//[0]0 1 2 3 ... 127 (0~7)行 +//[1]0 1 2 3 ... 127 (8~15)行 +//[2]0 1 2 3 ... 127 (16~23)行 +//[3]0 1 2 3 ... 127 (24~31)行 +//[4]0 1 2 3 ... 127 (32~39)行 +//[5]0 1 2 3 ... 127 (40~47)行 +//[6]0 1 2 3 ... 127 (48~55)行 +//[7]0 1 2 3 ... 127 (56~63)行 + +//数组每个bit存储OLED每个像素点的颜色值(1-亮(白色),0-灭(黑色)) +//SSD1306共64*128点阵,每个数组元素为8位,表示1列8个像素点,一共128列, +//因此数组的大小为64/8*128=1024 +static unsigned char OLED_buffer[1024] = {0x00}; + +#if SSD1306_USE_IIC +/******************************************************************* + * @name :void SSD1306InitGPIO(void) + * @date :2018-08-27 + * @function :初始化SSD1306的GPIO + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306InitGPIO(void) +{ + return; +} + +/******************************************************************* + * @name :void SSD1306IOInit(u8 i2cId) + * @date :2023-02-24 + * @function :初始化SSD1306的IIC,在此之前必须先初始化SSD1306的GPIO为IIC功能 + 即在调用本函数之前先调用iot_gpio_iic.h中的初始化接口函数 + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306InitIO(u8 i2cId) +{ + u32 ret = KP_ERR_SUCCESS; -#define SSD1306_I2C_ADDR (0x3C <<1) -#define OLED_IIC_BAUDRATE 400000 - - -//定义I2C和SPI的宏 -#define SSD1306_USE_IIC 1 -#define SSD1306_USE_SPI 0 - - -//OLED显存总共分为8页 -//每页8行,一行128个像素点 -//OLED的显存 -//存放格式如下. -//[0]0 1 2 3 ... 127 (0~7)行 -//[1]0 1 2 3 ... 127 (8~15)行 -//[2]0 1 2 3 ... 127 (16~23)行 -//[3]0 1 2 3 ... 127 (24~31)行 -//[4]0 1 2 3 ... 127 (32~39)行 -//[5]0 1 2 3 ... 127 (40~47)行 -//[6]0 1 2 3 ... 127 (48~55)行 -//[7]0 1 2 3 ... 127 (56~63)行 - -//数组每个bit存储OLED每个像素点的颜色值(1-亮(白色),0-灭(黑色)) -//SSD1306共64*128点阵,每个数组元素为8位,表示1列8个像素点,一共128列, -//因此数组的大小为64/8*128=1024 -static unsigned char OLED_buffer[1024] = {0x00}; - -#if SSD1306_USE_IIC -/******************************************************************* - * @name :void SSD1306InitGPIO(void) - * @date :2018-08-27 - * @function :初始化SSD1306的GPIO - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306InitGPIO(void) -{ - return; -} - -/******************************************************************* - * @name :void SSD1306IOInit(u8 i2cId) - * @date :2023-02-24 - * @function :初始化SSD1306的IIC,在此之前必须先初始化SSD1306的GPIO为IIC功能 - 即在调用本函数之前先调用iot_gpio_iic.h中的初始化接口函数 - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306InitIO(u8 i2cId) -{ - u32 ret = KP_ERR_SUCCESS; - - /* IIC初始化 */ - ret = IoTI2cInit(i2cId, OLED_IIC_BAUDRATE); - if (ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("IoTI2cInit failed :%#x \r\n", ret); - return; - } - - /* IIC设置波特率 */ - ret = IoTI2cSetBaudrate(i2cId, OLED_IIC_BAUDRATE); - if (ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("IoTI2cSetBaudrate failed :%#x \r\n", ret); - return; - } - - printf("SSD1306InitIO success \r\n"); -} - -/******************************************************************* - * @name :void OLED_Reset(void) - * @date :2018-08-27 - * @function :Reset OLED screen - * @parameters :dat:0-Display full black - 1-Display full white - * @retvalue :None -********************************************************************/ -void SSD1306Reset(void) -{ - /* for I2C - do nothing */ -} - -u32 SSD1306WriteData(u32 iicId, u8 *data, u32 byteLen) -{ - u8 buff[WIDTH * 2] = {0}; - if (byteLen <= WIDTH) { - for (u32 i = 0; i < byteLen; i++) { - buff[i*2] = SSD1306_CTRL_DATA | SSD1306_MASK_CONT; - buff[i*2+1] = data[i]; - } - data[(data_len - 1) * 2] = SSD1306_CTRL_DATA; - int ret = IoTI2cWrite(iicId, SSD1306_I2C_ADDR, buff, sizeof(buff)); - //printf("IoTI2cWrite ret = %d\n",ret); - } else { - } -} - -/******************************************************************* - * @name :void OLED_WR_Byte(unsigned dat,unsigned cmd) - * @date :2018-08-27 - * @function :Write a byte of content to the OLED screen - * @parameters :dat:Content to be written - dataType:0-write command - 1-write data - * @retvalue :None -********************************************************************/ -u32 SSD1306WriteByte(u32 spiId, u8 dat, u32 dataType) -{ - u32 ret = KP_ERR_SUCCESS; - - // 先确定数据类型 - if(dataType) { - // 高电平写数据 - ret = SSD1306_DC_Set(); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("SSD1306_DC_Set failed :%#x \r\n", ret); - return ret; - } - } else { - // 低电平写命令 - ret = SSD1306_DC_Clr(); - if(ret != KP_ERR_SUCCESS){ - IOT_PRINTF_FUNC("SSD1306_DC_Clr failed :%#x \r\n", ret); + /* IIC初始化 */ + ret = IoTI2cInit(i2cId, OLED_IIC_BAUDRATE); + if (ret != KP_ERR_SUCCESS) { + IOT_PRINTF_FUNC("IoTI2cInit failed :%#x \r\n", ret); + return; + } + + /* IIC设置波特率 */ + ret = IoTI2cSetBaudrate(i2cId, OLED_IIC_BAUDRATE); + if (ret != KP_ERR_SUCCESS) { + IOT_PRINTF_FUNC("IoTI2cSetBaudrate failed :%#x \r\n", ret); + return; + } + + printf("SSD1306InitIO success \r\n"); +} + +/******************************************************************* + * @name :void OLED_Reset(void) + * @date :2018-08-27 + * @function :Reset OLED screen + * @parameters :dat:0-Display full black + 1-Display full white + * @retvalue :None +********************************************************************/ +void SSD1306Reset(void) +{ + /* for I2C - do nothing */ +} + +u32 SSD1306WriteData(u32 iicId, u8 *data, u32 byteLen) +{ + u8 buff[WIDTH * 2] = {0}; + if (byteLen <= WIDTH) { + for (u32 i = 0; i < byteLen; i++) { + buff[i*2] = SSD1306_CTRL_DATA | SSD1306_MASK_CONT; + buff[i*2+1] = data[i]; + } + data[(data_len - 1) * 2] = SSD1306_CTRL_DATA; + int ret = IoTI2cWrite(iicId, SSD1306_I2C_ADDR, buff, sizeof(buff)); + //printf("IoTI2cWrite ret = %d\n",ret); + } else { + } +} + +/******************************************************************* + * @name :void OLED_WR_Byte(unsigned dat,unsigned cmd) + * @date :2018-08-27 + * @function :Write a byte of content to the OLED screen + * @parameters :dat:Content to be written + dataType:0-write command + 1-write data + * @retvalue :None +********************************************************************/ +u32 SSD1306WriteByte(u32 spiId, u8 dat, u32 dataType) +{ + u32 ret = KP_ERR_SUCCESS; + + // 先确定数据类型 + if(dataType) { + // 高电平写数据 + ret = SSD1306_DC_Set(); + if(ret != KP_ERR_SUCCESS){ + IOT_PRINTF_FUNC("SSD1306_DC_Set failed :%#x \r\n", ret); return ret; - } - } - - // 低电平片选 - ret = SSD1306_CS_Clr(); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("SSD1306_CS_Clr failed :%#x \r\n", ret); - return ret; - } - - // 写数据 - ret = SSD1306WriteData(spiId, dat); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("Ssd1306WriteData failed :%#x \r\n", ret); - return ret; - } - - // 取消片选 - ret = SSD1306_CS_Set(); - if(ret != KP_ERR_SUCCESS) { - IOT_PRINTF_FUNC("SSD1306_CS_Set failed :%#x \r\n", ret); - return ret; - } - - return KP_ERR_SUCCESS; -} -#endif -/******************************************************************* - * @name :void OLED_Init(void) - * @date :2018-08-27 - * @function :initialise OLED SH1106 control IC - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306Init(void) -{ - //SSD1306InitGPIO(); //初始化GPIO - //delay_ms(200); - SSD1306Reset(); //复位OLED - printf("%s,%s,%d \r\n", __FILE__, __func__, __LINE__); - -/**************初始化SSD1306*****************/ - SSD1306WriteByte(0xAE, SSD1306_CMD); /*display off*/ - SSD1306WriteByte(0x00, SSD1306_CMD); /*set lower column address*/ - SSD1306WriteByte(0x10, SSD1306_CMD); /*set higher column address*/ - SSD1306WriteByte(0x40, SSD1306_CMD); /*set display start line*/ - SSD1306WriteByte(0xB0, SSD1306_CMD); /*set page address*/ - SSD1306WriteByte(0x81, SSD1306_CMD); /*contract control*/ - SSD1306WriteByte(0xFF, SSD1306_CMD); /*128*/ - SSD1306WriteByte(0xA1, SSD1306_CMD); /*set segment remap*/ - SSD1306WriteByte(0xA6, SSD1306_CMD); /*normal / reverse*/ - SSD1306WriteByte(0xA8, SSD1306_CMD); /*multiplex ratio*/ - SSD1306WriteByte(0x3F, SSD1306_CMD); /*duty = 1/64*/ - SSD1306WriteByte(0xC8, SSD1306_CMD); /*Com scan direction*/ - SSD1306WriteByte(0xD3, SSD1306_CMD); /*set display offset*/ - SSD1306WriteByte(0x00, SSD1306_CMD); - SSD1306WriteByte(0xD5, SSD1306_CMD); /*set osc division*/ - SSD1306WriteByte(0x80, SSD1306_CMD); - SSD1306WriteByte(0xD9, SSD1306_CMD); /*set pre-charge period*/ - SSD1306WriteByte(0XF1, SSD1306_CMD); - SSD1306WriteByte(0xDA, SSD1306_CMD); /*set COM pins*/ - SSD1306WriteByte(0x12, SSD1306_CMD); - SSD1306WriteByte(0xDB, SSD1306_CMD); /*set vcomh*/ - SSD1306WriteByte(0x30, SSD1306_CMD); - SSD1306WriteByte(0x8D, SSD1306_CMD); /*set charge pump disable*/ - SSD1306WriteByte(0x14, SSD1306_CMD); - SSD1306WriteByte(0xAF, SSD1306_CMD); /*display ON*/ - - printf("%s,%s,%d \r\n", __FILE__, __func__, __LINE__); -} - -/******************************************************************* - * @name :void OLED_Set_Pos(unsigned char x, unsigned char y) - * @date :2018-08-27 - * @function :Set coordinates in the OLED screen - * @parameters :x:x coordinates - y:y coordinates - * @retvalue :None -********************************************************************/ -void SSD1306SetPos(unsigned char x, unsigned char y) -{ - SSD1306WriteByte(YLevel+y/PAGE_SIZE, SSD1306_CMD); - SSD1306WriteByte((((x+2)&0xf0)>>4)|0x10, SSD1306_CMD); - SSD1306WriteByte(((x+2)&0x0f), SSD1306_CMD); -} - -/******************************************************************* - * @name :void OLED_Display_On(void) - * @date :2018-08-27 - * @function :Turn on OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOn(void) -{ - SSD1306WriteByte(0X8D, SSD1306_CMD); //SET DCDC命令 - SSD1306WriteByte(0X14, SSD1306_CMD); //DCDC ON - SSD1306WriteByte(0XAF, SSD1306_CMD); //DISPLAY ON -} - -/******************************************************************* - * @name :void OLED_Display_Off(void) - * @date :2018-08-27 - * @function :Turn off OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOff(void) -{ - SSD1306WriteByte(0X8D, SSD1306_CMD); //SET DCDC命令 - SSD1306WriteByte(0X10, SSD1306_CMD); //DCDC OFF - SSD1306WriteByte(0XAE, SSD1306_CMD); //DISPLAY OFF -} - -/******************************************************************* - * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) - * @date :2018-08-27 - * @function :set the value of pixel to RAM - * @parameters :x:the x coordinates of pixel - y:the y coordinates of pixel - color:the color value of the point - 1-white - 0-black - * @retvalue :None -********************************************************************/ -void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) -{ - if(color) - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; - } - else - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); - } -} - -/******************************************************************* - * @name :void OLED_Display(void) - * @date :2018-08-27 - * @function :Display in OLED screen - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306Display(void) -{ - u8 i,n; - for(i=0;i>4)|0x10, SSD1306_CMD); + SSD1306WriteByte(((x+2)&0x0f), SSD1306_CMD); +} + +/******************************************************************* + * @name :void OLED_Display_On(void) + * @date :2018-08-27 + * @function :Turn on OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOn(void) +{ + SSD1306WriteByte(0X8D, SSD1306_CMD); //SET DCDC命令 + SSD1306WriteByte(0X14, SSD1306_CMD); //DCDC ON + SSD1306WriteByte(0XAF, SSD1306_CMD); //DISPLAY ON +} + +/******************************************************************* + * @name :void OLED_Display_Off(void) + * @date :2018-08-27 + * @function :Turn off OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOff(void) +{ + SSD1306WriteByte(0X8D, SSD1306_CMD); //SET DCDC命令 + SSD1306WriteByte(0X10, SSD1306_CMD); //DCDC OFF + SSD1306WriteByte(0XAE, SSD1306_CMD); //DISPLAY OFF +} + +/******************************************************************* + * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) + * @date :2018-08-27 + * @function :set the value of pixel to RAM + * @parameters :x:the x coordinates of pixel + y:the y coordinates of pixel + color:the color value of the point + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) +{ + if(color) + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; + } + else + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); + } +} + +/******************************************************************* + * @name :void OLED_Display(void) + * @date :2018-08-27 + * @function :Display in OLED screen + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306Display(void) +{ + u8 i,n; + for(i=0;i>4)|0x10, SSD1306_CMD); - SSD1306WriteByte(((x+2)&0x0f), SSD1306_CMD); -} - -/******************************************************************* - * @name :void OLED_Display_On(void) - * @date :2018-08-27 - * @function :Turn on OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOn(void) -{ - SSD1306WriteByte(0X8D, SSD1306_CMD); //SET DCDC命令 - SSD1306WriteByte(0X14, SSD1306_CMD); //DCDC ON - SSD1306WriteByte(0XAF, SSD1306_CMD); //DISPLAY ON -} - -/******************************************************************* - * @name :void OLED_Display_Off(void) - * @date :2018-08-27 - * @function :Turn off OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOff(void) -{ - SSD1306WriteByte(0X8D, SSD1306_CMD); //SET DCDC命令 - SSD1306WriteByte(0X10, SSD1306_CMD); //DCDC OFF - SSD1306WriteByte(0XAE, SSD1306_CMD); //DISPLAY OFF -} - -/******************************************************************* - * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) - * @date :2018-08-27 - * @function :set the value of pixel to RAM - * @parameters :x:the x coordinates of pixel - y:the y coordinates of pixel - color:the color value of the point - 1-white - 0-black - * @retvalue :None -********************************************************************/ -void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) -{ - if(color) - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; - } - else - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); - } -} - -/******************************************************************* - * @name :void OLED_Display(void) - * @date :2018-08-27 - * @function :Display in OLED screen - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306Display(void) -{ - u8 i,n; - for(i=0;i>4)|0x10, SSD1306_CMD); + SSD1306WriteByte(((x+2)&0x0f), SSD1306_CMD); +} + +/******************************************************************* + * @name :void OLED_Display_On(void) + * @date :2018-08-27 + * @function :Turn on OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOn(void) +{ + SSD1306WriteByte(0X8D, SSD1306_CMD); //SET DCDC命令 + SSD1306WriteByte(0X14, SSD1306_CMD); //DCDC ON + SSD1306WriteByte(0XAF, SSD1306_CMD); //DISPLAY ON +} + +/******************************************************************* + * @name :void OLED_Display_Off(void) + * @date :2018-08-27 + * @function :Turn off OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOff(void) +{ + SSD1306WriteByte(0X8D, SSD1306_CMD); //SET DCDC命令 + SSD1306WriteByte(0X10, SSD1306_CMD); //DCDC OFF + SSD1306WriteByte(0XAE, SSD1306_CMD); //DISPLAY OFF +} + +/******************************************************************* + * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) + * @date :2018-08-27 + * @function :set the value of pixel to RAM + * @parameters :x:the x coordinates of pixel + y:the y coordinates of pixel + color:the color value of the point + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) +{ + if(color) + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; + } + else + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); + } +} + +/******************************************************************* + * @name :void OLED_Display(void) + * @date :2018-08-27 + * @function :Display in OLED screen + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306Display(void) +{ + u8 i,n; + for(i=0;i>4)|0x10, SSD1306_CMD); - SSD1306WRByte(((x+2)&0x0f), SSD1306_CMD); -} - -/******************************************************************* - * @name :void OLED_Display_On(void) - * @date :2018-08-27 - * @function :Turn on OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOn(void) -{ - SSD1306WRByte(0X8D, SSD1306_CMD); //SET DCDC命令 - SSD1306WRByte(0X14, SSD1306_CMD); //DCDC ON - SSD1306WRByte(0XAF, SSD1306_CMD); //DISPLAY ON -} - -/******************************************************************* - * @name :void OLED_Display_Off(void) - * @date :2018-08-27 - * @function :Turn off OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOff(void) -{ - SSD1306WRByte(0X8D, SSD1306_CMD); //SET DCDC命令 - SSD1306WRByte(0X10, SSD1306_CMD); //DCDC OFF - SSD1306WRByte(0XAE, SSD1306_CMD); //DISPLAY OFF -} - -/******************************************************************* - * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) - * @date :2018-08-27 - * @function :set the value of pixel to RAM - * @parameters :x:the x coordinates of pixel - y:the y coordinates of pixel - color:the color value of the point - 1-white - 0-black - * @retvalue :None -********************************************************************/ -void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) -{ - if(color) - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; - } - else - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); - } -} - -/******************************************************************* - * @name :void OLED_Display(void) - * @date :2018-08-27 - * @function :Display in OLED screen - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306Display(void) -{ - u8 i,n; - for(i=0;i>4)|0x10, SSD1306_CMD); + SSD1306WRByte(((x+2)&0x0f), SSD1306_CMD); +} + +/******************************************************************* + * @name :void OLED_Display_On(void) + * @date :2018-08-27 + * @function :Turn on OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOn(void) +{ + SSD1306WRByte(0X8D, SSD1306_CMD); //SET DCDC命令 + SSD1306WRByte(0X14, SSD1306_CMD); //DCDC ON + SSD1306WRByte(0XAF, SSD1306_CMD); //DISPLAY ON +} + +/******************************************************************* + * @name :void OLED_Display_Off(void) + * @date :2018-08-27 + * @function :Turn off OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOff(void) +{ + SSD1306WRByte(0X8D, SSD1306_CMD); //SET DCDC命令 + SSD1306WRByte(0X10, SSD1306_CMD); //DCDC OFF + SSD1306WRByte(0XAE, SSD1306_CMD); //DISPLAY OFF +} + +/******************************************************************* + * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) + * @date :2018-08-27 + * @function :set the value of pixel to RAM + * @parameters :x:the x coordinates of pixel + y:the y coordinates of pixel + color:the color value of the point + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) +{ + if(color) + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; + } + else + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); + } +} + +/******************************************************************* + * @name :void OLED_Display(void) + * @date :2018-08-27 + * @function :Display in OLED screen + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306Display(void) +{ + u8 i,n; + for(i=0;i>4)|0x10); - SSD1306WRCmd(((x+2)&0x0f)); -} - -/******************************************************************* - * @name :void OLED_Display_On(void) - * @date :2018-08-27 - * @function :Turn on OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOn(void) -{ - SSD1306WRCmd(0X8D); //SET DCDC命令 - SSD1306WRCmd(0X14); //DCDC ON - SSD1306WRCmd(0XAF); //DISPLAY ON -} - -/******************************************************************* - * @name :void OLED_Display_Off(void) - * @date :2018-08-27 - * @function :Turn off OLED display - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306DisplayOff(void) -{ - SSD1306WRCmd(0X8D); //SET DCDC命令 - SSD1306WRCmd(0X10); //DCDC OFF - SSD1306WRCmd(0XAE); //DISPLAY OFF -} - -/******************************************************************* - * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) - * @date :2018-08-27 - * @function :set the value of pixel to RAM - * @parameters :x:the x coordinates of pixel - y:the y coordinates of pixel - color:the color value of the point - 1-white - 0-black - * @retvalue :None -********************************************************************/ -void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) -{ - if(color) - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; - } - else - { - OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); - } -} - -/******************************************************************* - * @name :void OLED_Display(void) - * @date :2018-08-27 - * @function :Display in OLED screen - * @parameters :None - * @retvalue :None -********************************************************************/ -void SSD1306Display(void) -{ - u8 i,n; - for(i=0;i>4)|0x10); + SSD1306WRCmd(((x+2)&0x0f)); +} + +/******************************************************************* + * @name :void OLED_Display_On(void) + * @date :2018-08-27 + * @function :Turn on OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOn(void) +{ + SSD1306WRCmd(0X8D); //SET DCDC命令 + SSD1306WRCmd(0X14); //DCDC ON + SSD1306WRCmd(0XAF); //DISPLAY ON +} + +/******************************************************************* + * @name :void OLED_Display_Off(void) + * @date :2018-08-27 + * @function :Turn off OLED display + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306DisplayOff(void) +{ + SSD1306WRCmd(0X8D); //SET DCDC命令 + SSD1306WRCmd(0X10); //DCDC OFF + SSD1306WRCmd(0XAE); //DISPLAY OFF +} + +/******************************************************************* + * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) + * @date :2018-08-27 + * @function :set the value of pixel to RAM + * @parameters :x:the x coordinates of pixel + y:the y coordinates of pixel + color:the color value of the point + 1-white + 0-black + * @retvalue :None +********************************************************************/ +void SSD1306SetPixel(unsigned char x, unsigned char y,unsigned char color) +{ + if(color) + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] |= (1<<(y%PAGE_SIZE))&0xff; + } + else + { + OLED_buffer[(y/PAGE_SIZE)*WIDTH+x] &= ~((1<<(y%PAGE_SIZE))&0xff); + } +} + +/******************************************************************* + * @name :void OLED_Display(void) + * @date :2018-08-27 + * @function :Display in OLED screen + * @parameters :None + * @retvalue :None +********************************************************************/ +void SSD1306Display(void) +{ + u8 i,n; + for(i=0;i -#include - -/* 基本数据类型 */ -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; -typedef unsigned long long u64; -typedef unsigned long ulong; -typedef char s8; -typedef short s16; -typedef int s32; -typedef long long s64; -typedef long slong; - -#undef ERROR -#define ERROR (-1) - -#define KP_ERR_SUCCESS 0 -#define KP_ERR_FAILURE (-1) - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define IOT_U8_MAX 0xFF -#define IOT_U16_MAX 0xFFFF -#define IOT_U32_MAX 0xFFFFFFFF -#define IOT_U64_MAX 0xFFFFFFFFFFFFFFFFUL - -#define msleep(x) usleep((x)*1000) - -typedef enum { - GPIO_OUT_LOW = 0, /* 低电平 */ - GPIO_OUT_HIGH = 1 /* 高电平 */ -} gpio_out_value; - +#ifndef __IOT_BASE_TYPE_H__ +#define __IOT_BASE_TYPE_H__ + +#include +#include + +/* 基本数据类型 */ +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef unsigned long ulong; +typedef char s8; +typedef short s16; +typedef int s32; +typedef long long s64; +typedef long slong; + +#undef ERROR +#define ERROR (-1) + +#define KP_ERR_SUCCESS 0 +#define KP_ERR_FAILURE (-1) + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define IOT_U8_MAX 0xFF +#define IOT_U16_MAX 0xFFFF +#define IOT_U32_MAX 0xFFFFFFFF +#define IOT_U64_MAX 0xFFFFFFFFFFFFFFFFUL + +#define msleep(x) usleep((x)*1000) + +typedef enum { + GPIO_OUT_LOW = 0, /* 低电平 */ + GPIO_OUT_HIGH = 1 /* 高电平 */ +} gpio_out_value; + typedef enum { /** Physical port 0 */ - IOT_UART_IDX_0, + IOT_UART_IDX_0, /** Physical port 1 */ - IOT_UART_IDX_1, + IOT_UART_IDX_1, /** Physical port 2 */ - IOT_UART_IDX_2, + IOT_UART_IDX_2, /** Maximum value */ - IOT_UART_IDX_MAX -}uart_port_idx; - - -typedef enum { - PWM_PORT_PWM0 = 0, /* PWM0端口 */ - PWM_PORT_PWM1 = 1, /* PWM1端口 */ - PWM_PORT_PWM2 = 2, /* PWM2端口 */ - PWM_PORT_PWM3 = 3, /* PWM3端口 */ - PWM_PORT_PWM4 = 4, /* PWM4端口 */ - PWM_PORT_PWM5 = 5, /* PWM5端口 */ - PWM_PORT_MAX /* 最大值,不可使用 */ -} pwm_port; - -typedef enum { - PWM_OUT_STOP = 0, /* PWM停止 */ - PWM_OUT_START = 1 /* PWM启动 */ -} pwm_out_value; - + IOT_UART_IDX_MAX +}uart_port_idx; + + +typedef enum { + PWM_PORT_PWM0 = 0, /* PWM0端口 */ + PWM_PORT_PWM1 = 1, /* PWM1端口 */ + PWM_PORT_PWM2 = 2, /* PWM2端口 */ + PWM_PORT_PWM3 = 3, /* PWM3端口 */ + PWM_PORT_PWM4 = 4, /* PWM4端口 */ + PWM_PORT_PWM5 = 5, /* PWM5端口 */ + PWM_PORT_MAX /* 最大值,不可使用 */ +} pwm_port; + +typedef enum { + PWM_OUT_STOP = 0, /* PWM停止 */ + PWM_OUT_START = 1 /* PWM启动 */ +} pwm_out_value; + typedef enum { /** I2C hardware index 0 */ - IOT_I2C_IDX_0, + IOT_I2C_IDX_0, /** I2C hardware index 1 */ - IOT_I2C_IDX_1, -} i2c_port_idx; - - -typedef enum { - LED_OFF = 0, - LED_ON = 1, - LED_SPARK = 2 -} led_state; -#define LED_SPARK_INTERVAL_TIME 30 - -#define IOT_DEBUG(fmt, args...) do { \ - printf("[IOT][%s][%d]", __FILE__, __LINE__); \ - printf(fmt, ##args); \ - printf("\r\n"); \ - } while (0) - -#define IOT_PRINTF_FUNC(fmt, args...) do { \ - printf("[%s]", __FUNCTION__); \ - printf(fmt, ##args); \ - printf("\r\n"); \ - } while (0) - - - -#endif + IOT_I2C_IDX_1, +} i2c_port_idx; + + +typedef enum { + LED_OFF = 0, + LED_ON = 1, + LED_SPARK = 2 +} led_state; +#define LED_SPARK_INTERVAL_TIME 30 + +#define IOT_DEBUG(fmt, args...) do { \ + printf("[IOT][%s][%d]", __FILE__, __LINE__); \ + printf(fmt, ##args); \ + printf("\r\n"); \ + } while (0) + +#define IOT_PRINTF_FUNC(fmt, args...) do { \ + printf("[%s]", __FUNCTION__); \ + printf(fmt, ##args); \ + printf("\r\n"); \ + } while (0) + + + +#endif diff --git a/my_adc/BUILD.gn b/my_adc/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b67edda245237432193c92ac9d93f09241e562a6 --- /dev/null +++ b/my_adc/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. +# 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. + +static_library("adc_example") { + sources = [ + "adc_example.c", + "../common/iot_led/led_gpio.c", + ] + + include_dirs = [ + "//base/iot_hardware/peripheral/interfaces/kits", + # "//device/board/bearpi/bearpi_hm_nano/iot_hardware_hals/include", + "//device/board/isoftstone/qihang/app/include", + "//device/board/isoftstone/qihang/app/common/inc", + "//device/board/isoftstone/qihang/app/common/iot_led", + ] +} diff --git a/my_adc/README.md b/my_adc/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ffa1eabdda838d8176ea5f59c0e1f7d1de4c07b2 --- /dev/null +++ b/my_adc/README.md @@ -0,0 +1,103 @@ +# BearPi-HM_Nano开发板基础外设开发——ADC采样 +本示例将演示如何在BearPi-HM_Nano开发板上通过按下按键改变GPIO口的电压,并使用ADC读取GPIO的电压值。 + +## ADC API分析 +本案例主要使用了以下API完成ADC采样的功能。 +### IoTAdcRead() +```c +unsigned int IoTAdcRead(unsigned int channel, unsigned short *data, IotAdcEquModelSel equModel, + IotAdcCurBais curBais, unsigned short rstCnt); +``` + **描述:** + +根据输入参数从指定的ADC通道读取一段采样数据。 + + +**参数:** + +|参数名|描述| +|:--|:------| +| channel | 表示ADC通道。 | +| data |表示指向存储读取数据的地址的指针。 | +| equModel | 表示平均算法的次数。 | +| curBais | 表示模拟功率控制模式。 | +| rstCnt | 指示从重置到转换开始的时间计数。一次计数等于334纳秒。值的范围必须从0到0xFF。| + + + +## 硬件设计 +本案例将使用板载用户按键F1来模拟GPIO口电压的变化。通过查看芯片手册可知GPIO_11对应的是 ADC Channel 5 ,所以需要编写软件去读取ADC Channel 5的电压,程序设计时先将GPIO_11上拉,使GPIO_11的电压一直处于高电平,当按键按下时GPIO_11接地,此时GPIO_11的电压变为 0 V。 + +![按键电路](../../docs/figures/B4_basic_adc/按键电路.png "按键电路") + +## 软件设计 + +**主要代码分析** + +该函数通过使用AdcRead()函数来读取 `ADC_CHANNEL_5` 的数值存储在data中, `IOT_ADC_EQU_MODEL_8` 表示8次平均算法模式,`IOT_ADC_CUR_BAIS_DEFAULT` 表示默认的自动识别模式,最后通过 `data * 1.8 * 4 / 4096.0` 计算出实际的电压值。 +```c +/** + * @brief get ADC sampling value and convert it to voltage + * + */ +static float GetVoltage(void) +{ + unsigned int ret; + unsigned short data; + + ret = IoTAdcRead(ADC_CHANNEL, &data, IOT_ADC_EQU_MODEL_8, IOT_ADC_CUR_BAIS_DEFAULT, 0xff); + if (ret != IOT_SUCCESS) { + printf("ADC Read Fail\n"); + } + + return (float)data * ADC_VREF_VOL * ADC_COEFFICIENT / ADC_RATIO; +} +``` + + + +## 编译调试 + +### 修改 BUILD.gn 文件 + + +修改`device\bearpi\bearpi_hm_nano\app` 路径下 BUILD.gn 文件,指定 `adc_example` 参与编译。 + +```r +#"B1_basic_led_blink:led_example", +#"B2_basic_button:button_example", +# "B3_basic_pwm_led:pwm_example", +"B4_basic_adc:adc_example", +#"B5_basic_i2c_nfc:i2c_example", +# "B6_basic_uart:uart_example", +``` + + + + +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,当F1按键未按下时采集到的电压为3.3V左右,当按键按下时,电压变为0.2V左右。 +```c +======================================= +*************ADC_example*********** +======================================= +vlt:3.371V +======================================= +*************ADC_example*********** +======================================= +vlt:3.371V +======================================= +*************ADC_example*********** +======================================= +vlt:3.373V +======================================= +*************ADC_example*********** +======================================= +vlt:0.248V +======================================= +*************ADC_example*********** +======================================= +vlt:0.244V +``` + diff --git a/my_adc/adc_example.c b/my_adc/adc_example.c new file mode 100644 index 0000000000000000000000000000000000000000..0ee6ca2a1a4925c4eea1ec4d783d05f31ed0ee3d --- /dev/null +++ b/my_adc/adc_example.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. + * 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 +#include + +#include "cmsis_os2.h" +#include "iot_adc.h" +#include "iot_errno.h" +#include "iot_gpio_ex.h" +#include "ohos_init.h" +#include "led_gpio.h" + +#define ADC_TASK_STACK_SIZE (1024 * 8) +#define ADC_TASK_PRIO 24 +#define ADC_GPIO 13 +#define ADC_CHANNEL 6 +#define ADC_TASK_DELAY_1S 1000000 + +#define ADC_VREF_VOL 1.8 +#define ADC_COEFFICIENT 4 +#define ADC_RATIO 4096 + +#define LED_GPIO 5 + + +/** + * @brief get ADC sampling value and convert it to voltage + * + */ +static float GetVoltage(void) +{ + unsigned int ret; + unsigned short data; + ret = IoTAdcRead(ADC_CHANNEL, &data, IOT_ADC_EQU_MODEL_8, IOT_ADC_CUR_BAIS_DEFAULT, 0xff); + if (ret != IOT_SUCCESS) { + printf("ADC Read Fail\n"); + } + + return (float)data * ADC_VREF_VOL * ADC_COEFFICIENT / ADC_RATIO; +} + +void LedTask(){ + LedGpioInit(LED_GPIO); + float data; + while(1){ + data = GetVoltage(); + if(data > 0.27) + { + LedGpioCtrl(1); + } + else{ + LedGpioCtrl(0); + } + sleep(3); + } +} + +/** + * @brief Adc task get adc sampling voltage + * + */ +static void AdcTask(void) +{ + float voltage; + + // set GPIO_11 to pull-up mode + IoTGpioSetPull(ADC_GPIO, IOT_GPIO_PULL_UP); + while (1) { + printf("=======================================\r\n"); + printf("***************ADC_example*************\r\n"); + printf("=======================================\r\n"); + + // get adc sampling voltage + voltage = GetVoltage(); + printf("vlt:%.3fV\n", voltage); + + // delay 1s + usleep(ADC_TASK_DELAY_1S); + } +} + + + +/** + * @brief Main Entry of the Adc Example + * + */ +static void AdcExampleEntry(void) +{ + osThreadAttr_t attr; + + attr.name = "AdcTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = ADC_TASK_STACK_SIZE; + attr.priority = ADC_TASK_PRIO; + + if (osThreadNew((osThreadFunc_t)AdcTask, NULL, &attr) == NULL) { + printf("Failed to create AdcTask!\n"); + } + + attr.name = "LedTask"; + if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) { + printf("Failed to create LedTask!\n"); + } +} + +APP_FEATURE_INIT(AdcExampleEntry); \ No newline at end of file diff --git "a/\346\263\250\346\204\217\344\272\213\351\241\271.txt" "b/\346\263\250\346\204\217\344\272\213\351\241\271.txt" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391