实现全部功能

master
hebi 2024-03-23 14:45:09 +08:00
parent af0e7e1df2
commit cea1101ba6
27 changed files with 6401 additions and 30328 deletions

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
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
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

View File

@ -1,15 +1,12 @@
# open_usb_power_supply # USB_PowerSupply
#### Description #### Description
基于AT32F415开发的USB便携式移动电压源 基于雅特力, AT32F415x开发的USB可调电源
1. 可以将USB电源适配器通过一个DC-DC可调升降压电源芯片转换后输出一个从1.0V~30V的可调DC电源
支持USB PD3.0/PD2.0BC1.2协议支持5V~20V输入 2.支持PD3.0协议可以通过协议沟通使其输出5V9V12V15V20V的电压
输出电压从2.7V ~ 20V可调3A的输出电流带载能力可满足日常实验使用 2. 输入电压,电流的实时检测和显示
从100mA~3A的限流可调 2. 输出电压,电流的实时检测和显示
电源输入电压,电流实时监测 3. 输出电流可设定,超过设定输出电流关断输出
电源输出电压,电流实时监测
电压检测分辨率8mV电流检测分辨率40uV/10mR=4uA
#### Software Architecture #### Software Architecture
Software architecture description Software architecture description

101
README.md
View File

@ -1,59 +1,42 @@
# open_usb_power_supply # USB_PowerSupply
#### 介绍 #### 介绍
基于AT32F415开发的USB便携式移动电压源 基于雅特力, AT32F415x开发的USB可调电源
- 支持USB PD3.0/PD2.0BC1.2协议支持5V~20V输入 1. 可以将USB电源适配器通过一个DC-DC可调升降压电源芯片转换后输出一个从1.0V~30V的可调DC电源
- 输出电压从2.7V ~ 20V可调3A的输出电流带载能力可满足日常实验使用 2.支持PD3.0协议可以通过协议沟通使其输出5V9V12V15V20V的电压
- 从100mA~3A的限流可调 2. 输入电压,电流的实时检测和显示
- 电源输入电压,电流实时监测 2. 输出电压,电流的实时检测和显示
- 电源输出电压,电流实时监测 3. 输出电流可设定,超过设定输出电流关断输出
- 电压检测分辨率8mV电流检测分辨率40uV/10mR=4uA
- 320x240 TFT屏实时显示用电情况可做为一个简易功率计使用监测用电设备的用电能力 #### 软件架构
- 可通过BLE与上位机进行通信实现更多应用的拓展开发 软件架构说明
- 外围器件少实现原理简单非常方便DIY
- 小巧方便不依赖特定电源只要是USB适配器都可以使用
- 软硬件全部开源 #### 安装教程
1. xxxx
#### 软件架构 2. xxxx
- 本项目使用的软件架构为本人自行开发,此软件架构的核心是所有的功能模块被独立分开,模块与模块之间以消息的方式进行数据耦合,各种模块维护各自模块的状态,本着以功能内聚大,以数据耦合为主,尽量不使用逻辑耦合,或者直接修改对方数据的方式。 3. xxxx
- 如下是程序框架图,下面对部分模块进行简要说明,详细的大家可以看看源代码,如有不明白的地方欢迎大家留言讨论:
![软件框图](docs/prgram_flowchart.png) #### 使用说明
- **mcu_os**
  核心是mcu_os部分这部分实现了消息处理任务调度内存管理等功能本项目中的usr_main_app、usr_input_task、 1. xxxx
  usr_display_task几个功能任务模块就是居于此基础之上进行消息传递实现系统UI的各个功能需求。 2. xxxx
- **usr_display_task** 3. xxxx
  负责接收来自usr_main_app发来的一些状态信息在LCD屏幕上实现各种界面显示。
- **usr_main_app** #### 参与贡献
  负责接收来自usr_input_task发出的用户输入事件对用户输入事件进行响应并把一些状态信息发送给usr_display_task
- **usr_input_task** 1. Fork 本仓库
  负责调用驱动层的io_key,读取io_key状态信息生成按键事件并把按键事件发送给usr_main_app 2. 新建 Feat_xxx 分支
3. 提交代码
#### 安装教程 4. 新建 Pull Request
1. xxxx
2. xxxx #### 特技
3. xxxx
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
#### 使用说明 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
1. xxxx 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
2. xxxx 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
3. xxxx 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

19
mcu_code/.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${default}",
"${workspaceFolder}/project/AT32_IDE/user/mcu_os/mcu"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "gnu++14"
}
],
"version": 4
}

View File

@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1487030108176016805" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-211910334941496890" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>
@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1427620041157912972" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-152500267923393057" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

View File

@ -128,9 +128,26 @@ void uart_print_init(uint32_t baudrate) {
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(PRINT_UART_TX_GPIO, &gpio_init_struct); gpio_init(PRINT_UART_TX_GPIO, &gpio_init_struct);
/* configure the usart2 rx pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_3;
gpio_init_struct.gpio_pull = GPIO_PULL_UP;
gpio_init(GPIOA, &gpio_init_struct);
/* config usart nvic interrupt */
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
nvic_irq_enable(USART2_IRQn, 0, 0);
/* configure uart param */ /* configure uart param */
usart_init(PRINT_UART, baudrate, USART_DATA_8BITS, USART_STOP_1_BIT); usart_init(PRINT_UART, baudrate, USART_DATA_8BITS, USART_STOP_1_BIT);
usart_transmitter_enable(PRINT_UART, TRUE); usart_transmitter_enable(PRINT_UART, TRUE);
usart_receiver_enable(PRINT_UART, TRUE);
/* enable usart2 and usart3 interrupt */
usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE);
usart_enable(PRINT_UART, TRUE); usart_enable(PRINT_UART, TRUE);
} }

View File

@ -57,6 +57,8 @@ extern "C" {
#define PRINT_UART_TX_PIN GPIO_PINS_2 #define PRINT_UART_TX_PIN GPIO_PINS_2
#define PRINT_UART_TX_GPIO GPIOA #define PRINT_UART_TX_GPIO GPIOA
#define PRINT_UART_TX_GPIO_CRM_CLK CRM_GPIOA_PERIPH_CLOCK #define PRINT_UART_TX_GPIO_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
#define PRINT_UART_RX_PIN GPIO_PINS_3
#define PRINT_UART_RX_GPIO GPIOA
/******************* define button *******************/ /******************* define button *******************/

View File

@ -24,7 +24,7 @@ u8 sc8721_regs[10];
* @param limit_current uint in mA * @param limit_current uint in mA
* @return int * @return int
*************************************************************************/ *************************************************************************/
int sc8721_current_limit_cfg(uint16_t limit_current/*mA*/){ int sc8721_current_limit_cfg(int32_t limit_current/*mA*/){
// IOUT_ILIM // IOUT_ILIM
//CSO_SET = IOUT_ILIM*Rs*RCSO/(4mV*2kΩ)-1 //CSO_SET = IOUT_ILIM*Rs*RCSO/(4mV*2kΩ)-1
u8 cso_set; u8 cso_set;
@ -42,6 +42,7 @@ int sc8721_current_limit_cfg(uint16_t limit_current/*mA*/){
ret=-1; ret=-1;
MO_LOG("write error:%d,ch_reg:0x%x\r\n", i2c_status, tmp[0]); MO_LOG("write error:%d,ch_reg:0x%x\r\n", i2c_status, tmp[0]);
} else { } else {
// MO_LOG("curr limit:%x\r\n",cso_set);
} }
return ret; return ret;
@ -111,7 +112,7 @@ int sc8721_out_vol_cfg(uint16_t out_vol/*mV*/){
tmp[2] = (sc8721_regs[VOUT_SET_MSB_REG-1+1]&0xe0)|vout_set; tmp[2] = (sc8721_regs[VOUT_SET_MSB_REG-1+1]&0xe0)|vout_set;
tmp[3] = (sc8721_regs[VOUT_SET_MSB_REG-1+2]&0xFB)|(CFG_LOAD_BIT); tmp[3] = (sc8721_regs[VOUT_SET_MSB_REG-1+2]&0xFB)|(CFG_LOAD_BIT);
// tmp[4] = (sc8721_regs[VOUT_SET_MSB_REG-1+3])|0X80; // tmp[4] = (sc8721_regs[VOUT_SET_MSB_REG-1+3])|0X80;
MO_LOG(" VOL MSB:0x%x,LSB:0x%x\r\n", vout_set_msb, vout_set); // MO_LOG(" VOL MSB:0x%x,LSB:0x%x\r\n", vout_set_msb, vout_set);
i2c_status = usr_i2c_master_transmit(SC8721_IIC_DEV_ADD, tmp, 4, 1000); i2c_status = usr_i2c_master_transmit(SC8721_IIC_DEV_ADD, tmp, 4, 1000);
if (i2c_status != I2C_OK) { if (i2c_status != I2C_OK) {
@ -155,7 +156,7 @@ i2c_status_type get_sc8721_status(u8 reg, u8 *dat_buf){
return i2c_status; return i2c_status;
} }
MO_LOG("sc8721 s1:%x s2: %x\r\n", dat_buf[0], dat_buf[1]); // MO_LOG("sc8721 s1:%x s2: %x\r\n", dat_buf[0], dat_buf[1]);
return i2c_status; return i2c_status;
} }

View File

@ -42,7 +42,7 @@ extern "C"{
int sc8721_out_vol_cfg(uint16_t out_vol/*mV*/); int sc8721_out_vol_cfg(uint16_t out_vol/*mV*/);
int sc8721_current_limit_cfg(uint16_t limit_current/*mA*/); int sc8721_current_limit_cfg(int32_t limit_current/*mA*/);
i2c_status_type get_sc8721_status(u8 reg, u8 *dat_buf); i2c_status_type get_sc8721_status(u8 reg, u8 *dat_buf);
i2c_status_type get_sc8721_init(void); i2c_status_type get_sc8721_init(void);

View File

@ -13,29 +13,42 @@
#include "mo_config.h" #include "mo_config.h"
#include "io_key.h" #include "io_key.h"
/*#TODO: You have to config below items which depend on your hardware cfg and which MCU you used.*/
#define key_get_gpio_state(port,pin) gpio_input_data_bit_read((gpio_type*)port,pin)
static KEY_TASK_T k_task; static KEY_TASK_T k_task;
/**************************************************************************
* @brief Get the key state object
* #TODO: You have to make the function below (get_gpio_key_state) that depend on your
hardware cfg and which chips you used.
* @param port
* @param pin
* @param param
* @return IO_KEY_STATE
*************************************************************************/
static IO_KEY_STATE get_a_key_state(void *port,u16 pin,void *param){
return gpio_input_data_bit_read((gpio_type*)port,pin);
}
const ExKyeInfo ex_key_map[GPIO_KEY_MAX] = { const ExKyeInfo ex_key_map[GPIO_KEY_MAX] = {
{ {
.kcode = HW_KEY_LEFT, .kcode = HW_KEY_LEFT,
.port = GPIOB, .port = GPIOB,
.pin = GPIO_PINS_1, .pin = GPIO_PINS_1,
.k_active_level = IO_PIN_RESET, .k_active_level = IO_PIN_RESET,
.get_k_state = get_a_key_state,
}, },
{ {
.kcode = HW_KEY_RIGHT, .kcode = HW_KEY_RIGHT,
.port = GPIOB, .port = GPIOB,
.pin = GPIO_PINS_2, .pin = GPIO_PINS_2,
.k_active_level = IO_PIN_RESET, .k_active_level = IO_PIN_RESET,
.get_k_state = get_a_key_state,
}, },
{ {
.kcode = HW_KEY_CENTER, .kcode = HW_KEY_CENTER,
.port = GPIOB, .port = GPIOB,
.pin = GPIO_PINS_0, .pin = GPIO_PINS_0,
.k_active_level = IO_PIN_RESET, .k_active_level = IO_PIN_RESET,
.get_k_state = get_a_key_state,
}, },
}; };
@ -44,28 +57,31 @@ const ExKyeInfo ex_key_map[GPIO_KEY_MAX] = {
void io_key_task_handle(void) { /*#TODO:Invoked in 1mS loop*/ void io_key_task_handle(void) { /*#TODO:Invoked in 1mS loop*/
IO_KEY_STATE pio; IO_KEY_STATE pio;
u8 j; u8 j;
const ExKyeInfo *pKTable;
k_task.app_tick++; k_task.app_tick++;
if (k_task.app_tick < KEY_POLLING_INTERVAL) return; if (k_task.app_tick < KEY_POLLING_INTERVAL) return;
k_task.app_tick = 0; k_task.app_tick = 0;
// MO_LOG("PIO:%d\r\n",23); // MO_LOG("PIO:%d\r\n",23);
for (j = 0; j < GPIO_KEY_MAX; j++) { for (j = 0; j < GPIO_KEY_MAX; j++) {
if (k_task.pKeyTable[j].port != 0) { pKTable=&k_task.pKeyTable[j];
pio = key_get_gpio_state(k_task.pKeyTable[j].port, k_task.pKeyTable[j].pin);
if (pKTable->port != 0) {
pio = pKTable->get_k_state(pKTable->port,pKTable->pin,NULL);
// MO_LOG("PIO:%d\r\n",pio); // MO_LOG("PIO:%d\r\n",pio);
if (pio != k_task.pKeyTable[j].k_active_level) { /*Key Up*/ if (pio != pKTable->k_active_level) { /*Key Up*/
if (k_task.ex_k_cnt[j] != 0) { if (k_task.ex_k_cnt[j] != 0) {
k_task.ex_k_cnt[j]--; k_task.ex_k_cnt[j]--;
if (k_task.ex_k_cnt[j] == 0 && k_task.k_event_cb) { if (k_task.ex_k_cnt[j] == 0 && k_task.k_event_cb) {
k_task.k_event_cb(IO_K_EVENT_VK_UP, k_task.pKeyTable[j].kcode); k_task.k_event_cb(IO_K_EVENT_VK_UP, pKTable->kcode);
} }
} }
} else { /*Key Down*/ } else { /*Key Down*/
if (k_task.ex_k_cnt[j] < KEY_DEBOUNCE_TIME) { if (k_task.ex_k_cnt[j] < KEY_DEBOUNCE_TIME) {
k_task.ex_k_cnt[j]++; k_task.ex_k_cnt[j]++;
if (k_task.ex_k_cnt[j] >= KEY_DEBOUNCE_TIME && k_task.k_event_cb) { if (k_task.ex_k_cnt[j] >= KEY_DEBOUNCE_TIME && k_task.k_event_cb) {
k_task.k_event_cb(IO_K_EVENT_VK_DW, k_task.pKeyTable[j].kcode); k_task.k_event_cb(IO_K_EVENT_VK_DW, pKTable->kcode);
} }
} }
} }
@ -73,10 +89,26 @@ void io_key_task_handle(void) { /*#TODO:Invoked in 1mS loop*/
} }
} }
/**************************************************************************
* @brief #TODO: you should to init the GPIO as input mode or other input devices
* in below function (key_gpio_init)
*
*************************************************************************/
static void key_gpio_init(void){
}
/**************************************************************************
* @brief
*
* @param k_event_cb
*************************************************************************/
void io_key_task_init(io_k_event_cb k_event_cb) { void io_key_task_init(io_k_event_cb k_event_cb) {
memset(&k_task, 0, sizeof(k_task)); memset(&k_task, 0, sizeof(k_task));
k_task.pKeyTable = ex_key_map; k_task.pKeyTable = ex_key_map;
k_task.k_event_cb = k_event_cb; k_task.k_event_cb = k_event_cb;
key_gpio_init();
} }
/**************************************************************/ /**************************************************************/

View File

@ -60,14 +60,15 @@ typedef void (*io_k_event_cb)(ioKeyEvent k_event,mo_hw_key_t kcode);
#endif #endif
typedef enum { IO_PIN_RESET = 0U, IO_PIN_SET } IO_PinState; typedef enum { IO_PIN_RESET = 0U, IO_PIN_SET } IO_PinState;
#define IO_KEY_STATE IO_PinState #define IO_KEY_STATE IO_PinState
typedef IO_KEY_STATE (*get_key_state)(void *port,u16 pin,void *param);
typedef struct ex_key_infor { typedef struct ex_key_infor {
mo_hw_key_t kcode; mo_hw_key_t kcode;
void *port; /**/ void *port; /**/
u16 pin; u16 pin;
IO_KEY_STATE k_active_level; IO_KEY_STATE k_active_level;
get_key_state get_k_state;
} ExKyeInfo; } ExKyeInfo;
typedef struct key_task { typedef struct key_task {

View File

@ -105,7 +105,7 @@ typedef struct button_task {
btn_msg_cb_handle btn_msg_cb; btn_msg_cb_handle btn_msg_cb;
} btn_task_t; } btn_task_t;
u8 mcu_btn_init(btn_msg_cb_handle btn_msg_cb);/*#TODO: Need Invoked to init btn function in main loop*/ u8 mcu_btn_init(btn_msg_cb_handle btn_msg_cb);/*#TODO: Need Invoked to init btn function in main fun.*/
void mcu_button_loop(u8 interval/*mS*/); /*#TODO: Invoked in a loop*/ void mcu_button_loop(u8 interval/*mS*/); /*#TODO: Invoked in a loop*/

View File

@ -62,8 +62,11 @@ typedef enum {
USR_LCD_CFG_UI_ACTIVE_UPDATE, USR_LCD_CFG_UI_ACTIVE_UPDATE,
USR_LCD_TEST_MSG, USR_LCD_TEST_MSG,
USR_LCD_PD_REQ_UI_UPDATE, USR_LCD_PD_REQ_UI_UPDATE,
USR_UART_RX_RECEIVED_DATAS,
USR_UPDATE_CFG_VOLTAGE_TO_IC, USR_UPDATE_CFG_VOLTAGE_TO_IC,
USR_SYNC_PD_REQ_VOL_TO_HOST,
USR_SYNC_OVOL_TO_HOST,
USR_HOST_CONNECTED_TO_SYNC_DATS,
/*****user event end******************************/ /*****user event end******************************/
/*****System event start from 0x8000***/ /*****System event start from 0x8000***/

View File

@ -27,6 +27,10 @@ extern "C"{
#define CURR_mA "mA" #define CURR_mA "mA"
#define CURR_uA "uA" #define CURR_uA "uA"
#define POWER_W " W"
#define POWER_mW "mW"
#define POWER_uW "uW"
#define TABLE_START_Y 124 #define TABLE_START_Y 124
#define TABLE_START_X 0 #define TABLE_START_X 0
#define ROW_DISTANCE 10 #define ROW_DISTANCE 10

View File

@ -77,17 +77,29 @@ const CurScaleInforT c_scale_table[]={
.p_Cunit_str="mA", .p_Cunit_str="mA",
.curr_actual_scale = 1000, .curr_actual_scale = 1000,
}, },
{ .curr_dis_scale=2,/*Unit is uA*/ { .curr_dis_scale=5,/*Unit is uA*/
.p_Cunit_str="mA", .p_Cunit_str="mA",
.curr_actual_scale = 2000, .curr_actual_scale = 5000,
}, },
{ .curr_dis_scale=3,/*Unit is uA*/ { .curr_dis_scale=10,/*Unit is uA*/
.p_Cunit_str="mA", .p_Cunit_str="mA",
.curr_actual_scale = 3000, .curr_actual_scale = 10000,
}, },
{ .curr_dis_scale=7,/*Unit is uA*/ { .curr_dis_scale=20,/*Unit is uA*/
.p_Cunit_str="mA", .p_Cunit_str="mA",
.curr_actual_scale = 7000, .curr_actual_scale = 20000,
},
{ .curr_dis_scale=40,/*Unit is uA*/
.p_Cunit_str="mA",
.curr_actual_scale = 40000,
},
{ .curr_dis_scale=60,/*Unit is uA*/
.p_Cunit_str="mA",
.curr_actual_scale = 60000,
},
{ .curr_dis_scale=80,/*Unit is uA*/
.p_Cunit_str="mA",
.curr_actual_scale = 80000,
}, },
}; };
@ -104,6 +116,42 @@ static void monitor_vol_curr_input(mo_u32 vol,mo_u32 curr){
} }
} }
static mo_u32 get_max_curr_by_input_buf(void){
mo_u32 dat_index;
mo_u32 curr,max_curr=0;
mo_u32 i=0;
dat_index=dis_tsk.cycle_buf_start;
while (dat_index != dis_tsk.cycle_buf_end){
curr = dis_tsk.vc[dat_index].out_curr;
if(curr > max_curr) max_curr = curr;
i++;
dat_index = (dis_tsk.cycle_buf_start+i)%INPUT_DAT_MAX;
}
return max_curr;
}
static mo_u32 get_max_voltage_by_input_buf(void){
mo_u32 dat_index;
mo_u32 curr,max=0;
mo_u32 i=0;
dat_index=dis_tsk.cycle_buf_start;
while (dat_index != dis_tsk.cycle_buf_end){
curr = dis_tsk.vc[dat_index].out_vol;
if(curr > max) max = curr;
i++;
dat_index = (dis_tsk.cycle_buf_start+i)%INPUT_DAT_MAX;
}
return max;
}
static void covert_to_str(char *p_str_des,mo_u32 t_dat,mo_u32 t_dat2,u8 str_len){ static void covert_to_str(char *p_str_des,mo_u32 t_dat,mo_u32 t_dat2,u8 str_len){
mo_u32 i; mo_u32 i;
@ -165,26 +213,74 @@ static char *curr_dat_to_string(u8 str_len,char *p_str_des,mo_u32 curr_dat){
}else{ }else{
curr_uint = CURR_uA; curr_uint = CURR_uA;
sprintf(p_str_des,"%d",curr_dat); sprintf(p_str_des,"%d",curr_dat);
for(i=0; i<str_len; i++){
if(p_str_des[i]=='\0'){
p_str_des[i] = '0';
}
}
} }
return curr_uint; return curr_uint;
} }
static char *power_to_string(u8 str_len,char *p_str_des,mo_u32 v,mo_u32 c){
mo_u32 i;
char *pw_uint=0;
mo_u32 pw;
mo_u32 t_dat,t_dat2;
pw = (v/10)*(c/100); /*unit uW*/
if(p_str_des==NULL)return "\0";
t_dat = pw/1000;
if(t_dat > 999){
pw_uint = POWER_W;
t_dat2 = t_dat%1000;
t_dat = t_dat/1000;
// sprintf(p_str_des,"%d.%d",t_dat,t_dat2);
covert_to_str(p_str_des,t_dat,t_dat2,str_len);
}else if(t_dat){
pw_uint = POWER_mW;
t_dat2 = pw%1000;
// sprintf(p_str_des,"%d.%d",t_dat,t_dat2);
covert_to_str(p_str_des,t_dat,t_dat2,str_len);
}else{
pw_uint = POWER_uW;
sprintf(p_str_des,"%d",pw);
for(i=0; i<str_len; i++){
if(p_str_des[i]=='\0'){
p_str_des[i] = '0';
}
}
}
return pw_uint;
}
static void display_monitor_dat_handle(MonitorDatsT dats){ static void display_monitor_dat_handle(MonitorDatsT dats){
char tmp[32]={0}; char tmp[32]={0};
char send_to_buf[128];
mo_u32 pw; mo_u32 pw;
char *curr_uint; char *curr_uint;
/******input monitor ui*/ /******input monitor ui*/
memset(tmp,0,sizeof(tmp)); memset(tmp,0,sizeof(tmp));
memset(send_to_buf,0,sizeof(send_to_buf));
vol_dat_to_string(5,tmp,dats.in_vol); vol_dat_to_string(5,tmp,dats.in_vol);
LCD_ShowString(10,55,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(10,55,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0);
LCD_ShowString(75,55,"V",IN_VOL_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(75,55,"V",IN_VOL_COLOR,DIS_BACKGROUND,24,0);
sprintf(send_to_buf, "i_vol=%s@V,",tmp);
memset(tmp,0,sizeof(tmp)); memset(tmp,0,sizeof(tmp));
curr_uint=curr_dat_to_string(5,tmp,dats.in_curr); curr_uint=curr_dat_to_string(5,tmp,dats.in_curr);
LCD_ShowString(10,82,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(10,82,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0);
LCD_ShowString(75,82,curr_uint,IN_CURR_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(75,82,curr_uint,IN_CURR_COLOR,DIS_BACKGROUND,24,0);
strcat(send_to_buf, "i_cur=");
strcat(send_to_buf, tmp);
strcat(send_to_buf, "@");
strcat(send_to_buf, curr_uint);
/************************/ /************************/
/*******out monitor ui*/ /*******out monitor ui*/
@ -192,17 +288,31 @@ static void display_monitor_dat_handle(MonitorDatsT dats){
vol_dat_to_string(5,tmp,dats.out_vol); vol_dat_to_string(5,tmp,dats.out_vol);
LCD_ShowString(120,45,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(120,45,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0);
LCD_ShowString(180,45,"V",OUT_VOL_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(180,45,"V",OUT_VOL_COLOR,DIS_BACKGROUND,24,0);
strcat(send_to_buf, ",o_vol=");
pw = (dats.out_curr/1000*dats.out_vol); strcat(send_to_buf, tmp);
strcat(send_to_buf, "@V,");
// pw = (dats.out_curr/1000*dats.out_vol);
memset(tmp,0,sizeof(tmp)); memset(tmp,0,sizeof(tmp));
vol_dat_to_string(5,tmp,pw); curr_uint = power_to_string(5,tmp,dats.out_vol,dats.out_curr);
LCD_ShowString(204,45,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(204,45,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0);
LCD_ShowString(264,45,"mW",OUT_PW_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(264,45,curr_uint,OUT_PW_COLOR,DIS_BACKGROUND,24,0);
//o_pw=500@mW
strcat(send_to_buf, "o_pw=");
strcat(send_to_buf, tmp);
strcat(send_to_buf, "@");
strcat(send_to_buf, curr_uint);
memset(tmp,0,sizeof(tmp)); memset(tmp,0,sizeof(tmp));
curr_uint=curr_dat_to_string(5,tmp,dats.out_curr); curr_uint=curr_dat_to_string(5,tmp,dats.out_curr);
LCD_ShowString(135,73,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,32,0); LCD_ShowString(135,73,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,32,0);
LCD_ShowString(215,73,curr_uint,OUT_CURR_COLOR,DIS_BACKGROUND,32,0); LCD_ShowString(215,73,curr_uint,OUT_CURR_COLOR,DIS_BACKGROUND,32,0);
strcat(send_to_buf, ",o_cur=");
strcat(send_to_buf, tmp);
strcat(send_to_buf, "@");
strcat(send_to_buf, curr_uint);
strcat(send_to_buf, "\n");
printf("%s",send_to_buf);
/*************************/ /*************************/
} }
@ -220,7 +330,15 @@ static void display_cfg_dat_handle(CfigDatsT dats){
curr_uint=curr_dat_to_string(5,tmp,dats.limit_curr*1000); curr_uint=curr_dat_to_string(5,tmp,dats.limit_curr*1000);
LCD_ShowString(220,5,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(220,5,tmp,RUN_NUM_COLOR,DIS_BACKGROUND,24,0);
LCD_ShowString(280,5,curr_uint,CFG_CURR_COLOR,DIS_BACKGROUND,24,0); LCD_ShowString(280,5,curr_uint,CFG_CURR_COLOR,DIS_BACKGROUND,24,0);
}
static void cfg_dat_send_to_host_handle(CfigDatsT dats){
char tmp[32]={0};
char *curr_uint;
memset(tmp,0,sizeof(tmp));
vol_dat_to_string(5,tmp,dats.out_vol);
printf("o_cfg=%s@V\n",tmp);
} }
static void display_pd_req_cfg_ui(u8 vol){ static void display_pd_req_cfg_ui(u8 vol){
@ -228,6 +346,10 @@ static void display_pd_req_cfg_ui(u8 vol){
LCD_ShowString((24+12),(38),"V",IN_VOL_COLOR,DIS_BACKGROUND,12,0); LCD_ShowString((24+12),(38),"V",IN_VOL_COLOR,DIS_BACKGROUND,12,0);
} }
static void cfg_pd_req_send_to_host(u8 vol){
printf("i_cfg=%d@V\n",vol);
}
static void display_draw_main_ui(void){ static void display_draw_main_ui(void){
CfigDatsT cfg_dat={.out_vol=2700,.limit_curr=3000}; CfigDatsT cfg_dat={.out_vol=2700,.limit_curr=3000};
/*********USB IN PUT*****************/ /*********USB IN PUT*****************/
@ -379,8 +501,9 @@ static void draw_monitor_run_table_ui(mo_u32 v,mo_u32 c){
if(dis_tsk.monitor_table_en==0)return; if(dis_tsk.monitor_table_en==0)return;
monitor_vol_curr_input(v,c); monitor_vol_curr_input(v,c);
vol_scale = get_v_scale_infor_by_input_vol(v);
cur_scale = get_curr_scale_infor_by_input_curr(c); vol_scale = get_v_scale_infor_by_input_vol(get_max_voltage_by_input_buf());
cur_scale = get_curr_scale_infor_by_input_curr(get_max_curr_by_input_buf());
usr_LCD_Fill(TABLE_START_X,TABLE_START_Y,TABLE_START_X+TABLE_WIDTH,\ usr_LCD_Fill(TABLE_START_X,TABLE_START_Y,TABLE_START_X+TABLE_WIDTH,\
TABLE_START_Y+TABLE_HEIGHT,DIS_BACKGROUND); TABLE_START_Y+TABLE_HEIGHT,DIS_BACKGROUND);
@ -499,6 +622,16 @@ static void display_task_handle(mo_task tsk, mo_msg_id msg_id, mo_msg msg) {
case USR_LCD_PD_REQ_UI_UPDATE: case USR_LCD_PD_REQ_UI_UPDATE:
display_pd_req_cfg_ui(*(mo_u8*)msg); display_pd_req_cfg_ui(*(mo_u8*)msg);
break; break;
case USR_SYNC_PD_REQ_VOL_TO_HOST:
cfg_pd_req_send_to_host(*(mo_u8*)msg);
break;
case USR_SYNC_OVOL_TO_HOST:{
CfigDatsT *dats = (CfigDatsT*)msg;
cfg_dat_send_to_host_handle(*dats);
}
break;
case USR_HOST_CONNECTED_TO_SYNC_DATS:
break;
default: default:
break; break;

View File

@ -37,14 +37,21 @@ static void out_voltage_decrease_handle(u16 step){
CfigDatsT *cdat; CfigDatsT *cdat;
if(main_tsk.cfg_dat.out_vol>VOUT_MIN){ if(main_tsk.cfg_dat.out_vol>VOUT_MIN){
main_tsk.cfg_dat.out_vol-=step;
if(main_tsk.cfg_dat.out_vol<VOUT_MIN)main_tsk.cfg_dat.out_vol=VOUT_MIN; if(main_tsk.cfg_dat.out_vol>step)main_tsk.cfg_dat.out_vol-=step;
//sc8721_out_vol_cfg(main_tsk.cfg_dat.out_vol); else main_tsk.cfg_dat.out_vol=VOUT_MIN;
cdat = (CfigDatsT*)mo_malloc(sizeof(CfigDatsT)); cdat = (CfigDatsT*)mo_malloc(sizeof(CfigDatsT));
if(cdat){ if(cdat){
*cdat = main_tsk.cfg_dat; *cdat = main_tsk.cfg_dat;
mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0); mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0);
} }
cdat = (CfigDatsT*)mo_malloc(sizeof(CfigDatsT));
if(cdat){
*cdat = main_tsk.cfg_dat;
mo_msg_send(get_usr_display_task(),USR_SYNC_OVOL_TO_HOST,cdat,0);
}
} }
} }
@ -60,15 +67,39 @@ static void out_voltage_increase_handle(u16 step) {
*cdat = main_tsk.cfg_dat; *cdat = main_tsk.cfg_dat;
mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0); mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0);
} }
cdat = (CfigDatsT*)mo_malloc(sizeof(CfigDatsT));
if(cdat){
*cdat = main_tsk.cfg_dat;
mo_msg_send(get_usr_display_task(),USR_SYNC_OVOL_TO_HOST,cdat,0);
}
} }
} }
static void out_voltage_set_handle(mo_u32 ovl) {
CfigDatsT *cdat;
main_tsk.cfg_dat.out_vol = ovl;
if(main_tsk.cfg_dat.out_vol>VOUT_MAX)main_tsk.cfg_dat.out_vol=VOUT_MAX;
if(main_tsk.cfg_dat.out_vol<VOUT_MIN)main_tsk.cfg_dat.out_vol=VOUT_MIN;
//sc8721_out_vol_cfg(main_tsk.cfg_dat.out_vol);
cdat = (CfigDatsT*)mo_malloc(sizeof(CfigDatsT));
if(cdat){
*cdat = main_tsk.cfg_dat;
mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0);
}
}
static void out_limit_curr_decrease_handle(u16 step){ static void out_limit_curr_decrease_handle(u16 step){
CfigDatsT *cdat; CfigDatsT *cdat;
if(main_tsk.cfg_dat.limit_curr>OC_MIN){ if(main_tsk.cfg_dat.limit_curr>OC_MIN){
main_tsk.cfg_dat.limit_curr-=step;
if(main_tsk.cfg_dat.limit_curr<OC_MIN)main_tsk.cfg_dat.limit_curr=OC_MIN; if(main_tsk.cfg_dat.limit_curr>step)main_tsk.cfg_dat.limit_curr-=step;
else main_tsk.cfg_dat.limit_curr=OC_MIN;
sc8721_current_limit_cfg(main_tsk.cfg_dat.limit_curr); sc8721_current_limit_cfg(main_tsk.cfg_dat.limit_curr);
cdat = (CfigDatsT*)mo_malloc(sizeof(CfigDatsT)); cdat = (CfigDatsT*)mo_malloc(sizeof(CfigDatsT));
@ -77,6 +108,7 @@ static void out_limit_curr_decrease_handle(u16 step){
mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0); mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0);
} }
} }
// MO_LOG("limit_curr:%d\r\n",main_tsk.cfg_dat.limit_curr);
} }
static void out_limit_curr_increase_handle(u16 step) { static void out_limit_curr_increase_handle(u16 step) {
@ -92,6 +124,7 @@ static void out_limit_curr_increase_handle(u16 step) {
mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0); mo_msg_send(get_usr_display_task(),USR_LCD_UPDATE_OUT_CFG_DAT,cdat,0);
} }
} }
// MO_LOG("limit_curr:%d\r\n",main_tsk.cfg_dat.limit_curr);
} }
static void cfg_increase_handle(u16 step){ static void cfg_increase_handle(u16 step){
@ -171,6 +204,43 @@ static mo_u8 pd_req_vol_inc_handle(void){
} }
static mo_u8 set_pd_req_vol_handle(PD_REQ_VOL_T pd_req_vol){
mo_u8 vol;
main_tsk.pd_req_vol = pd_req_vol;
switch (pd_req_vol){
case PD_REQ_5V:
CFG_PD_SET(1,0,0);
vol=5;
break;
case PD_REQ_9V:
CFG_PD_SET(0,0,0);
vol=9;
break;
case PD_REQ_12V:
CFG_PD_SET(0,0,1);
vol=12;
break;
case PD_REQ_15V:
CFG_PD_SET(0,1,1);
vol=15;
break;
case PD_REQ_20V:
CFG_PD_SET(0,1,0);
vol=20;
break;
default:
CFG_PD_SET(0,0,0);
vol=9;
main_tsk.pd_req_vol = PD_REQ_9V;
break;
}
return vol;
}
static void key_event_handle(mo_key_event_msg_t *k_event){ static void key_event_handle(mo_key_event_msg_t *k_event){
switch (k_event->vk_code){ switch (k_event->vk_code){
@ -227,6 +297,12 @@ static void key_event_handle(mo_key_event_msg_t *k_event){
mo_msg_send(get_usr_display_task(),USR_LCD_PD_REQ_UI_UPDATE,p_vol,0); mo_msg_send(get_usr_display_task(),USR_LCD_PD_REQ_UI_UPDATE,p_vol,0);
} }
p_vol = (mo_u8*)mo_malloc(sizeof(mo_u8));
if(p_vol){
*p_vol = req_vol;
mo_msg_send(get_usr_display_task(),USR_SYNC_OVOL_TO_HOST,p_vol,0);
}
} }
break; break;
@ -234,15 +310,149 @@ static void key_event_handle(mo_key_event_msg_t *k_event){
break; break;
} }
} }
#define MAX_BUF_SIZE__ 128
mo_s8 usr_mem_cpy(mo_u8 *start_add,mo_u8 *end_add, mo_u8 *p_get_dat){
uint16_t max_dat=0;
if(start_add==NULL || end_add==NULL || p_get_dat==NULL)return -1;
while(&start_add[max_dat] != end_add && max_dat<MAX_BUF_SIZE__){
p_get_dat[max_dat]=start_add[max_dat];
max_dat++;
}
p_get_dat[max_dat]='\0';
return 0;
}
#define MAX_POINT_LEN 3
const mo_u32 _10_pw_table[]={
1ul,/*10^0*/
10ul,/*10^1*/
100ul,/*10^2*/
1000ul,/*10^3*/
10000ul,/*10^4*/
100000ul,/*10^5*/
1000000ul,/*10^6*/
10000000ul,/*10^7*/
100000000ul,/*10^8*/
1000000000ul,/*10^9*/
};
int str_vol_to_s32(mo_u8 *p_str,mo_s32 *int_dat){
mo_u8 *p_start=p_str;
mo_u8 *p_point;
mo_u8 int_bits=0,point_bits=0;
int i;
mo_s32 tmp_dat=0;
if(p_str == NULL || int_dat==NULL)return -1;
p_point = (strpbrk(p_str, "."));
if(p_point){
p_point[0]='\0';
p_point++;
int_bits=strlen(p_str);
point_bits = strlen(p_point);
if(point_bits>MAX_POINT_LEN)point_bits=MAX_POINT_LEN;
// MO_LOG("point_bits:%d\r\n",point_bits);
}else{
int_bits=strlen(p_str);
}
for(i=int_bits; i>0; i--){
tmp_dat += (p_str[i-1]-'0')*_10_pw_table[int_bits-i];
}
*int_dat=tmp_dat*1000ul;
tmp_dat=0;
for(i=0; i<point_bits; i++){
tmp_dat += ((p_point[i]-'0')*_10_pw_table[(MAX_POINT_LEN-(i+1))]);
}
*int_dat+=tmp_dat;
// MO_LOG("dec vol:%d,%d,%d\r\n",*int_dat,point_bits,tmp_dat);
return 0;
}
static void uart_rx_msg_handle(mo_u8 *p_dat){
mo_u8 buf[MAX_BUF_SIZE__+1];
mo_u8 dat_buf[MAX_BUF_SIZE__+1];
mo_u8 max_cmd=30;
mo_u8 *p_in_dat=p_dat;
mo_u8 *p_cmd_end;
mo_u8 *p_dat_end;
// MO_LOG("rec,%s\r\n",p_dat);
while (max_cmd--){
p_cmd_end = (strpbrk(p_in_dat, "="));
if(p_cmd_end==NULL)break;
p_dat_end = (strpbrk(p_in_dat, "@"));
if(p_dat_end==NULL)break;
usr_mem_cpy(p_in_dat,p_cmd_end,buf);
usr_mem_cpy(&p_cmd_end[1],p_dat_end,dat_buf);
// MO_LOG("decode:%s,%s\r\n",buf,dat_buf);
if(strcmp("i_cfg",buf)==0){
// MO_LOG("dat:%s\r\n",dat_buf);
mo_u8 *p_vol;
mo_u8 req_vol;
req_vol = set_pd_req_vol_handle(dat_buf[0]-'0');
p_vol = (mo_u8*)mo_malloc(sizeof(mo_u8));
if(p_vol){
*p_vol = req_vol;
mo_msg_send(get_usr_display_task(),USR_LCD_PD_REQ_UI_UPDATE,p_vol,0);
}
}else if(strcmp("o_cfg",buf)==0){
mo_s32 int_dat;
// MO_LOG("dat:%s\r\n",dat_buf);
if(str_vol_to_s32(dat_buf,&int_dat) != -1) {
out_voltage_set_handle(int_dat);
}
}else if(strcmp("sync_cfg",buf)==0){
// mo_msg_send(get_usr_display_task(),USR_HOST_CONNECTED_TO_SYNC_DATS,NULL,0);
mo_u8 *p_vol;
CfigDatsT *cdat;
p_vol = (mo_u8*)mo_malloc(sizeof(mo_u8));
if(p_vol){
*p_vol = main_tsk.pd_req_vol;
mo_msg_send(get_usr_display_task(),USR_SYNC_PD_REQ_VOL_TO_HOST,p_vol,0);
}
cdat = (CfigDatsT*)mo_malloc(sizeof(CfigDatsT));
if(cdat){
*cdat = main_tsk.cfg_dat;
mo_msg_send(get_usr_display_task(),USR_SYNC_OVOL_TO_HOST,cdat,0);
}
}
else{
// MO_LOG("not support this cmd:%s,%s\r\n",buf,dat_buf);
}
p_in_dat = (p_dat_end+1);
if(*p_in_dat=='\n')break;
}
}
static void main_task_handle(mo_task tsk, mo_msg_id msg_id, mo_msg msg) { static void main_task_handle(mo_task tsk, mo_msg_id msg_id, mo_msg msg) {
switch (msg_id) { switch (msg_id) {
case SYS_KEY_EVENT: { case SYS_KEY_EVENT: {
mo_key_event_msg_t *k_event = (mo_key_event_msg_t *)msg; if(msg!=NULL){
MO_LOG("vk_code:%d,vk_patt:%d,click:%d\r\n", k_event->vk_code, k_event->vk_patt, k_event->click_num); mo_key_event_msg_t *k_event = (mo_key_event_msg_t *)msg;
key_event_handle(k_event); // MO_LOG("vk_code:%d,vk_patt:%d,click:%d\r\n", k_event->vk_code, k_event->vk_patt, k_event->click_num);
key_event_handle(k_event);
}
} break; } break;
case USR_CFG_UP_CONTINUOUS:{ case USR_CFG_UP_CONTINUOUS:{
cfg_increase_handle(50); cfg_increase_handle(50);
@ -332,14 +542,18 @@ static void main_task_handle(mo_task tsk, mo_msg_id msg_id, mo_msg msg) {
//mo_msg_cancel_all(tsk,USR_UPDATE_CFG_VOLTAGE_TO_IC); //mo_msg_cancel_all(tsk,USR_UPDATE_CFG_VOLTAGE_TO_IC);
} }
mo_msg_cancel_all(tsk,USR_UPDATE_CFG_VOLTAGE_TO_IC); mo_msg_cancel_all(tsk,USR_UPDATE_CFG_VOLTAGE_TO_IC);
mo_msg_send(tsk,USR_UPDATE_CFG_VOLTAGE_TO_IC,NULL,70); mo_msg_send(tsk,USR_UPDATE_CFG_VOLTAGE_TO_IC,NULL,25);
} }
break; break;
case USR_CFG_TIMEOUT_HANDLE: case USR_CFG_TIMEOUT_HANDLE:
main_tsk.cfg_mode = CFG_MODE_NULL; main_tsk.cfg_mode = CFG_MODE_NULL;
mo_msg_send(get_usr_display_task(),USR_LCD_CFG_UI_INACTIVE,0,0); mo_msg_send(get_usr_display_task(),USR_LCD_CFG_UI_INACTIVE,0,0);
break; break;
case USR_UART_RX_RECEIVED_DATAS:
if(msg!=NULL){
uart_rx_msg_handle(msg);
}
break;
default: default:
break; break;
} }

View File

@ -23,14 +23,14 @@ extern "C" {
#include "mo_msg.h" #include "mo_msg.h"
#include "usr_input_task.h" #include "usr_input_task.h"
#define VOUT_MAX 20000ul /*mV*/ #define VOUT_MAX 21000ul /*mV*/
#define VOUT_MIN 2700ul /*mV*/ #define VOUT_MIN 2700ul /*mV*/
#define DEFAULT_O_VOL 2700ul /*mV*/ #define DEFAULT_O_VOL 2700ul /*mV*/
#define DEFAULT_OC_LIMIT 3000ul /*mA*/ #define DEFAULT_OC_LIMIT 3000ul /*mA*/
#define OC_MAX 3000ul /*mA*/ #define OC_MAX 3000ul /*mA*/
#define OC_MIN 10ul /*mA*/ #define OC_MIN 100ul /*mA*/
#define PD_CFG1_PORT GPIOA #define PD_CFG1_PORT GPIOA
#define PD_CFG2_PORT GPIOA #define PD_CFG2_PORT GPIOA
@ -78,7 +78,7 @@ typedef enum {
typedef struct config_datas_{ typedef struct config_datas_{
mo_u32 out_vol; mo_u32 out_vol;
mo_u32 limit_curr;/*mA*/ mo_s32 limit_curr;/*mA*/
}CfigDatsT; }CfigDatsT;

View File

@ -26,6 +26,7 @@
/* includes ------------------------------------------------------------------*/ /* includes ------------------------------------------------------------------*/
#include "at32f415_int.h" #include "at32f415_int.h"
#include "usr_main_app.h"
/* private includes ----------------------------------------------------------*/ /* private includes ----------------------------------------------------------*/
/* add user code begin private includes */ /* add user code begin private includes */
@ -215,4 +216,41 @@ void SysTick_Handler(void)
{ {
mo_tick_inc(); mo_tick_inc();
} }
/**
* @brief this function handles usart2 handler.
* @param none
* @retval none
*/
#define USART_RX_BUFFER_SIZE 256
static uint8_t usart2_rx_buffer[USART_RX_BUFFER_SIZE];
static uint16_t usart2_rx_counter=0;
void USART2_IRQHandler(void){
uint8_t dat;
uint8_t *p_dat;
if(usart_interrupt_flag_get(USART2, USART_RDBF_FLAG) != RESET){
/* read one byte from the receive data register */
dat = usart_data_receive(USART2);
usart2_rx_buffer[usart2_rx_counter++] = dat;
if(dat == '\n'){
p_dat = mo_malloc(usart2_rx_counter+1);
if(p_dat){
memcpy(p_dat,usart2_rx_buffer,usart2_rx_counter);
p_dat[usart2_rx_counter]='\0';
mo_msg_send(get_usr_main_task(),USR_UART_RX_RECEIVED_DATAS,p_dat,0);
}
usart2_rx_counter=0;
}
if(usart2_rx_counter>=USART_RX_BUFFER_SIZE){
usart2_rx_counter=0;
}
}
}
/* add user code end 1 */ /* add user code end 1 */

View File

@ -69,7 +69,7 @@ int main(void) {
gpio_bits_reset(GPIOA, GPIO_PINS_10 | GPIO_PINS_8 | GPIO_PINS_9); gpio_bits_reset(GPIOA, GPIO_PINS_10 | GPIO_PINS_8 | GPIO_PINS_9);
/***************MOS START******************/ /***************MOS START******************/
#if MO_DEBUG_EN #if MO_DEBUG_EN
uart_print_init(115200); uart_print_init(1000000);
#endif #endif
MO_LOG("enter main\r\n"); MO_LOG("enter main\r\n");