132 lines
3.5 KiB
C
132 lines
3.5 KiB
C
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved.
|
|
*
|
|
* Description: common_pm.h
|
|
*
|
|
* Author: luziquan@ss-tjd.com
|
|
*
|
|
* Create: 2024-05-29
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#ifndef COMMON_PM_H
|
|
#define COMMON_PM_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
#endif
|
|
|
|
#define POWER_MANAGER_SUCC 0
|
|
#define POWER_MANAGER_FAIL 0xFFFFFFFF
|
|
#define POWER_MANAGER_ARBITRA_FAIL 0x80000001
|
|
|
|
typedef enum
|
|
{
|
|
PM_POWER_STATUS_OFF = 0,
|
|
PM_POWER_STATUS_ON = 1,
|
|
} power_status_t;
|
|
|
|
typedef enum {
|
|
GPIO_INPUT,
|
|
GPIO_OUTPUT
|
|
} gpio_dir_t;
|
|
|
|
typedef enum {
|
|
PM_EVENT_SUSPEND,
|
|
PM_EVENT_RESUME
|
|
} pm_event_t;
|
|
|
|
typedef enum {
|
|
PM_STATUS_ON,
|
|
PM_STATUS_OFF
|
|
} screen_status_t;
|
|
|
|
typedef enum
|
|
{
|
|
POWER_MODEL_SCREEN_ID = 0,
|
|
POWER_MODEL_ENCODER_ID,
|
|
POWER_MODEL_HRSENSOR_ID,
|
|
POWER_MODEL_MSENSOR_ID,
|
|
POWER_MODEL_GSENSOR_ID,
|
|
POWER_MODEL_ALIPAY_ID,
|
|
POWER_MODEL_GPS_ID,
|
|
POWER_MODEL_BUTTON_ID,
|
|
POWER_MODEL_MOTOR_ID,
|
|
POWER_MODEL_MAX_ID,
|
|
} power_model_id_t;
|
|
|
|
typedef void (*lp_event_callback)(pm_event_t event);
|
|
typedef void (*screen_event_callback)(screen_status_t status);
|
|
typedef void (*shutdown_event_callback)(void);
|
|
typedef void (*recover_event_callback)(void);
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t ldo_gpio;
|
|
lp_event_callback lp_callback;
|
|
power_status_t status : 1;
|
|
} power_manager_device_t;
|
|
|
|
struct power_manager_class_ops
|
|
{
|
|
int32_t (*open)(void);
|
|
int32_t (*close)(void);
|
|
uint32_t (*get_model_power_status)(const power_model_id_t model_id);
|
|
uint32_t (*set_model_power_status)(const power_model_id_t model_id, const power_status_t status);
|
|
|
|
/**
|
|
* @brief 注册低功耗事件
|
|
* @param power_model_id_t 驱动模块ID
|
|
* @param lp_event_callback 低功耗事件回调
|
|
* @return uint32_t
|
|
*/
|
|
uint32_t (*register_lp_on_event)(const power_model_id_t model_id, lp_event_callback callback);
|
|
uint32_t (*unregister_lp_on_event)(const power_model_id_t model_id);
|
|
|
|
/**
|
|
* @brief 注册亮灭屏幕事件
|
|
* @param screen_event_callback
|
|
* @return uint32_t
|
|
*/
|
|
uint32_t (*register_screen_on_event)(screen_event_callback callback);
|
|
uint32_t (*unregister_screen_on_event)(screen_event_callback callback);
|
|
|
|
/**
|
|
* @brief 注册关机事件
|
|
* @param shutdown_event_callback
|
|
* @note 关机事件会在系统关机和重启时调用
|
|
* @return uint32_t
|
|
*/
|
|
uint32_t (*register_shutdown_event)(shutdown_event_callback callback);
|
|
uint32_t (*unregister_shutdown_event)(shutdown_event_callback callback);
|
|
|
|
/**
|
|
* @brief 注册恢复事件
|
|
* @param recover_event_callback
|
|
* @note 恢复事件会在恢复出厂设置时调用
|
|
* @return uint32_t
|
|
*/
|
|
uint32_t (*register_recover_event)(recover_event_callback callback);
|
|
uint32_t (*unregister_recover_event)(recover_event_callback callback);
|
|
};
|
|
|
|
const struct power_manager_class_ops *tjd_driver_common_pm_get_ops(void);
|
|
|
|
void tjd_driver_pm_lp_enter(pm_event_t event);
|
|
void tjd_driver_pm_screen_event(screen_status_t status);
|
|
void tjd_driver_pm_power_down_event(void);
|
|
void tjd_driver_pm_shutdown_event(void);
|
|
void tjd_driver_pm_recover_event(void);
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
#endif |