libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
power.cpp
1#include "power.hpp"
2
3#include <cstring>
4
5using namespace LibXR;
6
7namespace
8{
9
16int PowerCommand(PowerManager* power, int argc, char** argv)
17{
18 if (argc == 2 && std::strcmp(argv[1], "reset") == 0)
19 {
20 power->Reset();
21 return 0;
22 }
23 if (argc == 2 && std::strcmp(argv[1], "shutdown") == 0)
24 {
25 power->Shutdown();
26 return 0;
27 }
28 if (argc == 2 && std::strcmp(argv[1], "bootloader") == 0)
29 {
30 power->JumpToBootloader();
31 return 0;
32 }
33 STDIO::Print<"usage: power reset|shutdown|bootloader\r\n">();
34 return -1;
35}
36
37} // namespace
38
40{
41 auto* command = new RamFS::File(RamFS::CreateCommand("power", PowerCommand, this));
42 ramfs.Add(*command);
43}
44
46{
47 if (pin.Read() == level)
48 {
50 }
51}
通用输入输出(GPIO)接口类。 General Purpose Input/Output (GPIO) interface class.
Definition gpio.hpp:14
virtual bool Read()=0
读取 GPIO 引脚状态 / Reads the GPIO pin state.
电源管理器基类 / Abstract base class for Power Manager
Definition power.hpp:21
virtual void Reset()=0
复位电源管理模块 / Resets the power management module
virtual void Shutdown()=0
关闭系统电源 / Shuts down the system power
void RegisterCommand(RamFS &ramfs)
在 RamFS 根目录注册 power 命令 / Registers the power command in the RamFS root
Definition power.cpp:39
void CheckBootloaderPin(GPIO &pin, bool level)
启动时按引脚电平进入启动加载器 / Pin-level bootloader entry at startup
Definition power.cpp:45
virtual void JumpToBootloader()
跳转到启动加载器 / Jumps to the bootloader
Definition power.hpp:58
文件节点片段 / File-node fragment
Definition ramfs.hpp:10
轻量级内存文件系统 / Lightweight in-memory file system
Definition ramfs.hpp:23
static File CreateCommand(const char *name, int(*exec)(ArgType arg, int argc, char **argv), ArgType &&arg)
创建命令兼容入口,返回可执行文件 / Create a command-compatible executable file
Definition ramfs.hpp:92
void Add(File &file)
添加文件节点到根目录 / Add a file node to the root directory
Definition ramfs.hpp:139
static int Print(Args &&... args)
将一个编译期 brace 字面量打印到当前 STDIO 输出 / Print one compile-time brace literal to the active STDIO output
Definition stdio.hpp:227
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14