Update soc adaptation source code

Signed-off-by: zounan <zounan@goodix.com>
This commit is contained in:
lidongshan
2021-11-30 16:58:18 +08:00
parent a5e301e81d
commit 508e3a2fe6
81 changed files with 4102 additions and 4283 deletions
Executable
+22
View File
@@ -0,0 +1,22 @@
# Copyright (c) 2021 GOODIX.
# 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.
if (ohos_kernel_type == "liteos_m") {
import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
module_group(module_name) {
modules = [
"gr551x",
]
}
}
+14
View File
@@ -0,0 +1,14 @@
# Copyright (c) 2021 GOODIX.
# 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.
rsource "*/Kconfig.liteos_m.defconfig.series"
+14
View File
@@ -0,0 +1,14 @@
# Copyright (c) 2021 GOODIX.
# 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.
rsource "*/Kconfig.liteos_m.series"
+22
View File
@@ -0,0 +1,22 @@
# Copyright (c) 2021 GOODIX.
# 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.
config SOC_COMPANY_GOODIX
bool
if SOC_COMPANY_GOODIX
config SOC_COMPANY
default "goodix"
rsource "*/Kconfig.liteos_m.soc"
endif # SOC_COMPANY_GOODIX
Regular → Executable
+176 -176
View File
@@ -1,177 +1,177 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Regular → Executable
View File
Regular → Executable
+173 -61
View File
@@ -1,93 +1,207 @@
# 快速上手GR5515 SK开发板
# device_gr551x
## 开发板介绍
## 介绍
### 开发板概述
GR5515 Starter Kit(以下简称GR5515 SK)套件是基于的GR551x芯片(支持Bluetooth 5.1)设计的开发平台,包含Starter Kit开发板(以下简称GR5515 SK板)、原理图和使用指南。用户可以在该平台上熟悉GR551x开发工具以及快速搭建自己的产品原型并验证相关功能。
以下内容步骤参考[quickstart-lite-env-setup-linux](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-env-setup-linux.md)
开发板如下图所示:
系统要求:Ubuntu16.04 和 Ubuntu18.04 64位系统版本。
![](./figures/GR5515_SK_Board.png)
### 开发板功能
* 支持Bluetooth 5.1的单模低功耗蓝牙SoC
* 多功能按键和LED指示灯
* 支持Arduino模块插接接口,IO电压可以通过level shift灵活配置
* 支持调试功能的SEGGER J-Link OB
* UART转USB接口
* Micro USB接口连接PC
* 1.44寸TFT彩色显示屏
* 板上集成QSPI Flash
为了更好的使用GR5515 Starter Kit套件,建议参考下表相关资料。
| 名称 | 描述 |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GR5515 Starter Kit用户指南 | 介绍GR5515 Starter Kit套件使用方法: [《GR5515 Starter Kit用户指南》]( https://docs.goodix.com/zh/online/detail/gr5515_starter_kit_user_guide/V1.7/42a03ba92cad1d63afd9baa8bb8c37df) |
| GR551x开发者指南 | GR551x软硬件介绍、快速使用及资源总览: [《GR551x开发者指南》]( https://docs.goodix.com/zh/online/detail/gr551x_develop_guide/V2.3/27f7d503bcd7ad1d63fa5b316b3bde4f) |
| J-Link用户指南 | J-Link使用说明:www.segger.com/downloads/jlink/UM08001_JLink.pdf |
| GR5515-SK-BASIC-RevC | GR5515 Starter Kit开发板原理图:[《GR5515-SK-BASIC-RevC.pdf》]( https://product.goodix.com/zh/docview/GR5515-SK-BASIC-RevC_Rev.1.5?objectId=100&objectType=document&version=133) |
编译环境搭建包含如下几步:
## 代码下载
1. 安装必要的库和工具
2. 安装python3
3. 安装hb
4. 安装编译工具链
5. 获取源码
6. 确认目录结构
7. 编译流程
8. 烧录
## 工具安装
### 安装repo
1. 创建repo安装目录:命令行输入`mkdir ~/bin`
2. 下载repo:命令行输入`wget https://storage.googleapis.com/git-repo-downloads/repo -P ~/bin/`
3. 改变执行权限:命令行输入`chmod a+x ~/bin/repo`
4. 设置环境变量:在~/.bashrc文件的最后输入`export PATH=~/bin:$PATHexport REPO_URL=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/`
4. 设置环境变量:在~/.bashrc文件的最后输入`export PATH=~/bin:$PATH``export REPO_URL=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/`
5. 重启shell
### 下载系统
笔者使用的系统版本标签是3.0.0_LTS,仅在此版本进行了验证,建议读者下载此版本的源码。
### 安装必要的库和工具
源码下载步骤:
> - 通常系统默认安装samba、vim等常用软件,需要做适当适配以支持Linux服务器与Windows工作台之间的文件共享。
1. 打包下载所有文件,此时默认的Harmony版本为3.0.0_LTS`repo init -u https://gitee.com/openharmony-sig/manifest.git -b OpenHarmony-3.0-LTS --no-repo-verify -m devboard_gr5515.xml`
> - 使用如下apt-get命令安装编译所需的必要的库和工具:
```
sudo apt-get install build-essential gcc g++ make zlib* libffi-dev e2fsprogs pkg-config flex bison perl bc openssl libssl-dev libelf-dev libc6-dev-amd64 binutils binutils-dev libdwarf-dev u-boot-tools mtd-utils gcc-arm-linux-gnueabi
```
### 安装Python3
1. 打开Linux编译服务器终端。
2. 输入如下命令,查看python版本号:
```
python3 --version
```
如果低于python3.7版本,不建议直接升级,请按照如下步骤重新安装。以python3.8为例,按照以下步骤安装python。
1. 运行如下命令,查看Ubuntu版本:
```
cat /etc/issue
```
1. 根据Ubuntu不同版本,安装python。
- 如果Ubuntu 版本为18+,运行如下命令。
```
sudo apt-get install python3.8
```
- 如果Ubuntu版本为16。
a. 安装依赖包
```
sudo apt update && sudo apt install software-properties-common
```
b. 添加deadsnakes PPA 源,然后按回车键确认安装。
```
sudo add-apt-repository ppa:deadsnakes/ppa
```
c. 安装python3.8
```
sudo apt upgrade && sudo apt install python3.8
```
3. 设置python和python3软链接为python3.8。
```
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
```
4. 安装并升级Python包管理工具(pip3),任选如下一种方式。
- **命令行方式:**
```
sudo apt-get install python3-setuptools python3-pip -y
sudo pip3 install --upgrade pip
```
- **安装包方式:**
```
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
```
### 安装hb
#### 前提条件
请先安装Python 3.7.4及以上版本,请见[安装Python3](#section1238412211211)。
#### 安装方法
1. 运行如下命令安装hb
```
python3 -m pip install --user ohos-build
```
2. 设置环境变量
```
vim ~/.bashrc
```
将以下命令拷贝到.bashrc文件的最后一行,保存并退出。
```
export PATH=~/.local/bin:$PATH
```
执行如下命令更新环境变量。
```
source ~/.bashrc
```
3. 执行"hb -h",有打印以下信息即表示安装成功:
```
usage: hb
OHOS build system
positional arguments:
{build,set,env,clean}
build Build source code
set OHOS build settings
env Show OHOS build env
clean Clean output
optional arguments:
-h, --help show this help message and exit
```
### 安装编译工具链
1. 编译链工具推荐使用gcc-arm-none-eabi-10-2020-q4-major。(下载网站:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads )。
2. 执行`vim ~/.bashrc`。
3. 将工具链的路径加入环境变量, 如:`export PATH=/home/tools/ARM/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH`。
3. 保存后执行`source ~/.bashrc`使环境变量生效。
## 获取代码流程
1. 打包下载所有文件,此时默认的Harmony版本为Master`repo init -u https://gitee.com/openharmony-sig/manifest.git -b OpenHarmony-3.0-LTS --no-repo-verify -m devboard_gr5515.xml`。
2. 下载好仓库后,输入:`repo sync -c`,也就是下载当前分支的代码。
3. 下载好代码后,输入:`repo forall -c 'git lfs pull'`,下载部分大容量二进制文件。
### 下载GR5515源码
如果下载系统时选择了打包下载,可跳过此步。
1. 从https://gitee.com/openharmony-sig/devboard_device_goodix_gr551x.git 下载device仓内容。
2. 从https://gitee.com/openharmony-sig/devboard_vendor_goodix_gr5515_sk_basic.git 下载vendor仓内容。
## 确认目录结构
在device文件夹下,确保device文件夹目录结构如下
```shell
user:~/Harmony/device$ tree -L 3
user:~/Harmony/device/soc$ tree -L 3
.
└── goodix
── gr551x
├── adapter # 外设驱动、BLE、文件系统适配
├── BUILD.gn # GN构建脚本
├── components # 组件
├── drivers # HDF外设驱动
├── hcs # 设备描述文件
├── sdk_liteos # Liteos GR551x SDK适配
└── tools # 固件生成工具
── BUILD.gn # GN构建脚本
├── gr551x # gr551x soc适配目录
│   ├── adapter # 外设驱动、BLE、文件系统适配
│   ├── BUILD.gn # GN构建脚本
│   ├── components # 组件
│   ├── drivers # HDF外设驱动
│   ├── hcs # 设备描述文件
│   ├── Kconfig.liteos_m.defconfig.gr551x # gr551x Kconfig默认配置
│   ├── Kconfig.liteos_m.defconfig.series # series Kconfig默认配置
│   ├── Kconfig.liteos_m.series # series Kconfig配置项
│   ├── Kconfig.liteos_m.soc # soc Kconfig配置项
│   ├── sdk_liteos # Liteos GR551x SDK适配
│   └── tools # 固件生成工具
├── Kconfig.liteos_m.defconfig # liteos_m Kconfig默认配置
├── Kconfig.liteos_m.series # liteos_m series配置项
└── Kconfig.liteos_m.soc # liteos_m soc配置项
```
在vendor文件夹下,确保vendor文件夹目录结构如下
```shell
user:~/Harmony/vendor$ tree -L 3
.
└── goodix
├── gr5515_sk_iotlink_demo # BLE IOT应用示例工程
│   ├── BUILD.gn # GN构建脚本
│   ├── config.json # 子系统裁配置裁剪脚本
│   ├── hals # 产品参数配置
│   ├── hdf_config # HDF硬件描述配置
│   ├── kernel_configs # Kconfig配置输出
│   ├── patches # 源码补丁
│   └── patch.yml # 补丁执行脚本
└── gr5515_sk_xts_demo # XTS测试示例工程
@@ -95,17 +209,12 @@ user:~/Harmony/vendor$ tree -L 3
├── config.json # 子系统裁配置裁剪脚本
├── tests # 测试用例
├── hals # 产品参数配置
   ├── hdf_config # HDF硬件描述配置
   ├── kernel_configs # Kconfig配置输出
├── patches # 源码补丁
└── patch.yml # 补丁执行脚本
```
## 设置编译工具链
1. 编译链工具推荐使用gcc-arm-none-eabi-10-2020-q4-major。(下载网站:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads )。
2. 执行`vim ~/.bashrc`
3. 将工具链的路径加入环境变量, 如:`export PATH=/home/tools/ARM/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH`
3. 保存后执行`source ~/.bashrc`使环境变量生效。
## 编译工程
进入源码根目录编译工程
@@ -120,6 +229,8 @@ user:~/Harmony/vendor$ tree -L 3
`hb build -f --patch` 打patch并开始编译,后续修改了文件只需要执行`hb build -f`即可,不需要重复以上步骤。
如果hb set命令提示报错,请先执行一次`pip3 install build/lite`
## 固件烧录
生成的固件位于out/gr551x/${Project_name}/bin/application_fw.bin,固件烧录工具GProgrammer下载地址:https://product.goodix.com/zh/software_tool/gprogrammer 。
@@ -129,6 +240,7 @@ user:~/Harmony/vendor$ tree -L 3
## 相关仓库
[devboard_device_goodix_gr551x](https://gitee.com/openharmony-sig/devboard_device_goodix_gr551x)
[devboard_vendor_goodix_gr5515_sk_basic](https://gitee.com/openharmony-sig/devboard_vendor_goodix_gr5515_sk_basic)
[device_board_goodix](https://gitee.com/openharmony-sig/device_board_goodix)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 686 KiB

Regular → Executable
+15 -17
View File
@@ -13,22 +13,13 @@
import("//build/lite/config/subsystem/lite_subsystem.gni")
import("//build/lite/config/component/lite_component.gni")
import("//kernel/liteos_m/liteos.gni")
copy("link-script") {
sources = [ "sdk_liteos/platform/startup/gr551x.ld"]
outputs = [ "$root_build_dir/bin/link.ld" ]
}
copy("hilink_btsdk_lib") {
sources = [ "components/hilink/debug/libhilinkbtsdk.a"]
outputs = [ "$root_build_dir/libs/libhilinkbtsdk.a" ]
}
copy("hichain_lib") {
sources = [ "components/hichain/libhichain_account.a"]
outputs = [ "$root_build_dir/libs/libhichain_account.a" ]
}
copy("sdk_lib") {
sources = [ "sdk_liteos/gr551x_sdk/components/sdk/linker/lib_gcc/libble_sdk.a"]
outputs = [ "$root_build_dir/libs/libble_sdk.a" ]
@@ -94,17 +85,24 @@ source_set("device_soc"){
deps = [
":link-script",
":sdk_lib",
":hilink_btsdk_lib",
":hichain_lib",
":rom_symbol",
"//kernel/liteos_m:kernel",
":sdk_lib",
":rom_symbol",
"//build/lite/config/component/cJSON:cjson_static",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static"
]
}
group("gr551x") {
source_set("hdf_drivers") {
deps = [
":device_soc",
"drivers:drivers",
]
}
module_name = get_path_info(rebase_path("."), "name")
module_group(module_name) {
modules = [ ]
deps = [
":device_soc",
":hdf_drivers",
]
}
+17
View File
@@ -0,0 +1,17 @@
# Copyright (c) 2021 GOODIX.
# 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.
config SOC
string
default "gr551x"
depends on SOC_GR551x
+31
View File
@@ -0,0 +1,31 @@
# Copyright (c) 2021 GOODIX.
# 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.
if SOC_SERIES_GR551x
rsource "Kconfig.liteos_m.defconfig.gr551x"
config SOC_SERIES
string
default "gr551x"
config NUM_IRQS
int
default 45
config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 64000000
endif
+21
View File
@@ -0,0 +1,21 @@
# Copyright (c) 2021 GOODIX.
# 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.
config SOC_SERIES_GR551x
bool "Goodix gr551x Series"
select ARM
select SOC_COMPANY_GOODIX
select CPU_CORTEX_M4
help
Enable support for goddix gr551x series
+21
View File
@@ -0,0 +1,21 @@
# Copyright (c) 2021 GOODIX.
# 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.
choice
prompt "goodix gr551x series SoC"
depends on SOC_SERIES_GR551x
config SOC_GR551x
bool "SoC GR551x"
endchoice
+1 -1
View File
@@ -27,7 +27,7 @@
#define CN_BLE_EVENT_TASK_PRIOR 16
#define CN_BLE_EVENT_TASK_NAME "BLE_EVENT"
#define BLE_MSG_QUEUE_LEN 5
#define BLE_MSG_QUEUE_LEN 16
#define BLE_MSG_INFO_SIZE sizeof(ble_msg_t)
static uint32_t g_bleMsgHandle;
View File
+36 -6
View File
@@ -334,6 +334,29 @@ int BleGattSecurityRsp(BdAddr bdAddr, bool accept)
return OHOS_BT_STATUS_SUCCESS;
}
int HILINK_BT_GetMacAddr(unsigned char* result, unsigned int length)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s--- Entry!!! ", __FUNCTION__);
uint8_t addr[6];
uint16_t lenght = 6;
if (result == NULL) {
return OHOS_BT_STATUS_PARM_INVALID;
}
if (nvds_get(0xC001, &lenght, (uint8_t*)addr))
{
return OHOS_BT_STATUS_PARM_INVALID;
}
result[0] = addr[5];
result[1] = addr[4];
result[2] = addr[3];
result[3] = addr[2];
result[4] = addr[1];
result[5] = addr[0];
return OHOS_BT_STATUS_SUCCESS;
}
int GetDeviceMacAddress(unsigned char* result)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s--- Entry!!! ", __FUNCTION__);
@@ -468,7 +491,7 @@ int BleStartAdvEx(int *advId, const StartAdvRawData rawData, BleAdvParams advPar
static void app_gap_adv_start_cb(uint8_t inst_idx, uint8_t status)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---status:%d--- Entry!!! ", __FUNCTION__, status);
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---status:%d--- Entry!!! ", __FUNCTION__, status);
if (s_gatt_callbacks && s_gatt_callbacks->advEnableCb)
{
ble_msg_t tx_msg =
@@ -485,7 +508,7 @@ static void app_gap_adv_start_cb(uint8_t inst_idx, uint8_t status)
static void app_gap_adv_stop_cb(uint8_t inst_idx, uint8_t status, gap_stopped_reason_t reason)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s--- status:%d--- Entry!!! ", __FUNCTION__, status);
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s--- status:%d--- Entry!!! ", __FUNCTION__, status);
if (s_gatt_callbacks && s_gatt_callbacks->advDisableCb && GAP_STOPPED_REASON_ON_USER == reason)
{
ble_msg_t tx_msg =
@@ -501,9 +524,10 @@ static void app_gap_adv_stop_cb(uint8_t inst_idx, uint8_t status, gap_stopped_re
static void app_gap_connect_cb(uint8_t conn_idx, uint8_t status, const gap_conn_cmp_t *p_conn_param)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---conn_idx:%d--- Entry!!! ", __FUNCTION__, conn_idx);
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---conn_idx:%d--- Entry!!! ", __FUNCTION__, conn_idx);
if (!status)
{
ble_gap_phy_update(conn_idx, BLE_GAP_PHY_LE_2MBPS, BLE_GAP_PHY_LE_2MBPS, 0);
memcpy(s_conn_info[conn_idx].peer_addr.addr, p_conn_param->peer_addr.addr, 6);
if (g_gatt_server_callbacks && g_gatt_server_callbacks->connectServerCb)
{
@@ -523,7 +547,7 @@ static void app_gap_connect_cb(uint8_t conn_idx, uint8_t status, const gap_conn_
static void app_gap_disconnect_cb(uint8_t conn_idx, uint8_t status, uint8_t reason)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---conn_idx:%d--- Entry!!! ", __FUNCTION__, conn_idx);
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---conn_idx:%d--- Entry!!! ", __FUNCTION__, conn_idx);
if (!status)
{
if (g_gatt_server_callbacks && g_gatt_server_callbacks->disconnectServerCb)
@@ -546,8 +570,14 @@ static void app_gap_disconnect_cb(uint8_t conn_idx, uint8_t status, uint8_t reas
static void app_gap_connection_update_req_cb(uint8_t conn_idx, const gap_conn_param_t *p_conn_param_update_req)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---conn_idx:%d--- Entry!!! ", __FUNCTION__, conn_idx);
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---conn_idx:%d--- Entry!!! ", __FUNCTION__, conn_idx);
ble_gap_conn_param_update_reply(conn_idx, true);
gap_conn_update_param_t gap_conn_param;
gap_conn_param.interval_min = 6;
gap_conn_param.interval_max = 6;
gap_conn_param.slave_latency = 0;
gap_conn_param.sup_timeout = 400;
ble_gap_conn_param_update(conn_idx, &gap_conn_param);
}
static void app_gatt_mtu_exchange_cb(uint8_t conn_idx, uint8_t status, uint16_t mtu)
@@ -570,7 +600,7 @@ static void app_gatt_mtu_exchange_cb(uint8_t conn_idx, uint8_t status, uint16_t
static void app_sec_rcv_enc_req_cb(uint8_t conn_idx, sec_enc_req_t *p_enc_req)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---conn_idx:%d--- Entry!!! ", __FUNCTION__, conn_idx);
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---conn_idx:%d--- Entry!!! ", __FUNCTION__, conn_idx);
s_sec_enc_req_type = p_enc_req->req_type;
View File
+148 -47
View File
@@ -12,10 +12,156 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gr551x_spi_flash.h"
#include "app_log.h"
#include "gr55xx_dfu.h"
#include <stdint.h>
#include <stdbool.h>
#define FLASH_OP_PAGE_SIZE (0x1000)
#define FLASH_SIZE_MAX (0x000E1000)
#define IMG_INFO_DFU_ADDR (0x01002000UL)
static uint32_t flash_op_save_offset = 0;
static uint32_t flash_op_erase_offset = 0;
typedef struct
{
uint16_t pattern;
uint16_t version;
boot_info_t boot_info;
uint8_t comments[12];
} fw_img_info_t;
bool HILINK_OtaAdapterFlashInit(void)
{
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---Entry!!! ", __FUNCTION__);
flash_init_t flash_init;
flash_init.spi_type = FLASH_QSPI_ID1;
flash_init.flash_io.spi_cs.gpio = APP_IO_TYPE_NORMAL;
flash_init.flash_io.spi_cs.pin = APP_IO_PIN_15;
flash_init.flash_io.spi_cs.mux = APP_IO_MUX_2;
flash_init.flash_io.spi_clk.gpio = APP_IO_TYPE_NORMAL;
flash_init.flash_io.spi_clk.pin = APP_IO_PIN_9;
flash_init.flash_io.spi_clk.mux = APP_IO_MUX_2;
flash_init.flash_io.spi_io0.qspi_io0.gpio = APP_IO_TYPE_NORMAL;
flash_init.flash_io.spi_io0.qspi_io0.pin = APP_IO_PIN_8;
flash_init.flash_io.spi_io0.qspi_io0.mux = APP_IO_MUX_2;
flash_init.flash_io.spi_io1.qspi_io1.gpio = APP_IO_TYPE_NORMAL;
flash_init.flash_io.spi_io1.qspi_io1.pin = APP_IO_PIN_14;
flash_init.flash_io.spi_io1.qspi_io1.mux = APP_IO_MUX_2;
flash_init.flash_io.qspi_io2.gpio = APP_IO_TYPE_NORMAL;
flash_init.flash_io.qspi_io2.pin = APP_IO_PIN_13;
flash_init.flash_io.qspi_io2.mux = APP_IO_MUX_2;
flash_init.flash_io.qspi_io3.gpio = APP_IO_TYPE_NORMAL;
flash_init.flash_io.qspi_io3.pin = APP_IO_PIN_12;
flash_init.flash_io.qspi_io3.mux = APP_IO_MUX_2;
if (!spi_flash_init(&flash_init))
{
APP_LOG_ERROR(">>>>>>>>>>>>>>>>>>>>>>>>>%s fail !!! ", __FUNCTION__);
return false;
}
if (!spi_flash_sector_erase(flash_op_erase_offset, FLASH_OP_PAGE_SIZE))
{
APP_LOG_ERROR(">>>>>>>>>>>>>>>>>>>>>>>>>>Erase Bank1 address: 0x%08x fail !!! ", flash_op_erase_offset);
return false;
}
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>Erase Bank1 address: 0x%08x ", flash_op_erase_offset);
flash_op_erase_offset += FLASH_OP_PAGE_SIZE;
return true;
}
unsigned int HILINK_OtaAdapterGetUpdateIndex(void)
{
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s--- Entry!!! ", __FUNCTION__);
return 0;
}
int HILINK_OtaAdapterFlashErase(unsigned int size)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---size:%d Entry!!! ", __FUNCTION__, size);
if(spi_flash_sector_erase(0, size))
{
return 0;
}
APP_LOG_ERROR(">>>>>>>>>>>>>>>>>>>>>>>>>>%s fail !!! ", __FUNCTION__);
return -1;
}
int HILINK_OtaAdapterFlashWrite(const unsigned char *buf, unsigned int buflen)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s--- buflen %d !!! ", __FUNCTION__, buflen);
if ((flash_op_save_offset + buflen) > flash_op_erase_offset)
{
if (!spi_flash_sector_erase(flash_op_erase_offset, FLASH_OP_PAGE_SIZE))
{
APP_LOG_ERROR(">>>>>>>>>>>>>>>>>>>>>>>>>>Erase Bank1 address: 0x%08x fail !!! ", flash_op_erase_offset);
return false;
}
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>Erase Bank1 address: 0x%08x ", flash_op_erase_offset);
flash_op_erase_offset += FLASH_OP_PAGE_SIZE;
}
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>Write Bank1 address: 0x%08x len: 0x%08x", flash_op_save_offset, buflen);
if (buflen != spi_flash_write(flash_op_save_offset, (uint8_t *)buf, buflen))
{
APP_LOG_ERROR(">>>>>>>>>>>>>>>>>>>>>>>>>>Write Bank1 address: 0x%08x fail !!! ", flash_op_save_offset);
return -1;
}
flash_op_save_offset += buflen;
return 0;
}
int HILINK_OtaAdapterFlashRead(unsigned int offset, unsigned char *buf, unsigned int buflen)
{
APP_LOG_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---buflen:%d Entry!!! ", __FUNCTION__, buflen);
if (buflen == spi_flash_read(offset, buf, buflen))
{
return 0;
}
APP_LOG_ERROR(">>>>>>>>>>>>>>>>>>>>>>>>>>%s error: read size is not buflen !!! ", __FUNCTION__);
return -1;
}
bool HILINK_OtaAdapterFlashFinish(void)
{
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---Entry!!! ", __FUNCTION__);
return true;
}
unsigned int HILINK_OtaAdapterFlashMaxSize(void)
{
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s---0x%08x Entry!!! ", __FUNCTION__, FLASH_SIZE_MAX);
return FLASH_SIZE_MAX;
}
void HILINK_OtaAdapterRestart(int flag)
{
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>%s--- Entry!!! ", __FUNCTION__);
(void)flag;
fw_img_info_t img_info;
spi_flash_read(flash_op_save_offset - 48, (uint8_t *)&img_info, sizeof(fw_img_info_t));
hal_flash_write(IMG_INFO_DFU_ADDR, (uint8_t *)&img_info, sizeof(fw_img_info_t));
hal_nvic_system_reset();
return;
}
int HilinkGetMcuVersion(char *version,unsigned int inlen, unsigned int *outlen)
{
return 0;
}
int HilinkGetRebootFlag(void)
{
return 1;
@@ -35,53 +181,8 @@ int HilinkOtaEndProcess(int status)
return 0;
}
void HILINK_OtaAdapterRestart(int flag)
{
return;
}
int HilinkNotifyOtaStatus(int flag, unsigned int len, unsigned int type)
{
return 0;
}
unsigned int HILINK_OtaAdapterFlashMaxSize(void)
{
return 0;
}
bool HILINK_OtaAdapterFlashFinish(void)
{
return true;
}
int HILINK_OtaAdapterFlashRead(unsigned int offset, unsigned char *buf, unsigned int buflen)
{
return 0;
}
int HILINK_OtaAdapterFlashWrite(const unsigned char *buf, unsigned int buflen)
{
return 0;
}
int HILINK_OtaAdapterFlashErase(unsigned int size)
{
return 0;
}
unsigned int HILINK_OtaAdapterGetUpdateIndex(void)
{
return 0;
}
bool HILINK_OtaAdapterFlashInit(void)
{
return true;
}
int getDeviceVersion(char **firmwareVer, unsigned int inlen, unsigned int *outlen)
{
return 0;
}
int HilinkGetMcuVersion(char *version,unsigned int inlen, unsigned int *outlen)
{
return 0;
}
-2
View File
@@ -12,7 +12,6 @@
# limitations under the License.
static_library("hal_iothardware") {
if (board_name == "gr551x") {
sources = [
"hal_iot_flash.c",
"hal_iot_gpio.c",
@@ -27,5 +26,4 @@ static_library("hal_iothardware") {
"//utils/native/lite/include",
"//base/iot_hardware/peripheral/interfaces/kits",
]
}
}
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
+6 -14
View File
@@ -21,6 +21,7 @@
#include "dirent.h"
#include <cmsis_os2.h>
#include "app_log.h"
#include "config.h"
#define MaxOpenFile 32
#define FR_OK 0
@@ -73,8 +74,8 @@ void FileSystemInit(void)
APP_LOG_ERROR("[LFS] File system mutex init failed!!!");
}
//app_lfs_format();
ret = app_lfs_init();
app_lfs_format();
ret = app_lfs_init(LOSCFG_LFS_MAX_BLOCK_COUNT);
if (ret != 0) {
APP_LOG_ERROR("[LFS] File system init failed! ret=%d", ret);
}
@@ -149,7 +150,7 @@ static char *get_file_name(const char *path)
}
int HalFileOpen(const char *path, int oflag, int mode)
{
{
int ret = 0;
int fd = 0;
char *file_name;
@@ -213,21 +214,12 @@ int HalFileRead(int fd, char *buf, unsigned int len)
fs_lock();
ret = app_lfs_file_read(&File[fd - 1].file, (uint8_t *)buf, len);
fs_unlock();
for (int i = 0; i < ret; i++)
{
printf("0x%02x ", (unsigned char)buf[i]);
}
printf("\r\n");
return ret;
}
int HalFileWrite(int fd, const char *buf, unsigned int len)
{
for (int i = 0; i < len; i++)
{
printf("0x%02x ", (unsigned char)buf[i]);
}
printf("\r\n");
int ret = 0;
if ((fd > MaxOpenFile) || (fd <= 0)) {
@@ -285,7 +277,7 @@ int HalFileStat(const char *path, unsigned int *fileSize)
ret = app_lfs_file_stat(file_name, &info);
fs_unlock();
*fileSize = info.size;
*fileSize = info.size;
return ((ret == 0) ? 0 : -1);
}
View File
Binary file not shown.
Binary file not shown.
-223
View File
@@ -1,223 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
* Description: 蓝牙SDK提供demo示例代码
*/
#include "hilink_bt_api.h"
#include <stdio.h>
/* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改 */
typedef struct {
const char* sn; /* 设备唯一标识,比如sn号,长度范围(0,40] */
const char* prodId; /* 设备HiLink认证号,长度范围(0,5] */
const char* model; /* 设备型号,长度范围(0,32] */
const char* dev_t; /* 设备类型,长度范围(0,4] */
const char* manu; /* 设备制造商,长度范围(0,4] */
const char* mac; /* 设备MAC地址,固定32字节 */
const char* hiv; /* 设备Hilink协议版本,长度范围(0,32] */
const char* fwv; /* 设备固件版本,长度范围[0,64] */
const char* hwv; /* 设备硬件版本,长度范围[0,64] */
const char* swv; /* 设备软件版本,长度范围[0,64] */
const int prot_t; /* 设备协议类型,取值范围[1,3] */
} dev_info_t;
/*
* 设备类型英文名和厂商英文名长度之和不能超过17字节
* 如果需要发送蓝牙广播,设备类型英文名和厂商英文名长度分别不能超过4字节
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
typedef struct {
const char* devTypeName; /* 设备类型英文名称 */
const char* manuName; /* 厂商英文名称 */
} DevNameEn;
/*
* 设备基本信息
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
#define DEVICE_SN "12345678"
#define PRODUCT_ID "2XXX"
#define DEVICE_MODEL "model-X"
#define DEVICE_TYPE "000"
#define MANUAFACTURER "000"
#define DEVICE_MAC "AABBCCDDEEFF"
/*
* 请确保设备类型英文名和厂商英文名长度之和不超过17字节
* 如果需要发送蓝牙广播,设备类型英文名和厂商英文名长度分别不能超过4字节
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
#define DEVICE_TYPE_NAME "other"
#define MANUAFACTURER_NAME "HW"
/*
* 设备信息定义
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
dev_info_t dev_info = {
DEVICE_SN,
PRODUCT_ID,
DEVICE_MODEL,
DEVICE_TYPE,
MANUAFACTURER,
DEVICE_MAC,
"1.0.0",
"1.0.0",
"1.0.0",
"1.0.0",
1
};
/*
* 设备名称定义, 请确保设备类型英文名和厂商英文名长度之和不超过17字节
* 如果需要发送蓝牙广播,设备类型英文名和厂商英文名长度分别不能超过4字节
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
DevNameEn g_devNameEn = {
DEVICE_TYPE_NAME,
MANUAFACTURER_NAME
};
/* 蓝牙sdk单独使用的定义 */
#define SUB_PRODUCT_ID "00"
#define ADV_TX_POWER 0xF8
#define MIN_LEN(a, b) (((a) < (b)) ? (a) : (b))
static HILINK_BT_DevInfo g_btDevInfo;
static int PutServiceOta(const void *svc, const unsigned char *in, unsigned int inLen,
unsigned char **out, unsigned int *outLen)
{
(void)inLen;
(void)out;
(void)outLen;
printf("service:%s, payload:%s", (char *)svc, (char *)in);
return 0;
}
static int GetServiceOta(const void *svc, const unsigned char *in, unsigned int inLen,
unsigned char **out, unsigned int *outLen)
{
(void)inLen;
(void)out;
(void)outLen;
printf("service:%s, payload:%s", (char *)svc, (char *)in);
return 0;
}
/* 服务信息 */
static HILINK_BT_SvcInfo g_svcInfo[] = {
{ 64, "ota", PutServiceOta, GetServiceOta, 0, NULL },
};
/* Profile */
static HILINK_BT_Profile g_profile = {
.svcNum = sizeof(g_svcInfo) / sizeof(g_svcInfo[0]),
.svcInfo = g_svcInfo,
};
/* 蓝牙发送数据接口打桩函数,由厂家实现 */
static int HILINK_BT_FeedBackBtData(const unsigned char *buf, unsigned int len)
{
(void)buf;
(void)len;
return 0;
}
/*
* 功能: 获取设备sn号
* 参数[in]: len sn的最大长度, 39字节
* 参数[out]: sn 设备sn
* 注意: sn指针的字符串长度为0时将使用设备mac地址作为sn
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
void HilinkGetDeviceSn(unsigned int len, char *sn)
{
if (sn == NULL) {
return;
}
const char *ptr = DEVICE_SN;
int tmp = MIN_LEN(len ,sizeof(DEVICE_SN));
for (int i = 0; i < tmp; i++) {
sn[i] = ptr[i];
}
return;
}
/*
* 获取设备的子型号,长度固定两个字节
* subProdId为保存子型号的缓冲区,len为缓冲区的长度
* 如果产品定义有子型号,则填入两字节子型号,并以'\0'结束, 返回0
* 没有定义子型号,则返回-1
* 该接口需设备开发者实现
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
int HILINK_GetSubProdId(char *subProdId, int len)
{
if (subProdId == NULL) {
return -1;
}
const char *ptr = SUB_PRODUCT_ID;
int tmp = MIN_LEN((unsigned int)len ,sizeof(SUB_PRODUCT_ID));
for (int i = 0; i < tmp; i++) {
subProdId[i] = ptr[i];
}
return 0;
}
/*
* 获取设备表面的最强点信号发射功率强度,最强点位置的确定以及功率测试方
* 法,参照hilink认证蓝牙靠近发现功率设置及测试方法指导文档,power为出参
* ,单位dbm,返回设备表面的最强信号强度值,如果厂商不想使用蓝牙靠近发现功
* 能,接口直接返-1,如果需要使用蓝牙靠近发现,则接口返回0,如需及时生效,需
* 调用HILINK_BT_StartAdvertise()方法启动广播
*/
int HILINK_BT_GetDevSurfacePower(char *power)
{
if (power == NULL) {
return -1;
}
*power = ADV_TX_POWER;
return 0;
}
/* 获取蓝牙SDK设备相关信息 */
HILINK_BT_DevInfo *HILINK_BT_GetDevInfo(void)
{
g_btDevInfo.manuName = (char *)g_devNameEn.manuName;
g_btDevInfo.devName = (char *)g_devNameEn.devTypeName;
g_btDevInfo.productId = (char *)dev_info.prodId;
g_btDevInfo.mac = (char *)dev_info.mac;
g_btDevInfo.model = (char *)dev_info.model;
g_btDevInfo.devType = (char *)dev_info.dev_t;
g_btDevInfo.hiv = (char *)dev_info.hiv;
g_btDevInfo.protType = dev_info.prot_t;
return &g_btDevInfo;
}
int main(void)
{
int ret;
ret = HILINK_BT_Init(&g_profile);
if (ret != 0) {
printf("init fail");
return ret;
}
ret = HILINK_BT_Process();
if (ret != 0) {
printf("process fail");
return ret;
}
/* 设置蓝牙发送接口 */
ret = HILINK_BT_RegisterBtDataSendCallback(HILINK_BT_FeedBackBtData);
if (ret != 0) {
printf("set callback fail");
return ret;
}
return 0;
}
@@ -1,231 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
* Description: BLE辅助配网SDK API头文件
*/
#ifndef BLE_CFG_NET_API_H
#define BLE_CFG_NET_API_H
#ifdef __cplusplus
extern "C" {
#endif
/* WIFI信息长度宏定义 */
#define WIFI_SSID_MAX_LEN 32
#define WIFI_PWD_MAX_LEN 64
#define WIFI_PSK_LEN 32
#define WIFI_BSSID_LEN 6
#define BLE_UUID_LEN 16
/* 用户发送的数据类型 */
typedef enum {
NETCFG_DATA,
CUSTOM_DATA,
CUSTOM_SEC_DATA,
DATA_TYPE_BUTT
} BLE_DataType;
/* 属性类型定义 */
typedef enum {
ATTR_TYPE_SERVICE = 0,
ATTR_TYPE_CHAR,
ATTR_TYPE_CHAR_VALUE,
ATTR_TYPE_CHAR_CLIENT_CONFIG,
ATTR_TYPE_CHAR_USER_DESC,
} BLE_AttrType;
/* UUID长度定义 */
typedef enum {
UUID_TYPE_NULL = 0,
UUID_TYPE_16_BIT,
UUID_TYPE_32_BIT,
UUID_TYPE_128_BIT,
} BLE_UuidType;
/* BLE辅助配网状态定义 */
typedef enum {
CFG_NET_PROCESS_SUCCESS = 0x00,
CFG_NET_BLE_CONNECT,
CFG_NET_BLE_DIS_CONNECT,
CFG_NET_SPEKE_SUCCESS,
CFG_NET_PROCESS_START,
CFG_NET_RECEIVE_PARA,
CFG_NET_WIFI_CONNECT,
CFG_NET_SESSIONKEY_SUCCESS,
CFG_NET_FAIL_UNKUNOWN = 0x100,
CFG_NET_FAIL_WIFI_SSID,
CFG_NET_FAIL_WIFI_PWD,
CFG_NET_FAIL_SESSIONKEY
} BLE_CfgNetStatus;
/* 手机侧传过来的WIFI信息,格式复用短距配网格式 */
typedef struct {
unsigned char ssid[WIFI_SSID_MAX_LEN + 1];
unsigned char pwd[WIFI_PWD_MAX_LEN + 1];
unsigned char psk[WIFI_PSK_LEN + 1];
unsigned char bssid[WIFI_BSSID_LEN + 1];
unsigned char ssidLen;
unsigned char pwdLen;
unsigned char pskLen;
unsigned char bssidLen;
int authMode;
int wifiInfoSrc;
int channelNumber;
} BLE_WifiInfo;
/*
* 获取设备PIN码函数类型
* pincode: 存放pin码的缓冲区
* size: 缓冲区的长度
* len: 返回的pin码实际长度
*/
typedef int (*BLE_GetDevPinCode)(unsigned char *pinCode, unsigned int size, unsigned int *len);
/*
* 获取设备信息函数类型,len即是入参也是出参,入参代表buff缓冲区长度,出参代表获取的设备信息实际长度
* 格式要求:{"productId":"%s", "sn":"%s", "vendor":"%s"}
*/
typedef int (*BLE_GetDeviceInfo)(unsigned char *devInfo, unsigned int *len);
/*
* 设置配网信息函数类型
.* 数据格式:{"ssid":"%s","password":"%s","devId":"%s","psk":"%s","code":"%s","random":"%s","vendorData":"%s"}
*/
typedef int (*BLE_SetCfgNetInfo)(const unsigned char *netInfo, unsigned int len);
/* 接收用户数据函数类型 */
typedef int (*BLE_RcvCustomData)(unsigned char *buff, unsigned int len);
/* 配网过程状态处理函数类型 */
typedef int (*BLE_CfgNetProcess)(BLE_CfgNetStatus status);
/* BLE GATT服务读函数类型 */
typedef int (*BLE_GattRead)(unsigned char *buff, unsigned int *len);
/* BLE GATT服务写函数类型 */
typedef int (*BLE_GattWrite)(const unsigned char *buff, unsigned int len);
/* BLE GATT服务指示函数类型 */
typedef int (*BLE_GattIndicate)(unsigned char *buff, unsigned int len);
/* BLE GATT回调函数指针 */
typedef struct {
BLE_GattRead readCb;
BLE_GattWrite writeCb;
BLE_GattIndicate indicateCb;
} BLE_GattOperateFunc;
/* BLE配置参数 */
typedef struct {
int isBlePair;
int isDeinitBleStack;
int data1; /* 为后期配置参数预留,暂不使用 */
int data2; /* 为后期配置参数预留,暂不使用 */
int data3; /* 为后期配置参数预留,暂不使用 */
} BLE_ConfPara;
/* BLE GATT服务 */
typedef struct {
BLE_AttrType attrType;
unsigned int permission;
BLE_UuidType uuidType;
unsigned char uuid[BLE_UUID_LEN];
unsigned char *value;
unsigned char valLen;
unsigned char properties;
BLE_GattOperateFunc func;
} BLE_GattAttr;
/* GATT服务(单个service及其下挂的全部characteristics和descriptions) */
typedef struct {
unsigned int attrNum;
BLE_GattAttr *attrList;
} BLE_GattService;
/* GATT列表(包含多个services和返回的handle) */
typedef struct {
unsigned int num;
BLE_GattService *service;
int *handle;
} BLE_GattList;
/* GATT句柄列表 */
typedef struct {
unsigned int num;
int *handle;
} BLE_GattHandleList;
/* BLE的广播数据和扫描应答数据 */
typedef struct {
unsigned char *advData;
unsigned int advDataLen;
unsigned char *rspData;
unsigned int rspDataLen;
} BLE_AdvData;
/* BLE的广播参数 */
typedef struct {
unsigned char advType;
unsigned char discMode;
unsigned char connMode;
unsigned int minInterval;
unsigned int maxInterval;
unsigned int channelMap;
unsigned int timeout;
int txPower;
} BLE_AdvPara;
/* 广播参数和数据 */
typedef struct {
BLE_AdvPara *advPara;
BLE_AdvData *advData;
} BLE_AdvInfo;
/* BLE初始化参数 */
typedef struct {
BLE_ConfPara *confPara;
BLE_AdvInfo *advInfo;
BLE_GattList *gattList;
} BLE_InitPara;
/* BLE配网回调函数 */
typedef struct {
BLE_GetDevPinCode getDevPinCodeCb;
BLE_GetDeviceInfo getDeviceInfoCb;
BLE_SetCfgNetInfo setCfgNetInfoCb;
BLE_RcvCustomData rcvCustomDataCb;
BLE_CfgNetProcess cfgNetProcessCb;
} BLE_CfgNetCb;
/*
* BLE配网资源申请:BLE协议栈启动、配网回调函数挂接
* 如为厂家实现协议栈para传NULL,如需华为实现协议栈则需赋值para结构体内容
*/
int BLE_CfgNetInit(BLE_InitPara *para, BLE_CfgNetCb *cb);
/*
* BLE配网资源注销:配网回调函数清理、BLE协议栈销毁
* flag为0:只销毁控制和调度线程,flag为1销毁蓝牙协议栈
*/
int BLE_CfgNetDeInit(const BLE_GattHandleList *handleList, unsigned int flag);
/* BLE配网广播控制:参数代表广播时间,0:停止;0xFFFFFFFF:一直广播,其他:广播指定时间后停止,单位秒 */
int BLE_CfgNetAdvCtrl(unsigned int advSecond);
/*
* 更新广播参数,更新完成后需调用BLE_CfgNetAdvCtrl启动广播
* 传入空值时可启动hilink构造的广播
*/
int BLE_CfgNetAdvUpdate(const BLE_AdvInfo *advInfo);
/* BLE配网断开连接:防止其他任务长时间占用BLE连接 */
int BLE_CfgNetDisConnect(void);
/* BLE发送用户数据:用户数据发送,与接收回调函数配套使用 */
int BLE_SendCustomData(BLE_DataType dataType, const unsigned char *buff, unsigned int len);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,106 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
* Description: 蓝牙SDK API头文件
*/
#ifndef HILINK_BT_API_H
#define HILINK_BT_API_H
#include "ble_cfg_net_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* 销毁蓝牙协议栈标志 */
#define BLE_DEINIT_FALG 0x1234ABCD
/* 产品信息定义结构体 */
typedef struct {
char *manuName; /* 设备制造商,长度范围(0,4] */
char *devName; /* 设备名称 */
char *productId; /* 设备HiLink认证号,长度范围(0,5] */
char *sn; /* 设备唯一标识,比如sn号,长度范围(0,40] */
char *mac; /* 设备MAC地址,固定32字节 */
char *subProductId; /* 设备子productId */
char *model; /* 设备型号,长度范围(0,32] */
char *devType; /* 设备类型,长度范围(0,4] */
char *hiv; /* 设备Hilink协议版本,长度范围(0,32] */
int protType; /* 设备协议类型,取值范围[1,3] */
} HILINK_BT_DevInfo;
/* 发送蓝牙数据回调函数类型 */
typedef int (*HILINK_BT_SendBtDataCallback)(const unsigned char *buf, unsigned int len);
/* 厂家实现协议栈使用,注册蓝牙数据发送接口 */
int HILINK_BT_RegisterBtDataSendCallback(HILINK_BT_SendBtDataCallback callback);
/* 厂家实现协议栈使用,注册蓝牙OTA数据发送接口 */
int HILINK_BT_RegisterOtaDataSendCallback(HILINK_BT_SendBtDataCallback callback);
/* 厂家实现协议栈使用,处理蓝牙数据 */
int HILINK_BT_ProcessBtData(const unsigned char *buf, unsigned int len);
/* 厂家实现协议栈使用,处理蓝牙OTA的控制数据 */
int HILINK_BT_ProcessOtaCtrl(const unsigned char *buf, unsigned int len);
/* 厂家实现协议栈使用,处理蓝牙OTA的传输数据 */
int HILINK_BT_ProcessOtaData(const unsigned char *buf, unsigned int len);
/* 厂家实现协议栈使用,断开蓝牙连接时,释放通道占用资源 */
void HILINK_BT_DisconnectFreeResource(void);
/* 返回值0代表支持本地控和二次配网,其他值代表不支持 */
int HILINK_BT_SupportLocalControl(void);
/* 设备硬重置时厂商调用的接口 */
int HILINK_BT_HardRevoke(void);
/*
* 获取设备表面的最强点信号发射功率强度,最强点位置的确定以及功率测试方
* 法,参照hilink认证蓝牙靠近发现功率设置及测试方法指导文档,power为出参
* ,单位dbm,返回设备表面的最强信号强度值,如果厂商不想使用蓝牙靠近发现功
* 能,接口直接返-1,如果需要使用蓝牙靠近发现,则接口返回0,如需及时生效,需
* 调用HILINK_BT_StartAdvertise()方法启动广播
*/
int HILINK_BT_GetDevSurfacePower(char *power);
/*
* 获取设备的子型号,长度固定两个字节
* subProdId为保存子型号的缓冲区,len为缓冲区的长度
* 如果产品定义有子型号,则填入两字节子型号,并以'\0'结束, 返回0
* 没有定义子型号,则返回-1
* 该接口需设备开发者实现
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
int HILINK_GetSubProdId(char *subProdId, int len);
/*
* 获取设备SN
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
void HilinkGetDeviceSn(unsigned int len, char *sn);
/*
* 获取设备相关版本号
* 返回0表示版本号获取成功,返回其他表示版本号获取失败
* 注意,此接口为HiLink内部调用函数
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
int getDeviceVersion(char **firmwareVer, char **softwareVer, char **hardwareVer);
/*
* 厂家设置linux系统读写文件的路径,路径长度不能超过33个字节,包含结束符
* 要求存储路径是非易失性的,版本升级不影响该路径文件
*/
void HILINK_BT_SetConfigDirPath(const char *configDirPath);
/*
* 厂家自定义格式化输出字符串
* 返回0表示失败,其他表示实际输出的字节数
*/
int HILINK_BT_Printf(const char *format, ...);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,235 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
* Description: 蓝牙SDK 功能函数头文件
*/
#ifndef HILINK_BT_FUNCTION_H
#define HILINK_BT_FUNCTION_H
#include "hilink_bt_api.h"
#include "ble_cfg_net_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* 广播最大长度 */
#define ADV_VALUE_MAX_LEN 31
typedef enum {
HILINK_BT_SDK_STATUS_SVC_RUNNING = 0, /* 正常运行 */
HILINK_BT_SDK_STATUS_DEINIT, /* 注销 */
HILINK_BT_SDK_STATUS_NAME_SET_ABNORM, /* 蓝牙名称设置异常 */
HILINK_BT_SDK_STATUS_DISCOVER_MODE_SET_ABNORM, /* 蓝牙可发现模式设置异常 */
HILINK_BT_SDK_STATUS_REG_APP_ABNORM, /* 注册BLE应用异常 */
HILINK_BT_SDK_STATUS_SVC_CREATE_ABNORM, /* 服务创建异常 */
HILINK_BT_SDK_STATUS_CHAR_ADD_ABNORM, /* 属性添加异常 */
HILINK_BT_SDK_STATUS_DESC_ADD_ABNORM, /* 描述添加异常 */
HILINK_BT_SDK_STATUS_SVC_START_ABNORM, /* 服务启动异常 */
HILINK_BT_SDK_STATUS_ADV_PARA_SET_ABNORM, /* 广播参数设置异常 */
HILINK_BT_SDK_STATUS_ADV_DATA_SET_ABNORM, /* 广播数据设置异常 */
HILINK_BT_SDK_STATUS_ADV_START_ABNORM, /* 广播启动异常 */
} HILINK_BT_SdkStatus;
/* GATTS char属性取值 */
typedef enum {
HILINK_BT_CHAR_PROP_WRITE_WITHOUT_RESP = 0x04,
HILINK_BT_CHAR_PROP_WRITE = 0x08,
HILINK_BT_CHAR_PROP_READ = 0x02,
HILINK_BT_CHAR_PROP_NOTIFY = 0x10,
HILINK_BT_CHAR_PROP_INDICATE = 0x20
} HILINK_BT_CharProperty;
/* GATTS char权限取值 */
typedef enum {
HILINK_BT_CHAR_PERM_READ = 0x01,
HILINK_BT_CHAR_PERM_READ_ENCRYPTED = 0x02,
HILINK_BT_CHAR_PERM_READ_ENCRYPTED_MITM = 0x04,
HILINK_BT_CHAR_PERM_WRITE = 0x10,
HILINK_BT_CHAR_PERM_WRITE_ENCRYPTED = 0x20,
HILINK_BT_CHAR_PERM_WRITE_ENCRYPTED_MITM = 0x40,
HILINK_BT_CHAR_PERM_WRITE_SIGNED = 0x80,
HILINK_BT_CHAR_PERM_WRITE_SIGNED_MITM = 0x100,
} HILINK_BT_CharPermission;
/* GATTS desc属性取值 */
typedef enum {
HILINK_BT_DESC_PERM_WRITE = 0x01,
HILINK_BT_DESC_PERM_READ = 0x02
} HILINK_BT_DescPermission;
/* 属性值类型: 整型和属性 */
typedef enum {
HILINK_BT_CMD_DATA_TYPE_INT,
HILINK_BT_CMD_DATA_TYPE_STR,
} HILINK_BT_CmdDataType;
/* hilink蓝牙应用层数据编码类型 */
typedef enum {
HILINK_BT_CMD_DATA_MODE_TLV = 0x00, /* TLV格式: 降低报文占用的空间 */
HILINK_BT_CMD_DATA_MODE_JSON = 0x01 /* JSON格式: 扩展性更好,默认格式 */
} HILINK_BT_CmdDataMode;
/* 发送蓝牙SDK状态回调函数类型 */
typedef void (*HILINK_BT_SdkEventCallBack)(HILINK_BT_SdkStatus event, const void *param);
/* 自定义gatt服务读事件回调 */
typedef int (*HILINK_BT_GattReadCallback)(unsigned char *out, unsigned int *outLen);
/* 自定义gatt服务写事件回调 */
typedef int (*HILINK_BT_GattWriteCallback)(const unsigned char *in, unsigned int inLen);
/* 产品功能命令定义结构体 */
typedef struct {
unsigned char attrIdx;
char *attr;
HILINK_BT_CmdDataType dataType;
int (*putFunc)(const void *data, unsigned int len);
int (*getFunc)(void *buf, unsigned int *bufLen, unsigned int len);
} HILINK_BT_AttrInfo;
/* 产品功能定义结构体 */
typedef struct {
unsigned char svcIdx;
char *service;
int (*putFunc)(const void *svc, const unsigned char *in, unsigned int inLen,
unsigned char **out, unsigned int *outLen);
int (*getFunc)(const void *svc, const unsigned char *in, unsigned int inLen,
unsigned char **out, unsigned int *outLen);
unsigned char attrNum;
HILINK_BT_AttrInfo *attrInfo;
} HILINK_BT_SvcInfo;
/* 产品Profile定义结构体 */
typedef struct {
unsigned int svcNum;
HILINK_BT_SvcInfo *svcInfo;
} HILINK_BT_Profile;
/* 蓝牙gatt character描述 */
typedef struct {
char *descUuid;
/* gatt属性描述读写权限:取值由HILINK_BT_DescPermission类型的成员或运算得出 */
unsigned int descPermission;
} HILINK_BT_GattProfileDesc;
/* 蓝牙gatt character */
typedef struct {
char *charUuid;
/* gatt char权限:取值由HILINK_BT_CharPermission类型的成员或运算得出 */
unsigned int charPermission;
/* gatt char属性:取值由HILINK_BT_CharProperty类型的成员或运算得出 */
unsigned int charProperty;
HILINK_BT_GattReadCallback readFunc;
HILINK_BT_GattWriteCallback writeFunc;
HILINK_BT_GattProfileDesc *desc;
unsigned char descNum;
} HILINK_BT_GattProfileChar;
/* 蓝牙gatt 服务 */
typedef struct {
char *svcUuid;
int isPrimary;
HILINK_BT_GattProfileChar *character;
unsigned char charNum;
} HILINK_BT_GattProfileSvc;
/* 厂商自定义蓝牙gatt服务列表 */
typedef struct {
HILINK_BT_GattProfileSvc *service;
unsigned char serviceNum;
} HILINK_BT_GattServiceList;
/* 配置保存回调结构体 */
typedef struct {
int (*createItem)(const char *name, unsigned int size);
int (*readItem)(const char *name, unsigned char *buf, unsigned int len);
int (*writeItem)(const char *name, const unsigned char *buf, unsigned int len);
int (*deleteItem)(const char *name);
int (*destroyConfMgr)(void);
int (*getHichainFlashAddr)(unsigned int *start, unsigned int *size);
} HILINK_BT_ConfigInterface;
/* 获取广播数据结构体 */
typedef struct {
unsigned int advSvcDataLen;
unsigned char advSvcData[ADV_VALUE_MAX_LEN];
unsigned int advRspDataLen;
unsigned char advRspData[ADV_VALUE_MAX_LEN];
} HILINK_BT_AdvertiseData;
/* 设置应用层编码模式 */
int HILINK_BT_SetEncodeMode(HILINK_BT_CmdDataMode mode);
/* 查询应用层编码模式 */
HILINK_BT_CmdDataMode HILINK_BT_GetEncodeMode(void);
/* 初始化启动HiLink Bluetooth SDK */
int HILINK_BT_Init(const HILINK_BT_Profile *profile);
/* 启动HiLink BT SDK处理,调用HiLink协议栈 */
int HILINK_BT_Process(void);
/*
* 结束HiLink Bluetooth SDK
* flag为0:只销毁控制和调度线程,flag为1销毁蓝牙协议栈,该函数不可重入
*/
int HILINK_BT_DeInit(unsigned int flag);
/* 添加HiLink服务信息service信息 */
int HILINK_BT_AddHiLilnkService(const HILINK_BT_SvcInfo *serviceArray, unsigned int serviceNum);
/* 通知服务状态 */
int HILINK_BT_ReportServiceState(const void *service, const void *buf, unsigned int len);
/* 通知属性状态 */
int HILINK_BT_ReportAttrState(const void *svc, const void *attr, const void *buf, unsigned int len);
/* 查询蓝牙数据发送接口 */
HILINK_BT_SendBtDataCallback HILINK_BT_GetBtDataSendCallback(void);
/* 查询蓝牙OTA数据发送接口 */
HILINK_BT_SendBtDataCallback HILINK_BT_GetOtaDataSendCallback(void);
/* 设置蓝牙SDK事件处理函数 */
int HILINK_BT_SetSdkEventCallback(HILINK_BT_SdkEventCallBack callback);
/*
* 设置BLE最大连接数量
* 入参connNum的范围为[1,10]
* 最大连接数上限为10,超过10个按10个执行
* 最小连接数为1,小于1按1个执行
* 若不调用该接口,默认最大连接数为1
*/
void HILINK_BT_SetMaxConnNum(int connNum);
/* 查询蓝牙SDK最大连接数量 */
int HILINK_BT_GetMaxConnNum(void);
/* 添加蓝牙SDK自定义gatt服务 */
int HILINK_BT_SetGattProfile(HILINK_BT_GattServiceList *gattServiceList);
/* 注册配置保存回调函数到HiLink Bluetooth SDK,若不调用该函数,则默认使用HiLink Bluetooth SDK保存配置实现 */
int HILINK_BT_RegisterConfigInterface(const HILINK_BT_ConfigInterface *interface);
/* 启动广播 */
int HILINK_BT_StartAdvertise(void);
/* 停止广播 */
int HILINK_BT_StopAdvertise(void);
/* 上报蓝牙反馈数据 */
int HILINK_BT_IndicateSvcCharData(const char *svcUuid, const char *charUuid, const char *buf, unsigned int len);
/* 获取蓝牙SDK设备相关信息 */
HILINK_BT_DevInfo *HILINK_BT_GetDevInfo(void);
/* 获取靠近发现中广播数据 */
int HILINK_BT_GetAdvertiseData(HILINK_BT_AdvertiseData *advertiseData);
/* 获取BLE厂商注册的回调函数 */
BLE_CfgNetCb *GetBleCfgNetCallback(void);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,32 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
* Description: 蓝牙SDK配网API头文件
*/
#ifndef HILINK_BT_NETCFG_API_H
#define HILINK_BT_NETCFG_API_H
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*HILINK_BT_ProcessNetCfgCb)(const unsigned char *in, unsigned int inLen,
unsigned char *out, unsigned int outLen);
/* 启动配网 */
int HILINK_BT_StartNetCfg(void);
/* 停止配网 */
int HILINK_BT_StopNetCfg(void);
/* 通知配网状态 */
int HILINK_BT_NotifyNetCfgStatus(int status);
/* 注册接收到配网信息的处理函数 */
int HILINK_BT_RegisterNetCfgDataCb(HILINK_BT_ProcessNetCfgCb callback);
#ifdef __cplusplus
}
#endif
#endif
Binary file not shown.
View File
Regular → Executable
+14 -9
View File
@@ -11,16 +11,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos/hdf.gni")
import("//build/lite/config/component/lite_component.gni")
import("drivers.gni")
group("drivers") {
public_deps = [
]
deps = [
"uart",
]
public_deps = []
if (hdf_drivers_gpio_enable) {
public_deps += [ "gpio:gpio" ]
}
if (hdf_drivers_uart_enable) {
public_deps += [ "uart:uart" ]
}
}
config("public") {
configs = [ "cfiflash:public" ]
}
+39
View File
@@ -0,0 +1,39 @@
# Copyright (c) 2021 GOODIX.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
declare_args() {
hdf_drivers_gpio_enable = true
hdf_drivers_uart_enable = true
}
hdf_include_dirs = [
"//drivers/adapter/khdf/liteos_m/osal/include/",
"//drivers/adapter/khdf/liteos/platform/include/",
"//drivers/framework/ability/sbuf/include",
"//drivers/framework/include",
"//drivers/framework/include/osal",
"//drivers/framework/include/config",
"//drivers/framework/include/core",
"//drivers/framework/include/platform",
"//drivers/framework/include/utils",
"//drivers/framework/core/host/include",
"//drivers/framework/core/shared/include",
"//drivers/framework/core/common/include/host",
"//drivers/framework/utils/include",
"//drivers/framework/include/platform",
"//drivers/framework/support/platform/include",
"//drivers/framework/support/platform/include/fwk",
"//drivers/framework/support/platform/include/common",
]
+21
View File
@@ -0,0 +1,21 @@
# Copyright (c) 2021 GOODIX.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
import("../drivers.gni")
static_library("gpio") {
sources = [ "gpio_gr55xx.c" ]
include_dirs = hdf_include_dirs
}
+573
View File
@@ -0,0 +1,573 @@
/*
* Copyright (c) 2021 GOODIX.
* 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 "app_io.h"
#include "app_gpiote.h"
#include "device_resource_if.h"
#include "gpio/gpio_core.h"
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "stdio.h"
#define HDF_LOG_TAG gpio_gr55xx
#define GR55_IO_NUM_GPIO 32
#define GR55_IO_NUM_AON 8
#define GR55_IO_NUM_MSIO 5
#define GR55_IO_NUM_MAX (GR55_IO_NUM_GPIO + GR55_IO_NUM_AON + GR55_IO_NUM_MSIO)
#define GR55_IO_BASE_GPIO 0
#define GR55_IO_BASE_AON GR55_IO_NUM_GPIO
#define GR55_IO_BASE_MSIO (GR55_IO_NUM_GPIO + GR55_IO_NUM_AON)
#define GR55_IO_PULL_DEFAULT APP_IO_PULLUP
#define GR55_IO_MODE_DEFAULT APP_IO_MODE_OUT_PUT
// #define HDF_LOGI printf
// #define HDF_LOGE printf
// #define GR55_GPIO_DEBUG
struct Gr55xxGpioPortConfig {
app_io_mode_t mode;
app_io_pull_t pull;
GpioIrqFunc irqFunc;
app_handle_mode_t handleMode;
void *arg;
};
struct Gr55xxGpioCntlr {
struct GpioCntlr cntlr;
};
static struct Gr55xxGpioCntlr s_gr55xxGpioCntlr;
struct Gr55xxGpioPortConfig s_portCfg[GR55_IO_NUM_MAX];
static inline struct Gr55xxGpioCntlr *ToGr55xxGpioCntlr(struct GpioCntlr *cntlr)
{
return (struct Gr55xxGpioCntlr *)cntlr;
}
static inline app_io_type_t Gr55xxPinMap(uint32_t id, uint32_t *pin)
{
if (id < GR55_IO_BASE_AON)
{
*pin = 1 << (id - GR55_IO_BASE_GPIO);
return APP_IO_TYPE_NORMAL;
}
else if (id < GR55_IO_BASE_MSIO)
{
*pin = 1 << (id - GR55_IO_BASE_AON);
return APP_IO_TYPE_AON;
}
else
{
*pin = 1 << (id - GR55_IO_BASE_MSIO);
return APP_IO_TYPE_MSIO;
}
}
static void Gr55xxPortConfigInit(void)
{
uint16_t cnt;
for (cnt = 0; cnt < GR55_IO_NUM_MAX; cnt++)
{
s_portCfg[cnt].irqFunc = NULL;
s_portCfg[cnt].arg = NULL;
s_portCfg[cnt].pull = GR55_IO_PULL_DEFAULT;
s_portCfg[cnt].mode = GR55_IO_MODE_DEFAULT;
s_portCfg[cnt].handleMode = APP_IO_NONE_WAKEUP;
}
}
static int32_t Gr55xxGpioSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
{
uint32_t pin = 0;
app_io_init_t io_init;
app_io_type_t io_type;
if (gpio >= GR55_IO_NUM_MAX)
{
return HDF_ERR_INVALID_PARAM;
}
io_type = Gr55xxPinMap(gpio, &pin);
io_init.pin = pin;
io_init.pull = s_portCfg[gpio].pull;
io_init.mux = APP_IO_MUX_7;
io_init.mode = GR55_IO_MODE_DEFAULT;
if (dir == GPIO_DIR_IN)
{
io_init.mode = APP_IO_MODE_INPUT;
}
else if (dir == GPIO_DIR_OUT)
{
io_init.mode = APP_IO_MODE_OUT_PUT;
}
s_portCfg[gpio].mode = io_init.mode;
if (APP_DRV_SUCCESS == app_io_init(io_type, &io_init))
{
return HDF_SUCCESS;
}
else
{
return HDF_FAILURE;
}
}
static int32_t Gr55xxGpioGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir)
{
if (gpio >= GR55_IO_NUM_MAX)
{
return HDF_ERR_INVALID_PARAM;
}
*dir = s_portCfg[gpio].mode;
return HDF_SUCCESS;
}
static int32_t Gr55xxGpioWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
{
uint32_t pin = 0;
app_io_type_t io_type;
if (gpio >= GR55_IO_NUM_MAX)
{
return HDF_ERR_INVALID_PARAM;
}
io_type = Gr55xxPinMap(gpio, &pin);
if (val == GPIO_VAL_LOW)
{
app_io_write_pin(io_type, pin, APP_IO_PIN_RESET);
}
else if (val == GPIO_VAL_HIGH)
{
app_io_write_pin(io_type, pin, APP_IO_PIN_SET);
}
return HDF_SUCCESS;
}
static int32_t Gr55xxGpioRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
{
uint32_t pin = 0;
app_io_type_t io_type;
app_io_pin_state_t io_state;
if (gpio >= GR55_IO_NUM_MAX)
{
return HDF_ERR_INVALID_PARAM;
}
io_type = Gr55xxPinMap(gpio, &pin);
io_state = app_io_read_pin(io_type, pin);
if (APP_IO_PIN_RESET == io_state)
{
*val = GPIO_VAL_LOW;
}
else
{
*val = GPIO_VAL_HIGH;
}
return HDF_SUCCESS;
}
static int get_pin_index(uint32_t pin)
{
int index = 0;
while ((pin & 1) != 1)
{
index++;
pin = pin >> 1;
}
return index;
}
static void app_io_callback(app_gpiote_evt_t *p_evt)
{
uint32_t gpio = 0;
if (p_evt->type == APP_IO_TYPE_NORMAL)
{
gpio = get_pin_index(p_evt->pin);
}
else if (p_evt->type == APP_IO_TYPE_AON)
{
gpio = get_pin_index(p_evt->pin) + GR55_IO_BASE_AON;
}
else
{
HDF_LOGE("%s, type error", __func__);
}
if (s_portCfg[gpio].irqFunc != NULL)
{
HDF_LOGI("%s, Func@[%p], arg@[%p]\r\n", __func__, s_portCfg[gpio].irqFunc, s_portCfg[gpio].arg);
s_portCfg[gpio].irqFunc(gpio, s_portCfg[gpio].arg);
}
}
static void Gr55xxGpioteDebug(const char *pfunc, app_gpiote_param_t *pgpiote_param)
{
#ifdef GR55_GPIO_DEBUG
HDF_LOGI("%s, type: [%d]\r\n", pfunc, pgpiote_param->type);
HDF_LOGI("%s, pin : [%d]\r\n", pfunc, pgpiote_param->pin);
HDF_LOGI("%s, mode: [%d]\r\n", pfunc, pgpiote_param->mode);
HDF_LOGI("%s, handle_mode: [%d]\r\n", pfunc, pgpiote_param->handle_mode);
HDF_LOGI("%s, io_evt_cb: [%p]\r\n", pfunc, pgpiote_param->io_evt_cb);
#else
(void)pgpiote_param;
#endif
}
static int32_t Gr55xxGpioEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
{
uint32_t pin = 0;
app_io_type_t io_type;
app_gpiote_param_t gpiote_param;
if (gpio >= GR55_IO_NUM_MAX)
{
return HDF_ERR_INVALID_PARAM;
}
if (NULL == s_portCfg[gpio].irqFunc)
{
return HDF_FAILURE;
}
io_type = Gr55xxPinMap(gpio, &pin);
gpiote_param.type = io_type;
gpiote_param.pin = pin;
gpiote_param.pull = s_portCfg[gpio].pull;
gpiote_param.mode = s_portCfg[gpio].mode;
gpiote_param.handle_mode = s_portCfg[gpio].handleMode;
gpiote_param.io_evt_cb = app_io_callback;
Gr55xxGpioteDebug(__func__, &gpiote_param);
app_gpiote_init(&gpiote_param, 1);
HDF_LOGI("%s: io irq(%u@%p) enabled!", __func__, gpio, s_portCfg[gpio].irqFunc);
return HDF_SUCCESS;
}
static int32_t Gr55xxGpioDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
{
uint32_t pin = 0;
app_io_type_t io_type;
app_gpiote_param_t gpiote_param;
if (gpio >= GR55_IO_NUM_MAX)
{
return HDF_ERR_INVALID_PARAM;
}
if (NULL == s_portCfg[gpio].irqFunc)
{
return HDF_FAILURE;
}
io_type = Gr55xxPinMap(gpio, &pin);
gpiote_param.type = io_type;
gpiote_param.pin = pin;
gpiote_param.pull = s_portCfg[gpio].pull;
gpiote_param.mode = s_portCfg[gpio].mode;
gpiote_param.handle_mode = APP_IO_NONE_WAKEUP;
gpiote_param.io_evt_cb = NULL;
Gr55xxGpioteDebug(__func__, &gpiote_param);
app_gpiote_init(&gpiote_param, 1);
HDF_LOGI("%s: io irq(%u@%p) disabled!", __func__, gpio, s_portCfg[gpio].irqFunc);
return HDF_SUCCESS;
}
static int32_t Gr55xxGpioSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode,
GpioIrqFunc func, void *arg)
{
uint32_t pin = 0;
app_io_type_t io_type;
app_gpiote_param_t gpiote_param;
if ((gpio >= GR55_IO_NUM_MAX) || (NULL == func))
{
return HDF_ERR_INVALID_PARAM;
}
io_type = Gr55xxPinMap(gpio, &pin);
if (APP_IO_TYPE_MSIO == io_type)
{
HDF_LOGE("%s, IO type not support", __func__);
return HDF_ERR_INVALID_PARAM;
}
switch (mode)
{
case GPIO_IRQ_TRIGGER_RISING:
s_portCfg[gpio].mode = APP_IO_MODE_IT_RISING;
break;
case GPIO_IRQ_TRIGGER_FALLING:
s_portCfg[gpio].mode = APP_IO_MODE_IT_FALLING;
break;
case GPIO_IRQ_TRIGGER_HIGH:
s_portCfg[gpio].mode = APP_IO_MODE_IT_HIGH;
break;
case GPIO_IRQ_TRIGGER_LOW:
s_portCfg[gpio].mode = APP_IO_MODE_IT_LOW;
break;
default:
HDF_LOGE("%s, IRQ mode not support", __func__);
return HDF_ERR_INVALID_PARAM;
}
s_portCfg[gpio].irqFunc = func;
s_portCfg[gpio].arg = arg;
gpiote_param.mode = s_portCfg[gpio].mode;
gpiote_param.io_evt_cb = app_io_callback;
Gr55xxGpioteDebug(__func__, &gpiote_param);
//app_gpiote_init(&gpiote_param, 1);
HDF_LOGI("%s: io irq(%u@%p) registered!", __func__, gpio, func);
return HDF_SUCCESS;
}
static int32_t Gr55xxGpioUnsetIrq(struct GpioCntlr *cntlr, uint16_t gpio)
{
uint32_t pin = 0;
app_io_type_t io_type;
app_gpiote_param_t gpiote_param;
if (gpio >= GR55_IO_NUM_MAX)
{
return HDF_ERR_INVALID_PARAM;
}
if (NULL == s_portCfg[gpio].irqFunc)
{
return HDF_SUCCESS;
}
s_portCfg[gpio].irqFunc = NULL;
s_portCfg[gpio].arg = NULL;
io_type = Gr55xxPinMap(gpio, &pin);
gpiote_param.type = io_type;
gpiote_param.pin = pin;
gpiote_param.mode = s_portCfg[gpio].mode;
gpiote_param.pull = s_portCfg[gpio].pull;
gpiote_param.handle_mode = APP_IO_NONE_WAKEUP;
gpiote_param.io_evt_cb = NULL;
Gr55xxGpioteDebug(__func__, &gpiote_param);
app_gpiote_init(&gpiote_param, 1);
return HDF_SUCCESS;
}
static struct GpioMethod g_method = {
.request = NULL,
.release = NULL,
.write = Gr55xxGpioWrite,
.read = Gr55xxGpioRead,
.setDir = Gr55xxGpioSetDir,
.getDir = Gr55xxGpioGetDir,
.toIrq = NULL,
.setIrq = Gr55xxGpioSetIrq,
.unsetIrq = Gr55xxGpioUnsetIrq,
.enableIrq = Gr55xxGpioEnableIrq,
.disableIrq = Gr55xxGpioDisableIrq,
};
static int32_t Gr55xxGpioInitCntlrMem(struct Gr55xxGpioCntlr *gr55Gpio)
{
(void)gr55Gpio;
return HDF_SUCCESS;
}
static void Gr55xxGpioRleaseCntlrMem(struct Gr55xxGpioCntlr *gr55Gpio)
{
(void)gr55Gpio;
}
static int32_t Gr55xxGpioReadDrs(struct Gr55xxGpioCntlr *gr55Gpio, const struct DeviceResourceNode *node)
{
int32_t ret;
uint16_t configNum = 0;
uint16_t gpioIndex;
uint16_t pullConfig;
uint16_t handleModeConfig;
struct DeviceResourceIface *drsOps = NULL;
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint16ArrayElem == NULL) {
HDF_LOGE("%s: invalid drs ops fail!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint16(node, "configNum", &configNum, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read configNum fail!", __func__);
return ret;
}
if (configNum >= GR55_IO_NUM_MAX) {
HDF_LOGE("%s: configNum(%d) invalid!", __func__, configNum);
return HDF_ERR_INVALID_PARAM;
}
for (size_t i = 0; i < configNum; i++)
{
ret = drsOps->GetUint16ArrayElem(node, "gpioIndex", i, &gpioIndex, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read gpioIndex fail!", __func__);
return ret;
}
ret = drsOps->GetUint16ArrayElem(node, "pull", i, &pullConfig, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read regStep fail!", __func__);
return ret;
}
ret = drsOps->GetUint16ArrayElem(node, "handleMode", i, &handleModeConfig, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read handleModeConfig fail!", __func__);
return ret;
}
if (gpioIndex >= GR55_IO_NUM_MAX) {
HDF_LOGE("%s: gpioIndex(%d) invalid!", __func__, gpioIndex);
return HDF_ERR_INVALID_PARAM;
}
if (pullConfig >= APP_IO_PULL_MAX) {
HDF_LOGE("%s: pullConfig(%d) invalid!", __func__, pullConfig);
return HDF_ERR_INVALID_PARAM;
}
if (handleModeConfig > APP_IO_ENABLE_WAKEUP) {
HDF_LOGE("%s: handleModeConfig(%d) invalid!", __func__, handleModeConfig);
return HDF_ERR_INVALID_PARAM;
}
s_portCfg[gpioIndex].pull = pullConfig;
s_portCfg[gpioIndex].handleMode = handleModeConfig;
}
return HDF_SUCCESS;
}
static void Gr55xxGpioDebugCntlr(const struct Gr55xxGpioCntlr *gr55Gpio)
{
(void)gr55Gpio;
}
static int32_t GR55xxGpioBind(struct HdfDeviceObject *device)
{
(void)device;
HDF_LOGI("%s: Enter", __func__);
return HDF_SUCCESS;
}
static int32_t GR55xxGpioInit(struct HdfDeviceObject *device)
{
int32_t ret;
struct Gr55xxGpioCntlr *gr55Gpio = &s_gr55xxGpioCntlr;
HDF_LOGI("%s: Enter", __func__);
if (device == NULL || device->property == NULL) {
HDF_LOGE("%s: device or property null!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
Gr55xxPortConfigInit();
ret = Gr55xxGpioReadDrs(gr55Gpio, device->property);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read drs fail:%d", __func__, ret);
return ret;
}
ret = Gr55xxGpioInitCntlrMem(gr55Gpio);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: err init cntlr mem:%d", __func__, ret);
return ret;
}
gr55Gpio->cntlr.count = GR55_IO_NUM_MAX;
gr55Gpio->cntlr.priv = (void *)device->property;
gr55Gpio->cntlr.ops = &g_method;
gr55Gpio->cntlr.device.hdfDev = device;
ret = GpioCntlrAdd(&gr55Gpio->cntlr);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: err add controller:%d", __func__, ret);
return ret;
}
Gr55xxGpioDebugCntlr(gr55Gpio);
HDF_LOGI("%s: dev service:%s init success!", __func__, HdfDeviceGetServiceName(device));
return HDF_SUCCESS;
}
static void GR55xxGpioRelease(struct HdfDeviceObject *device)
{
struct GpioCntlr *cntlr = NULL;
struct Gr55xxGpioCntlr *gr55Gpio = NULL;
HDF_LOGI("%s, Enter\r\n", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is null!", __func__);
return;
}
cntlr = GpioCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("%s: no service binded!", __func__);
return;
}
GpioCntlrRemove(cntlr);
app_gpiote_deinit();
gr55Gpio = ToGr55xxGpioCntlr(cntlr);
Gr55xxGpioRleaseCntlrMem(gr55Gpio);
}
struct HdfDriverEntry g_gpioDriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_GPIO",
.Bind = GR55xxGpioBind,
.Init = GR55xxGpioInit,
.Release = GR55xxGpioRelease,
};
HDF_INIT(g_gpioDriverEntry);
+22
View File
@@ -0,0 +1,22 @@
# Copyright (c) 2021 GOODIX.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
import("../drivers.gni")
static_library("uart") {
sources = [ "uart_gr55xx.c" ]
include_dirs = hdf_include_dirs
}
+681
View File
@@ -0,0 +1,681 @@
/*
* Copyright (c) 2021 GOODIX.
* 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 "los_sem.h"
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "osal_time.h"
#include "uart/uart_core.h"
#include "uart_if.h"
#include "uart_gr55xx.h"
#define HDF_LOG_TAG uart_gr55xx
// #define HDF_LOGI printf
// #define HDF_LOGE printf
// #define GR55_UART_DEBUG
static uint32_t uart_rx_sem[APP_UART_ID_MAX];
static uint32_t uart_tx_mutex[APP_UART_ID_MAX];
static uint32_t uart_rx_mutex[APP_UART_ID_MAX];
static uint32_t g_rx_num[APP_UART_ID_MAX];
static void app_uart0_callback(app_uart_evt_t *p_evt);
static void app_uart1_callback(app_uart_evt_t *p_evt);
static void Gr55xxUartDeviceDump(struct UartDriverData *udd);
static const app_uart_evt_handler_t *evt_handler[APP_UART_ID_MAX] = {
app_uart0_callback,
app_uart1_callback
};
static void app_uart0_callback(app_uart_evt_t *p_evt)
{
if (p_evt->type == APP_UART_EVT_RX_DATA) {
g_rx_num[APP_UART_ID_0] = p_evt->data.size;
LOS_SemPost(uart_rx_sem[APP_UART_ID_0]);
} else if (p_evt->type == APP_UART_EVT_ERROR) {
LOS_SemPost(uart_rx_sem[APP_UART_ID_0]);
}
}
static void app_uart1_callback(app_uart_evt_t *p_evt)
{
if (p_evt->type == APP_UART_EVT_RX_DATA) {
g_rx_num[APP_UART_ID_1] = p_evt->data.size;
LOS_SemPost(uart_rx_sem[APP_UART_ID_1]);
} else if (p_evt->type == APP_UART_EVT_ERROR) {
LOS_SemPost(uart_rx_sem[APP_UART_ID_1]);
}
}
static int32_t Gr55xxUartConfig(struct UartDriverData *udd)
{
uint32_t ret;
app_uart_params_t *params = NULL;
if (NULL == udd)
return HDF_FAILURE;
params = &udd->params;
params->id = udd->id;
params->init.baud_rate = udd->baudrate;
switch (udd->attr.dataBits)
{
case UART_ATTR_DATABIT_5:
params->init.data_bits = UART_DATABITS_5;
break;
case UART_ATTR_DATABIT_6:
params->init.data_bits = UART_DATABITS_6;
break;
case UART_ATTR_DATABIT_7:
params->init.data_bits = UART_DATABITS_7;
break;
case UART_ATTR_DATABIT_8:
default:
params->init.data_bits = UART_DATABITS_8;
break;
}
switch (udd->attr.stopBits)
{
default:
case UART_ATTR_STOPBIT_1:
params->init.stop_bits = UART_STOPBITS_1;
break;
case UART_ATTR_STOPBIT_1P5:
params->init.stop_bits = UART_STOPBITS_1_5;
break;
case UART_ATTR_STOPBIT_2:
params->init.stop_bits = UART_STOPBITS_2;
break;
}
switch (udd->attr.parity)
{
default:
case UART_ATTR_PARITY_NONE:
params->init.parity = UART_PARITY_NONE;
break;
case UART_ATTR_PARITY_ODD:
params->init.parity = UART_PARITY_ODD;
break;
case UART_ATTR_PARITY_EVEN:
params->init.parity = UART_PARITY_EVEN;
break;
}
ret = app_uart_init(params, udd->eventCallback, &udd->txBuffer);
if (ret != 0) {
HDF_LOGE("%s , app uart init failed\r\n", __func__);
return HDF_FAILURE;
}
Gr55xxUartDeviceDump(udd);
return HDF_SUCCESS;
}
static int32_t Gr55xxRead(struct UartHost *host, uint8_t *data, uint32_t size)
{
int32_t ret;
uint32_t uwRet = 0;
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if (udd->state != UART_STATE_USEABLE) {
return HDF_FAILURE;
}
LOS_MuxPend(uart_rx_mutex[udd->id], LOS_WAIT_FOREVER);
g_rx_num[udd->id] = 0;
LOS_SemPend(uart_rx_sem[udd->id], 0);
ret = app_uart_receive_async(udd->id, data, size);
if (ret != 0) {
LOS_MuxPost(uart_rx_mutex[udd->id]);
return HDF_FAILURE;
}
uwRet = LOS_SemPend(uart_rx_sem[udd->id], LOS_WAIT_FOREVER);
if (uwRet != LOS_OK) {
LOS_MuxPost(uart_rx_mutex[udd->id]);
return HDF_FAILURE;
}
LOS_MuxPost(uart_rx_mutex[udd->id]);
return g_rx_num[udd->id];
}
static int32_t Gr55xxWrite(struct UartHost *host, uint8_t *data, uint32_t size)
{
int32_t ret;
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if (udd->state != UART_STATE_USEABLE) {
return HDF_FAILURE;
}
LOS_MuxPend(uart_tx_mutex[udd->id], LOS_WAIT_FOREVER);
ret = app_uart_transmit_sync(udd->id, data, size, 1000);
if (ret != 0) {
LOS_MuxPost(uart_tx_mutex[udd->id]);
HDF_LOGE("uart_%d send %d data failed", udd->id, size);
return HDF_FAILURE;
}
LOS_MuxPost(uart_tx_mutex[udd->id]);
HDF_LOGI("uart_%d send %d data success", udd->id, size);
return HDF_SUCCESS;
}
static int32_t Gr55xxGetBaud(struct UartHost *host, uint32_t *baudRate)
{
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL || baudRate == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if (udd->state != UART_STATE_USEABLE) {
return HDF_FAILURE;
}
*baudRate = udd->baudrate;
return HDF_SUCCESS;
}
static int32_t Gr55xxSetBaud(struct UartHost *host, uint32_t baudRate)
{
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if (udd->state != UART_STATE_USEABLE) {
return HDF_FAILURE;
}
if ((baudRate > 0) && (baudRate <= CONFIG_MAX_BAUDRATE)) {
udd->baudrate = baudRate;
if (udd->config == NULL) {
HDF_LOGE("%s: not support", __func__);
return HDF_ERR_NOT_SUPPORT;
}
if (udd->config(udd) != HDF_SUCCESS) {
HDF_LOGE("%s: config baudrate %d failed", __func__, baudRate);
return HDF_FAILURE;
}
} else {
HDF_LOGE("%s: invalid baudrate, which is:%d", __func__, baudRate);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t Gr55xxGetAttribute(struct UartHost *host, struct UartAttribute *attribute)
{
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL || attribute == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if (udd->state != UART_STATE_USEABLE) {
return HDF_FAILURE;
}
*attribute = udd->attr;
return HDF_SUCCESS;
}
static int32_t Gr55xxSetAttribute(struct UartHost *host, struct UartAttribute *attribute)
{
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL || attribute == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if (udd->state != UART_STATE_USEABLE) {
return HDF_FAILURE;
}
udd->attr = *attribute;
if (udd->config == NULL) {
HDF_LOGE("%s: not support", __func__);
return HDF_ERR_NOT_SUPPORT;
}
if (udd->config(udd) != HDF_SUCCESS) {
HDF_LOGE("%s: config failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t Gr55xxSetTransMode(struct UartHost *host, enum UartTransMode mode)
{
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if (udd->state != UART_STATE_USEABLE) {
return HDF_FAILURE;
}
if (mode == UART_MODE_RD_BLOCK) {
udd->flags |= UART_FLG_RD_BLOCK;
} else if (mode == UART_MODE_RD_NONBLOCK) {
// udd->flags &= ~UART_FLG_RD_BLOCK;
//only support block mode
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t Gr55xxInit(struct UartHost *host)
{
struct UartDriverData *udd = NULL;
uint32_t uwRet = 0;
uint8_t *ptx_buf = NULL;
if (host == NULL || host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if (udd->id >= APP_UART_ID_MAX)
return HDF_ERR_INVALID_PARAM;
if (udd->state == UART_STATE_NOT_OPENED) {
udd->state = UART_STATE_OPENING;
uwRet = LOS_BinarySemCreate(0, &uart_rx_sem[udd->id]);
if (uwRet != LOS_OK) {
return HDF_FAILURE;
}
uwRet = LOS_MuxCreate(&uart_tx_mutex[udd->id]);
if (uwRet != LOS_OK) {
LOS_SemDelete(&uart_rx_sem[udd->id]);
return HDF_FAILURE;
}
uwRet = LOS_MuxCreate(&uart_rx_mutex[udd->id]);
if (uwRet != LOS_OK) {
LOS_SemDelete(uart_rx_sem[udd->id]);
LOS_SemDelete(uart_tx_mutex[udd->id]);
return HDF_FAILURE;
}
ptx_buf = (uint8_t *)OsalMemCalloc(TX_BUF_SIZE);
if (ptx_buf == NULL) {
HDF_LOGE("%s: alloc tx buffer failed", __func__);
LOS_SemDelete(uart_rx_sem[udd->id]);
LOS_SemDelete(uart_tx_mutex[udd->id]);
LOS_SemDelete(uart_rx_mutex[udd->id]);
return HDF_ERR_MALLOC_FAIL;
}
udd->txBuffer.tx_buf = ptx_buf;
udd->txBuffer.tx_buf_size = TX_BUF_SIZE;
udd->eventCallback = evt_handler[udd->id];
udd->config = Gr55xxUartConfig;
if (udd->config(udd) != HDF_SUCCESS) {
goto FREE_INITALED_PARA;
}
}
udd->state = UART_STATE_USEABLE;
udd->count++;
return HDF_SUCCESS;
FREE_INITALED_PARA:
LOS_SemDelete(uart_rx_sem[udd->id]);
LOS_SemDelete(uart_tx_mutex[udd->id]);
LOS_SemDelete(uart_rx_mutex[udd->id]);
(void)OsalMemFree(udd->txBuffer.tx_buf);
udd->txBuffer.tx_buf = NULL;
return HDF_FAILURE;
}
static int32_t Gr55xxDeinit(struct UartHost *host)
{
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
udd = (struct UartDriverData *)host->priv;
if ((--udd->count) != 0) {
return HDF_SUCCESS;
}
LOS_SemDelete(uart_rx_sem[udd->id]);
LOS_SemDelete(uart_tx_mutex[udd->id]);
LOS_SemDelete(uart_rx_mutex[udd->id]);
if (NULL != udd->txBuffer.tx_buf) {
(void)OsalMemFree(udd->txBuffer.tx_buf);
udd->txBuffer.tx_buf = NULL;
}
udd->state = UART_STATE_NOT_OPENED;
return HDF_SUCCESS;
}
static int32_t Gr55xxPollEvent(struct UartHost *host, void *filep, void *table)
{
struct UartDriverData *udd = NULL;
if (host == NULL || host->priv == NULL) {
HDF_LOGE("%s: host is NULL", __func__);
return HDF_FAILURE;
}
udd = (struct UartDriverData *)host->priv;
if (UART_STATE_USEABLE != udd->state) {
return HDF_FAILURE;
}
return 0;
}
struct UartHostMethod g_uartHostMethod = {
.Init = Gr55xxInit,
.Deinit = Gr55xxDeinit,
.Read = Gr55xxRead,
.Write = Gr55xxWrite,
.SetBaud = Gr55xxSetBaud,
.GetBaud = Gr55xxGetBaud,
.SetAttribute = Gr55xxSetAttribute,
.GetAttribute = Gr55xxGetAttribute,
.SetTransMode = Gr55xxSetTransMode,
.pollEvent = Gr55xxPollEvent,
};
static int32_t UartGetConfigFromHcs(struct UartDriverData *udd, const struct DeviceResourceNode *node)
{
uint32_t rcData;
struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (iface == NULL || iface->GetUint32 == NULL) {
HDF_LOGE("%s: face is invalid", __func__);
return HDF_FAILURE;
}
if (iface->GetUint32(node, "id", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read id fail", __func__);
return HDF_FAILURE;
}
udd->id = rcData;
if (iface->GetUint32(node, "baudrate", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read baudrate fail", __func__);
return HDF_FAILURE;
}
udd->baudrate = rcData;
if (iface->GetUint32(node, "pin_tx_type", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read pin_tx_type fail", __func__);
return HDF_FAILURE;
}
udd->params.pin_cfg.tx.type = rcData;
if (iface->GetUint32(node, "pin_tx_pin", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read pin_tx_pin fail", __func__);
return HDF_FAILURE;
}
udd->params.pin_cfg.tx.pin = (1 << rcData);
if (iface->GetUint32(node, "pin_tx_mux", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read pin_tx_pin fail", __func__);
return HDF_FAILURE;
}
udd->params.pin_cfg.tx.mux = rcData;
if (iface->GetUint32(node, "pin_tx_pull", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read pin_tx_pin fail", __func__);
return HDF_FAILURE;
}
udd->params.pin_cfg.tx.pull = rcData;
if (iface->GetUint32(node, "pin_rx_type", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read pin_rx_type fail", __func__);
return HDF_FAILURE;
}
udd->params.pin_cfg.rx.type = rcData;
if (iface->GetUint32(node, "pin_rx_pin", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read pin_rx_pin fail", __func__);
return HDF_FAILURE;
}
udd->params.pin_cfg.rx.pin = (1 << rcData);
if (iface->GetUint32(node, "pin_rx_mux", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read pin_rx_pin fail", __func__);
return HDF_FAILURE;
}
udd->params.pin_cfg.rx.mux = rcData;
if (iface->GetUint32(node, "pin_rx_pull", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read pin_rx_pin fail", __func__);
return HDF_FAILURE;
}
udd->params.pin_cfg.rx.pull = rcData;
if (iface->GetUint32(node, "use_mode_type", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read use_mode_type fail", __func__);
return HDF_FAILURE;
}
udd->params.use_mode.type = rcData;
if (iface->GetUint32(node, "use_mode_tx_dma_ch", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read use_mode_tx_dma_ch fail", __func__);
return HDF_FAILURE;
}
udd->params.use_mode.tx_dma_channel = rcData;
if (iface->GetUint32(node, "use_mode_rx_dma_ch", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read use_mode_rx_dma_ch fail", __func__);
return HDF_FAILURE;
}
udd->params.use_mode.rx_dma_channel = rcData;
if (iface->GetUint32(node, "rx_timeout_mode", &rcData, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read rx_timeout_mode fail", __func__);
return HDF_FAILURE;
}
udd->params.init.rx_timeout_mode = rcData;
return HDF_SUCCESS;
}
static void Gr55xxUartDeviceDump(struct UartDriverData *udd)
{
#ifdef GR55_UART_DEBUG
if (NULL == udd) {
HDF_LOGI("%s > dump error\r\n", __func__);
}
HDF_LOGI("%s > udd.id: %d\r\n", __func__, udd->id);
HDF_LOGI("%s > udd.baudrate: %d\r\n", __func__, udd->baudrate);
HDF_LOGI("%s > udd.count: %d\r\n", __func__, udd->count);
HDF_LOGI("%s > udd.state: %d\r\n", __func__, udd->state);
HDF_LOGI("%s > params.id: %d\r\n", __func__, udd->params.id);
HDF_LOGI("%s > params.init.baud_rate: %d\r\n", __func__, udd->params.init.baud_rate);
HDF_LOGI("%s > params.init.data_bits: %d\r\n", __func__, udd->params.init.data_bits);
HDF_LOGI("%s > params.init.hw_flow_ctrl: %d\r\n", __func__, udd->params.init.hw_flow_ctrl);
HDF_LOGI("%s > params.init.parity: %d\r\n", __func__, udd->params.init.parity);
HDF_LOGI("%s > params.init.rx_timeout_mode: %d\r\n", __func__, udd->params.init.rx_timeout_mode);
HDF_LOGI("%s > params.init.stop_bits: %d\r\n", __func__, udd->params.init.stop_bits);
HDF_LOGI("%s > params.pin_cfg.tx.mux: %d\r\n", __func__, udd->params.pin_cfg.tx.mux);
HDF_LOGI("%s > params.pin_cfg.tx.pin: %d\r\n", __func__, udd->params.pin_cfg.tx.pin);
HDF_LOGI("%s > params.pin_cfg.tx.pull: %d\r\n", __func__, udd->params.pin_cfg.tx.pull);
HDF_LOGI("%s > params.pin_cfg.tx.type: %d\r\n", __func__, udd->params.pin_cfg.tx.type);
HDF_LOGI("%s > params.pin_cfg.rx.mux: %d\r\n", __func__, udd->params.pin_cfg.rx.mux);
HDF_LOGI("%s > params.pin_cfg.rx.pin: %d\r\n", __func__, udd->params.pin_cfg.rx.pin);
HDF_LOGI("%s > params.pin_cfg.rx.pull: %d\r\n", __func__, udd->params.pin_cfg.rx.pull);
HDF_LOGI("%s > params.pin_cfg.rx.type: %d\r\n", __func__, udd->params.pin_cfg.rx.type);
HDF_LOGI("%s > params.use_mode.type: %d\r\n", __func__, udd->params.use_mode.type);
#else
(void)udd;
#endif
}
static int32_t Gr55xxAttach(struct UartHost *host, struct HdfDeviceObject *device)
{
int32_t ret;
struct UartDriverData *udd = NULL;
if (device->property == NULL) {
HDF_LOGE("%s: property is null", __func__);
return HDF_FAILURE;
}
udd = (struct UartDriverData *)OsalMemCalloc(sizeof(*udd));
if (udd == NULL) {
HDF_LOGE("%s: OsalMemCalloc udd error", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = UartGetConfigFromHcs(udd, device->property);
if (ret != HDF_SUCCESS || udd->id >= APP_UART_ID_MAX) {
(void)OsalMemFree(udd);
return HDF_FAILURE;
}
udd->state = UART_STATE_NOT_OPENED;
udd->config = NULL;
udd->eventCallback = NULL;
udd->count = 0;
udd->params.id = udd->id;
udd->params.init.baud_rate = udd->baudrate;
udd->attr.dataBits = DEFAULT_DATABITS;
udd->attr.stopBits = DEFAULT_STOPBITS;
udd->attr.parity = DEFAULT_PARITY;
host->priv = udd;
host->num = udd->id;
// UartAddDev(host);
return HDF_SUCCESS;
}
static void Gr55xxDetach(struct UartHost *host)
{
struct UartDriverData *udd = NULL;
if (host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return;
}
udd = (struct UartDriverData *)host->priv;
if (udd->state != UART_STATE_NOT_OPENED) {
HDF_LOGE("%s: uart driver data state invalid", __func__);
return;
}
// UartRemoveDev(host);
(void)OsalMemFree(udd);
host->priv = NULL;
}
static int32_t HdfUartDeviceBind(struct HdfDeviceObject *device)
{
HDF_LOGI("%s: enter\r\n", __func__);
if (device == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
return (UartHostCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
}
int32_t HdfUartDeviceInit(struct HdfDeviceObject *device)
{
int32_t ret;
struct UartHost *host = NULL;
HDF_LOGI("%s: enter\r\n", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = UartHostFromDevice(device);
if (host == NULL) {
HDF_LOGE("%s: host is null", __func__);
return HDF_FAILURE;
}
ret = Gr55xxAttach(host, device);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: attach error", __func__);
return HDF_FAILURE;
}
host->method = &g_uartHostMethod;
return ret;
}
void HdfUartDeviceRelease(struct HdfDeviceObject *device)
{
struct UartHost *host = NULL;
HDF_LOGI("%s: enter", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is null", __func__);
return;
}
host = UartHostFromDevice(device);
if (host == NULL) {
HDF_LOGE("%s: host is null", __func__);
return;
}
if (host->priv != NULL) {
Gr55xxDetach(host);
}
UartHostDestroy(host);
}
struct HdfDriverEntry g_hdfUartDevice = {
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_UART",
.Bind = HdfUartDeviceBind,
.Init = HdfUartDeviceInit,
.Release = HdfUartDeviceRelease,
};
HDF_INIT(g_hdfUartDevice);
+67
View File
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2021 GOODIX.
* 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 UART_GR55XX_H
#define UART_GR55XX_H
#include "poll.h"
#include "uart_if.h"
#include "app_uart.h"
#include "app_io.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
struct UartDriverData;
typedef int32_t (*app_uart_cfg_handler_t)(struct UartDriverData *udd);
#define DEFAULT_BAUDRATE 115200
#define DEFAULT_DATABITS UART_ATTR_DATABIT_8
#define DEFAULT_STOPBITS UART_ATTR_STOPBIT_1
#define DEFAULT_PARITY UART_ATTR_PARITY_NONE
#define CONFIG_MAX_BAUDRATE 921600
#define TX_BUF_SIZE 0X100
struct UartDriverData {
uint32_t id;
uint32_t baudrate;
int32_t count;
struct UartAttribute attr;
app_uart_params_t params;
app_uart_evt_handler_t eventCallback;
app_uart_cfg_handler_t config;
app_uart_tx_buf_t txBuffer;
int32_t state;
#define UART_STATE_NOT_OPENED 0
#define UART_STATE_OPENING 1
#define UART_STATE_USEABLE 2
#define UART_STATE_SUSPENED 3
uint32_t flags;
#define UART_FLG_DMA_RX (1 << 0)
#define UART_FLG_DMA_TX (1 << 1)
#define UART_FLG_RD_BLOCK (1 << 2)
};
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* UART_PL011_H */
+19
View File
@@ -0,0 +1,19 @@
# Copyright (c) 2021 GOODIX.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
# module_name = "hdf_hcs"
# hdf_driver(module_name) {
# hcs_sources = [ "hdf.hcs" ]
# }
+53
View File
@@ -0,0 +1,53 @@
root {
module = "goodix,gr551x";
device_info {
match_attr = "hdf_manager";
template host {
hostName = "";
priority = 100;
template device {
template deviceNode {
policy = 0;
priority = 100;
preload = 0;
permission = 0664;
moduleName = "";
serviceName = "";
deviceMatchAttr = "";
}
}
}
platform :: host {
hostName = "platform_host";
priority = 50;
device_gpio :: device {
device0 :: deviceNode {
policy = 0;
priority = 10;
permission = 0644;
moduleName = "HDF_PLATFORM_GPIO";
serviceName = "HDF_PLATFORM_GPIO";
deviceMatchAttr = "goodix_gr55xx_gpio";
}
}
device_uart :: device {
device0 :: deviceNode {
policy = 1;
priority = 40;
permission = 0644;
moduleName = "HDF_PLATFORM_UART";
serviceName = "HDF_PLATFORM_UART_0";
deviceMatchAttr = "goodix_gr55xx_uart_0";
}
device1 :: deviceNode {
policy = 2;
permission = 0644;
priority = 40;
moduleName = "HDF_PLATFORM_UART";
serviceName = "HDF_PLATFORM_UART_1";
deviceMatchAttr = "goodix_gr55xx_uart_1";
}
}
}
}
}
+12
View File
@@ -0,0 +1,12 @@
root {
platform {
gpio_config {
match_attr = "goodix_gr55xx_gpio";
configNum = 1;
gpioIndex = [0];
pull = [0];
handleMode = [0];
}
}
}
+3 -39
View File
@@ -1,39 +1,3 @@
#include "device_info.hcs"
root {
platform {
gpio_config {
match_attr = "gpio_config";
pin = [0, 1];
realPin = [5, 27];
config = [5, 2];
pinNum = 2;
}
i2c_config {
i2c0 {
match_attr = "i2c0_config";
port = 0;
speed = 200000;
scl_pin = 4;
sda_pin = 5;
use_dma = 0;
use_sync = 1;
as_master = 1;
address_width = 8;
mode = 0;
}
i2c1 {
match_attr = "i2c1_config";
port = 1;
speed = 200000;
scl_pin = 6;
sda_pin = 7;
use_dma = 0;
use_sync = 1;
as_master = 1;
address_width = 8;
mode = 0;
}
}
}
}
#include "device_info/device_info.hcs"
#include "gpio/gpio_config.hcs"
#include "uart/uart_config.hcs"
+63
View File
@@ -0,0 +1,63 @@
root {
platform {
template uart_controller {
match_attr = "";
id = 0;
baudrate = 115200;
pin_tx_type = 0;
pin_tx_pin = 0;
pin_tx_mux = 0;
pin_tx_pull = 0;
pin_rx_type = 0;
pin_rx_pin = 0;
pin_rx_mux = 0;
pin_rx_pull = 0;
use_mode_type = 0;
use_mode_tx_dma_ch = 0;
use_mode_rx_dma_ch = 0;
rx_timeout_mode = 1;
}
controller_uart0 :: uart_controller {
match_attr = "goodix_gr55xx_uart_0";
id = 0; /* APP_UART_ID_0 */
baudrate = 115200;
pin_tx_type = 0; /* APP_IO_TYPE_NORMAL */
pin_tx_pin = 10; /* APP_IO_PIN_10 */
pin_tx_mux = 2; /* APP_IO_MUX_2 */
pin_tx_pull = 1; /* APP_IO_PULLUP */
pin_rx_type = 0; /* APP_IO_TYPE_NORMAL */
pin_rx_pin = 11; /* APP_IO_PIN_11 */
pin_rx_mux = 2; /* APP_IO_MUX_2 */
pin_rx_pull = 1; /* APP_IO_PULLUP */
use_mode_type = 0; /* APP_UART_TYPE_INTERRUPT */
use_mode_tx_dma_ch = 0; /* DMA_Channel0 */
use_mode_rx_dma_ch = 1; /* DMA_Channel1 */
rx_timeout_mode = 1; /* UART_RECEIVER_TIMEOUT_ENABLE */
}
controller_uart1 :: uart_controller {
match_attr = "goodix_gr55xx_uart_1";
id = 1; /* APP_UART_ID_1 */
baudrate = 115200;
pin_tx_type = 0; /* APP_IO_TYPE_NORMAL */
pin_tx_pin = 9; /* APP_IO_PIN_7 */
pin_tx_mux = 3; /* APP_IO_MUX_3 */
pin_tx_pull = 1; /* APP_IO_PULLUP */
pin_rx_type = 0; /* APP_IO_TYPE_NORMAL */
pin_rx_pin = 8; /* APP_IO_PIN_6 */
pin_rx_mux = 3; /* APP_IO_MUX_3 */
pin_rx_pull = 1; /* APP_IO_PULLUP */
use_mode_type = 0; /* APP_UART_TYPE_INTERRUPT */
rx_timeout_mode = 1; /* UART_RECEIVER_TIMEOUT_ENABLE */
}
}
}
-182
View File
@@ -1,182 +0,0 @@
# Copyright (c) 2021 GOODIX.
# 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.
# Kernel type, e.g. "linux", "liteos_a", "liteos_m".
kernel_type = "liteos_m"
# Kernel version.
kernel_version = "3.0.0"
# Board CPU type, e.g. "cortex-a7", "riscv32".
board_cpu = "cortex-m4"
# Board arch, e.g. "armv7-a", "rv32imac".
board_arch = ""
# Toolchain name used for system compiling.
# E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf.
# Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toochain.
board_toolchain = "arm-none-eabi-gcc"
use_board_toolchain = true
# The toolchain path instatlled, it's not mandatory if you have added toolchian path to your ~/.bashrc.
board_toolchain_path = ""
# Compiler prefix.
board_toolchain_prefix = "arm-none-eabi-"
# Compiler type, "gcc" or "clang".
board_toolchain_type = "gcc"
# Board related common compile flags.
board_cflags = [
"-std=c99",
"--inline",
"-ggdb",
"-O1",
"-ffunction-sections",
"-fdata-sections",
"-mfloat-abi=softfp",
"-mfpu=fpv4-sp-d16",
"-mapcs-frame",
"-mcpu=cortex-m4",
"-mthumb",
"-mthumb-interwork",
"-gdwarf-2",
"-MD",
"-fno-stack-protector",
"-DAPP_LFS_BLOCK_COUNT=10",
]
board_cxx_flags = [ ]
board_ld_flags = [
"-nostartfiles",
"-mcpu=cortex-m4",
"-mfloat-abi=softfp",
"-mfpu=fpv4-sp-d16",
"-mapcs-frame",
"-mthumb",
"-mthumb-interwork",
"-Wl,--gc-sections",
"-Wl,--start-group",
"-Llibs",
"-lmusl-c",
"-lmusl-m",
"-Wl,--whole-archive",
"-lhuks_3.0_sdk",
"-larch",
"-lbootstrap",
"-lexchook",
"-lsamgr",
"-lsamgr_adapter",
"-lsysparam",
"-ltoken_static",
"-lbroadcast",
"-lhilog_lite",
"-lhiview_lite",
"-lkernel",
"-lsamgr_source",
"-lutils",
"-lcmsis",
"-lhal_sysparam",
"-lposix",
"-lbacktrace",
"-lcpup",
"-lhal_token_static",
"-lutils_kv_store",
"-lble_sdk",
"-lhilinkbtsdk",
"-lhichain_account",
"-Wl,--no-whole-archive",
"-Wl,--end-group",
"-Tbin/link.ld",
"-Trom_symbol_gcc.txt",
"-Wl,-Map=bin/application.map",
]
# Board related headfiles search path.
board_include_dirs = [
"//kernel/liteos_m/kernel/arch/arm/cortex-m4/gcc",
"//kernel/liteos_m/kernel/arch/include",
"//kernel/liteos_m/kernel/include",
"//kernel/liteos_m/kal/cmsis",
"//kernel/liteos_m/kal/posix/include",
"//kernel/liteos_m/utils",
"//kernel/liteos_m/components/exchook",
"//utils/native/lite/kal/timer",
"//utils/native/lite/include",
"//kernel/liteos_m/components/fs/fatfs",
"//third_party/FatFs/source",
"//third_party/cmsis/CMSIS/Core/Include",
"//third_party/musl/porting/liteos_m/kernel/include",
"//third_party/bounds_checking_function/include",
"//third_party/openssl",
"//third_party/openssl/include",
"//third_party/openssl/crypto/include",
"//third_party/openssl/crypto/ec",
"//third_party/mbedtls/include",
"//foundation/communication/bluetooth/interfaces/innerkits/native_c/include",
"//device/goodix/gr551x/sdk_liteos/platform/include",
"//device/goodix/gr551x/adapter/hals/bluetooth",
"//device/goodix/gr551x/components/hilink/include",
"//device/goodix/gr551x/sdk_liteos/config",
"//device/goodix/gr551x/sdk_liteos/liteos_m",
"//device/goodix/gr551x/components/watchdog",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/app_drivers/inc",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/boards",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/drivers_ext/gr551x",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/drivers_ext/st7735",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/drivers_ext/vs1005",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/app_lfs",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/app_alarm",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/app_assert",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/app_error",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/app_key",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/app_log",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/app_queue",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/app_timer",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/at_cmd",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/bsp",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/dfu_master",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/dfu_port",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/gui",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/gui/gui_config",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/hal_flash",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/hci_uart",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/pmu_calibration",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/ring_buffer",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/sensorsim",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/libraries/utility",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/patch/ind",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/components/sdk/",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/drivers/inc",
"//device/goodix/gr551x/sdk_liteos/gr551x_sdk/toolchain/gr551x/include",
]
# Board adapter dir for OHOS components.
board_adapter_dir = ""
# Sysroot path.
board_configed_sysroot = ""
# Board storage type, it used for file system generation.
storage_type = ""
+2 -2
View File
@@ -172,11 +172,11 @@
// <o> Code load address
// <i> Default: 0x01002000
#define APP_CODE_LOAD_ADDR 0x01002000
#define APP_CODE_LOAD_ADDR 0x0100b000
// <o> Code run address
// <i> Default: 0x01002000
#define APP_CODE_RUN_ADDR 0x01002000
#define APP_CODE_RUN_ADDR 0x0100b000
// <ol.0..5> System clock
// <0=> 64MHZ
View File
@@ -0,0 +1,225 @@
/**
****************************************************************************************
*
* @file gr551x_adc_voltage_api.c
*
* @brief GR551x ADC voltage module.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <math.h>
#include "gr55xx_hal.h"
#include "gr55xx_sys.h"
#include "gr551x_adc_voltage_api.h"
/*
* DEFINE
*****************************************************************************************
*/
#define ADC_UNUSED_CONV_LENGTH (16UL) /**< Invaild calibrated buffer. */
#define ADC_USED_CONV_LENGTH (16UL) /**< Used calibrated buffer. */
/*
* STRUCTURES
*****************************************************************************************
*/
typedef struct {
uint32_t offset_int_0p8;
uint32_t slope_int_0p8;
uint32_t offset_int_1p2;
uint32_t slope_int_1p2;
uint32_t offset_int_1p6;
uint32_t slope_int_1p6;
uint32_t offset_int_2p0;
uint32_t slope_int_2p0;
uint32_t offset_ext_1p0;
uint32_t slope_ext_1p0;
} adc_trim_params_t;
/*
* GLOBAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
/*
* STATIC VARIABLE DEFINITIONS
*****************************************************************************************
*/
static uint32_t diff_int_vref = 0;
static uint16_t diff_int_offset = 0;
static double diff_ext_vref = 0;
static uint16_t diff_ext_offset = 0;
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
static void load_trim_for_sdk(adc_trim_params_t *param)
{
adc_trim_info_t adc_trim = {0};
if(SDK_SUCCESS == sys_adc_trim_get(&adc_trim))
{
param->offset_int_0p8 = adc_trim.offset_int_0p8;
param->slope_int_0p8 = adc_trim.slope_int_0p8;
param->offset_int_1p2 = adc_trim.offset_int_1p2;
param->slope_int_1p2 = adc_trim.slope_int_1p2;
param->offset_int_1p6 = adc_trim.offset_int_1p6;
param->slope_int_1p6 = adc_trim.slope_int_1p6;
param->offset_int_2p0 = adc_trim.offset_int_2p0;
param->slope_int_2p0 = adc_trim.slope_int_2p0;
param->offset_ext_1p0 = adc_trim.offset_ext_1p0;
param->slope_ext_1p0 = adc_trim.slope_ext_1p0;
}
return;
}
static uint16_t diff_calculate_offset(adc_handle_t *hadc)
{
uint32_t sum = 0;
uint32_t adc_channel_n = 0;
uint32_t adc_channel_p = 0;
uint16_t conversion_avg = 0;
uint16_t conversion[ADC_UNUSED_CONV_LENGTH + ADC_USED_CONV_LENGTH] = {0};
adc_channel_n = hadc->init.channel_n;
adc_channel_p = hadc->init.channel_p;
hadc->init.channel_n = ADC_INPUT_SRC_REF;
hadc->init.channel_p = ADC_INPUT_SRC_REF;
hal_adc_deinit(hadc);
hal_adc_init(hadc);
hal_adc_poll_for_conversion(hadc, conversion, ADC_UNUSED_CONV_LENGTH + ADC_USED_CONV_LENGTH);
for(uint16_t i = ADC_UNUSED_CONV_LENGTH; i < ADC_UNUSED_CONV_LENGTH + ADC_USED_CONV_LENGTH; i++)
{
sum += conversion[i];
}
conversion_avg = sum / ADC_USED_CONV_LENGTH;
hadc->init.channel_n = adc_channel_n;
hadc->init.channel_p = adc_channel_p;
hal_adc_deinit(hadc);
hal_adc_init(hadc);
return (conversion_avg << 1);
}
void hal_gr551x_adc_voltage_intern(adc_handle_t *hadc, uint16_t *inbuf, double *outbuf, uint32_t buflen)
{
double cslope = 0, coffset = 0;
adc_trim_params_t trim = {0};
load_trim_for_sdk(&trim);
if (ADC_REF_VALUE_0P8 == hadc->init.ref_value)
{
coffset = (double)trim.offset_int_0p8;
cslope = (-1) * (double)trim.slope_int_0p8;
}
else if (ADC_REF_VALUE_1P2 == hadc->init.ref_value)
{
coffset = (double)trim.offset_int_1p2;
cslope = (-1) * (double)trim.slope_int_1p2;
}
else if (ADC_REF_VALUE_1P6 == hadc->init.ref_value)
{
coffset = (double)trim.offset_int_1p6;
cslope = (-1) * (double)trim.slope_int_1p6;
}
// else if (ADC_REF_VALUE_2P0 == hadc->init.ref_value)
// {
// coffset = (double)trim.offset_int_2p0;
// cslope = (-1) * (double)trim.slope_int_2p0;
// }
if (ADC_INPUT_SINGLE == hadc->init.input_mode)
{
for (uint32_t i = 0; i < buflen; i++)
{
outbuf[i] = ((double)inbuf[i] - coffset) / cslope;
}
}
else
{
if (diff_int_vref != hadc->init.ref_value)
{
diff_int_vref = hadc->init.ref_value;
diff_int_offset = diff_calculate_offset(hadc);
}
coffset = (double)diff_int_offset;
for (uint32_t i = 0; i < buflen; i++)
{
outbuf[i] = (coffset - (double)inbuf[i] * 2) / cslope;
}
}
return;
}
void hal_gr551x_adc_voltage_extern(adc_handle_t *hadc, double vref, uint16_t *inbuf, double *outbuf, uint32_t buflen)
{
double cslope = 0, coffset = 0;
adc_trim_params_t trim = {0};
load_trim_for_sdk(&trim);
if (ADC_INPUT_SINGLE == hadc->init.input_mode)
{
coffset = (double)trim.offset_ext_1p0;
cslope = ((-1) * (double)trim.slope_ext_1p0) * 1.0f / vref;
for (uint32_t i = 0; i < buflen; i++)
{
outbuf[i] = ((double)inbuf[i] - coffset) / cslope;
}
}
else
{
if (fabs(diff_ext_vref - vref) > 0.00001)
{
diff_ext_vref = vref;
diff_ext_offset = diff_calculate_offset(hadc);
}
coffset = (double)diff_ext_offset;
cslope = ((-1) * (double)trim.slope_ext_1p0) * 1.0f / vref;
for (uint32_t i = 0; i < buflen; i++)
{
outbuf[i] = (coffset - (double)inbuf[i] * 2) / cslope;
}
}
return;
}
@@ -0,0 +1,90 @@
/**
****************************************************************************************
*
* @file gr551x_adc_voltage_api.h
*
* @brief Header file - GR551x ADC voltage module.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************
*/
#ifndef __GR551X_ADC_VOLTAGE_API_H__
#define __GR551X_ADC_VOLTAGE_API_H__
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <stdint.h>
#include "gr55xx_hal_adc.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
/**
****************************************************************************************
* @brief Convert the ADC conversion results to a voltage value(internal reference).
*
* @param[in] hadc: Pointer to a ADC handle which contains the configuration information for
* the specified ADC module.
* @param[in] inbuf: Pointer to data buffer which storage ADC conversion results.
* @param[out] outbuf: Pointer to data buffer which to storage voltage results.
* @param[in] length: Length of data buffer, ranging between 0 and 4095.
*
* @return Result of operation.
****************************************************************************************
*/
void hal_gr551x_adc_voltage_intern(adc_handle_t *hadc, uint16_t *inbuf, double *outbuf, uint32_t buflen);
/**
****************************************************************************************
* @brief Convert the ADC conversion results to a voltage value(external reference).
*
* @param[in] hadc: Pointer to a ADC handle which contains the configuration information for
* the specified ADC module.
* @param[in] ref: slope of ADC.
* @param[in] inbuf: Pointer to data buffer which storage ADC conversion results.
* @param[out] outbuf: Pointer to data buffer which to storage voltage results.
* @param[in] length: Length of data buffer, ranging between 0 and 4095.
*
* @return Result of operation.
****************************************************************************************
*/
void hal_gr551x_adc_voltage_extern(adc_handle_t *hadc, double vref, uint16_t *inbuf, double *outbuf, uint32_t buflen);
#ifdef __cplusplus
}
#endif
#endif // __GR551X_ADC_VOLTAGE_API_H__
@@ -0,0 +1,647 @@
/**
****************************************************************************************
* @file gr551x_spi_flash.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <string.h>
#include "gr55xx_hal.h"
#include "gr551x_spi_flash.h"
/*
* DEFINES
*****************************************************************************************
*/
#define SPI_SPEED_1M (1000000)
#define SPI_SPEED_2M (2000000)
#define SPI_SPEED_4M (4000000)
#define SPI_SPEED_8M (8000000)
#define SPI_SPEED_16M (16000000)
#define SPI_SPEED_32M (32000000)
#define DEFAULT_QSPI_SPEED (SPI_SPEED_8M)
#define DEFAULT_QSPI_IO_CONFIG { { APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_15 }, { APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_9 },\
{ APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_8 }, { APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_14 },\
{ APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_13 }, { APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_12 } }
#define DEFAULT_QSPI_MODE_CONFIG { APP_QSPI_TYPE_DMA, DMA_Channel7 }
#define DEFAULT_QSPI_CONFIG { (SystemCoreClock / DEFAULT_QSPI_SPEED), QSPI_CLOCK_MODE_3, 0}
#define DEFAULT_QSPI_PARAM_CONFIG { APP_QSPI_ID_1, DEFAULT_QSPI_IO_CONFIG, DEFAULT_QSPI_MODE_CONFIG, DEFAULT_QSPI_CONFIG}
#define DEFAULT_SPIM_SPEED (SPI_SPEED_8M)
#define DEFAULT_SPIM_IO_CONFIG {{APP_IO_TYPE_NORMAL, APP_IO_MUX_7, APP_IO_PIN_15}, {APP_IO_TYPE_NORMAL, APP_IO_MUX_1, APP_IO_PIN_12},\
{APP_IO_TYPE_NORMAL, APP_IO_MUX_1, APP_IO_PIN_13}, {APP_IO_TYPE_NORMAL, APP_IO_MUX_1, APP_IO_PIN_14}}
#define DEFAULT_SPIM_MODE_CONFIG {APP_SPI_TYPE_DMA, DMA_Channel5, DMA_Channel6}
#define DEFAULT_SPIM_CONFIG {SPI_DATASIZE_8BIT, SPI_POLARITY_LOW, SPI_PHASE_1EDGE, (SystemCoreClock / DEFAULT_SPIM_SPEED), SPI_TIMODE_DISABLE, SPI_SLAVE_SELECT_0}
#define DEFAULT_SPIM_PARAM_CONFIG {APP_SPI_ID_MASTER, DEFAULT_SPIM_IO_CONFIG, DEFAULT_SPIM_MODE_CONFIG, DEFAULT_SPIM_CONFIG}
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
static volatile qspi_control_t g_qspi_ctl;
static dma_handle_t g_dma_handle;
static spi_handle_t g_spim_handle;
static qspi_handle_t g_qspi_handle;
static flash_init_t g_flash_init;
/*
* LOCAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
static void spi_app_qspi_callback(app_qspi_evt_t *p_evt)
{
if (p_evt->type == APP_QSPI_EVT_TX_CPLT)
{
g_qspi_ctl.qspi_tmt_done = 1;
}
if (p_evt->type == APP_QSPI_EVT_RX_DATA)
{
g_qspi_ctl.qspi_rcv_done = 1;
}
if (p_evt->type == APP_QSPI_EVT_ERROR)
{
g_qspi_ctl.qspi_tmt_done = 1;
g_qspi_ctl.qspi_rcv_done = 1;
}
}
void spi_app_spim_callback(app_spi_evt_t *p_evt)
{
if (p_evt->type == APP_SPI_EVT_TX_CPLT)
{
g_qspi_ctl.spi_tmt_done = 1;
}
if (p_evt->type == APP_SPI_EVT_RX_DATA)
{
g_qspi_ctl.spi_rcv_done = 1;
}
if (p_evt->type == APP_SPI_EVT_ERROR)
{
g_qspi_ctl.spi_tmt_done = 1;
g_qspi_ctl.spi_rcv_done = 1;
}
}
static void spi_flash_write_enable(void)
{
uint8_t control_frame[1] = {SPI_FLASH_CMD_WREN};
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while(g_qspi_ctl.spi_tmt_done == 0);
}
else
{
g_qspi_ctl.qspi_tmt_done = 0;
app_qspi_transmit_async(g_qspi_ctl.qspi_id, control_frame, sizeof(control_frame));
while(g_qspi_ctl.qspi_tmt_done == 0);
}
return;
}
static uint8_t spi_flash_read_status(void)
{
uint8_t status = 0;
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
uint8_t control_frame[1] = {SPI_FLASH_CMD_RDSR};
g_qspi_ctl.spi_rcv_done = 0;
app_spi_read_memory_async(g_qspi_ctl.spi_id, control_frame, (uint8_t*)&status, sizeof(control_frame), 1);
while(g_qspi_ctl.spi_rcv_done == 0);
}
else
{
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_RDSR,
.address = 0,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_00_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 0,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = 1,
};
g_qspi_ctl.qspi_rcv_done = 0;
app_qspi_command_receive_async(g_qspi_ctl.qspi_id, &command, (uint8_t*)&status);
while(g_qspi_ctl.qspi_rcv_done == 0);
}
return status;
}
static uint32_t spi_flash_device_size(void)
{
uint32_t flash_size = 0;
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
uint8_t data[5] = {0};
uint8_t control_frame[5] = {SPI_FLASH_CMD_SFUD, 0, 0, 0x34, DUMMY_BYTE};
g_qspi_ctl.spi_rcv_done = 0;
app_spi_read_memory_async(g_qspi_ctl.spi_id, control_frame, data, sizeof(control_frame), sizeof(data));
while(g_qspi_ctl.spi_rcv_done == 0);
if (data[0] != 0 && data[3] < 0xFF)
{
flash_size = ((data[3] << 24) + (data[2] << 16) + (data[1] << 8) + (data[0] << 0) + 1) / 8;
}
}
else
{
uint8_t data[4] = {0};
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_SFUD, // SPI_FLASH_CMD_SFUD //SPI_FLASH_CMD_RDSR
.address = 0x000034,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_24_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 8,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = sizeof(data),
};
g_qspi_ctl.qspi_rcv_done = 0;
app_qspi_command_receive_async(g_qspi_ctl.qspi_id, &command, data);
while(g_qspi_ctl.qspi_rcv_done == 0);
if (data[0] != 0 && data[3] < 0xFF)
{
flash_size = ((data[3] << 24) + (data[2] << 16) + (data[1] << 8) + (data[0] << 0) + 1) / 8;
}
}
return flash_size;
}
static uint32_t spim_flash_write(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
uint8_t control_frame[4] = {0};
control_frame[0] = SPI_FLASH_CMD_PP;
control_frame[1] = (address >> 16) & 0xFF;
control_frame[2] = (address >> 8) & 0xFF;
control_frame[3] = address & 0xFF;
g_qspi_ctl.spi_tmt_done = 0;
app_spi_write_memory_async(g_qspi_ctl.spi_id, control_frame, buffer, sizeof(control_frame), nbytes);
while(g_qspi_ctl.spi_tmt_done == 0);
return nbytes;
}
static uint32_t qspi_flash_write(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_PP,
.address = address,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_24_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 0,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = nbytes,
};
g_qspi_ctl.qspi_tmt_done = 0;
app_qspi_command_transmit_async(g_qspi_ctl.qspi_id, &command, buffer);
while(g_qspi_ctl.qspi_tmt_done == 0);
return nbytes;
}
static uint32_t spim_flash_read(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
uint8_t control_frame[4] = {0};
control_frame[0] = SPI_FLASH_CMD_READ;
control_frame[1] = (address >> 16) & 0xFF;
control_frame[2] = (address >> 8) & 0xFF;
control_frame[3] = address & 0xFF;
g_qspi_ctl.spi_rcv_done = 0;
app_spi_read_memory_async(g_qspi_ctl.spi_id, control_frame, buffer, sizeof(control_frame), nbytes);
while(g_qspi_ctl.spi_rcv_done == 0);
return nbytes;
}
static uint32_t qspi_flash_read(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_READ,
.address = address,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_24_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 0,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = nbytes,
};
g_qspi_ctl.qspi_rcv_done = 0;
app_qspi_command_receive_async(g_qspi_ctl.qspi_id, &command, buffer);
while(g_qspi_ctl.qspi_rcv_done == 0);
return nbytes;
}
bool spim_flash_sector_erase(uint32_t address)
{
uint8_t control_frame[4] = {0};
control_frame[0] = SPI_FLASH_CMD_SE;
control_frame[1] = (address >> 16) & 0xFF;
control_frame[2] = (address >> 8) & 0xFF;
control_frame[3] = address & 0xFF;
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while(g_qspi_ctl.spi_tmt_done == 0);
return true;
}
bool qspi_flash_sector_erase(uint32_t address)
{
uint8_t control_frame[4] = {0};
control_frame[0] = SPI_FLASH_CMD_SE;
control_frame[1] = (address >> 16) & 0xFF;
control_frame[2] = (address >> 8) & 0xFF;
control_frame[3] = address & 0xFF;
g_qspi_ctl.qspi_tmt_done = 0;
app_qspi_transmit_async(g_qspi_ctl.qspi_id, control_frame, sizeof(control_frame));
while(g_qspi_ctl.qspi_tmt_done == 0);
return true;
}
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
bool spi_flash_init(flash_init_t *p_flash_init)
{
memcpy(&g_flash_init, p_flash_init, sizeof(flash_init_t));
if (FLASH_SPIM_ID == p_flash_init->spi_type)
{
app_spi_params_t spim_params = DEFAULT_SPIM_PARAM_CONFIG;
spim_params.pin_cfg.cs.type = p_flash_init->flash_io.spi_cs.gpio;
spim_params.pin_cfg.cs.pin = p_flash_init->flash_io.spi_cs.pin;
spim_params.pin_cfg.cs.mux = p_flash_init->flash_io.spi_cs.mux;
spim_params.pin_cfg.cs.pull = APP_IO_NOPULL;
spim_params.pin_cfg.cs.enable = APP_SPI_PIN_ENABLE;
spim_params.pin_cfg.clk.type = p_flash_init->flash_io.spi_clk.gpio;
spim_params.pin_cfg.clk.pin = p_flash_init->flash_io.spi_clk.pin;
spim_params.pin_cfg.clk.mux = p_flash_init->flash_io.spi_clk.mux;
spim_params.pin_cfg.clk.pull = APP_IO_NOPULL;
spim_params.pin_cfg.clk.enable = APP_SPI_PIN_ENABLE;
spim_params.pin_cfg.mosi.type = p_flash_init->flash_io.spi_io0.qspi_io0.gpio;
spim_params.pin_cfg.mosi.pin = p_flash_init->flash_io.spi_io0.qspi_io0.pin;
spim_params.pin_cfg.mosi.mux = p_flash_init->flash_io.spi_io0.qspi_io0.mux;
spim_params.pin_cfg.mosi.pull = APP_IO_NOPULL;
spim_params.pin_cfg.mosi.enable = APP_SPI_PIN_ENABLE;
spim_params.pin_cfg.miso.type = p_flash_init->flash_io.spi_io1.qspi_io1.gpio;
spim_params.pin_cfg.miso.pin = p_flash_init->flash_io.spi_io1.qspi_io1.pin;
spim_params.pin_cfg.miso.mux = p_flash_init->flash_io.spi_io1.qspi_io1.mux;
spim_params.pin_cfg.miso.pull = APP_IO_NOPULL;
spim_params.pin_cfg.miso.enable = APP_SPI_PIN_ENABLE;
g_qspi_ctl.spi_id = APP_SPI_ID_MASTER;
app_spi_deinit(g_qspi_ctl.spi_id);
if (app_spi_init(&spim_params, spi_app_spim_callback))
{
return false;
}
}
else if ((FLASH_QSPI_ID0 == p_flash_init->spi_type) || (FLASH_QSPI_ID1 == p_flash_init->spi_type))
{
app_qspi_params_t qspi_params = DEFAULT_QSPI_PARAM_CONFIG;
if(FLASH_QSPI_ID0 == p_flash_init->spi_type){
g_qspi_ctl.qspi_id = APP_QSPI_ID_0;
}else{
g_qspi_ctl.qspi_id = APP_QSPI_ID_1;
}
qspi_params.id = g_qspi_ctl.qspi_id;
qspi_params.pin_cfg.cs.type = p_flash_init->flash_io.spi_cs.gpio;
qspi_params.pin_cfg.cs.pin = p_flash_init->flash_io.spi_cs.pin;
qspi_params.pin_cfg.cs.mux = p_flash_init->flash_io.spi_cs.mux;
qspi_params.pin_cfg.cs.pull = APP_IO_NOPULL;
qspi_params.pin_cfg.cs.enable = APP_SPI_PIN_ENABLE;
qspi_params.pin_cfg.clk.type = p_flash_init->flash_io.spi_clk.gpio;
qspi_params.pin_cfg.clk.pin = p_flash_init->flash_io.spi_clk.pin;
qspi_params.pin_cfg.clk.mux = p_flash_init->flash_io.spi_clk.mux;
qspi_params.pin_cfg.clk.pull = APP_IO_NOPULL;
qspi_params.pin_cfg.clk.enable = APP_SPI_PIN_ENABLE;
qspi_params.pin_cfg.io_0.type = p_flash_init->flash_io.spi_io0.qspi_io0.gpio;
qspi_params.pin_cfg.io_0.pin = p_flash_init->flash_io.spi_io0.qspi_io0.pin;
qspi_params.pin_cfg.io_0.mux = p_flash_init->flash_io.spi_io0.qspi_io0.mux;
qspi_params.pin_cfg.io_0.pull = APP_IO_NOPULL;
qspi_params.pin_cfg.io_0.enable = APP_SPI_PIN_ENABLE;
qspi_params.pin_cfg.io_1.type = p_flash_init->flash_io.spi_io1.qspi_io1.gpio;
qspi_params.pin_cfg.io_1.pin = p_flash_init->flash_io.spi_io1.qspi_io1.pin;
qspi_params.pin_cfg.io_1.mux = p_flash_init->flash_io.spi_io1.qspi_io1.mux;
qspi_params.pin_cfg.io_1.pull = APP_IO_NOPULL;
qspi_params.pin_cfg.io_1.enable = APP_SPI_PIN_ENABLE;
qspi_params.pin_cfg.io_2.type = p_flash_init->flash_io.qspi_io2.gpio;
qspi_params.pin_cfg.io_2.pin = p_flash_init->flash_io.qspi_io2.pin;
qspi_params.pin_cfg.io_2.mux = p_flash_init->flash_io.qspi_io2.mux;
qspi_params.pin_cfg.io_2.pull = APP_IO_NOPULL;
qspi_params.pin_cfg.io_2.enable = APP_SPI_PIN_ENABLE;
qspi_params.pin_cfg.io_3.type = p_flash_init->flash_io.qspi_io3.gpio;
qspi_params.pin_cfg.io_3.pin = p_flash_init->flash_io.qspi_io3.pin;
qspi_params.pin_cfg.io_3.mux = p_flash_init->flash_io.qspi_io3.mux;
qspi_params.pin_cfg.io_3.pull = APP_IO_NOPULL;
qspi_params.pin_cfg.io_3.enable = APP_SPI_PIN_ENABLE;
app_qspi_deinit(g_qspi_ctl.qspi_id);
if (app_qspi_init(&qspi_params, spi_app_qspi_callback))
{
return false;
}
//set qspi hold/wp pin to high
app_io_init_t io_init = APP_IO_DEFAULT_CONFIG;
io_init.mode = APP_IO_MODE_OUT_PUT;
io_init.pull = APP_IO_PULLUP;
io_init.pin = qspi_params.pin_cfg.io_2.pin;
io_init.mux = APP_IO_MUX_7;
if (app_io_init(qspi_params.pin_cfg.io_2.type, &io_init))
{
return false;
}
io_init.mode = APP_IO_MODE_OUT_PUT;
io_init.pull = APP_IO_PULLUP;
io_init.pin = qspi_params.pin_cfg.io_3.pin;
io_init.mux = APP_IO_MUX_7;
if (app_io_init(qspi_params.pin_cfg.io_3.type , &io_init))
{
return false;
}
if (app_io_write_pin(qspi_params.pin_cfg.io_2.type, qspi_params.pin_cfg.io_2.pin, APP_IO_PIN_SET))
{
return false;
}
if (app_io_write_pin(qspi_params.pin_cfg.io_3.type, qspi_params.pin_cfg.io_3.pin, APP_IO_PIN_SET))
{
return false;
}
}
return true;
}
uint32_t spi_flash_write(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
uint32_t page_ofs, write_size, write_cont = nbytes;
hal_status_t status = HAL_OK;
while (write_cont)
{
page_ofs = address & 0xFF;
write_size = EXFLASH_SIZE_PAGE_BYTES - page_ofs;
if (write_cont < write_size)
{
write_size = write_cont;
write_cont = 0;
}
else
{
write_cont -= write_size;
}
spi_flash_write_enable();
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
spim_flash_write(address, buffer, write_size);
}
else
{
qspi_flash_write(address, buffer, write_size);
}
while(spi_flash_read_status() & 0x1);
address += write_size;
buffer += write_size;
}
return ((status == HAL_OK) ? nbytes : 0);
}
uint32_t spi_flash_read(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
uint32_t count = 0;
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
count = spim_flash_read(address, buffer, nbytes);
}
else
{
count = qspi_flash_read(address, buffer, nbytes);
}
return count;
}
bool spi_flash_sector_erase(uint32_t address, uint32_t size)
{
bool status = true;
uint32_t erase_addr = address;
uint32_t sector_ofs, erase_size, erase_cont = size;
while (erase_cont)
{
sector_ofs = erase_addr & 0xFFF;
erase_size = EXFLASH_SIZE_SECTOR_BYTES - sector_ofs;
if (erase_cont < erase_size)
{
erase_size = erase_cont;
erase_cont = 0;
}
else
{
erase_cont -= erase_size;
}
spi_flash_write_enable();
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
status = spim_flash_sector_erase(erase_addr);
}
else
{
status = qspi_flash_sector_erase(erase_addr);
}
while(spi_flash_read_status() & 0x1);
erase_addr += erase_size;
}
return status;
}
bool spi_flash_chip_erase(void)
{
hal_status_t status = HAL_OK;
uint8_t control_frame[1] = {SPI_FLASH_CMD_CE};
spi_flash_write_enable();
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while(g_qspi_ctl.spi_tmt_done == 0);
}
else
{
g_qspi_ctl.qspi_tmt_done = 0;
app_qspi_transmit_async(g_qspi_ctl.qspi_id, control_frame, sizeof(control_frame));
while(g_qspi_ctl.qspi_tmt_done == 0);
}
while(spi_flash_read_status() & 0x1);
return ((status == HAL_OK) ? true : false);
}
void spi_flash_chip_reset(void)
{
uint8_t control_frame[1] = {SPI_FLASH_CMD_RSTEN};
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while(g_qspi_ctl.spi_tmt_done == 0);
}
else
{
hal_qspi_transmit(&g_qspi_handle, control_frame, sizeof(control_frame), 5000);
}
control_frame[0] = SPI_FLASH_CMD_RST;
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while(g_qspi_ctl.spi_tmt_done == 0);
}
else
{
hal_qspi_transmit(&g_qspi_handle, control_frame, sizeof(control_frame), 5000);
}
return;
}
uint32_t spi_flash_device_id(void)
{
uint8_t data[3] = {0};
if (FLASH_SPIM_ID == g_flash_init.spi_type)
{
uint8_t control_frame[1] = {SPI_FLASH_CMD_RDID};
g_qspi_ctl.spi_rcv_done = 0;
app_spi_read_memory_async(g_qspi_ctl.spi_id, control_frame, data, sizeof(control_frame), sizeof(data));
while(g_qspi_ctl.spi_rcv_done == 0);
}
else
{
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_RDID,
.address = 0,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_00_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 0,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = 3,
};
g_qspi_ctl.qspi_rcv_done = 0;
app_qspi_command_receive_async(g_qspi_ctl.qspi_id, &command, data);
while(g_qspi_ctl.qspi_rcv_done == 0);
}
return (((uint32_t)data[0] << 16) + ((uint32_t)data[1] << 8) + data[2]);
}
void spi_flash_device_info(uint32_t *id, uint32_t *size)
{
if (NULL == id || NULL == size)
{
return;
}
*id = spi_flash_device_id();
*size = spi_flash_device_size();
return;
}
@@ -0,0 +1,272 @@
/**
****************************************************************************************
* @file gr551x_spi_flash.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of spi flash library.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
#ifndef __GR551X_SPI_FLASH_H__
#define __GR551X_SPI_FLASH_H__
#include <stdbool.h>
#include "gr55xx_hal.h"
#include "app_io.h"
#include "app_qspi.h"
#include "app_spi.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup Flash operation instruction macro definition
* @{
*/
#define SPI_FLASH_CMD_WRSR 0x01
#define SPI_FLASH_CMD_WRSR1 0x31
#define SPI_FLASH_CMD_RDSR 0x05
#define SPI_FLASH_CMD_WREN 0x06
#define SPI_FLASH_CMD_WRDI 0x04
#define SPI_FLASH_CMD_READ 0x03
#define SPI_FLASH_CMD_FREAD 0x0B
#define SPI_FLASH_CMD_DOFR 0x3B
#define SPI_FLASH_CMD_DIOFR 0xBB
#define SPI_FLASH_CMD_QOFR 0x6B
#define SPI_FLASH_CMD_QIOFR 0xEB
#define SPI_FLASH_CMD_READ_RESET 0xFF
#define SPI_FLASH_CMD_PP 0x02
#define SPI_FLASH_CMD_SE 0x20
#define SPI_FLASH_CMD_BE_32 0x52
#define SPI_FLASH_CMD_BE_64 0xD8
#define SPI_FLASH_CMD_CE 0xC7
#define SPI_FLASH_CMD_PES 0x75
#define SPI_FLASH_CMD_PER 0x7A
#define SPI_FLASH_CMD_RDI 0xAB
#define SPI_FLASH_CMD_REMS 0x90
#define SPI_FLASH_CMD_RDID 0x9F
#define SPI_FLASH_CMD_RSTEN 0x66
#define SPI_FLASH_CMD_RST 0x99
#define SPI_FLASH_CMD_DP 0xB9
#define SPI_FLASH_CMD_RDP 0xAB
#define SPI_FLASH_CMD_SFUD 0x5A
#define DUMMY_BYTE 0xFF
#define SPI_FLASH_PAGE_SIZE 0x00100
#define SPI_FLASH_SECTOR_SIZE 0x01000
#define SPI_FLASH_BLOCK_SIZE 0x10000
#define SPI_FLASH_ADDRESS_MAX 0xFFFFF
/** @} */
/** @addtogroup Flash hardware interface default parameters
* @{
*/
#define DEFAULT_SPIM_GROUP0 {{APP_IO_TYPE_NORMAL, APP_IO_PIN_6, APP_IO_MUX_7}, {APP_IO_TYPE_NORMAL, APP_IO_PIN_3, APP_IO_MUX_2},\
{APP_IO_TYPE_NORMAL, APP_IO_PIN_4, APP_IO_MUX_2}, {APP_IO_TYPE_NORMAL, APP_IO_PIN_5, APP_IO_MUX_2}}
#define DEFAULT_SPIM_GROUP1 {{APP_IO_TYPE_NORMAL, APP_IO_PIN_4, APP_IO_MUX_7}, {APP_IO_TYPE_NORMAL, APP_IO_PIN_7, APP_IO_MUX_4},\
{APP_IO_TYPE_NORMAL, APP_IO_PIN_6, APP_IO_MUX_4}, {APP_IO_TYPE_NORMAL, APP_IO_PIN_5, APP_IO_MUX_4}}
#define DEFAULT_SPIM_GROUP2 {{APP_IO_TYPE_NORMAL, APP_IO_PIN_15, APP_IO_MUX_7}, {APP_IO_TYPE_NORMAL, APP_IO_PIN_12, APP_IO_MUX_1},\
{APP_IO_TYPE_NORMAL, APP_IO_PIN_13, APP_IO_MUX_1}, {APP_IO_TYPE_NORMAL, APP_IO_PIN_14, APP_IO_MUX_1}}
#define DEFAULT_SPIM_GROUP3 {{APP_IO_TYPE_NORMAL, APP_IO_PIN_17, APP_IO_MUX_7}, {APP_IO_TYPE_NORMAL, APP_IO_PIN_24, APP_IO_MUX_0},\
{APP_IO_TYPE_NORMAL, APP_IO_PIN_25, APP_IO_MUX_0}, {APP_IO_TYPE_NORMAL, APP_IO_PIN_16, APP_IO_MUX_0}}
/** @} */
/**
* @addtogroup Spi Flash IO configuration Structures
* @{
*/
typedef enum
{
FLASH_SPIM_ID, /**< SPI master module. */
FLASH_QSPI_ID0, /**< QSPI master module 0. */
FLASH_QSPI_ID1, /**< QSPI master module 1. */
FLASH_SPI_ID_MAX, /**< Only for check parameter, not used as input parameters. */
} spi_type_t;
typedef struct _spi_io
{
app_io_type_t gpio;
uint32_t pin;
app_io_mux_t mux;
} spi_io_t;
typedef struct _flash_io
{
spi_io_t spi_cs;
spi_io_t spi_clk;
union
{
spi_io_t spim_mosi;
spi_io_t qspi_io0;
} spi_io0;
union
{
spi_io_t spim_miso;
spi_io_t qspi_io1;
} spi_io1;
spi_io_t qspi_io2;
spi_io_t qspi_io3;
} flash_io_t;
typedef struct _flash_init
{
spi_type_t spi_type;
flash_io_t flash_io;
} flash_init_t;
typedef struct flash_control
{
uint8_t qspi_tmt_done;
uint8_t qspi_rcv_done;
app_qspi_id_t qspi_id;
uint8_t spi_tmt_done;
uint8_t spi_rcv_done;
app_spi_id_t spi_id;
} qspi_control_t;
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup HAL_SPI_FLASH_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the SPI FLASH DRIVER according to the specified parameters
* in the spi_flash_io_t.
*
* @param[in] p_params: Pointer to spi_flash_io_t parameter.
*
****************************************************************************************
*/
bool spi_flash_init(flash_init_t *p_flash_init);
/**
*******************************************************************************
* @brief Write flash Memory.
*
* @param[in] address: start address in flash to write data to.
* @param[in,out] buffer: buffer of data to write.
* @param[in] nbytes: number of bytes to write.
*
* @return number of bytes written
*******************************************************************************
*/
uint32_t spi_flash_write(uint32_t address, uint8_t *buffer, uint32_t nbytes);
/**
*******************************************************************************
* @brief Read flash Memory.
*
* @param[in] address: start address in flash to read data.
* @param[in,out] buffer: buffer to read data to.
* @param[in] nbytes: number of bytes to read.
*
* @return number of bytes read
*******************************************************************************
*/
uint32_t spi_flash_read(uint32_t address, uint8_t *buffer, uint32_t nbytes);
/**
*******************************************************************************
* @brief Erase flash region.
*
* @note All sectors that have address in range of [addr, addr+len]
* will be erased. If addr is not sector aligned, preceding data
* on the sector that addr belongs to will also be erased.
* If (addr + size) is not sector aligned, the whole sector
* will also be erased.
*
* @param[in] address: start address in flash to write data to.
* @param[in] size: number of bytes to write.
*
* @retval true: If successful.
* @retval false: If failure.
*******************************************************************************
*/
bool spi_flash_sector_erase(uint32_t address, uint32_t size);
/**
*******************************************************************************
* @brief Erase flash chip.
*
* @retval true: If successful.
* @retval false: If failure.
*******************************************************************************
*/
bool spi_flash_chip_erase(void);
/**
*******************************************************************************
* @brief Reset flash chip.
*
*******************************************************************************
*/
void spi_flash_chip_reset(void);
/**
*******************************************************************************
* @brief Get flash chip id.
*
* @retval Flash chip id.
*******************************************************************************
*/
uint32_t spi_flash_device_id(void);
/**
*******************************************************************************
* @brief Get Flash information.
*
* @param[in,out] id: Pointer to flash id.
* @param[in,out] size: Pointer to flash size.
*
*******************************************************************************
*/
void spi_flash_device_info(uint32_t *id, uint32_t *size);
/** @} */
#ifdef __cplusplus
}
#endif
#endif // __GR551X_SPI_FLASH_H__
@@ -0,0 +1,101 @@
/**
****************************************************************************************
*
* @file gr551x_temp_api.c
*
* @brief GR551x temperature module.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include "gr55xx_hal.h"
#include "gr55xx_sys.h"
#include "gr551x_temp_api.h"
/*
* GLOBAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
/*
* STATIC VARIABLE DEFINITIONS
*****************************************************************************************
*/
static adc_handle_t gr551x_temp_handle = {0};
static double adc_temp = 0;
static double adc_slope = 0;
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
void hal_gr551x_temp_init(void)
{
adc_trim_info_t adc_trim = {0};
gr551x_temp_handle.init.channel_n = ADC_INPUT_SRC_TMP;
gr551x_temp_handle.init.channel_p = ADC_INPUT_SRC_TMP;
gr551x_temp_handle.init.input_mode = ADC_INPUT_SINGLE;
gr551x_temp_handle.init.ref_source = ADC_REF_SRC_BUF_INT;
gr551x_temp_handle.init.ref_value = ADC_REF_VALUE_0P8;
gr551x_temp_handle.init.clock = ADC_CLK_1P6M;
hal_adc_init(&gr551x_temp_handle);
if(SDK_SUCCESS == sys_adc_trim_get(&adc_trim))
{
adc_temp = (double)adc_trim.adc_temp;
adc_slope = (-1) * (double)adc_trim.slope_int_0p8;
}
else
{
adc_temp = 4979;
adc_slope = -4932;
}
return;
}
double hal_gr551x_temp_read(void)
{
uint16_t conver_buff[16] = {0};
uint16_t average = 0;
/* Got the average of Temp */
hal_adc_poll_for_conversion(&gr551x_temp_handle, conver_buff, 16);
for(uint8_t i = 0; i < 8; i++)
{
average += conver_buff[8 + i];
}
average = average >> 3;
return (((double)average - adc_temp) / adc_slope) / (-0.00175) + 25.0;
}
@@ -0,0 +1,75 @@
/**
****************************************************************************************
*
* @file gr551x_temp_api.h
*
* @brief Header file - GR551x temperature module.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************
*/
#ifndef __GR551X_TEMP_API_H__
#define __GR551X_TEMP_API_H__
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialize ADC temperature detection.
*
****************************************************************************************
*/
void hal_gr551x_temp_init(void);
/**
****************************************************************************************
* @brief Get the chip internal temperature.
*
* @return The value of temperature. Unit (Centigrade).
****************************************************************************************
*/
double hal_gr551x_temp_read(void);
#ifdef __cplusplus
}
#endif
#endif // __GR551X_TEMP_API_H__
@@ -0,0 +1,88 @@
/**
****************************************************************************************
*
* @file gr551x_tim_delay.c
*
* @brief GR551x tim delay.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include "gr551x_tim_delay.h"
/*
* STATIC VARIABLE DEFINITIONS
*****************************************************************************************
*/
static uint32_t fus = 0;
static uint32_t fms = 0;
static dual_timer_regs_t *tim_regs;
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
void tim_delay_init(dual_timer_regs_t *timx)
{
fus = SystemCoreClock / 1000000;
fms = SystemCoreClock / 1000;
tim_regs = timx;
tim_regs->RELOAD = 0xFFFFFFFF;
/* Disable tim, period mode, 32-bit counter, one-shot mdoe */
tim_regs->CTRL = 0x43;
}
void tim_delay_us(uint32_t us)
{
uint32_t load = us * fus - 1;
tim_regs->RELOAD = load;
/* Enable tim */
tim_regs->CTRL |= 0x80;
while(tim_regs->VALUE != 0);
tim_regs->CTRL &= ~0x80;
/* Clear flag */
tim_regs->INTCLR = 1;
}
void tim_delay_ms(uint32_t ms)
{
uint32_t load = ms * fms - 1;
tim_regs->RELOAD = load;
/* Enable tim */
tim_regs->CTRL |= 0x80;
while(tim_regs->VALUE != 0);
tim_regs->CTRL &= ~0x80;
/* Clear flag */
tim_regs->INTCLR = 1;
}
@@ -0,0 +1,85 @@
/**
****************************************************************************************
*
* @file gr551x_tim_delay.h
*
* @brief Header file - GR551x tim delay.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************
*/
#ifndef __GR551X_TIM_DELAY_H__
#define __GR551X_TIM_DELAY_H__
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <stdint.h>
#include "gr55xx.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialize the DUAL TIM according to the specified register
* in the dual_timer_regs_t.
****************************************************************************************
*/
void tim_delay_init(dual_timer_regs_t *timx);
/**
*****************************************************************************************
* @brief Delay the function execution.
*
* @param[in] us: Microsecond.
*****************************************************************************************
*/
void tim_delay_us(uint32_t us);
/**
*****************************************************************************************
* @brief Delay the function execution.
*
* @param[in] ms: Millisecond.
*****************************************************************************************
*/
void tim_delay_ms(uint32_t ms);
#ifdef __cplusplus
}
#endif
#endif // __GR551X_TIM_DELAY_H__
@@ -0,0 +1,103 @@
/**
****************************************************************************************
*
* @file gr551x_vbat_api.c
*
* @brief GR551x battery module.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include "gr55xx_hal.h"
#include "gr55xx_sys.h"
#include "gr551x_vbat_api.h"
/*
* GLOBAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
/*
* STATIC VARIABLE DEFINITIONS
*****************************************************************************************
*/
static adc_handle_t gr551x_vbat_handle = {0};
static double adc_offset = 0;
static double adc_slope = 0;
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
void hal_gr551x_vbat_init(void)
{
adc_trim_info_t adc_trim = {0};
gr551x_vbat_handle.init.channel_n = ADC_INPUT_SRC_BAT;
gr551x_vbat_handle.init.channel_p = ADC_INPUT_SRC_BAT;
gr551x_vbat_handle.init.input_mode = ADC_INPUT_SINGLE;
gr551x_vbat_handle.init.ref_source = ADC_REF_SRC_BUF_INT;
gr551x_vbat_handle.init.ref_value = ADC_REF_VALUE_0P8;
gr551x_vbat_handle.init.clock = ADC_CLK_1P6M;
hal_adc_init(&gr551x_vbat_handle);
if(SDK_SUCCESS == sys_adc_trim_get(&adc_trim))
{
adc_offset = (double)adc_trim.offset_int_0p8;
adc_slope = (-1) * (double)adc_trim.slope_int_0p8;
}
else
{
adc_offset = 8362;
adc_slope = -4754;
}
return;
}
double hal_gr551x_vbat_read(void)
{
uint16_t conver_buff[16] = {0};
uint16_t average = 0;
/* Got the average of Vbat */
SET_BITS(AON->SNSADC_CFG, AON_SNSADC_CFG_VBAT_EN_Msk);
hal_adc_poll_for_conversion(&gr551x_vbat_handle, conver_buff, 16);
CLEAR_BITS(AON->SNSADC_CFG, AON_SNSADC_CFG_VBAT_EN_Msk);//disable vbat for power save
for(uint8_t i = 0; i < 8; i++)
{
average += conver_buff[8 + i];
}
average = average >> 3;
return (((double)average - adc_offset) / adc_slope) * (27.0 / 7.0);
}
@@ -0,0 +1,75 @@
/**
****************************************************************************************
*
* @file gr551x_vbat_api.h
*
* @brief Header file - GR551x battery module.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************
*/
#ifndef __GR551X_VBAT_API_H__
#define __GR551X_VBAT_API_H__
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialize ADC battery voltage detection.
*
****************************************************************************************
*/
void hal_gr551x_vbat_init(void);
/**
****************************************************************************************
* @brief Get the battery voltage.
*
* @return The volatge of battery. Unit (volt).
****************************************************************************************
*/
double hal_gr551x_vbat_read(void);
#ifdef __cplusplus
}
#endif
#endif // __GR551X_VBAT_API_H__
@@ -60,8 +60,7 @@ int app_lfs_device_sync(const struct lfs_config *c);
static uint32_t s_app_lfs_start_addr;
static lfs_t s_app_lfs_instance;
static const struct lfs_config s_app_lfs_cfg =
static struct lfs_config s_app_lfs_cfg =
{
.context = NULL,
.read = app_lfs_block_read,
@@ -71,7 +70,6 @@ static const struct lfs_config s_app_lfs_cfg =
.read_size = APP_LFS_READ_SIZE,
.prog_size = APP_LFS_PROG_SIZE,
.block_size = APP_LFS_BLOCK_SIZE,
.block_count = APP_LFS_BLOCK_COUNT,
.block_cycles = APP_LFS_BLOCK_CYCLES,
.cache_size = APP_LFS_CACHE_SIZE,
.lookahead_size = APP_LFS_LOOKAHEAD_SIZE,
@@ -90,8 +88,8 @@ static void s_lfs_start_addr_get(void)
hal_flash_get_info(&flash_id, &flash_size);
nvds_start_addr = APP_LFS_FLASH_BASE + flash_size - hal_flash_sector_size() * NVDS_NUM_SECTOR;
s_app_lfs_start_addr = nvds_start_addr - APP_LFS_BLOCK_COUNT * APP_LFS_BLOCK_SIZE;
APP_LOG_INFO("LFS Flash start addr=0x%x, All size=%dKB", s_app_lfs_start_addr, APP_LFS_BLOCK_COUNT * APP_LFS_BLOCK_SIZE / 1024);
s_app_lfs_start_addr = nvds_start_addr - s_app_lfs_cfg.block_count * APP_LFS_BLOCK_SIZE;
APP_LOG_INFO("LFS Flash start addr=0x%x, All size=%dKB", s_app_lfs_start_addr, s_app_lfs_cfg.block_count * APP_LFS_BLOCK_SIZE / 1024);
}
int app_lfs_block_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
@@ -147,10 +145,11 @@ int app_lfs_device_sync(const struct lfs_config *c)
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
int app_lfs_init(void)
int app_lfs_init(int lfs_block_count)
{
int error_code = APP_LFS_ERR_OK;
s_app_lfs_cfg.block_count = lfs_block_count;
error_code = lfs_mount(&s_app_lfs_instance, &s_app_lfs_cfg);
if (LFS_ERR_OK != error_code)
{
@@ -71,10 +71,6 @@
#define APP_LFS_BLOCK_CYCLES 500
#endif
#ifndef APP_LFS_BLOCK_COUNT
#define APP_LFS_BLOCK_COUNT 10
#endif
#ifndef APP_LFS_LOOKAHEAD_SIZE
#define APP_LFS_LOOKAHEAD_SIZE 32
#endif
@@ -137,10 +133,12 @@ typedef void (*app_lfs_traverse_cb_t)(char *name, uint32_t size);
*****************************************************************************************
* @brief Initialize APP Little File System instance.
*
* @param[in] lfs_block_count: Number of flash blocks used by the LFS file system.
*
* @return Result of initialization.
*****************************************************************************************
*/
int app_lfs_init(void);
int app_lfs_init(int lfs_block_count);
/**
*****************************************************************************************
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
View File
View File
View File
+1 -1
View File
@@ -42,7 +42,7 @@ void SystemPeripheralsInit(void)
}
bsp_log_init();
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>GR551x system start!!!");
APP_LOG_INFO("GR551x system start!!!");
}
/* Initialize Hardware RNG peripherals. */
+3 -298
View File
@@ -12,198 +12,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "los_task.h"
#include "los_interrupt.h"
#include "los_compiler.h"
#include "los_arch_interrupt.h"
#include "cmsis_os2.h"
#include "gr55xx.h"
#include "main.h"
#include "log_serial.h"
#include "core_cm4.h"
#include "ble_cfg_net_api.h"
#include "hilink_bt_api.h"
#include "hilink_bt_function.h"
#include "hilink_bt_netcfg_api.h"
#include "app_log.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#define CN_MINISECONDS_IN_SECOND 1000
#define CN_MAINBOOT_TASK_STACKSIZE 0X4000
#define CN_MAINBOOT_TASK_PRIOR 2
#define CN_MAINBOOT_TASK_NAME "MainBoot"
#define DEVICE_SN "12345678"
/*
* 设备基本信息
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
#define DEVICE_SN "12345678"
#define PRODUCT_ID "2EKT"
#define DEVICE_MODEL "D12"
#define DEVICE_TYPE "000"
#define MANUAFACTURER "832"
#define DEVICE_MAC "AABBCCDDEEFF"
/*
* 请确保设备类型英文名和厂商英文名长度之和不超过17字节
* 如果需要发送蓝牙广播,设备类型英文名和厂商英文名长度分别不能超过4字节
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
#define DEVICE_TYPE_NAME "YH"
#define MANUAFACTURER_NAME "L"
/* 蓝牙sdk单独使用的定义 */
#define SUB_PRODUCT_ID "00"
#define ADV_TX_POWER 0xF8
/* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改 */
typedef struct {
const char* sn; /* 设备唯一标识,比如sn号,长度范围(0,40] */
const char* prodId; /* 设备HiLink认证号,长度范围(0,5] */
const char* model; /* 设备型号,长度范围(0,32] */
const char* dev_t; /* 设备类型,长度范围(0,4] */
const char* manu; /* 设备制造商,长度范围(0,4] */
const char* mac; /* 设备MAC地址,固定32字节 */
const char* hiv; /* 设备Hilink协议版本,长度范围(0,32] */
const char* fwv; /* 设备固件版本,长度范围[0,64] */
const char* hwv; /* 设备硬件版本,长度范围[0,64] */
const char* swv; /* 设备软件版本,长度范围[0,64] */
const int prot_t; /* 设备协议类型,取值范围[1,3] */
} dev_info_t;
/*
* 设备类型英文名和厂商英文名长度之和不能超过17字节
* 如果需要发送蓝牙广播,设备类型英文名和厂商英文名长度分别不能超过4字节
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
typedef struct {
const char* devTypeName; /* 设备类型英文名称 */
const char* manuName; /* 厂商英文名称 */
} DevNameEn;
#define MIN_LEN(a, b) (((a) < (b)) ? (a) : (b))
/*
* 设备名称定义, 请确保设备类型英文名和厂商英文名长度之和不超过17字节
* 如果需要发送蓝牙广播,设备类型英文名和厂商英文名长度分别不能超过4字节
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
DevNameEn g_devNameEn = {
DEVICE_TYPE_NAME,
MANUAFACTURER_NAME
};
/*
* 设备信息定义
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
dev_info_t dev_info = {
DEVICE_SN,
PRODUCT_ID,
DEVICE_MODEL,
DEVICE_TYPE,
MANUAFACTURER,
DEVICE_MAC,
"1.0.0",
"1.0.0",
"1.0.0",
"1.0.0",
1
};
static int PutServiceOta(const void *svc, const unsigned char *in, unsigned int inLen,
unsigned char **out, unsigned int *outLen);
static int GetServiceOta(const void *svc, const unsigned char *in, unsigned int inLen,
unsigned char **out, unsigned int *outLen);
static int ble_rcv_custom_data(unsigned char *buff, unsigned int len)
{
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>custom data: %s", buff);
return 0;
}
static BLE_ConfPara isblepair =
{
.isBlePair = 1,
};
static BLE_InitPara ble_init_param =
{
.confPara = &isblepair,
.advInfo = NULL,
.gattList = NULL,
};
static BLE_CfgNetCb ble_cfg_net_cb =
{
.rcvCustomDataCb = ble_rcv_custom_data,
};
static HILINK_BT_DevInfo g_btDevInfo;
/* 服务信息 */
static HILINK_BT_SvcInfo g_svcInfo[] =
{
{ 64, "ota", PutServiceOta, GetServiceOta, 0, NULL },
};
/* Profile */
static HILINK_BT_Profile g_profile =
{
.svcNum = sizeof(g_svcInfo) / sizeof(g_svcInfo[0]),
.svcInfo = g_svcInfo,
};
/* 蓝牙发送数据接口打桩函数,由厂家实现 */
static int HILINK_BT_FeedBackBtData(const unsigned char *buf, unsigned int len)
{
(void)buf;
(void)len;
return 0;
}
static int PutServiceOta(const void *svc, const unsigned char *in, unsigned int inLen,
unsigned char **out, unsigned int *outLen)
{
(void)inLen;
(void)out;
(void)outLen;
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>service:%s, payload:%s", (char *)svc, (char *)in);
return 0;
}
static int GetServiceOta(const void *svc, const unsigned char *in, unsigned int inLen,
unsigned char **out, unsigned int *outLen)
{
(void)inLen;
(void)out;
(void)outLen;
APP_LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>service:%s, payload:%s", (char *)svc, (char *)in);
return 0;
}
static void hilink_bt_event_handler(HILINK_BT_SdkStatus event, const void *param)
{
if (HILINK_BT_SDK_STATUS_SVC_RUNNING == event)
{
BLE_CfgNetAdvCtrl(0xfffffffe);
}
}
static void MainBoot(void)
{
UINT32 uwRet;
@@ -216,35 +36,25 @@ static void MainBoot(void)
stTask.usTaskPrio = CN_MAINBOOT_TASK_PRIOR; /* Os task priority is 6 */
uwRet = LOS_TaskCreate(&taskID, &stTask);
if (uwRet != LOS_OK) {
APP_LOG_ERROR(">>>>>>>>>>>>>>>>>>>>>>>>>>MainBoot task create failed!!!");
APP_LOG_ERROR("MainBoot task create failed!!!");
}
}
static void BleAdapterPreInit(void)
{
//The device name must be set here
ble_gap_device_name_set(BLE_GAP_WRITE_PERM_NOAUTH, DEVICE_TYPE_NAME, strlen(DEVICE_TYPE_NAME));
BleEventTaskInit();
}
/***
* @brief This is the ohos entry, and you could call this in your main funciton after the
* necessary hardware has been initialized.
*/
void OHOS_Boot(void)
{
UINT32 ret;
UINT32 ret;
ret = LOS_KernelInit();
if (ret == LOS_OK) {
OSVectorInit();
SystemPeripheralsInit();
FileSystemInit();
BleAdapterPreInit();
HILINK_BT_SetSdkEventCallback(hilink_bt_event_handler);
BLE_CfgNetInit(&ble_init_param, &ble_cfg_net_cb);
HardwareRandomInit();
DeviceManagerStart();
MainBoot();
LOS_Start();
}
@@ -256,109 +66,4 @@ VOID HalDelay(UINT32 ticks)
delay_ms(ticks);
}
/**
* @brief Convert miniseconds to system ticks
* @param ms Indicates the mimiseconds to convert
* @return Returns the corresponding ticks of specified time
*/
uint32_t Time2Tick(uint32_t ms)
{
uint64_t ret;
ret = ((uint64_t)ms * osKernelGetTickFreq()) / CN_MINISECONDS_IN_SECOND;
return (uint32_t)ret;
}
/* 获取蓝牙SDK设备相关信息 */
HILINK_BT_DevInfo *HILINK_BT_GetDevInfo(void)
{
g_btDevInfo.manuName = (char *)g_devNameEn.manuName;
g_btDevInfo.devName = (char *)g_devNameEn.devTypeName;
g_btDevInfo.productId = (char *)dev_info.prodId;
g_btDevInfo.mac = (char *)dev_info.mac;
g_btDevInfo.model = (char *)dev_info.model;
g_btDevInfo.devType = (char *)dev_info.dev_t;
g_btDevInfo.hiv = (char *)dev_info.hiv;
g_btDevInfo.protType = dev_info.prot_t;
return &g_btDevInfo;
}
unsigned char A_C[48] =
{
0x49, 0x3F, 0x45, 0x4a, 0x3a, 0x72, 0x38, 0x7b, 0x36, 0x32, 0x50, 0x3c, 0x49, 0x39, 0x63, 0x38,
0x72, 0xcb, 0x6d, 0xc5, 0xae, 0xe5, 0x4a, 0x82, 0xd3, 0xe5, 0x6d, 0xf5, 0x36, 0x82, 0x62, 0xeb,
0x89, 0x30, 0x6c, 0x88, 0x32, 0x56, 0x23, 0xfd, 0xb8, 0x67, 0x90, 0xa7, 0x7b, 0x61, 0x1e, 0xae
};
unsigned char *HILINK_GetAutoAc(void)
{
return A_C;
}
int HiLinkGetPinCode(void)
{
return -1;
}
/*
* 功能: 获取设备sn号
* 参数[in]: len sn的最大长度, 39字节
* 参数[out]: sn 设备sn
* 注意: sn指针的字符串长度为0时将使用设备mac地址作为sn
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
void HILINK_GetDeviceSn(unsigned int len, char *sn)
{
if (sn == NULL) {
return;
}
const char *ptr = DEVICE_SN;
int tmp = MIN_LEN(len ,sizeof(DEVICE_SN));
for (int i = 0; i < tmp; i++) {
sn[i] = ptr[i];
}
return;
}
/*
* 获取设备的子型号,长度固定两个字节
* subProdId为保存子型号的缓冲区,len为缓冲区的长度
* 如果产品定义有子型号,则填入两字节子型号,并以'\0'结束, 返回0
* 没有定义子型号,则返回-1
* 该接口需设备开发者实现
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
*/
int HILINK_GetSubProdId(char *subProdId, int len)
{
if (subProdId == NULL) {
return -1;
}
const char *ptr = SUB_PRODUCT_ID;
int tmp = MIN_LEN((unsigned int)len ,sizeof(SUB_PRODUCT_ID));
for (int i = 0; i < tmp; i++) {
subProdId[i] = ptr[i];
}
return 0;
}
/*
* 获取设备表面的最强点信号发射功率强度,最强点位置的确定以及功率测试方
* 法,参照hilink认证蓝牙靠近发现功率设置及测试方法指导文档,power为出参
* ,单位dbm,返回设备表面的最强信号强度值,如果厂商不想使用蓝牙靠近发现功
* 能,接口直接返-1,如果需要使用蓝牙靠近发现,则接口返回0,如需及时生效,需
* 调用HILINK_BT_StartAdvertise()方法启动广播
*/
int HILINK_BT_GetDevSurfacePower(char *power)
{
if (power == NULL) {
return -1;
}
*power = ADV_TX_POWER;
return 0;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */
+11 -4
View File
@@ -25,12 +25,13 @@
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x800; /* required amount of heap */
_Min_Stack_Size = 0x2000; /* required amount of stack */
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_sstack = _estack - _Min_Stack_Size;
/* Memories definition */
MEMORY
{
@@ -54,7 +55,7 @@ SECTIONS
.text :
{
. = ALIGN(4);
_stext = .;
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
@@ -191,6 +192,12 @@ SECTIONS
. = ALIGN(4);
} >FLASH
.hdf_drivers_entry :
{
_hdf_drivers_start = .;
KEEP(*(.hdf.driver))
_hdf_drivers_end = .;
} >FLASH
/* Used by the startup to initialize data */
_sidata = LOADADDR(.data);
+1 -1
View File
@@ -287,6 +287,6 @@ SVC_Handler:
BLXNE R12
BX LR
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/*****END OF FILE****/
+18 -2
View File
@@ -82,12 +82,28 @@ void bsp_log_init(void)
__attribute__((weak)) int _read(int file, char *ptr, int len)
{
return 0;
return 0;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
bsp_uart_send(ptr, len);
return len;
return len;
}
int HiLogWriteInternal(const char *buffer, size_t bufLen)
{
if (!buffer)
return -1;
// because it's called as HiLogWriteInternal(buf, strlen(buf) + 1)
if (bufLen < 2)
return 0;
if (buffer[bufLen - 2] != '\n') {
*((char *)buffer + bufLen - 1) = '\n';
} else {
bufLen--;
}
int ret = app_uart_transmit_sync(LOG_UART_ID, buffer, bufLen, 1000);
return ret;
}
View File
View File
Regular → Executable
+13 -7
View File
@@ -1,7 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: zhangqf
# Copyright (c) 2021 GOODIX.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,6 +11,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: zhangqf
"""
This module use arm-none-eabi-xxx function to deal the xxx.elf file. we recept two parameters, and the
format of the usage: bin_create.py input_file.elf out_file.bin. Thanks for use this module
@@ -29,8 +29,7 @@ import re
import os
import json
TARGET_IMG_NAME = "application_fw"
CUSTOM_CONFIG = "../../../device/goodix/gr551x/sdk_liteos/config/custom_config.h"
CUSTOM_CONFIG = "../../../device/soc/goodix/gr551x/sdk_liteos/config/custom_config.h"
BufSize = 1024
PatternValue = 0x4744
@@ -323,8 +322,12 @@ class GenFirmware():
img_info_byte = self.img_info.to_bytes()
for x in img_info_byte:
f_w.write(x)
for i in range(MaxCommentsLen):
for i in range(len(self.img_info.comments)):
f_w.write(self.img_info.comments[i].encode('utf-8'))
if (len(self.img_info.comments) < MaxCommentsLen):
for i in range(MaxCommentsLen - len(self.img_info.comments)):
pad=' ';
f_w.write(str(pad).encode('utf-8'))
for i in range(8):
a = 0
f_w.write(a.to_bytes(1, byteorder='little', signed=False))
@@ -386,11 +389,14 @@ def main(input = ""):
def make_bin(input_file = "", output_file = "", list_file=""):
shell_script = '''arm-none-eabi-objcopy -O binary -S {src_file} {dst_file}'''.format(src_file = input_file, dst_file = output_file)
cmd_output = os.system(shell_script)
main(output_file)
shell_script = '''arm-none-eabi-size {src_file}
arm-none-eabi-objdump -D {src_file} > {list_file}'''.format(src_file = input_file, dst_file = output_file,
list_file=list_file)
cmd_output = os.system(shell_script)
return
if __name__ == "__main__":