diff --git a/demo/button_example/BUILD.gn b/demo/button_example/BUILD.gn index b55ba56174cadffbe2e673043a1ee29f5235beb3..8c0ad09f7aeb58b5f4b86e949d4d64aa782d4eb1 100644 --- a/demo/button_example/BUILD.gn +++ b/demo/button_example/BUILD.gn @@ -22,7 +22,7 @@ static_library("buttonExample") { "//commonlibrary/utils_lite/include", "//kernel/liteos_m/kal/cmsis", "//base/iothardware/peripheral/interfaces/inner_api", - "//device/soc/hisilicon/ws63v100/sdkv100/include/driver", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", + "//device/soc/hisilicon/ws63v100/sdk/include/driver", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", ] } diff --git a/demo/button_example/README.md b/demo/button_example/README.md index 5e229026433294142482cd41d5af75995e2786ab..b6e43d0c43533f23fa18cae2e357c7dcd1e26c59 100644 --- a/demo/button_example/README.md +++ b/demo/button_example/README.md @@ -20,7 +20,7 @@ "button_example:buttonExample", ] -3. 修改`device\soc\hisilicon\ws63v100\sdkv100\libs_url\ws63\cmake\ohos.cmake`文件添加 `"buttonExample"`,如下: +3. 修改`device\soc\hisilicon\ws63v100\sdk\libs_url\ws63\cmake\ohos.cmake`文件添加 `"buttonExample"`,如下: ``` elseif(${TARGET_COMMAND} MATCHES "ws63-liteos-app") @@ -32,7 +32,7 @@ endif() ``` -4. 修改`device\soc\hisilicon\ws63v100\sdkv100\build\config\target_config\ws63\config.py`文件在`'ws63-liteos-app'`中`'ram_component': []'`添加 `"buttonExample"`,如下: +4. 修改`device\soc\hisilicon\ws63v100\sdk\build\config\target_config\ws63\config.py`文件在`'ws63-liteos-app'`中`'ram_component': []'`添加 `"buttonExample"`,如下: ``` @@ -64,7 +64,7 @@ ``` -5. 在openharmony源码目录下执行:`hb build -f` +5. 在openharmony源码目录下执行:`rm -rf out && hb set -p nearlink_dk_3863 && hb build -f` ## 三、运行结果 diff --git a/demo/button_example/button_example_main.c b/demo/button_example/button_example_main.c index 4065c5f2b7d718c0b42552858675e8f3d2e99f5e..3121efbcc61c489be5e8dac5e89cea93133f8c3e 100644 --- a/demo/button_example/button_example_main.c +++ b/demo/button_example/button_example_main.c @@ -62,7 +62,7 @@ static void OnButtonPressed(char *arg) static void *ButtonGPIODemo(const char *arg) { (void)arg; - + (void)osal_msleep(1000); printf("AppTask start\r\n"); // 初始化GPIO @@ -84,22 +84,28 @@ static void *ButtonGPIODemo(const char *arg) switch (g_ledState) { case LED_ON: IoTGpioSetOutputVal(IOT_GPIO_IDX_GREEN_LED, IOT_GPIO_VALUE0); - TaskMsleep(1000); + osDelay(100); + break; case LED_OFF: IoTGpioSetOutputVal(IOT_GPIO_IDX_GREEN_LED, IOT_GPIO_VALUE1); - TaskMsleep(1000); + + osDelay(100); break; case LED_SPARK: IoTGpioSetOutputVal(IOT_GPIO_IDX_GREEN_LED, IOT_GPIO_VALUE0); - TaskMsleep(200); + + osDelay(20); IoTGpioSetOutputVal(IOT_GPIO_IDX_GREEN_LED, IOT_GPIO_VALUE1); - TaskMsleep(200); + + osDelay(20); break; default: - TaskMsleep(1000); + + osDelay(100); break; } + } } @@ -112,7 +118,7 @@ static void AppTask(void) attr.cb_mem = NULL; attr.cb_size = 0U; attr.stack_mem = NULL; - attr.stack_size = 1024; /* 堆栈大小为1024 */ + attr.stack_size = 2048; attr.priority = osPriorityNormal; // 报错 diff --git a/demo/demo_uart/BUILD.gn b/demo/demo_uart/BUILD.gn index 916fd336d06553d488abb973e806d80c0d56e768..b955b60a7b43fce7cbc6c1deec100a39199d0b6d 100644 --- a/demo/demo_uart/BUILD.gn +++ b/demo/demo_uart/BUILD.gn @@ -22,13 +22,13 @@ static_library("demo_uart") { "//base/iothardware/peripheral/interfaces/inner_api", "//utils/native/lite/include", "//kernel/liteos_m/components/cmsis/2.0", - "//device/soc/hisilicon/ws63v100/sdkv100/kernel/liteos/liteos_v208.5.0/Huawei_LiteOS/compat/linux/include", + "//device/soc/hisilicon/ws63v100/sdk/kernel/liteos/liteos_v208.5.0/Huawei_LiteOS/compat/linux/include", "//base/startup/init/interfaces/innerkits/include", - "//device/soc/hisilicon/ws63v100/sdkv100/include/driver", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/drivers/hal/uart", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/chips/ws63/porting/uart", - "//device/soc/hisilicon/ws63v100/sdkv100/middleware/utils/common_headers/native", + "//device/soc/hisilicon/ws63v100/sdk/include/driver", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", + "//device/soc/hisilicon/ws63v100/sdk/drivers/drivers/hal/uart", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/porting/uart", + "//device/soc/hisilicon/ws63v100/sdk/middleware/utils/common_headers/native", ] } diff --git a/demo/demo_uart/README.md b/demo/demo_uart/README.md index 96d4bcfda8e296d5a93911a36b857b3db5e3858e..ec6c63ca7752d4559db692f42241e10c2fce8867 100644 --- a/demo/demo_uart/README.md +++ b/demo/demo_uart/README.md @@ -21,7 +21,7 @@ ] ``` -3. 修改`device\soc\hisilicon\ws63v100\sdkv100\libs_url\ws63\cmake\ohos.cmake`文件添加 `"demo_uart"`,如下: +3. 修改`device\soc\hisilicon\ws63v100\sdk\libs_url\ws63\cmake\ohos.cmake`文件添加 `"demo_uart"`,如下: ``` elseif(${TARGET_COMMAND} MATCHES "ws63-liteos-app") set(COMPONENT_LIST "begetutil" "hilog_lite_static" "samgr_adapter" "bootstrap" "fsmanager_static" "hal_update_static" "hilog_static" "inithook" "samgr_source" @@ -32,7 +32,7 @@ endif() ``` -4. 修改`device\soc\hisilicon\ws63v100\sdkv100\build\config\target_config\ws63\config.py`文件在`'ws63-liteos-app'`中`'ram_component': []'`添加 `"demo_uart"`,如下: +4. 修改`device\soc\hisilicon\ws63v100\sdk\build\config\target_config\ws63\config.py`文件在`'ws63-liteos-app'`中`'ram_component': []'`添加 `"demo_uart"`,如下: ``` 'ws63-liteos-app': { 'base_target_name': 'target_ws63_app_rom_template', @@ -60,7 +60,7 @@ 'copy_files_to_interim': True }, ``` -5. 在openharmony源码目录下执行:`hb build -f` +5. 在openharmony源码目录下执行:`rm -rf out && hb set -p nearlink_dk_3863 && hb build -f` diff --git a/demo/easy_wifi_demo/README.md b/demo/easy_wifi/README.md similarity index 72% rename from demo/easy_wifi_demo/README.md rename to demo/easy_wifi/README.md index f1d6769ef61327496840e29b59bf516c562027a7..d0ce0aaf036d30ffa2aba79a7227bd7de64664e9 100644 --- a/demo/easy_wifi_demo/README.md +++ b/demo/easy_wifi/README.md @@ -69,38 +69,42 @@ OpenharmonyWiFi STA模式的API接口有: | netifapi_dhcps_stop | 停止DHCP服务端 | -## 如何编译 +## 实验步骤 -本项目下有两个示例代码,源码位于`demo`目录下; -1. 将easy_wifi_demo文件夹克隆到本地openharmony源码的applications\sample\wifi-iot\app目录下; -2. 修改openharmony的`applications\sample\wifi-iot\app\BUILD.gn`文件: - * 将其中的 features 改为: +1. 实验需要两块开发板 +2. 将easy_wifi目录复制到openharmony源码的`applications\sample\wifi-iot\app`目录下, +3. 修改openharmony源码的`applications\sample\wifi-iot\app\BUILD.gn`文件,将其中的 `features` 改为: + +``` features = [ - "easy_wifi_demo/demo:wifi_demo", - "easy_wifi_demo/src:easy_wifi", + "easy_wifi/demo:wifi_demo", + "easy_wifi/src:easy_wifi", + ] +``` +4. 在`device\soc\hisilicon\ws63v100\sdk\build\config\target_config\ws63\config.py`文件中,找到`'ws63-liteos-app'`部分,在其`'ram_component'`中,添加以下代码: +``` +"wifi_demo","easy_wifi" +``` + +5. 在`device\soc\hisilicon\ws63v100\sdk\libs_url\ws63\cmake\ohos.cmake`文件中,找到`"ws63-liteos-app"`部分,在其`set(COMPONENT_LIST`部分,添加以下代码: +``` +"wifi_demo" "easy_wifi" +``` +6. 在openharmony sdk根目录目录执行:`rm -rf out && hb set -p nearlink_dk_3863 && hb build -f` + +7. 给第一块开发板烧录 + +8. 修改源码中的`applications\sample\wifi-iot\app\easy_wifi\demo\BUILD.gn`文件,将其中的 `sources` 改为: + +``` + sources = [ + #"wifi_connect_demo.c", + "wifi_hotspot_demo.c", ] +``` + +9. 在openharmony sdk根目录目录执行:`rm -rf out && hb set -p nearlink_dk_3863 && hb build -f` -3. 修改`device\soc\hisilicon\ws63v100\sdkv100\libs_url\ws63\cmake\ohos.cmake`文件添加`"wifi_demo"和"easy_wifi"`; - -4. 修改`device\soc\hisilicon\ws63v100\sdkv100\build\config\target_config\ws63\config.py`文件在`'ws63-liteos-app'`中`'ram_component': []'`添加 `"wifi_demo"和"easy_wifi"`; - -5. 设置一块开发板为sta模式,修改`applications\sample\wifi-iot\app\easy_wifi_demo\demo\BUILD.gn`, - * static_library("wifi_demo") { - sources = [ - "wifi_connect_demo.c", - #"wifi_hotspot_demo.c", - ] - } - 设置另一块开发板为ap模式,修改`applications\sample\wifi-iot\app\easy_wifi_demo\demo\BUILD.gn`, - * static_library("wifi_demo") { - sources = [ - #"wifi_connect_demo.c", - "wifi_hotspot_demo.c", - ] - } - -6. 选择要编译的产品:hb set -p nearlink_dk_3863,开始编译:hb build -f,生成的固件在`out/nearlink_dk_3863/nearlink_dk_3863/ws63-liteos-app`目录下,两块开发板需要烧录不同固件; - -7. 重启两块ws63开发板,两块开发板会建立wifi连接,一段时间后会自动断开连接。 +10. 给第二块开发板烧录 diff --git a/demo/easy_wifi_demo/BUILD.gn b/demo/easy_wifi/demo/BUILD.gn similarity index 55% rename from demo/easy_wifi_demo/BUILD.gn rename to demo/easy_wifi/demo/BUILD.gn index de24657da286c64e92ea11c9f044eca404e7ce4e..1b8490beca8f44b08d620707643e314aa168587d 100644 --- a/demo/easy_wifi_demo/BUILD.gn +++ b/demo/easy_wifi/demo/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 HiHope Open Source Organization . +# Copyright (C) 2024 HiHope Open Source Organization . # 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 @@ -11,11 +11,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/lite/config/component/lite_component.gni") +static_library("wifi_demo") { + sources = [ + "wifi_connect_demo.c", + #"wifi_hotspot_demo.c", + ] -lite_component("app") { - features = [ - "demo:wifi_demo", - "src:easy_wifi", - ] + include_dirs = [ + "//commonlibrary/utils_lite/include", + "//kernel/liteos_m/kal/cmsis", + "//base/iothardware/peripheral/interfaces/inner_api", + "//device/soc/hisilicon/ws63v100/sdk/include/middleware/services/wifi", + "../src", + ] } diff --git a/demo/easy_wifi/demo/wifi_connect_demo.c b/demo/easy_wifi/demo/wifi_connect_demo.c new file mode 100644 index 0000000000000000000000000000000000000000..611cdf649ab6f2029207d31aeb567d532733ccf2 --- /dev/null +++ b/demo/easy_wifi/demo/wifi_connect_demo.c @@ -0,0 +1,52 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 "ohos_init.h" +#include "cmsis_os2.h" +#include "wifi_connecter.h" + +#define SSID "HiSpark_AP" +#define KEY "123456789" + +static void WifiConnectTask(void) +{ + + if (ConnectToHotspot(SSID,KEY) != 0) + { + printf("Connect to AP failed!\n"); + } + else + { + printf("Connect to AP success!\n"); + } +} + + +static void WifiConnectDemo(void) +{ + + osThreadAttr_t attr; + attr.name = "WifiConnectTask"; + attr.stack_size = 0x1000; + attr.priority = osPriorityNormal; + if (osThreadNew(WifiConnectTask, NULL, &attr) == NULL) + { + printf("[WifiConnectDemo] Falied to create WifiConnectTask!\n"); + } +} + +SYS_RUN(WifiConnectDemo); diff --git a/demo/easy_wifi/demo/wifi_hotspot_demo.c b/demo/easy_wifi/demo/wifi_hotspot_demo.c new file mode 100644 index 0000000000000000000000000000000000000000..33137a9177bf4545ae5413c1c7240af2d116701a --- /dev/null +++ b/demo/easy_wifi/demo/wifi_hotspot_demo.c @@ -0,0 +1,58 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 "ohos_init.h" +#include "cmsis_os2.h" +#include "wifi_starter.h" + + +#define SSID "HiSpark_AP" +#define KEY "123456789" +#define WIFI_SEC_TYPE_PSK 2 +#define CHANNEL 7 + +static void WifiHotspotTask(void) +{ + + if (StartHotspot(SSID, KEY, WIFI_SEC_TYPE_PSK, CHANNEL) != 0) + { + printf("StartHotspot failed!\n"); + } + else + { + printf("StartHotspot success!\n"); + } +} + + +static void WifiHotspotDemo(void) +{ + + osThreadAttr_t attr; + attr.name = "WifiHotspotTask"; + attr.stack_size = 0x1000; + attr.priority = osPriorityNormal; + + + if (osThreadNew(WifiHotspotTask, NULL, &attr) == NULL) + { + printf("[WifiHotspotDemo] Falied to create WifiHotspotTask!\n"); + } +} + + +SYS_RUN(WifiHotspotDemo); diff --git a/demo/easy_wifi_demo/src/BUILD.gn b/demo/easy_wifi/src/BUILD.gn similarity index 46% rename from demo/easy_wifi_demo/src/BUILD.gn rename to demo/easy_wifi/src/BUILD.gn index a204563827a480ac1b067eeb0900dca35301cfbd..6ec49f6e613937d999b04fd15e223a7032a47cb2 100644 --- a/demo/easy_wifi_demo/src/BUILD.gn +++ b/demo/easy_wifi/src/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 HiHope Open Source Organization . +# Copyright (C) 2024 HiHope Open Source Organization . # 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 @@ -10,26 +10,28 @@ # 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("easy_wifi") { sources = [ "wifi_connecter.c", "wifi_starter.c", ] + + defines = [ "LWIP_CONFIG_FILE=\"lwip/lwipopts_default.h\"" ] include_dirs = [ "//commonlibrary/utils_lite/include", -# "//kernel/liteos_m/components/cmsis/2.0", -# "//base/iot_hardware/interfaces/kits/wifiiot_lite", -# "//foundation/communication/interfaces/kits/wifi_lite/wifiservice", - "//foundation/communication/wifi_lite/interfaces/wifiservice", -# "//vendor/hisi/hi3861/hi3861/third_party/lwip_sack/include/", - "//device/soc/hisilicon/ws63v100/sdkv100/open_source/lwip/lwip_v2.1.3/src/include", - "//device/soc/hisilicon/ws63v100/sdkv100/open_source/lwip/lwip_adapter/liteos_207/src/include", - "//device/soc/hisilicon/ws63v100/sdkv100/kernel/liteos/liteos_v208.5.0/Huawei_LiteOS/compat/linux/include", - "//device/soc/hisilicon/ws63v100/sdkv100/kernel/osal/include/lock", - "//device/soc/hisilicon/ws63v100/sdkv100/kernel/osal/include/schedule" + "//kernel/liteos_m/kal/cmsis", + "//base/iothardware/peripheral/interfaces/inner_api", + "//device/soc/hisilicon/ws63v100/sdk/open_source/lwip/lwip_v2.1.3/src/include", + "//device/soc/hisilicon/ws63v100/sdk/open_source/lwip/lwip_adapter/liteos_207/src/include", + "//device/soc/hisilicon/ws63v100/sdk/kernel/liteos/liteos_v208.5.0/Huawei_LiteOS/compat/linux/include", + "//device/soc/hisilicon/ws63v100/sdk/kernel/osal/include/lock", + "//device/soc/hisilicon/ws63v100/sdk/kernel/osal/include/schedule", + "//device/soc/hisilicon/ws63v100/sdk/middleware/utils/common_headers/native", + "//device/soc/hisilicon/ws63v100/sdk/kernel/osal/include", + "//device/soc/hisilicon/ws63v100/sdk/include/middleware/services/wifi", ] - defines = [ "LWIP_CONFIG_FILE=\"lwip/lwipopts_default.h\"" ] } diff --git a/demo/easy_wifi/src/wifi_connecter.c b/demo/easy_wifi/src/wifi_connecter.c new file mode 100644 index 0000000000000000000000000000000000000000..72e33c834d31a785ff3b24e66ee55715d0e7193d --- /dev/null +++ b/demo/easy_wifi/src/wifi_connecter.c @@ -0,0 +1,222 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 "stdlib.h" +#include "ohos_init.h" +#include "cmsis_os2.h" +#include "lwip/netifapi.h" +#include "lwip/nettool/misc.h" +#include "soc_osal.h" +#include "errcode.h" +#include "wifi_device.h" +#include "wifi_hotspot.h" +#include "wifi_hotspot_config.h" +#include "wifi_linked_info.h" +#include "wifi_device_config.h" + +#define WIFI_IFNAME_MAX_SIZE 64 +#define WIFI_MAX_SSID_LEN 33 +#define WIFI_SCAN_AP_LIMIT 64 +#define WIFI_MAC_LEN 6 +#define WIFI_NOT_AVALLIABLE 0 +#define WIFI_AVALIABE 1 +#define WIFI_GET_IP_MAX_COUNT 300 +#define WIFI_CONN_STATUS_MAX_GET_TIMES 5 /* 获取连接信息最大尝试次数 */ +#define DHCP_BOUND_STATUS_MAX_GET_TIMES 20 /* 获取绑定状态最大尝试次数 */ +#define WIFI_STA_IP_MAX_GET_TIMES 5 /* 获取IP最大尝试次数 */ + +/*STA 匹配目标AP +param1:待连接的网络名称 +param2:待连接的网络接入密码 +param3:wifi sta配置结构体 +*/ +errcode_t get_match_network(char *expected_ssid, + char *key, + wifi_sta_config_stru *expected_bss) +{ + uint32_t num = WIFI_IFNAME_MAX_SIZE; /* 64:可以扫描到的Wi-Fi网络数量 */ + uint32_t bss_index = 0; + + /* 获取扫描结果 */ + uint32_t scan_len = sizeof(wifi_scan_info_stru) * num; + wifi_scan_info_stru *result = osal_kmalloc(scan_len, OSAL_GFP_ATOMIC); + if (result == NULL) + { + return ERRCODE_MALLOC; + } + memset_s(result, scan_len, 0, scan_len); + if (wifi_sta_get_scan_info(result, &num) != ERRCODE_SUCC) + { + osal_kfree(result); + return ERRCODE_FAIL; + } + + /* 筛选扫描到的Wi-Fi网络,选择待连接的网络 */ + for (bss_index = 0; bss_index < num; bss_index++) + { + if (strlen(expected_ssid) == strlen(result[bss_index].ssid)) + { + if (memcmp(expected_ssid, result[bss_index].ssid, strlen(expected_ssid)) == 0) + { + break; + } + } + } + + /* 未找到待连接AP,可以继续尝试扫描或者退出 */ + if (bss_index >= num) + { + osal_kfree(result); + return ERRCODE_FAIL; + } + + /* 找到网络后复制网络信息和接入密码 */ + if (memcpy_s(expected_bss->ssid, WIFI_MAX_SSID_LEN, result[bss_index].ssid, WIFI_MAX_SSID_LEN) != EOK) + { + osal_kfree(result); + return ERRCODE_MEMCPY; + } + if (memcpy_s(expected_bss->bssid, WIFI_MAC_LEN, result[bss_index].bssid, WIFI_MAC_LEN) != EOK) + { + osal_kfree(result); + return ERRCODE_MEMCPY; + } + expected_bss->security_type = result[bss_index].security_type; + if (memcpy_s(expected_bss->pre_shared_key, WIFI_MAX_KEY_LEN, key, strlen(key)) != EOK) + { + osal_kfree(result); + return ERRCODE_MEMCPY; + } + expected_bss->ip_type = DHCP; /* IP类型为动态DHCP获取 */ + + osal_kfree(result); + return ERRCODE_SUCC; +} + +errcode_t ConnectToHotspot(char *ssid, char *key) +{ + /*WiFi sta 网络设备名*/ + char ifname[] = "wlan0"; + wifi_sta_config_stru expected_bss = {0}; + wifi_linked_info_stru wifi_status; + while (wifi_sta_enable() != ERRCODE_SUCC) + { + printf("STA enable fail, retry...\r\n"); + osal_msleep(100); + } + + while (1) + { + /* 启动STA扫描。每次触发扫描至少间隔1s*/ + osal_msleep(1000); + printf("Start Scan !\r\n"); + if (wifi_sta_scan() != ERRCODE_SUCC) + { + printf("STA scan fail, try again !\r\n"); + continue; + } + + /* 等待扫描完成 */ + osal_msleep(3000); + + /* 获取待连接的网络 */ + if (get_match_network(ssid, key, &expected_bss) != ERRCODE_SUCC) + { + printf("Can not find AP, try again !\r\n"); + continue; + } + + printf("STA try connect.\r\n"); + /* 启动连接 */ + if (wifi_sta_connect(&expected_bss) != ERRCODE_SUCC) + { + continue; + } + + /* 检查网络是否连接成功 */ + uint8_t index = 0; + for (index = 0; index < WIFI_CONN_STATUS_MAX_GET_TIMES; index++) + { + osal_msleep(500); + memset_s(&wifi_status, sizeof(wifi_linked_info_stru), 0, sizeof(wifi_linked_info_stru)); + if (wifi_sta_get_ap_info(&wifi_status) != ERRCODE_SUCC) + { + continue; + } + if (wifi_status.conn_state == WIFI_CONNECTED) + { + break; + } + } + + if (wifi_status.conn_state == WIFI_CONNECTED) + { + break; + } + } + + /* DHCP获取IP地址 */ + printf("STA DHCP start.\r\n"); + struct netif *netif_p = NULL; + netif_p = netifapi_netif_find(ifname); + if (netif_p == NULL) + { + return ERRCODE_FAIL; + } + + // 启动DHCP客户端 + if (netifapi_dhcp_start(netif_p) != ERR_OK) + { + printf("STA DHCP Fail.\r\n"); + return ERRCODE_FAIL; + } + + // 等待绑定成功 + for (uint8_t i = 0; i < DHCP_BOUND_STATUS_MAX_GET_TIMES; i++) + { + osal_msleep(500); + if (netifapi_dhcp_is_bound(netif_p) == ERR_OK) + { + printf("STA DHCP bound success.\r\n"); + break; + } + } + + // 等待DHCP服务端分配IP地址 + for (uint8_t i = 0; i < WIFI_STA_IP_MAX_GET_TIMES; i++) + { + osal_msleep(10); + if (netif_p->ip_addr.u_addr.ip4.addr != 0) + { + printf("STA IP %u.%u.%u.%u\r\n", (netif_p->ip_addr.u_addr.ip4.addr & 0x000000ff), + (netif_p->ip_addr.u_addr.ip4.addr & 0x0000ff00) >> 8, + (netif_p->ip_addr.u_addr.ip4.addr & 0x00ff0000) >> 16, + (netif_p->ip_addr.u_addr.ip4.addr & 0xff000000) >> 24); + netifapi_netif_common(netif_p, dhcp_clients_info_show, NULL); + if (netifapi_dhcp_start(netif_p) != 0) + { + printf("STA DHCP Fail.\r\n"); + return ERRCODE_FAIL; + } + + /* 连接成功 */ + printf("STA connect success.\r\n"); + return ERRCODE_SUCC; + } + } + + printf("STA connect fail.\r\n"); + return ERRCODE_FAIL; +} diff --git a/demo/easy_wifi/src/wifi_connecter.h b/demo/easy_wifi/src/wifi_connecter.h new file mode 100644 index 0000000000000000000000000000000000000000..d3e608f88143480ab1f3f14906d4daa7a619ae05 --- /dev/null +++ b/demo/easy_wifi/src/wifi_connecter.h @@ -0,0 +1,24 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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_CONNECTER_H +#define WIFI_CONNECTER_H + +#include "errcode.h" + +errcode_t ConnectToHotspot(char *ssid, char *key); + + +#endif \ No newline at end of file diff --git a/demo/easy_wifi/src/wifi_starter.c b/demo/easy_wifi/src/wifi_starter.c new file mode 100644 index 0000000000000000000000000000000000000000..4ad4338464f882ae3cb3db9c4d95311f24f258c3 --- /dev/null +++ b/demo/easy_wifi/src/wifi_starter.c @@ -0,0 +1,80 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 "stdlib.h" +#include "ohos_init.h" +#include "cmsis_os2.h" +#include "lwip/netifapi.h" +#include "soc_osal.h" +#include "errcode.h" +#include "wifi_hotspot.h" +#include "wifi_hotspot_config.h" +#include "wifi_linked_info.h" +#include "wifi_device_config.h" + + +errcode_t StartHotspot(char *ssid, char *pre_shared_key, wifi_security_enum security_type, uint8_t channel_num) +{ + //WiFi SoftAP 网络设备名 + char ifname[] = "ap0"; + + // 设置IP地址、子网掩码、网关地址 + ip4_addr_t st_ipaddr = {0}; + ip4_addr_t st_netmask = {0}; + ip4_addr_t st_gw = {0}; + IP4_ADDR(&st_ipaddr, 192, 168, 43, 1); /* IP地址设置:192.168.43.1 */ + IP4_ADDR(&st_netmask, 255, 255, 255, 0); /* 子网掩码设置:255.255.255.0 */ + IP4_ADDR(&st_gw, 192, 168, 43, 2); /* 网关地址设置:192.168.43.2 */ + + // Hotspot的配置 + softap_config_stru hapd_conf = {0}; + memcpy_s(hapd_conf.ssid, sizeof(hapd_conf.ssid), ssid, strlen(ssid)); /* SSID */ + memcpy_s(hapd_conf.pre_shared_key, WIFI_MAX_KEY_LEN, pre_shared_key, WIFI_MAX_KEY_LEN); /* 密码 */ + hapd_conf.security_type = security_type; // WiFi安全类型 + hapd_conf.channel_num = channel_num; /* 工作信道 */ + + // 启动Hotspot + printf("Hotspot try enable.\r\n"); + while (wifi_softap_enable(&hapd_conf) != ERRCODE_SUCC) + { + printf("Hotspot enable fail, retry...\r\n"); + osal_msleep(100); + } + + //配置DHCP服务器 + struct netif *netif_p = NULL; + netif_p = netif_find(ifname); + if (netif_p == NULL) + { + printf("find netif fail.\r\n", ifname); + wifi_softap_disable(); + return ERRCODE_FAIL; + } + if (netifapi_netif_set_addr(netif_p, &st_ipaddr, &st_netmask, &st_gw) != ERR_OK) + { + printf("set addr fail.\r\n"); + wifi_softap_disable(); + return ERRCODE_FAIL; + } + if (netifapi_dhcps_start(netif_p, NULL, 0) != ERR_OK) + { + printf("dhcps start fail.\r\n"); + wifi_softap_disable(); + return ERRCODE_FAIL; + } + + printf("SoftAp start success.\r\n"); + return ERRCODE_SUCC; +} diff --git a/demo/easy_wifi/src/wifi_starter.h b/demo/easy_wifi/src/wifi_starter.h new file mode 100644 index 0000000000000000000000000000000000000000..92f3091c769c7b6858c79715da4059d878c639a2 --- /dev/null +++ b/demo/easy_wifi/src/wifi_starter.h @@ -0,0 +1,25 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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_STARTER_H +#define WIFI_STARTER_H + +#include "errcode.h" +#include "wifi_device_config.h" + +errcode_t StartHotspot(char *ssid, char *pre_shared_key, wifi_security_enum security_type, uint8_t channel_num); + + +#endif \ No newline at end of file diff --git a/demo/easy_wifi_demo/LICENSE b/demo/easy_wifi_demo/LICENSE deleted file mode 100644 index 5289a998501715d449324ac3dd4c5f93eebf39de..0000000000000000000000000000000000000000 --- a/demo/easy_wifi_demo/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * 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. - */ diff --git a/demo/easy_wifi_demo/demo/wifi_connect_demo.c b/demo/easy_wifi_demo/demo/wifi_connect_demo.c deleted file mode 100644 index 0d88a6daea3121c9a074f9247eb53baf326c16d0..0000000000000000000000000000000000000000 --- a/demo/easy_wifi_demo/demo/wifi_connect_demo.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * 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 "ohos_init.h" -#include "cmsis_os2.h" - -#include "wifi_connecter.h" -#define TEN 10 -#define ONE_HUNDRED 100 - -#if CHIP_WS63 -#define STACK_SIZE 10240 -#define MAX_CONNECT_RETRY_TIMES 16 -#define CONNECT_ATTEMPT_INTERVAL_MS 300 -#else -#define ATTR.STACK_SIZE 10240 -#endif - -static void WifiConnectTask(int *arg) -{ - (void)arg; - - osDelay(TEN); - - // setup your AP params - // 设置AP参数,包括SSID、预共享密钥、安全类型(PSK)、netID - WifiDeviceConfig apConfig = {0}; - if (strcpy_s(apConfig.ssid, sizeof(apConfig.ssid), "HiSpark-AP")) { - printf("OK"); - } - - if (strcpy_s(apConfig.preSharedKey, sizeof(apConfig.preSharedKey), "12345678")) { - printf("OK"); - } - - apConfig.securityType = WIFI_SEC_TYPE_PSK; - -#if CHIP_WS63 - int netId = -1; - - // demo启动时,系统的WiFi功能可能没有初始化完毕,需要等待不确定的时候。待优化。 - for (uint8_t i = 0; i < MAX_CONNECT_RETRY_TIMES; i++) { - osDelay(CONNECT_ATTEMPT_INTERVAL_MS); - netId = ConnectToHotspot(&apConfig); - if (netId >= 0) { - break; - } - } -#else - int netId = ConnectToHotspot(&apConfig); -#endif - - // 连接等待一定时间后自动断开 - int timeout = 60; - while (timeout--) { - printf("After %d seconds I will disconnect with AP!\r\n", timeout); - osDelay(ONE_HUNDRED); - } - // 断开热点连接 - DisconnectWithHotspot(netId); -} - -static void WifiConnectDemo(void) -{ - osThreadAttr_t attr; - - attr.name = "WifiConnectTask"; - attr.attr_bits = 0U; - attr.cb_mem = NULL; - attr.cb_size = 0U; - attr.stack_mem = NULL; -#if CHIP_WS63 - attr.stack_size = STACK_SIZE; -#else - attr.stack_size = ATTR.STACK_SIZE; -#endif - attr.priority = osPriorityNormal; - - if (osThreadNew(WifiConnectTask, NULL, &attr) == NULL) { - printf("[WifiConnectDemo] Failed to create WifiConnectTask!\n"); - } -} - -SYS_RUN(WifiConnectDemo); diff --git a/demo/easy_wifi_demo/demo/wifi_hotspot_demo.c b/demo/easy_wifi_demo/demo/wifi_hotspot_demo.c deleted file mode 100644 index 7972f43bd5a9e276959dab0ebe7bc4f7a6d54a8f..0000000000000000000000000000000000000000 --- a/demo/easy_wifi_demo/demo/wifi_hotspot_demo.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * 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 "ohos_init.h" -#include "cmsis_os2.h" - -#include "wifi_starter.h" -#define SEVEN 7 -#define TEN 10 -#define ONE_HUNDRED 100 - -#if CHIP_WS63 -#define STACK_SIZE 10240 -#define MAX_CONNECT_RETRY_TIMES 16 -#define CONNECT_ATTEMPT_INTERVAL_MS 300 -#else -#define ATTR.STACK_SIZE 10240 -#endif - -static void WifiHotspotTask(int *arg) -{ - (void)arg; - WifiErrorCode errCode; - HotspotConfig config = {0}; - - // 准备AP的配置参数 - if (strcpy_s(config.ssid, sizeof(config.ssid), "HiSpark-AP")) { - printf("OK"); - } - if (strcpy_s(config.preSharedKey, sizeof(config.preSharedKey), "12345678")) { - printf("OK"); - } - config.securityType = WIFI_SEC_TYPE_PSK; - config.band = HOTSPOT_BAND_TYPE_2G; - config.channelNum = SEVEN; - - osDelay(TEN); - - printf("starting AP ...\r\n"); -#if CHIP_WS63 - // demo启动时,系统的WiFi功能可能没有初始化完毕,需要等待不确定的时候。待优化。 - for (uint8_t i = 0; i < MAX_CONNECT_RETRY_TIMES; i++) { - osDelay(CONNECT_ATTEMPT_INTERVAL_MS); - errCode = StartHotspot(&config); - - if (WIFI_SUCCESS == errCode) { - break; - } - } -#else - errCode = StartHotspot(&config); -#endif - printf("StartHotspot: %d\r\n", errCode); - - int timeout = 60; - while (timeout--) { - printf("After %d seconds Ap will turn off!\r\n", timeout); - osDelay(ONE_HUNDRED); - } - - printf("stop AP ...\r\n"); - StopHotspot(); - printf("stop AP ...\r\n"); - osDelay(TEN); -} - -static void WifiHotspotDemo(void) -{ - osThreadAttr_t attr; - - attr.name = "WifiHotspotTask"; - attr.attr_bits = 0U; - attr.cb_mem = NULL; - attr.cb_size = 0U; - attr.stack_mem = NULL; -#if CHIP_WS63 - attr.stack_size = STACK_SIZE; -#else - attr.stack_size = ATTR.STACK_SIZE; -#endif - attr.priority = osPriorityNormal; - - if (osThreadNew(WifiHotspotTask, NULL, &attr) == NULL) { - printf("[WifiHotspotDemo] Failed to create WifiHotspotTask!\n"); - } -} - -SYS_RUN(WifiHotspotDemo); - diff --git a/demo/easy_wifi_demo/src/wifi_connecter.c b/demo/easy_wifi_demo/src/wifi_connecter.c deleted file mode 100644 index 0f6dae0a53283523b856173f35ca92fda4565b27..0000000000000000000000000000000000000000 --- a/demo/easy_wifi_demo/src/wifi_connecter.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * 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 "wifi_device.h" -#include "cmsis_os2.h" - -#include "lwip/netifapi.h" - -#if CHIP_WS63 -#include "lwip/nettool/misc.h" -#else -#include "lwip/api_shell.h" -#endif -#define ZERO 0 -#define ONE 1 -#define TWO 2 -#define THREE 3 -#define FOUR 4 -#define FIVE 5 -#define TEN 10 -#define ONE_HUNDRED 100 - -static void PrintLinkedInfo(WifiLinkedInfo* info) -{ - if (!info) return; - - static char macAddress[32] = {0}; - unsigned char* mac = info->bssid; - sprintf(macAddress,"%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - printf("bssid: %s, rssi: %d, connState: %d, reason: %d, ssid: %s\r\n", - macAddress, info->rssi, info->connState, info->disconnectedReason, info->ssid); -} - -static volatile int g_connected = 0; - -static void OnWifiConnectionChanged(int state, WifiLinkedInfo* info) -{ - if (!info) return; - -//debug -#if 1 - printf("OnWifiConnectionChanged info: %p\r\n", info); -#endif - - printf("%s %d, state = %d, info = \r\n", __FUNCTION__, __LINE__, state); - PrintLinkedInfo(info); - - if (state == WIFI_STATE_AVAILABLE) { - g_connected = 1; - } else { - g_connected = 0; - } -} - -static void OnWifiScanStateChanged(int state, int size) -{ - printf("%s %d, state = %X, size = %d\r\n", __FUNCTION__, __LINE__, state, size); -} - -static WifiEvent g_defaultWifiEventListener = { - .OnWifiConnectionChanged = OnWifiConnectionChanged, - .OnWifiScanStateChanged = OnWifiScanStateChanged -}; - -static struct netif* g_iface = NULL; - -int ConnectToHotspot(WifiDeviceConfig* apConfig) -{ - WifiErrorCode errCode; - int netId = -1; - - errCode = RegisterWifiEvent(&g_defaultWifiEventListener); - printf("RegisterWifiEvent: %d\r\n", errCode); - - errCode = EnableWifi(); - printf("EnableWifi: %d\r\n", errCode); - - errCode = AddDeviceConfig(apConfig, &netId); - printf("AddDeviceConfig: %d\r\n", errCode); - - g_connected = 0; - errCode = ConnectTo(netId); - printf("ConnectTo(%d): %d\r\n", netId, errCode); - - while (!g_connected) { // wait until connect to AP - osDelay(TEN); - } - printf("g_connected: %d\r\n", g_connected); - - g_iface = netifapi_netif_find("wlan0"); - if (g_iface) { - err_t ret = netifapi_dhcp_start(g_iface); - printf("netifapi_dhcp_start: %d\r\n", ret); - - osDelay(ONE_HUNDRED); // wait DHCP server give me IP - ret = netifapi_netif_common(g_iface, dhcp_clients_info_show, NULL); - printf("netifapi_netif_common: %d\r\n", ret); - } - return netId; -} - -void DisconnectWithHotspot(int netId) -{ - if (g_iface) { - err_t ret = netifapi_dhcp_stop(g_iface); - printf("netifapi_dhcp_stop: %d\r\n", ret); - } - - WifiErrorCode errCode = Disconnect(); // disconnect with your AP - printf("Disconnect: %d\r\n", errCode); - - errCode = UnRegisterWifiEvent(&g_defaultWifiEventListener); - printf("UnRegisterWifiEvent: %d\r\n", errCode); - - RemoveDevice(netId); // remove AP config - printf("RemoveDevice: %d\r\n", errCode); - - errCode = DisableWifi(); - printf("DisableWifi: %d\r\n", errCode); -} - diff --git a/demo/easy_wifi_demo/src/wifi_connecter.h b/demo/easy_wifi_demo/src/wifi_connecter.h deleted file mode 100644 index 8f5e5d4ea544f97581b8def4935479b5d5d11f31..0000000000000000000000000000000000000000 --- a/demo/easy_wifi_demo/src/wifi_connecter.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * 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_CONNECTER_H -#define WIFI_CONNECTER_H - -#include "wifi_device.h" - -int ConnectToHotspot(WifiDeviceConfig* apConfig); - -void DisconnectWithHotspot(int netId); - -#endif // WIFI_CONNECTER_H \ No newline at end of file diff --git a/demo/easy_wifi_demo/src/wifi_starter.c b/demo/easy_wifi_demo/src/wifi_starter.c deleted file mode 100644 index c87c73ff5fbc3e69e5c04bc48f014646905361d9..0000000000000000000000000000000000000000 --- a/demo/easy_wifi_demo/src/wifi_starter.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * 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 "wifi_starter.h" -#include "cmsis_os2.h" - -#include "lwip/netifapi.h" -#define ZERO 0 -#define ONE 1 -#define TWO 2 -#define THREE 3 -#define FOUR 4 -#define FIVE 5 -#define TEN 10 - -static volatile int g_hotspotStarted = 0; - -static void OnHotspotStateChanged(int state) -{ - printf("OnHotspotStateChanged: %d.\r\n", state); - if (state == WIFI_HOTSPOT_ACTIVE) { - g_hotspotStarted = 1; - } else { - g_hotspotStarted = 0; - } -} - -static volatile int g_joinedStations = 0; - -static void PrintStationInfo(StationInfo* info) -{ - if (!info) return; - static char macAddress[32] = {0}; - unsigned char* mac = info->macAddress; - sprintf(macAddress,"%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - printf(" PrintStationInfo: mac=%s, reason=%d.\r\n", macAddress, info->disconnectedReason); -} - -static void OnHotspotStaJoin(StationInfo* info) -{ -//debug -#if 1 - printf("OnWifiConnectionChanged info: %p\r\n", info); -#endif - g_joinedStations++; - PrintStationInfo(info); - printf("+OnHotspotStaJoin: active stations = %d.\r\n", g_joinedStations); -} - -static void OnHotspotStaLeave(StationInfo* info) -{ - g_joinedStations--; - PrintStationInfo(info); - printf("-OnHotspotStaLeave: active stations = %d.\r\n", g_joinedStations); -} - -WifiEvent g_defaultWifiEventListener = { - .OnHotspotStaJoin = OnHotspotStaJoin, - .OnHotspotStaLeave = OnHotspotStaLeave, - .OnHotspotStateChanged = OnHotspotStateChanged, -}; - -static struct netif* g_iface = NULL; - -int StartHotspot(const HotspotConfig* config) -{ - WifiErrorCode errCode = WIFI_SUCCESS; - - errCode = RegisterWifiEvent(&g_defaultWifiEventListener); - printf("RegisterWifiEvent: %d\r\n", errCode); - - errCode = SetHotspotConfig(config); - printf("SetHotspotConfig: %d\r\n", errCode); - - g_hotspotStarted = 0; - errCode = EnableHotspot(); - printf("EnableHotspot: %d\r\n", errCode); - - while (!g_hotspotStarted) { - osDelay(TEN); - } - printf("g_hotspotStarted = %d.\r\n", g_hotspotStarted); - -#if CHIP_WS63 -#else - g_iface = netifapi_netif_find("ap0"); - if (g_iface) { - ip4_addr_t ipaddr; - ip4_addr_t gateway; - ip4_addr_t netmask; - - IP4_ADDR(&ipaddr, 192, 168, 1, 1); /* input your IP for example: 192.168.1.1 */ - IP4_ADDR(&gateway, 192, 168, 1, 1); /* input your gateway for example: 192.168.1.1 */ - IP4_ADDR(&netmask, 255, 255, 255, 0); /* input your netmask for example: 255.255.255.0 */ - err_t ret = netifapi_netif_set_addr(g_iface, &ipaddr, &netmask, &gateway); - printf("netifapi_netif_set_addr: %d\r\n", ret); - - ret = netifapi_dhcps_start(g_iface, 0, 0); - printf("netifapi_dhcp_start: %d\r\n", ret); - } -#endif - return errCode; -} - -void StopHotspot(void) -{ - if (g_iface) { - err_t ret = netifapi_dhcps_stop(g_iface); - printf("netifapi_dhcps_stop: %d\r\n", ret); - } - - WifiErrorCode errCode = UnRegisterWifiEvent(&g_defaultWifiEventListener); - printf("UnRegisterWifiEvent: %d\r\n", errCode); - - errCode = DisableHotspot(); - printf("EnableHotspot: %d\r\n", errCode); -} diff --git a/demo/easy_wifi_demo/src/wifi_starter.h b/demo/easy_wifi_demo/src/wifi_starter.h deleted file mode 100644 index b13a3f97a9d43003ea21fb60792e1a735ce591de..0000000000000000000000000000000000000000 --- a/demo/easy_wifi_demo/src/wifi_starter.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * 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_CONNECTER_H -#define WIFI_CONNECTER_H - -#include -#include "wifi_hotspot.h" - -int StartHotspot(const HotspotConfig* config); - -void StopHotspot(void); - -#endif // WIFI_CONNECTER_H \ No newline at end of file diff --git a/demo/hello_world_demo/README.md b/demo/hello_world_demo/README.md deleted file mode 100644 index 28b66eb2bddcab53528d2f5522ed19d74a21abb2..0000000000000000000000000000000000000000 --- a/demo/hello_world_demo/README.md +++ /dev/null @@ -1,97 +0,0 @@ -# OLED显示hello world实验 - - -## 一、I2C API - -| API名称 | 说明 | -| ------------------------------------------------------------ | ------------------------------- | -| I2cInit (WifiIotI2cIdx id, unsigned int baudrate) | 用指定的波特速率初始化I2C设备 | -| I2cDeinit (WifiIotI2cIdx id) | 取消初始化I2C设备 | -| I2cWrite (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData) | 将数据写入I2C设备 | -| I2cRead (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData) | 从I2C设备中读取数据 | -| I2cWriteread (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData) | 向I2C设备发送数据并接收数据响应 | -| I2cRegisterResetBusFunc (WifiIotI2cIdx id, WifiIotI2cFunc pfn) | 注册I2C设备回调 | -| I2cSetBaudrate (WifiIotI2cIdx id, unsigned int baudrate) | 设置I2C设备的波特率 | - -## 二、ssd1306 API - -| API名称 | 说明 | -| ------------------------------------------------------------ | -------------------------- | -| void ssd1306_Init(void) | 初始化 | -| void ssd1306_Fill(SSD1306_COLOR color) | 以指定的颜色填充屏幕 | -| void ssd1306_SetCursor(uint8_t x, uint8_t y) | 定位光标 | -| void ssd1306_UpdateScreen(void) | 更新屏幕内容 | -| char ssd1306_DrawChar(char ch, FontDef Font, SSD1306_COLOR color) | 在屏幕缓冲区绘制1个字符 | -| char ssd1306_DrawString(char* str, FontDef Font, SSD1306_COLOR color) | 将完整字符串写入屏幕缓冲区 | -| void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color) | 在屏幕缓冲区中绘制一个像素 | -| void ssd1306_DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, SSD1306_COLOR color) | 用Bresenhem算法画直线 | -| void ssd1306_DrawPolyline(const SSD1306_VERTEX *par_vertex, uint16_t par_size, SSD1306_COLOR color) | 绘制多段线 | -| void ssd1306_DrawRectangle(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, SSD1306_COLOR color) | 绘制矩形 | -| void ssd1306_DrawArc(uint8_t x, uint8_t y, uint8_t radius, uint16_t start_angle, uint16_t sweep, SSD1306_COLOR color) | 绘图角度 | -| void ssd1306_DrawCircle(uint8_t par_x, uint8_t par_y, uint8_t par_r, SSD1306_COLOR color) | 用Bresenhem算法画圆 | -| void ssd1306_DrawBitmap(const uint8_t* bitmap, uint32_t size) | 绘图位图 | -| void ssd1306_DrawRegion(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t* data, uint32_t size, uint32_t stride) | 绘制区域 | - -## 三、如何编译 - -1. 将hello_world_demo目录复制到本地openharmony源码的applications\sample\wifi-iot\app目录下 - -2. 修改openharmony的`applications\sample\wifi-iot\app\BUILD.gn`文件: - * 将其中的 features 改为: - ``` - features = [ - "hello_world_demo:helloWorld", - ] - ``` - -3. 修改`device\soc\hisilicon\ws63v100\sdkv100\libs_url\ws63\cmake\ohos.cmake`文件添加 `"helloWorld"`,如下: - ``` - elseif(${TARGET_COMMAND} MATCHES "ws63-liteos-app") - set(COMPONENT_LIST "begetutil" "hilog_lite_static" "samgr_adapter" "bootstrap" "fsmanager_static" "hal_update_static" "hilog_static" "inithook" "samgr_source" - "broadcast" "hal_file_static" "init_log" "native_file" "udidcomm" - "cjson_static" "hal_sys_param" "hichainsdk" "hota" "init_utils" "param_client_lite" - "hiview_lite_static" "hal_sysparam" "hievent_lite_static" "huks_3.0_sdk" "samgr" "blackbox_lite" "hal_iothardware" "wifiservice" - "hidumper_mini" "helloWorld") - endif() - ``` - -4. 修改`device\soc\hisilicon\ws63v100\sdkv100\build\config\target_config\ws63\config.py`文件在`'ws63-liteos-app'`中`'ram_component': []'`添加 `"helloWorld"`,如下: - ``` - 'ws63-liteos-app': { - 'base_target_name': 'target_ws63_app_rom_template', - 'os': 'liteos', - 'defines': [ - ...... - ], - 'ram_component': [ - ....... - 'xo_trim_port', - "mqtt", - "helloWorld" - ], - 'ccflags': [ - "-DBOARD_ASIC", '-DPRE_ASIC', - ], - 'application': 'application', - 'bin_name': 'ws63-liteos-app', - 'smaller': True, - 'hso_enable_bt': True, - 'hso_enable': True, - 'codesize_statistic': True, - 'nv_update':True, - 'generate_efuse_bin': True, - 'copy_files_to_interim': True - }, - ``` -5. 在openharmony源码目录下执行:`hb build -f` - - -## 四、编译错误解决 -``` -本项目代码使用了鸿蒙IoT硬件子系统的I2C API接口,需要连接到hi3863的I2C相关接口;默认情况下,Hi3863的I2C编译配置没有打开,需要在`~/device/soc/hisilicon/ws63v100/sdkv100`目录下,运行`"python3 build.py -c ws63-liteos-app menuconfig"`脚本, Menuconfig 程序启动后,可通过 Menuconfig 对编译和系统功能进行配置: -切换到Drivers ---> Drivers --->I2C I2C Configuration ,选中I2C SUPPORT MASTER和Using I2C V150,退出并保存 -``` - -## 五、运行结果 - -烧录文件后,按下reset按键,会发现oled显示helloworld diff --git a/demo/hello_world_demo/led_example.c b/demo/hello_world_demo/led_example.c deleted file mode 100644 index 2065b1b1ab55bec4c0dff25fa6736d339f5381e4..0000000000000000000000000000000000000000 --- a/demo/hello_world_demo/led_example.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. - * 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 "ohos_init.h" -#include "cmsis_os2.h" -#include "iot_gpio.h" - -#if CHIP_WS63 -#include "iot_gpio_ex.h" -#endif - -#define LED_INTERVAL_TIME_US 300000 -#if CHIP_WS63 -#define LED_TASK_STACK_SIZE 4096 -#define LED_TASK_PRIO 25 -#define LED_TEST_GPIO 7 -#else -#define LED_TASK_STACK_SIZE 512 -#define LED_TASK_PRIO 25 -// for hispark_pegasus -#define LED_TEST_GPIO 9 -#endif - -static long long g_iState = 0; - -enum LedState { - LED_ON = 0, - LED_OFF, - LED_SPARK, -}; - -enum LedState g_ledState = LED_SPARK; - -static void *LedTask(const char *arg) -{ - (void)arg; - - - IoTGpioInit(LED_TEST_GPIO); -#if CHIP_WS63 - //V100 版本SDK中,有其它地方会修改GPIO_7的MODE。需要检查或者延迟。 - IoSetFunc(LED_TEST_GPIO, IOT_IO_FUNC_GPIO_7_GPIO); -#endif - IoTGpioSetDir(LED_TEST_GPIO, IOT_GPIO_DIR_OUT); - - while (1) { - switch (g_ledState) { - case LED_ON: - IoTGpioSetOutputVal(LED_TEST_GPIO, 1); - usleep(LED_INTERVAL_TIME_US); - g_iState++; - break; - case LED_OFF: - IoTGpioSetOutputVal(LED_TEST_GPIO, 0); - usleep(LED_INTERVAL_TIME_US); - g_iState++; - break; - case LED_SPARK: - IoTGpioSetOutputVal(LED_TEST_GPIO, 0); - usleep(LED_INTERVAL_TIME_US); - IoTGpioSetOutputVal(LED_TEST_GPIO, 1); - usleep(LED_INTERVAL_TIME_US); - g_iState++; - break; - default: - usleep(LED_INTERVAL_TIME_US); - break; - } - if (g_iState == 0xffffffff) { - g_iState = 0; - break; - } - } - return NULL; -} - -static void LedExampleEntry(void) -{ - osThreadAttr_t attr; - - attr.name = "LedTask"; - attr.attr_bits = 0U; - attr.cb_mem = NULL; - attr.cb_size = 0U; - attr.stack_mem = NULL; - attr.stack_size = LED_TASK_STACK_SIZE; - attr.priority = LED_TASK_PRIO; - - if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) { - printf("[LedExample] Failed to create LedTask!\n"); - } -} - -SYS_RUN(LedExampleEntry); diff --git a/demo/hello_world_demo/oled_demo.c b/demo/hello_world_demo/oled_demo.c deleted file mode 100644 index ff96cd6c135185602d175752004c3bd9b1b2e835..0000000000000000000000000000000000000000 --- a/demo/hello_world_demo/oled_demo.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. - * 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 "ohos_init.h" -#include "cmsis_os2.h" -#include "iot_i2c.h" -#include "iot_gpio.h" -#include "iot_errno.h" - -#include "oled_ssd1306.h" - -#if CHIP_WS63 -#define AHT20_BAUDRATE (400 * 1000) -#define AHT20_I2C_IDX 1 -#else -#define AHT20_BAUDRATE (400 * 1000) -#define AHT20_I2C_IDX 0 -#endif - -static void OledmentTask(const char *arg) -{ - (void)arg; - OledInit(); - OledFillScreen(0); - IoTI2cInit(AHT20_I2C_IDX, AHT20_BAUDRATE); - - OledShowString(20, 3, "Hello World", 1); /* 屏幕第20列3行显示1行 */ -} - -static void OledDemo(void) -{ - osThreadAttr_t attr; - attr.name = "OledmentTask"; - attr.attr_bits = 0U; - attr.cb_mem = NULL; - attr.cb_size = 0U; - attr.stack_mem = NULL; - attr.stack_size = 4096; /* 任务大小4096 */ - attr.priority = osPriorityNormal; - - if (osThreadNew(OledmentTask, NULL, &attr) == NULL) { - printf("[OledDemo] Failed to create OledmentTask!\n"); - } -} - -APP_FEATURE_INIT(OledDemo); \ No newline at end of file diff --git a/demo/hello_world_demo/oled_fonts.h b/demo/hello_world_demo/oled_fonts.h deleted file mode 100644 index 1d1771ccbfc7365369b2f7aa328d89232695f4de..0000000000000000000000000000000000000000 --- a/demo/hello_world_demo/oled_fonts.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. - * 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 OLED_FONTS_H -#define OLED_FONTS_H - -/************************************6*8的点阵************************************/ -static unsigned char g_f6X8[][6] = { - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp - { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // ! - { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // " - { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // # - { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $ - { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // % - { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // & - { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // ' - { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // ( - { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // ) - { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // * - { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // + - { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // , - { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // - - { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // . - { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // / - { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0 - { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1 - { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2 - { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3 - { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4 - { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5 - { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6 - { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7 - { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8 - { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9 - { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // : - { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;号 - { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // < - { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // = - { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // > - { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ? - { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @ - { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A - { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B - { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C - { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D - { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E - { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F - { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G - { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H - { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I - { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J - { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K - { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L - { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M - { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N - { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O - { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P - { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q - { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R - { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S - { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T - { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U - { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V - { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W - { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X - { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y - { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z - { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [ - { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55 - { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ] - { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^ - { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _ - { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // ' - { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a - { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b - { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c - { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d - { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e - { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f - { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g - { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h - { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i - { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j - { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k - { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l - { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m - { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n - { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o - { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p - { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q - { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r - { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s - { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t - { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u - { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v - { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w - { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x - { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y - { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z - { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 }, // horiz lines -}; - -/****************************************8*16的点阵************************************/ -static const unsigned char g_f8X16[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 - 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x30, 0x00, 0x00, 0x00, // ! 1 - 0x00, 0x10, 0x0C, 0x06, 0x10, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " 2 - 0x40, 0xC0, 0x78, 0x40, 0xC0, 0x78, 0x40, 0x00, 0x04, 0x3F, 0x04, 0x04, 0x3F, 0x04, 0x04, 0x00, // # 3 - 0x00, 0x70, 0x88, 0xFC, 0x08, 0x30, 0x00, 0x00, 0x00, 0x18, 0x20, 0xFF, 0x21, 0x1E, 0x00, 0x00, // $ 4 - 0xF0, 0x08, 0xF0, 0x00, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x21, 0x1C, 0x03, 0x1E, 0x21, 0x1E, 0x00, // % 5 - 0x00, 0xF0, 0x08, 0x88, 0x70, 0x00, 0x00, 0x00, 0x1E, 0x21, 0x23, 0x24, 0x19, 0x27, 0x21, 0x10, // & 6 - 0x10, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ' 7 - 0x00, 0x00, 0x00, 0xE0, 0x18, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x20, 0x40, 0x00, // ( 8 - 0x00, 0x02, 0x04, 0x18, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x18, 0x07, 0x00, 0x00, 0x00, // ) 9 - 0x40, 0x40, 0x80, 0xF0, 0x80, 0x40, 0x40, 0x00, 0x02, 0x02, 0x01, 0x0F, 0x01, 0x02, 0x02, 0x00, // * 10 - 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x1F, 0x01, 0x01, 0x01, 0x00, // + 11 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xB0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, // , 12 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // - 13 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, // . 14 - 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x04, 0x00, 0x60, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00, // / 15 - 0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x10, 0x0F, 0x00, // 0 16 - 0x00, 0x10, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // 1 17 - 0x00, 0x70, 0x08, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x30, 0x28, 0x24, 0x22, 0x21, 0x30, 0x00, // 2 18 - 0x00, 0x30, 0x08, 0x88, 0x88, 0x48, 0x30, 0x00, 0x00, 0x18, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, // 3 19 - 0x00, 0x00, 0xC0, 0x20, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x07, 0x04, 0x24, 0x24, 0x3F, 0x24, 0x00, // 4 20 - 0x00, 0xF8, 0x08, 0x88, 0x88, 0x08, 0x08, 0x00, 0x00, 0x19, 0x21, 0x20, 0x20, 0x11, 0x0E, 0x00, // 5 21 - 0x00, 0xE0, 0x10, 0x88, 0x88, 0x18, 0x00, 0x00, 0x00, 0x0F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00, // 6 22 - 0x00, 0x38, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, // 7 23 - 0x00, 0x70, 0x88, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x1C, 0x22, 0x21, 0x21, 0x22, 0x1C, 0x00, // 8 24 - 0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x00, 0x31, 0x22, 0x22, 0x11, 0x0F, 0x00, // 9 25 - 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, // : 26 - 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00, // ;号 27 - 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, // < 28 - 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, // = 29 - 0x00, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, // > 30 - 0x00, 0x70, 0x48, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x36, 0x01, 0x00, 0x00, // ? 31 - 0xC0, 0x30, 0xC8, 0x28, 0xE8, 0x10, 0xE0, 0x00, 0x07, 0x18, 0x27, 0x24, 0x23, 0x14, 0x0B, 0x00, // @ 32 - 0x00, 0x00, 0xC0, 0x38, 0xE0, 0x00, 0x00, 0x00, 0x20, 0x3C, 0x23, 0x02, 0x02, 0x27, 0x38, 0x20, // A 33 - 0x08, 0xF8, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, // B 34 - 0xC0, 0x30, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x07, 0x18, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, // C 35 - 0x08, 0xF8, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, // D 36 - 0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x23, 0x20, 0x18, 0x00, // E 37 - 0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, // F 38 - 0xC0, 0x30, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x07, 0x18, 0x20, 0x20, 0x22, 0x1E, 0x02, 0x00, // G 39 - 0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x21, 0x3F, 0x20, // H 40 - 0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // I 41 - 0x00, 0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, 0x00, // J 42 - 0x08, 0xF8, 0x88, 0xC0, 0x28, 0x18, 0x08, 0x00, 0x20, 0x3F, 0x20, 0x01, 0x26, 0x38, 0x20, 0x00, // K 43 - 0x08, 0xF8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00, // L 44 - 0x08, 0xF8, 0xF8, 0x00, 0xF8, 0xF8, 0x08, 0x00, 0x20, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x20, 0x00, // M 45 - 0x08, 0xF8, 0x30, 0xC0, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x20, 0x00, 0x07, 0x18, 0x3F, 0x00, // N 46 - 0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, // O 47 - 0x08, 0xF8, 0x08, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x01, 0x00, 0x00, // P 48 - 0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x18, 0x24, 0x24, 0x38, 0x50, 0x4F, 0x00, // Q 49 - 0x08, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x0C, 0x30, 0x20, // R 50 - 0x00, 0x70, 0x88, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x38, 0x20, 0x21, 0x21, 0x22, 0x1C, 0x00, // S 51 - 0x18, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x18, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00, // T 52 - 0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, // U 53 - 0x08, 0x78, 0x88, 0x00, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x07, 0x38, 0x0E, 0x01, 0x00, 0x00, // V 54 - 0xF8, 0x08, 0x00, 0xF8, 0x00, 0x08, 0xF8, 0x00, 0x03, 0x3C, 0x07, 0x00, 0x07, 0x3C, 0x03, 0x00, // W 55 - 0x08, 0x18, 0x68, 0x80, 0x80, 0x68, 0x18, 0x08, 0x20, 0x30, 0x2C, 0x03, 0x03, 0x2C, 0x30, 0x20, // X 56 - 0x08, 0x38, 0xC8, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00, // Y 57 - 0x10, 0x08, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x20, 0x38, 0x26, 0x21, 0x20, 0x20, 0x18, 0x00, // Z 58 - 0x00, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x00, // [ 59 - 0x00, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x38, 0xC0, 0x00, // \ 60 - 0x00, 0x02, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7F, 0x00, 0x00, 0x00, // ] 61 - 0x00, 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ^ 62 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // _ 63 - 0x00, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ` 64 - 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x19, 0x24, 0x22, 0x22, 0x22, 0x3F, 0x20, // a 65 - 0x08, 0xF8, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00, // b 66 - 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x20, 0x11, 0x00, // c 67 - 0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0xF8, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x10, 0x3F, 0x20, // d 68 - 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x22, 0x22, 0x22, 0x22, 0x13, 0x00, // e 69 - 0x00, 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x18, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // f 70 - 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x6B, 0x94, 0x94, 0x94, 0x93, 0x60, 0x00, // g 71 - 0x08, 0xF8, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20, // h 72 - 0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // i 73 - 0x00, 0x00, 0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, // j 74 - 0x08, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x24, 0x02, 0x2D, 0x30, 0x20, 0x00, // k 75 - 0x00, 0x08, 0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // l 76 - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x3F, 0x20, 0x00, 0x3F, // m 77 - 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20, // n 78 - 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, // o 79 - 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xA1, 0x20, 0x20, 0x11, 0x0E, 0x00, // p 80 - 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0xA0, 0xFF, 0x80, // q 81 - 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x20, 0x3F, 0x21, 0x20, 0x00, 0x01, 0x00, // r 82 - 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x33, 0x24, 0x24, 0x24, 0x24, 0x19, 0x00, // s 83 - 0x00, 0x80, 0x80, 0xE0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x00, 0x00, // t 84 - 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x10, 0x3F, 0x20, // u 85 - 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0E, 0x30, 0x08, 0x06, 0x01, 0x00, // v 86 - 0x80, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80, 0x80, 0x0F, 0x30, 0x0C, 0x03, 0x0C, 0x30, 0x0F, 0x00, // w 87 - 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x31, 0x2E, 0x0E, 0x31, 0x20, 0x00, // x 88 - 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x81, 0x8E, 0x70, 0x18, 0x06, 0x01, 0x00, // y 89 - 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x21, 0x30, 0x2C, 0x22, 0x21, 0x30, 0x00, // z 90 - 0x00, 0x00, 0x00, 0x00, 0x80, 0x7C, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x40, // { 91 - 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, // | 92 - 0x00, 0x02, 0x02, 0x7C, 0x80, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x3F, 0x00, 0x00, 0x00, 0x00, // } 93 - 0x00, 0x06, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ~ 94 -}; - -#endif \ No newline at end of file diff --git a/demo/hello_world_demo/oled_ssd1306.h b/demo/hello_world_demo/oled_ssd1306.h deleted file mode 100644 index 75c1d74bae54dcdb1a01242a57d46bb92cb9c0e0..0000000000000000000000000000000000000000 --- a/demo/hello_world_demo/oled_ssd1306.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. - * 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 OLED_SSD1306_H -#define OLED_SSD1306_H - -#include - -/** - * @brief ssd1306 OLED Initialize. - */ -uint32_t OledInit(void); - -/** - * @brief Set cursor position - * @param x the horizontal position of cursor - * @param y the vertical position of cursor - * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link wifiiot_errno.h} otherwise. - */ -void OledSetPosition(uint8_t x, uint8_t y); - -void OledFillScreen(uint8_t fillData); - -enum Font { - FONT6_X8 = 1, - FONT8_X16 -}; -typedef enum Font Font; - -void OledShowChar(uint8_t x, uint8_t y, uint8_t ch, Font font); -void OledShowString(uint8_t x, uint8_t y, const char* str, Font font); - -#endif // OLED_SSD1306_H diff --git "a/demo/hello_world_demo/\345\276\256\344\277\241\346\210\252\345\233\276_20240709112637.jpg" "b/demo/hello_world_demo/\345\276\256\344\277\241\346\210\252\345\233\276_20240709112637.jpg" deleted file mode 100644 index 36480f3d4fecc6989a9e5932c9897f3cc33a6826..0000000000000000000000000000000000000000 Binary files "a/demo/hello_world_demo/\345\276\256\344\277\241\346\210\252\345\233\276_20240709112637.jpg" and /dev/null differ diff --git a/demo/led_demo/BUILD.gn b/demo/led_demo/BUILD.gn index 4ff2c9df5bd1d9ed9070f28eeb344273c054d598..9c3435086bfd1535d56a5092070a1a44fcce6899 100644 --- a/demo/led_demo/BUILD.gn +++ b/demo/led_demo/BUILD.gn @@ -22,7 +22,7 @@ static_library("ledDemo") { "//commonlibrary/utils_lite/include", "//kernel/liteos_m/kal/cmsis", "//base/iothardware/peripheral/interfaces/inner_api", - "//device/soc/hisilicon/ws63v100/sdkv100/include/driver", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", + "//device/soc/hisilicon/ws63v100/sdk/include/driver", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", ] } diff --git a/demo/led_demo/README.md b/demo/led_demo/README.md index b5816558c96777729114d62beb2f1119bf7002c0..eb69a51a290c7a1dd7e3a0b99905bbdfd2335db9 100644 --- a/demo/led_demo/README.md +++ b/demo/led_demo/README.md @@ -20,7 +20,7 @@ "led_demo:ledDemo", ] -3. 修改`device\soc\hisilicon\ws63v100\sdkv100\libs_url\ws63\cmake\ohos.cmake`文件添加 `"ledDemo"`,如下: +3. 修改`device\soc\hisilicon\ws63v100\sdk\libs_url\ws63\cmake\ohos.cmake`文件添加 `"ledDemo"`,如下: ``` elseif(${TARGET_COMMAND} MATCHES "ws63-liteos-app") @@ -32,7 +32,7 @@ endif() ``` -4. 修改`device\soc\hisilicon\ws63v100\sdkv100\build\config\target_config\ws63\config.py`文件在`'ws63-liteos-app'`中`'ram_component': []'`添加 `"ledDemo"`,如下: +4. 修改`device\soc\hisilicon\ws63v100\sdk\build\config\target_config\ws63\config.py`文件在`'ws63-liteos-app'`中`'ram_component': []'`添加 `"ledDemo"`,如下: ``` @@ -64,7 +64,7 @@ ``` -5. 在openharmony源码目录下执行:`hb build -f` +5. 在openharmony源码目录下执行:`rm -rf out && hb set -p nearlink_dk_3863 && hb build -f` ## 三、运行结果 diff --git a/demo/led_demo/app_demo_led_control.c b/demo/led_demo/app_demo_led_control.c index 01f1952c92a74d0c179d763460265641fbb45b5d..dd9a74f721ab9b0a407e4833daf56e50dd3fe696 100644 --- a/demo/led_demo/app_demo_led_control.c +++ b/demo/led_demo/app_demo_led_control.c @@ -110,7 +110,7 @@ static void LedControlTask(void) attr.stack_mem = NULL; attr.stack_size = 1024; /* 堆栈大小为1024 */ attr.priority = osPriorityNormal; - // 报错 + if (osThreadNew((osThreadFunc_t)LedCntrolDemo, NULL, &attr) == NULL) { printf("[LedExample] Failed to create LedTask!\n"); } diff --git a/demo/oled_demo/README.md b/demo/oled_demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..367d99e836ab283bd67e898a5d30c11d8e55f0dc --- /dev/null +++ b/demo/oled_demo/README.md @@ -0,0 +1,60 @@ +# OLED显示hello world实验 + + +## 一、I2C API + +| API名称 | 说明 | +| ------------------------------------------------------------ | ------------------------------- | +| I2cInit (WifiIotI2cIdx id, unsigned int baudrate) | 用指定的波特速率初始化I2C设备 | +| I2cDeinit (WifiIotI2cIdx id) | 取消初始化I2C设备 | +| I2cWrite (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData) | 将数据写入I2C设备 | +| I2cRead (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData) | 从I2C设备中读取数据 | +| I2cWriteread (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData) | 向I2C设备发送数据并接收数据响应 | + +## 二、ssd1306 API + +本样例提供了一个HarmonyOS IoT硬件接口的SSD1306 OLED屏驱动库,其特点如下: + +* 使用Harmony OS的IoT硬件接口; +* 接口简洁易于使用、易于移植; +* 内置了测试程序,可直接进行测试; + +| API名称 | 说明 | +| ------------------------------------------------------------ | -------------------------------- | +| uint32_t OledInit(void); | 初始化 | +| void OledFillScreen(uint8_t fillData); | 填充屏幕 | +| void OledShowChar(uint8_t x, uint8_t y, uint8_t ch, Font font); | 显示一个字符 | +| void void OledShowString(uint8_t x, uint8_t y, const char* str, Font font); | 显示字符串 | + | + + +## 三、如何编译 + +1. 将oled_demo目录复制到openharmony源码的`applications\sample\wifi-iot\app`目录下, +2. 修改openharmony源码的`applications\sample\wifi-iot\app\BUILD.gn`文件,将其中的 `features` 改为: + +``` + features = [ + "oled_demo:oled_demo", + ] +``` +3. 在`device\soc\hisilicon\ws63v100\sdk\build\config\target_config\ws63\config.py`文件中,找到`'ws63-liteos-app'`部分,在其`'ram_component'`中,添加以下代码: +``` +"oled_demo" +``` + +4. 在`device\soc\hisilicon\ws63v100\sdk\libs_url\ws63\cmake\ohos.cmake`文件中,找到`"ws63-liteos-app"`部分,在其`set(COMPONENT_LIST`部分,添加以下代码: +``` +"oled_demo" +``` +5. 在openharmony sdk根目录目录执行:`rm -rf out && hb set -p nearlink_dk_3863 && hb build -f` + + + +## 四、效果演示 + + +烧录文件后,按下reset按键,程序开始运行,OLED屏幕会显示Hello,World! + + + diff --git a/demo/easy_wifi_demo/demo/BUILD.gn b/demo/oled_demo/demo/BUILD.gn similarity index 58% rename from demo/easy_wifi_demo/demo/BUILD.gn rename to demo/oled_demo/demo/BUILD.gn index 7af708b794f1cf8018876936f8ba88fb153b4f4b..8134e44aceed4c068f2864585eb9aaf2175ab869 100644 --- a/demo/easy_wifi_demo/demo/BUILD.gn +++ b/demo/oled_demo/demo/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 HiHope Open Source Organization . +# Copyright (C) 2024 HiHope Open Source Organization . # 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 @@ -10,20 +10,18 @@ # 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("wifi_demo") { +static_library("oled_demo") { sources = [ - #"wifi_connect_demo.c", - "wifi_hotspot_demo.c", + + "oled_demo.c", ] include_dirs = [ - "../src", "//commonlibrary/utils_lite/include", -# "//kernel/liteos_m/components/cmsis/2.0", -# "//base/iot_hardware/interfaces/kits/wifiiot_lite", -# "//foundation/communication/interfaces/kits/wifi_lite/wifiservice", - "//foundation/communication/wifi_lite/interfaces/wifiservice", -# "//vendor/hisi/hi3861/hi3861/third_party/lwip_sack/include/", + "//kernel/liteos_m/kal", + "//base/iothardware/peripheral/interfaces/inner_api", + "//device/soc/hisilicon/ws63v100/sdk/include/driver", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", + "../src", ] } diff --git a/demo/oled_demo/demo/oled_demo.c b/demo/oled_demo/demo/oled_demo.c new file mode 100644 index 0000000000000000000000000000000000000000..2f56e7b4b6aa4384cd3a835addc627c8bd2d639f --- /dev/null +++ b/demo/oled_demo/demo/oled_demo.c @@ -0,0 +1,54 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 "ohos_init.h" +#include "cmsis_os2.h" +#include "iot_gpio.h" +#include "iot_gpio_ex.h" +#include "oled_ssd1306.h" + + +static void OledTask(void *arg) +{ + (void)arg; + + // 初始化SSD1306 + OledInit(); + // 全屏黑色 + OledFillScreen(0x00); + // 显示字符串 + OledShowString(20, 2, "Hello,World!", FONT8x16); + +} + + +static void OledDemo(void) +{ + 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 = 0x1000; + attr.priority = osPriorityNormal; + if (osThreadNew(OledTask, NULL, &attr) == NULL) { + printf("[OledDemo] Falied to create OledTask!\n"); + } +} + + +APP_FEATURE_INIT(OledDemo); diff --git a/demo/hello_world_demo/BUILD.gn b/demo/oled_demo/src/BUILD.gn similarity index 66% rename from demo/hello_world_demo/BUILD.gn rename to demo/oled_demo/src/BUILD.gn index 4241abd7a898c8bf956d8658c0ee71264cb822eb..7004422e0d83acf697afefed5f7e3272fa446082 100644 --- a/demo/hello_world_demo/BUILD.gn +++ b/demo/oled_demo/src/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. +# Copyright (C) 2024 HiHope Open Source Organization . # 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 @@ -10,20 +10,17 @@ # 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("helloWorld") { +static_library("oled_ssd1306") { sources = [ + "oled_ssd1306.c", "hal_iot_gpio_ex.c", - "led_example.c", - "oled_demo.c", - "oled_ssd1306.c", ] include_dirs = [ "//commonlibrary/utils_lite/include", - "//kernel/liteos_m/kal/cmsis", + "//kernel/liteos_m/kal", "//base/iothardware/peripheral/interfaces/inner_api", - "//device/soc/hisilicon/ws63v100/sdkv100/include/driver", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", + "//device/soc/hisilicon/ws63v100/sdk/include/driver", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", ] } diff --git a/demo/hello_world_demo/hal_iot_gpio_ex.c b/demo/oled_demo/src/hal_iot_gpio_ex.c similarity index 66% rename from demo/hello_world_demo/hal_iot_gpio_ex.c rename to demo/oled_demo/src/hal_iot_gpio_ex.c index 1b86906ac5823b544c1d0539471b3d650ee635dd..581939e43284cd2ecad5413676ec4a55ee0973bb 100644 --- a/demo/hello_world_demo/hal_iot_gpio_ex.c +++ b/demo/oled_demo/src/hal_iot_gpio_ex.c @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. - * 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. + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 "iot_errno.h" diff --git a/demo/hello_world_demo/iot_gpio_ex.h b/demo/oled_demo/src/iot_gpio_ex.h similarity index 95% rename from demo/hello_world_demo/iot_gpio_ex.h rename to demo/oled_demo/src/iot_gpio_ex.h index 35ea4735c43fefc24f0b7a5c06eb1105bed018ff..f26e2f2a07a7f1f7c05838457e780eaa05896664 100644 --- a/demo/hello_world_demo/iot_gpio_ex.h +++ b/demo/oled_demo/src/iot_gpio_ex.h @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. - * 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. + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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. */ /** @@ -27,6 +27,8 @@ #ifndef IOT_GPIO_EX_H #define IOT_GPIO_EX_H +#define CHIP_WS63 1 + /** * @brief Enumerates GPIO pull-up or pull-down settings. */ diff --git a/demo/oled_demo/src/oled_fonts.h b/demo/oled_demo/src/oled_fonts.h new file mode 100644 index 0000000000000000000000000000000000000000..4a98aadbb67a5ac58978474bff7f6cedd18ed678 --- /dev/null +++ b/demo/oled_demo/src/oled_fonts.h @@ -0,0 +1,214 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 OLOED_FONTS_H +#define OLOED_FONTS_H + +static unsigned char F6x8[][6] = +{ + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp空格 + { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // ! + { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // " + { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // # + { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $ + { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // % + { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // & + { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // ' + { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // ( + { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // ) + { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // * + { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // + + { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // , + { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // - + { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // . + { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // / + { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0 + { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1 + { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2 + { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3 + { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4 + { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5 + { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6 + { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7 + { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8 + { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9 + { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // : + { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ; + { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // < + { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // = + { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // > + { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ? + { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @ + { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A + { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B + { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C + { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D + { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E + { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F + { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G + { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H + { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I + { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J + { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K + { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L + { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M + { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N + { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O + { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P + { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q + { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R + { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S + { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T + { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U + { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V + { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W + { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X + { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y + { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z + { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [ + { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, /* \ */ + { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ] + { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^ + { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _ + { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // ' + { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a + { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b + { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c + { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d + { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e + { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f + { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g + { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h + { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i + { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j + { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k + { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l + { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m + { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n + { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o + { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p + { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q + { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r + { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s + { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t + { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u + { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v + { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w + { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x + { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y + { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z + { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 }, // horiz lines +}; + +static const unsigned char F8X16[]= +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//sp空格 0 + 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1 + 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2 + 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3 + 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4 + 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5 + 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6 + 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7 + 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8 + 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9 + 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10 + 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14 + 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16 + 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17 + 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18 + 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19 + 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20 + 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21 + 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22 + 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23 + 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25 + 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26 + 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27 + 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28 + 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29 + 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30 + 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31 + 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32 + 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33 + 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34 + 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35 + 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38 + 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40 + 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41 + 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42 + 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43 + 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44 + 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45 + 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47 + 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49 + 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50 + 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51 + 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53 + 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54 + 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55 + 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56 + 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57 + 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58 + 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59 + 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60 + 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61 + 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63 + 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65 + 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66 + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67 + 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69 + 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71 + 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72 + 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73 + 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74 + 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75 + 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76 + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77 + 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79 + 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80 + 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81 + 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83 + 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84 + 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86 + 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87 + 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89 + 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90 + 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91 + 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92 + 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93 + 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94 +}; + +#endif diff --git a/demo/hello_world_demo/oled_ssd1306.c b/demo/oled_demo/src/oled_ssd1306.c similarity index 34% rename from demo/hello_world_demo/oled_ssd1306.c rename to demo/oled_demo/src/oled_ssd1306.c index e51e993ef74c0d1950c0de77d83c523d057ea27a..69f39dfb4c6a8a0223b3b0213d434a33d9db8d44 100644 --- a/demo/hello_world_demo/oled_ssd1306.c +++ b/demo/oled_demo/src/oled_ssd1306.c @@ -1,99 +1,72 @@ -/* - * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. - * 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. + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 "ohos_types.h" -#include "iot_errno.h" +#include +#include #include "iot_gpio.h" -#include "iot_i2c.h" #include "iot_gpio_ex.h" +#include "iot_i2c.h" +#include "iot_errno.h" #include "oled_fonts.h" #include "oled_ssd1306.h" - -#if CHIP_WS63 +// i2c波特率 +#define OLED_I2C_BAUDRATE (400000) // 400KHz +// i2c主机id #define OLED_I2C_IDX 1 -#else -#define OLED_I2C_IDX 0 -#endif - -#define OLED_WIDTH (128) -#if CHIP_WS63 -#define OLED_I2C_ADDR 0x3C -#else -// 默认地址为 0x78 -#define OLED_I2C_ADDR 0x78 -#endif -#define OLED_I2C_CMD 0x00 // 0000 0000 写命令 -#define OLED_I2C_DATA 0x40 // 0100 0000(0x40) 写数据 -#define OLED_I2C_BAUDRATE (400 * 1000) // 400k - -#define DELAY_100_MS (100 * 1000) - -typedef struct { - /** Pointer to the buffer storing data to send */ +// SSD1306驱动芯片从机地址 +#define OLED_I2C_ADDR 0x3C +// 写命令 +#define OLED_I2C_CMD 0x00 +// 写数据 +#define OLED_I2C_DATA 0x40 + + +typedef struct +{ unsigned char *sendBuf; - /** Length of data to send */ - unsigned int sendLen; - /** Pointer to the buffer for storing data to receive */ + unsigned int sendLen; unsigned char *receiveBuf; - /** Length of data received */ - unsigned int receiveLen; + unsigned int receiveLen; } IotI2cData; +//向OLED写一个字节 static uint32_t I2cWiteByte(uint8_t regAddr, uint8_t byte) { - unsigned int id = OLED_I2C_IDX; + uint8_t buffer[] = {regAddr, byte}; IotI2cData i2cData = {0}; - i2cData.sendBuf = buffer; i2cData.sendLen = sizeof(buffer) / sizeof(buffer[0]); - - return IoTI2cWrite(id, OLED_I2C_ADDR, i2cData.sendBuf, i2cData.sendLen); + return IoTI2cWrite(OLED_I2C_IDX, OLED_I2C_ADDR, i2cData.sendBuf, i2cData.sendLen); } -/** - * @brief Write a command byte to OLED device. - * - * @param cmd the commnad byte to be writen. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link wifiiot_errno.h} otherwise. - */ +//向OLED写一个命令字节 static uint32_t WriteCmd(uint8_t cmd) { return I2cWiteByte(OLED_I2C_CMD, cmd); } -/** - * @brief Write a data byte to OLED device. - * - * @param cmd the data byte to be writen. - * @return Returns {@link IOT_SUCCESS} if the operation is successful; - * returns an error code defined in {@link wifiiot_errno.h} otherwise. - */ -static uint32_t WriteData(uint8_t data) +//向OLED写一个数据字节 +uint32_t WriteData(uint8_t data) { return I2cWiteByte(OLED_I2C_DATA, data); } -/** - * @brief ssd1306 OLED Initialize. - */ +//初始化SSD1306显示屏驱动芯片 uint32_t OledInit(void) { + static const uint8_t initCmds[] = { 0xAE, // --display off 0x00, // ---set low column address @@ -124,104 +97,128 @@ uint32_t OledInit(void) 0xAF, // --turn on oled panel }; -#if CHIP_WS63 - IoTGpioInit(IOT_IO_NAME_GPIO_15); /* GPIO15 */ - IoSetFunc(IOT_IO_NAME_GPIO_15, IOT_IO_FUNC_GPIO_15_I2C1_SDA); /* GPIO13 SDA */ - IoTGpioInit(IOT_IO_NAME_GPIO_16); /* GPIO16 */ - IoSetFunc(IOT_IO_NAME_GPIO_16, IOT_IO_FUNC_GPIO_16_I2C1_SCL); /* GPIO16 SCL */ - - IoTI2cInit(OLED_I2C_IDX, OLED_I2C_BAUDRATE); /* baudrate: 400kbps */ -#else - IoTGpioInit(13); /* 初始化gpio13 */ - IoSetFunc(13, 6); /* gpio13使用6功能 */ - IoTGpioInit(14); /* 初始化gpio14 */ - IoSetFunc(14, 6); /* gpio14使用6功能 */ - - IoTI2cInit(0, OLED_I2C_BAUDRATE); -#endif - - for (size_t i = 0; i < ARRAY_SIZE(initCmds); i++) { + // 初始化GPIO + IoTGpioInit(1); + // 设置GPIO-15引脚功能为I2C1_SDA + IoSetFunc(IOT_IO_NAME_GPIO_15, IOT_IO_FUNC_GPIO_15_I2C1_SDA); + // 设置GPIO-16引脚功能为I2C1_SCL + IoSetFunc(IOT_IO_NAME_GPIO_16, IOT_IO_FUNC_GPIO_16_I2C1_SCL); + // 初始化I2C1 + IoTI2cInit(OLED_I2C_IDX, OLED_I2C_BAUDRATE); + + // 初始化SSD1306显示屏驱动芯片 + for (size_t i = 0; i < sizeof(initCmds) / sizeof(initCmds[0]); i++) + { + // 发送一个命令字节 uint32_t status = WriteCmd(initCmds[i]); - if (status != IOT_SUCCESS) { + if (status != IOT_SUCCESS) + { return status; } } + + // OLED初始化完成,返回成功 return IOT_SUCCESS; } +/// @brief 设置显示位置 +/// @param x x坐标,1像素为单位 +/// @param y y坐标,8像素为单位。即页面起始地址 +/// @return 无 void OledSetPosition(uint8_t x, uint8_t y) { + WriteCmd(0xb0 + y); - WriteCmd(((x & 0xf0) >> 4) | 0x10); /* 在0xf0右移4位,与0x10或,实现了写数据 */ WriteCmd(x & 0x0f); + WriteCmd(((x & 0xf0) >> 4) | 0x10); } -/* 全屏填充 */ +/// @brief 全屏填充 +/// @param fillData 填充的数据,1字节 +/// @return 无 void OledFillScreen(uint8_t fillData) -{ - for (uint8_t m = 0; m < 8; m++) { /* 循环8次实现横屏填充 */ +{ + uint8_t m = 0; + uint8_t n = 0; + for (m = 0; m < 8; m++) + { WriteCmd(0xb0 + m); WriteCmd(0x00); - WriteCmd(0x10); - - for (uint8_t n = 0; n < 128; n++) { /* 循环128次实现竖屏填充 */ + WriteCmd(0x10); + for (n = 0; n < 128; n++) + { WriteData(fillData); } } } -/** - * @brief 8*16 typeface - * @param x: write positon start from x axis - * @param y: write positon start from y axis - * @param ch: write data - * @param font: selected font - */ + + +/// @brief 显示一个字符 +/// @param x: x坐标,1像素为单位 +/// @param y: y坐标,8像素为单位 +/// @param ch: 要显示的字符 +/// @param font: 字库 void OledShowChar(uint8_t x, uint8_t y, uint8_t ch, Font font) { - uint8_t c = ch - ' '; // 得到偏移后的值 - uint8_t b = x; - uint8_t d = y; - if (b > OLED_WIDTH - 1) { - b = 0; - d = d + 2; /* 得到偏移后的值2 */ - } - - if (font == FONT8_X16) { - OledSetPosition(b, d); - for (uint8_t i = 0; i < 8; i++) { /* 循环8次实现横屏填充 */ - WriteData(g_f8X16[c * 16 + i]); /* 循环16次实现横屏填充 */ + + uint8_t c = 0; + uint8_t i = 0; + c = ch - ' '; + if (font == FONT8x16) + { + OledSetPosition(x, y); + for (i = 0; i < 8; i++) + { + WriteData(F8X16[c * 16 + i]); } - OledSetPosition(b, d + 1); - for (uint8_t i = 0; i < 8; i++) { /* 循环8次实现横屏填充 */ - WriteData(g_f8X16[c * 16 + i + 8]); /* 循环16次实现横屏填充8列 */ + OledSetPosition(x, y + 1); + + for (i = 0; i < 8; i++) + { + WriteData(F8X16[c * 16 + 8 + i]); } - } else { - OledSetPosition(b, d); - for (uint8_t i = 0; i < 6; i++) { /* 循环6次实现横屏填充 */ - WriteData(g_f6X8[c][i]); + } + else + { + OledSetPosition(x, y); + for (i = 0; i < 6; i++) + { + WriteData(F6x8[c][i]); } } } -void OledShowString(uint8_t x, uint8_t y, const char* str, Font font) +/// @brief 显示一个字符串 +/// @param x: x坐标,1像素为单位 +/// @param y: y坐标,8像素为单位 +/// @param str: 要显示的字符串 +/// @param font: 字库 +void OledShowString(uint8_t x, uint8_t y, const char *str, Font font) { + uint8_t j = 0; - uint8_t b = x; - uint8_t d = y; - if (str == NULL) { + + + if (str == NULL) + { printf("param is NULL,Please check!!!\r\n"); return; } - while (str[j]) { - OledShowChar(b, d, str[j], font); - b += 8; /* 循环8次实现横屏填充 */ - if (b > 120) { /* 循环120次实现横屏填充 */ - b = 0; - d += 2; /* 循环2次实现横屏填充 */ + while (str[j]) + { + + OledShowChar(x, y, str[j], font); + + x += 8; + if (x > 120) + { + x = 0; + y += 2; } + j++; } -} \ No newline at end of file +} diff --git a/demo/oled_demo/src/oled_ssd1306.h b/demo/oled_demo/src/oled_ssd1306.h new file mode 100644 index 0000000000000000000000000000000000000000..fd1c2e030c52ed036d0109ac74d1b260789dbf5c --- /dev/null +++ b/demo/oled_demo/src/oled_ssd1306.h @@ -0,0 +1,34 @@ + /* + Copyright (C) 2024 HiHope Open Source Organization . + 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 OLED_SSD1306_H +#define OLED_SSD1306_H +#include +// 字库类型 +typedef enum Font { + FONT6x8 = 1, + FONT8x16 +}Font; +uint32_t OledInit(void); +void OledSetPosition(uint8_t x, uint8_t y); +void OledFillScreen(uint8_t fillData); +//uint32_t WriteData(uint8_t data); + +//显示字符 +void OledShowChar(uint8_t x, uint8_t y, uint8_t ch, Font font); +//显示字符串 +void OledShowString(uint8_t x, uint8_t y, const char* str, Font font); + + +#endif diff --git a/demo/sle_uart_demo/BUILD.gn b/demo/sle_uart_demo/BUILD.gn index 9075db771f0f0d08bbae72388389800465ece53b..ae88819c55cecefd786b94024a27840a3222547d 100644 --- a/demo/sle_uart_demo/BUILD.gn +++ b/demo/sle_uart_demo/BUILD.gn @@ -24,18 +24,18 @@ static_library("sle_uart_demo") { ] include_dirs = [ "//base/startup/init/interfaces/innerkits/include", - "//device/soc/hisilicon/ws63v100/sdkv100/include/driver", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", - "//device/soc/hisilicon/ws63v100/sdkv100/include/middleware/services/bts/sle", + "//device/soc/hisilicon/ws63v100/sdk/include/driver", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", + "//device/soc/hisilicon/ws63v100/sdk/include/middleware/services/bts/sle", "//foundation/communication/sle", - "//device/soc/hisilicon/ws63v100/sdkv100/kernel/osal/include/debug", - "//device/soc/hisilicon/ws63v100/sdkv100/kernel/osal/include/memory", - "//device/soc/hisilicon/ws63v100/sdkv100/kernel/osal/include/schedule", - "//device/soc/hisilicon/ws63v100/sdkv100/include/driver", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", + "//device/soc/hisilicon/ws63v100/sdk/kernel/osal/include/debug", + "//device/soc/hisilicon/ws63v100/sdk/kernel/osal/include/memory", + "//device/soc/hisilicon/ws63v100/sdk/kernel/osal/include/schedule", + "//device/soc/hisilicon/ws63v100/sdk/include/driver", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/rom/drivers/chips/ws63/porting/pinctrl", "//base/iothardware/peripheral/interfaces/inner_api", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/drivers/hal/uart", - "//device/soc/hisilicon/ws63v100/sdkv100/drivers/chips/ws63/porting/uart", - "//device/soc/hisilicon/ws63v100/sdkv100/middleware/utils/common_headers/native", + "//device/soc/hisilicon/ws63v100/sdk/drivers/drivers/hal/uart", + "//device/soc/hisilicon/ws63v100/sdk/drivers/chips/ws63/porting/uart", + "//device/soc/hisilicon/ws63v100/sdk/middleware/utils/common_headers/native", ] } diff --git a/demo/sle_uart_demo/README.md b/demo/sle_uart_demo/README.md index 6c3ce520f070117459965031bb6cade5c3df4905..da4ff16f3790be58cac68512d5120c770a78cd58 100644 --- a/demo/sle_uart_demo/README.md +++ b/demo/sle_uart_demo/README.md @@ -59,7 +59,7 @@ ## 如何编译 -本项目下有两个示例代码,需要运行在两块WS63开发板上,一块作为服务端,一块作为客户端,SLE服务端需要注释掉`"sle_uart_client.c"`行,放开`"sle_uart_server_adv.c","sle_uart_server.c"`行,SLE客户端需要注释掉`"sle_uart_server_adv.c","sle_uart_server.c"`行,放开`"sle_uart_client.c"`行,之前生成的libsle_uart_demo.a静态库文件需要删除; +本项目下有两个示例代码,需要运行在两块WS63开发板上,一块作为服务端,一块作为客户端,SLE服务端需要注释掉`"sle_uart_client.c"`行,放开`"sle_uart_server_adv.c","sle_uart_server.c"`行,SLE客户端需要注释掉`"sle_uart_server_adv.c","sle_uart_server.c"`行,放开`"sle_uart_client.c"`行 1. 将sle_uart_demo文件夹克隆到本地openharmony源码的applications\sample\wifi-iot\app目录下; 2. 修改openharmony的`applications\sample\wifi-iot\app\BUILD.gn`文件: @@ -68,5 +68,5 @@ "sle_uart_demo:sle_uart_demo", ] 3. 在device/soc/hisilicon/ws63v100/sdkv100/build/config/target_config/ws63/config.py文件的`'ram_component': []`中添加`"sle_uart_demo"`,在device/soc/hisilicon/ws63v100/sdkv100/libs_url/ws63cmake/ohos.cmake文件的`set(COMPONENT_LIST)`中添加`"sle_uart_demo"`; -4. 执行编译命令:`hb build -f` +4. 执行编译命令:`rm -rf out && hb set -p nearlink_dk_3863 && hb build -f` 5. 运行结果:两块ws63开发板可以通过星闪功能转发串口数据,波特率默认为115200,服务端在接收到客户端发送的数据`"123"`后会打印`"client_send_data: 123"`; \ No newline at end of file diff --git a/demo/sle_uart_demo/sle_uart_client.c b/demo/sle_uart_demo/sle_uart_client.c index bf31af9a3c83b2016ca87f13001b047818cf4f2f..990d3a94a44c9416c0ea9de49cd8fc93a2cbf0be 100755 --- a/demo/sle_uart_demo/sle_uart_client.c +++ b/demo/sle_uart_demo/sle_uart_client.c @@ -35,7 +35,7 @@ #include "uart.h" #include "errcode.h" -#define SLE_MTU_SIZE_DEFAULT 512 +#define SLE_MTU_SIZE_DEFAULT 520 #define SLE_SEEK_INTERVAL_DEFAULT 100 #define SLE_SEEK_WINDOW_DEFAULT 100 #define UUID_16BIT_LEN 2 @@ -48,6 +48,7 @@ #define SLE_UART_CLIENT_LOG "[sle uart client]" #define UUID_LEN_2 2 + static char g_sle_uuid_app_uuid[] = { 0x39, 0xBE, 0xA8, 0x80, 0xFC, 0x70, 0x11, 0xEA, \ 0xB7, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static unsigned char uartReadBuff[100]; @@ -220,7 +221,7 @@ static void sle_uart_client_sample_exchange_info_cbk(uint8_t client_id, uint16_t find_param.end_hdl = 0xFFFF; int ret = ssapc_find_structure(client_id, conn_id, &find_param); - printf("ssapc_find_structure_errcode:%d\r\n",ret); + osal_printk("ssapc_find_structure_errcode:%d\r\n",ret); } static void sle_uart_client_sample_find_structure_cbk(uint8_t client_id, uint16_t conn_id, @@ -286,7 +287,7 @@ static errcode_t sle_uuid_client_register(void) errcode_t ret; SleUuid app_uuid = {0}; - printf("[uuid client] ssapc_register_client \r\n"); + osal_printk("[uuid client] ssapc_register_client \r\n"); app_uuid.len = sizeof(g_sle_uuid_app_uuid); if (memcpy_s(app_uuid.uuid, app_uuid.len, g_sle_uuid_app_uuid, sizeof(g_sle_uuid_app_uuid)) != EOK) { return ERRCODE_SLE_FAIL; @@ -331,7 +332,7 @@ void ssapc_notification_callbacks(uint8_t client_id, uint16_t conn_id, ssapc_han (void)status; data->data[data->data_len -1] = '\0'; - printf("server_send_data: %s\r\n",data->data); + osal_printk("server_send_data: %s\r\n",data->data); } void ssapc_indication_callbacks(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *data, @@ -383,8 +384,8 @@ static void SleClientExample(void) attr.priority = 25; if (osThreadNew(SleTask, NULL, &attr) == NULL) { - printf("[SleExample] Falied to create SleTask!\n"); - }else printf("[SleExample] create SleTask successfully !\n"); + osal_printk("[SleExample] Falied to create SleTask!\n"); + }else osal_printk("[SleExample] create SleTask successfully !\n"); } SYS_RUN(SleClientExample); // if test add it \ No newline at end of file diff --git a/demo/sle_uart_demo/sle_uart_server.c b/demo/sle_uart_demo/sle_uart_server.c index de60b57b20caa9ebeb910e8cb0e16df47240e861..bd402fe392eab6119dd33c23b774202b286e824f 100755 --- a/demo/sle_uart_demo/sle_uart_server.c +++ b/demo/sle_uart_demo/sle_uart_server.c @@ -42,7 +42,7 @@ #define BT_INDEX_4 4 #define BT_INDEX_0 0 #define UART_BUFF_LENGTH 0x100 - +#define SLE_MTU_SIZE_DEFAULT 520 /* 广播ID */ #define SLE_ADV_HANDLE_DEFAULT 1 /* sle server app uuid for test */ @@ -62,7 +62,7 @@ uint16_t g_sle_pair_hdl; #define UUID_16BIT_LEN 2 #define UUID_128BIT_LEN 16 -#define sample_at_log_print(fmt, args...) osal_printk(fmt, ##args) +#define sample_at_log_print(fmt, args...) printf(fmt, ##args) #define SLE_UART_SERVER_LOG "[sle uart server]" #define SLE_SERVER_INIT_DELAY_MS 1000 static sle_uart_server_msg_queue g_sle_uart_server_msg_queue = NULL; @@ -86,7 +86,7 @@ static void server_uart_rx_callback(const void *buffer, uint16_t length, bool er if(length > 0){ ret = uart_sle_send_data((uint8_t *)buffer,(uint8_t)length); if(ret != 0){ - osal_printk("\r\nsle_server_send_data_fail:%d\r\n", ret); + printf("\r\nsle_server_send_data_fail:%d\r\n", ret); } } @@ -345,7 +345,10 @@ static void sle_connect_state_changed_cbk(uint16_t conn_id, const SleAddr *addr, addr->addr[BT_INDEX_0], addr->addr[BT_INDEX_4]); if (conn_state == OH_SLE_ACB_STATE_CONNECTED) { g_sle_conn_hdl = conn_id; - + ssap_exchange_info_t parameter = { 0 }; + parameter.mtu_size = SLE_MTU_SIZE_DEFAULT; + parameter.version = 1; + ssaps_set_info(g_server_id, ¶meter); } else if (conn_state == OH_SLE_ACB_STATE_DISCONNECTED) { g_sle_conn_hdl = 0; g_sle_pair_hdl = 0;