aboutsummaryrefslogtreecommitdiff
path: root/platform/atm2/ATM22xx-x1x/driver/batt_model/batt_model.h
blob: 916dddef29471dc04dc877c805c3436ec285a156 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
 *******************************************************************************
 *
 * @file batt_model.h
 *
 * @brief Battery model common prototype
 *
 * Copyright (C) Atmosic 2022-2023
 *
 *******************************************************************************
 */

#pragma once

/**
 * @defgroup BATT_MODEL Battery model
 * @ingroup DRIVERS
 * @brief Driver for battery model
 * @{
 */

#ifdef __cplusplus
extern "C" {
#endif

/// Device abstract state for battery model
typedef enum {
    /// Invalid state. Use to report error when get state.
    DEV_INVALID,
    /// Reset state. It represents system is booting and doesn't decide whether
    /// goes to normal function or not.
    DEV_RESET,
    /// Active state. System is in normal function.
    DEV_ACTV,
    /// Hibernate state. It represents system is going to hibernation or waking
    /// up from hibernation.
    DEV_HIB,
    /// Soc off state. It represents system is going to SOC off or waking up
    /// from SOC off.
    DEV_SOCOFF,
} dev_state_t;

/// Device state getter and setter.
typedef struct {
    /// Get current device state.
    dev_state_t (*get)(void);
    /// Set current device state.
    void (*set)(dev_state_t);
} dev_state_fns_t;

/// Hibernation flag getter and setter
typedef struct {
    /// Get hibernation flag
    bool (*get)(uint8_t);
    /// Set hibernation flag
    void (*set)(uint8_t, bool);
} hib_flag_fns_t;

/// Callback functions from batt_model
typedef struct {
    /// Device state getter and setter.
    dev_state_fns_t state;
    /// Hibernation getter and setter.
    hib_flag_fns_t flag;
} batt_cbs;

/// Battery model virtual functions
typedef struct {
    /// Initialization of the battery model.
    void (*init)(batt_cbs const *);
    /// Issue a battery capacity sampling.
    bool (*sample)(void (*cb)(uint8_t level));
} batt_fns;

/**
 *******************************************************************************
 * @brief Retrieve the functions of battery model
 * return Battery model functions.
 *******************************************************************************
 */
batt_fns const *batt_model(void);
#ifdef __cplusplus
}
#endif

/// @} BATT_MODEL