优化这份代码:
/******************************************************************************
* Copyright (c) 2025 MeiG Smart Co.Ltd. All Rights Reserved.
*
* This program is the confidential and proprietary information of MeiG
* Smart Co.Ltd. ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with the terms
* of the license agreement you entered into with MeiG Smart Co.Ltd.
*
* Filename: volcano_gpio_app.cpp
*
* Description:
* Meig gpio Daemon App.
*
* Version: 1.0
* Date: 2025-06-07
* Author: zhanghong
*
* 1.0 2025-06-07 zhanghong First version
******************************************************************************/
#define __FILE_NAME__ "volcano_gpio_app.cpp"
#include <volcano_priv.hpp>
#include <thread>
#include <iostream>
#include <atomic>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
#include <sys/epoll.h>
#include <mutex>
#include <vector>
#include <volcano_gpio_port.hpp>
#include <volcano_gpio.hpp>
#include <poll.h>
#include <pthread.h>
#include <cstring>
#include <memory>
#include <semaphore.h>
#include <unordered_map>
#include <vector>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <string>
#include <chrono>
#include <condition_variable>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <linux/input.h>
#include <stdarg.h>
#include <syslog.h>
namespace volcano {
namespace app {
namespace gpio {
using RequestHandler = std::function<nlohmann::json(const nlohmann::json&)>;
auto g_manager_ptr = volcano::port::gpio::Iface::getInstance(); // 获取裸指针
std::atomic<bool> g_running{false};
std::thread g_event_thread;
std::mutex g_thread_mutex;
Gpio_Status Gpio_Status_Now;
int fd_gpio = -1;
static volcano_pin_driver_typeDef volcano_pin_table_gpio[] =
{
{59, MODULE_MCU+54,false},
{61, MODULE_MCU+52,false},
{62, MODULE_MCU+53,false},
{63, MODULE_MCU+55,false},
{71, MODULE_MCU+117,false},
{74, MODULE_MCU+116,false},
{100, MODULE_MCU+129,false},
{102, MODULE_MCU+126,false},
{104, MODULE_MCU+128,false},
{181, MODULE_MCU+50,false},
{249, MODULE_MCU+75,false},
{280, MODULE_MCU+103,false},
{283, MODULE_MCU+78,false},
{297, MODULE_MCU+65,false},
{298, MODULE_MCU+64,false},
{507, MODULE_MCU+48,false},
{508, MODULE_MCU+49,false}
};
struct Service {
Service(std::shared_ptr<volcano::app::Fmk> fmk) : fmk_(fmk) {
keep_run_ = true;
fmk_->msg_->register_service_j("volcano_gpio", [this](const nlohmann::json &req) -> nlohmann::json { return this->dispatch_request(req); });
thread_ = std::make_shared<std::thread>([this]() { this->run(); });
};
~Service() {
keep_run_ = false;
if (thread_) {
thread_->join();
thread_ = nullptr;
}
fmk_->msg_->unregister_service("volcano_gpio");
};
protected:
nlohmann::json dispatch_request(const nlohmann::json &req) {
VOLCANO_LOGD("GAO dispatch_request: req=%s", req.dump().c_str());
auto action_map = build_action_map();
auto action_it = req.find("action");
if (action_it != req.end()) {
std::string action = action_it->get<std::string>();
auto handler_it = action_map.find(action);
if (handler_it != action_map.end()) {
return handler_it->second(req);
}
}
return build_error_reply(volcano::err::BadRequest, "Unknown action");
}
void run() {
int n = 0;
while (this->keep_run_) {
std::this_thread::sleep_for(std::chrono::seconds(1));
VOLCANO_LOGD("volcano_gpio_app notice callback");
n++;
std::string s = "hello world " + std::to_string(n);
nlohmann::json notice = {{"n", n}, {"s", s}};
fmk_->msg_->publish_notice_j("volcano_gpio", notice);
}
};
/* int publicEintStatus(int test) {
nlohmann::json eint_info_notice = {
{"type", static_cast<int>(VOLCANO_GPIO_CB_TYPE_EINT1)},
{"msg", {
{"pin_name", 280},
{"level", test},
}}
};
VOLCANO_LOGD("publicEintStatus");
fmk_->msg_->publish_notice_j("volcano_gpio", eint_info_notice);
return volcano::err::Ok;
} */
int Volcano_gpio_Open(const char* deviceName)
{
fd_gpio = open(deviceName, O_RDWR);
if (fd_gpio < 0)
{
//LOGI("yangxin : can't open device");
return -1;
}
Gpio_Status_Now.ReqNum = 0;
return 0;
}
int volcano_ms_gpio_get_number(ENUM_PINNAME pin_name)
{
uint16_t index = 0;
int gpioNumber = 0;
for (index = 0; index < ARRAY_SIZE(volcano_pin_table_gpio); index++){
if( volcano_pin_table_gpio[index].pinname == pin_name ){
gpioNumber = volcano_pin_table_gpio[index].pinnumber;
}
}
VOLCANO_LOGD("volcano_ms_gpio_get_number gpioNumber = %d\n",gpioNumber);
return gpioNumber;
}
static void epoll_event_loop_eint() {
int fd,i;
struct pollfd fds[1];
int ret;
struct input_event ev;
unsigned int level;
int pin;
// 打开设备文件
fd = open("/dev/input/event0", O_RDONLY);
if (fd < 0) {
VOLCANO_LOGD("epoll_event_loop_eint Open");
//return EXIT_FAILURE;
}
// 准备pollfd结构体
fds[0].fd = fd;
fds[0].events = POLLIN; // 等待可读取状态
VOLCANO_LOGD("epoll_event_loop_eint : into wait_inter_event\n");
// 循环使用poll等待事件
while (g_running.load()) {
pin = 0;
level = 0;
// 等待事件,无超时(阻塞)
ret = poll(fds, 1, -1);
if (ret < 0) {
VOLCANO_LOGD("epoll_event_loop_eint Poll");
close(fd);
//return EXIT_FAILURE;
}
// 检查是否有事件
if (fds[0].revents & POLLIN) {
// 读取事件
ret = read(fd, &ev, sizeof(struct input_event));
if (ret < 0) {
VOLCANO_LOGD("epoll_event_loop_eint Read");
close(fd);
//return EXIT_FAILURE;
}
pin = ev.value >> 1;
level = ev.value & 0x1;
VOLCANO_LOGD("epoll_event_loop_eint 1111");
for(i=0; i<Gpio_Status_Now.ReqNum; i++){
if(Gpio_Status_Now.Gpio_Init[i].irq_num == (unsigned int)pin && ev.value != 0){
if(Gpio_Status_Now.Gpio_Init[i].callback != NULL)
{
//Gpio_Status_Now.Gpio_Init[i].callback(()Gpio_Status_Now.Gpio_Init[i].pin,level);
//self->publicEintStatus(level);
if(Gpio_Status_Now.Gpio_Init[i].callback != NULL)
cb_(Gpio_Status_Now.Gpio_Init[i].pin,level);
//self->cb(eint_pin_name,level);
VOLCANO_LOGD("epoll_event_loop_eint eint");
}
break;
}
}
// 处理事件
VOLCANO_LOGD("epoll_event_loop_eint : Event: time %ld.%06ld, type %d, pin %d, level %d\n",
ev.time.tv_sec, ev.time.tv_usec, ev.type, pin, level);
}
}
close(fd);
//return EXIT_SUCCESS;
/* int epoll_fd = epoll_create1(0);
if (epoll_fd == -1) {
perror("epoll_create1");
return;
}
int fd = open("/dev/input/event0", O_RDONLY | O_NONBLOCK);
if (fd < 0) {
perror("open");
close(epoll_fd);
return;
}
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = fd;
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) {
perror("epoll_ctl");
close(fd);
close(epoll_fd);
return;
}
VOLCANO_LOGD("epoll_event_loop_eint");
struct input_event inputEv;
while (g_running.load()) {
struct epoll_event events[1];
int nfds = epoll_wait(epoll_fd, events, 1, 500);
if (nfds > 0 && events[0].data.fd == fd) {
ssize_t n = read(fd, &inputEv, sizeof(inputEv));
if (n == sizeof(inputEv) && inputEv.type == EV_MSC && inputEv.code == MSC_RAW) {
unsigned int irq_num = inputEv.value >> 1;
int level = inputEv.value & 0x1;
for (int i = 0; i < Gpio_Status_Now.ReqNum; ++i) {
if (Gpio_Status_Now.Gpio_Init[i].irq_num == irq_num && inputEv.value != 0) {
self->publicEintStatus(level);
VOLCANO_LOGD("epoll_event_loop_eint eint");
break;
}
}
}
}
VOLCANO_LOGD("epoll_event_loop_eint test");
}
VOLCANO_LOGD("epoll_event_loop_eint");
close(fd);
close(epoll_fd); */
}
nlohmann::json on_volcano_ms_gpio_base_init(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
//auto manager = state_machine_.getManager();
//add lock???
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_base_init(pin_name);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_init(const nlohmann::json &req) {
/* VOLCANO_LOGD("on_volcano_ms_gpio_init: req=%s", req.dump().c_str());
//TODO
return {{"ret", volcano::err::Success}}; */
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
ENUM_PIN_DIRECTION dir = static_cast<ENUM_PIN_DIRECTION>(req.at("dir").get<int>());
ENUM_PIN_LEVEL level = static_cast<ENUM_PIN_LEVEL>(req.at("level").get<int>());
ENUM_PIN_PULLSEL pullSel = static_cast<ENUM_PIN_PULLSEL>(req.at("pullSel").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_init( pin_name, dir, level, pullSel);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_set_direction(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
ENUM_PIN_DIRECTION dir = static_cast<ENUM_PIN_DIRECTION>(req.at("dir").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_set_direction( pin_name, dir);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_get_direction(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_get_direction( pin_name);
if(err){
VOLCANO_LOGE("on_volcano_ms_gpio_get_direction: in");
}else{
VOLCANO_LOGE("on_volcano_ms_gpio_get_direction: out");
}
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_set_level(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
ENUM_PIN_LEVEL level = static_cast<ENUM_PIN_LEVEL>(req.at("level").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_set_level(pin_name, level);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_get_level(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_get_level(pin_name);
VOLCANO_LOGE("volcano_ms_gpio_get_level: %d", err);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_set_pull_selection(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
ENUM_PIN_PULLSEL pullSel = static_cast<ENUM_PIN_PULLSEL>(req.at("pullSel").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_set_pull_selection(pin_name, pullSel);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_get_pull_selection(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_get_pull_selection(pin_name);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_set_awake(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
ENUM_PIN_AWAKE en = static_cast<ENUM_PIN_AWAKE>(req.at("en").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_set_awake(pin_name, en);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_get_awake(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_get_awake(pin_name);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
nlohmann::json on_volcano_ms_gpio_uninit(const nlohmann::json &req) {
try {
ENUM_PINNAME pin_name = static_cast<ENUM_PINNAME>(req.at("pin_name").get<int>());
if (g_manager_ptr) {
int err = g_manager_ptr->mg_volcano_ms_gpio_uninit(pin_name);
return {{"ret", err}};
}else{
return {{"ret", volcano::err::InvalidReply}};
}
} catch (const std::exception &e) {
VOLCANO_LOGE("Invalid request: %s", e.what());
return {{"ret", volcano::err::InvalidReply}};
}
}
void handle_event(ENUM_PINNAME eint_pin_name, int level) {
VOLCANO_LOGD("handle_event");
nlohmann::json event_t = {
{"eint_pin_name", eint_pin_name},
{"level", level},
};
VOLCANO_LOGD("handle_event");
fmk_->msg_->publish_notice_j("volcano_gpio", event_t);
//UNUSED(sim_id);
//UNUSED(sim_id);
//UNUSED(event);
// ¿¿
}
nlohmann::json on_volcano_ms_eint_enable(const nlohmann::json &req) {
VOLCANO_LOGD("on_volcano_ms_eint_enable: req=%s", req.dump().c_str());
ENUM_PINNAME eint_pin_name = static_cast<ENUM_PINNAME>(req.at("eint_pin_name").get<int>());
ENUM_EINT_TYPE eint_type = static_cast<ENUM_EINT_TYPE>(req.at("eint_type").get<int>());
//volcano_ms_eint_callback eint1_callback = static_cast<volcano_ms_eint_callback>(req.at("eint1_callback").get<int>());
auto cb_ = [this]( ENUM_PINNAME eint_pin_name, int level) {
// auto app_cb = [this, agent_callback_id](int sim_id, int port_id, int result) {
this->handle_event(eint_pin_name,level);
};
if (g_manager_ptr){
int err = g_manager_ptr->mg_volcano_ms_eint_enable(eint_pin_name,eint_type);
VOLCANO_LOGD("on_volcano_ms_eint_enable: req=%d", err);
}
// return {{"ret", err}};
int ret = 0;
struct some_ioctl_data user_data;
int gpioNumber = 0;
uint8_t pin_name = 0;
bool existflag = 0;
uint8_t i = 0;
VOLCANO_LOGD("mg_volcano_ms_eint_enable");
if((eint_type < 0) || (eint_type > 3) )
return {{"ret", volcano::err::Success}};;
for (i = 0; i < ARRAY_SIZE(volcano_pin_table_gpio); i++){
if( volcano_pin_table_gpio[i].pinname == eint_pin_name )
existflag = 1;
}
VOLCANO_LOGD("mg_volcano_ms_eint_enable 1");
if(existflag == 0) return {{"ret", volcano::err::Success}};;
gpioNumber = volcano_ms_gpio_get_number(eint_pin_name);
pin_name = (uint8_t)gpioNumber;
VOLCANO_LOGD("mg_volcano_ms_eint_enable 2");
user_data.value = pin_name << 16 | eint_type << 2;
if (fd_gpio < 0){
ret = Volcano_gpio_Open(DEVICE_NAME);
if (ret < 0)
return {{"ret", volcano::err::Success}};
}
ret = ioctl(fd_gpio, GPIO_REQUEST, &user_data);
if (ret == -1)
{
VOLCANO_LOGD("yangxin : gpio:%d Already registered, please release first", pin_name);
return {{"ret", volcano::err::Success}};
}
if( user_data.ret_val < 0)
return {{"ret", volcano::err::Success}};
ret = ioctl(fd_gpio, GPIO_TO_IRQ, &user_data);
if (ret == -1)
{
VOLCANO_LOGD("yangxin : set gpio:%d failed", pin_name);
return {{"ret", volcano::err::Success}};
}
if( user_data.ret_val < 0)
return {{"ret", volcano::err::Success}};
std::lock_guard<std::mutex> lock(g_thread_mutex);
if (g_running.load()) {
VOLCANO_LOGD("[INFO] epoll thread already running");
//std::cout << "[INFO] epoll thread already running.\n";
//return 0;
}
g_running.store(true);
Gpio_Status_Now.Gpio_Init[Gpio_Status_Now.ReqNum].pin = eint_pin_name;
Gpio_Status_Now.Gpio_Init[Gpio_Status_Now.ReqNum].Gpio_InitNum = gpioNumber;
//Gpio_Status_Now.Gpio_Init[Gpio_Status_Now.ReqNum].callback = eint1_callback;
Gpio_Status_Now.Gpio_Init[Gpio_Status_Now.ReqNum].irq_num = user_data.use_data;
Gpio_Status_Now.ReqNum++;
g_event_thread = std::thread(epoll_event_loop_eint);
//g_event_thread = std::thread(&Service::epoll_event_loop_eint, this);
//std::cout << "[INFO] epoll thread started.\n";
//TODO
return {{"ret", volcano::err::Success}};
}
nlohmann::json on_volcano_ms_eint_disable(const nlohmann::json &req) {
VOLCANO_LOGD("on_volcano_ms_eint_disable: req=%s", req.dump().c_str());
std::lock_guard<std::mutex> lock(g_thread_mutex);
if (!g_running.load()) {
VOLCANO_LOGD("on_volcano_ms_eint_disable 1: req=%s", req.dump().c_str());
}
g_running.store(false);
if (g_event_thread.joinable()) {
g_event_thread.join();
VOLCANO_LOGD("[INFO] epoll thread stopped.\n");
std::cout << "[INFO] epoll thread stopped.\n";
}
//TODO
return {{"ret", volcano::err::Success}};
}
private:
std::unordered_map<std::string, RequestHandler> build_action_map() {
return {
{"volcano_ms_gpio_base_init", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_base_init(req); }},
{"volcano_ms_gpio_init", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_init(req); }},
{"volcano_ms_gpio_set_direction", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_set_direction(req); }},
{"volcano_ms_gpio_get_direction", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_get_direction(req); }},
{"volcano_ms_gpio_set_level", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_set_level(req); }},
{"volcano_ms_gpio_get_level", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_get_level(req); }},
{"volcano_ms_gpio_set_pull_selection", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_set_pull_selection(req); }},
{"volcano_ms_gpio_get_pull_selection", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_get_pull_selection(req); }},
{"volcano_ms_gpio_set_awake", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_set_awake(req); }},
{"volcano_ms_gpio_get_awake", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_get_awake(req); }},
{"volcano_ms_gpio_uninit", [this](const nlohmann::json &req) { return this->on_volcano_ms_gpio_uninit(req); }},
{"volcano_ms_eint_enable", [this](const nlohmann::json &req) { return this->on_volcano_ms_eint_enable(req); }},
{"volcano_ms_eint_disable", [this](const nlohmann::json &req) { return this->on_volcano_ms_eint_disable(req); }},
};
}
static nlohmann::json build_error_reply(const volcano::err::Code &code, const std::string &msg) {
nlohmann::json error_reply = {{"ret", code}, {"msg", msg}};
return error_reply;
}
std::shared_ptr<volcano::app::Fmk> fmk_;
std::shared_ptr<std::thread> thread_;
bool keep_run_ = false;
//std::function<void(ENUM_PINNAME, int)> cb_; // 存储回调函数
};
static std::shared_ptr<Service> s_service_ = nullptr;
static void service_init(std::shared_ptr<volcano::app::Fmk> fmk) { s_service_ = std::make_shared<Service>(fmk); };
static void service_deinit() { s_service_ = nullptr; };
} // namespace gpio
} // namespace app
} // namespace volcano
VOLCANO_APP(volcano::app::gpio::service_init, volcano::app::gpio::service_deinit);
不用管头文件