Skip to content

Commit d79239e

Browse files
committed
docs: Add documentation for power module
Add documentation for the power module. Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
1 parent fca316f commit d79239e

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

docs/modules/power.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,65 @@
11
# Power module
22

3-
What does this module do
3+
The power module manages power-related functionality for devices with nPM1300, like the Thingy:91 X, including the following:
4+
- Monitoring battery voltage and calculating remaining battery percentage.
5+
- Handling VBUS (USB) connect and disconnect events to enable or disable UART peripherals.
6+
- Publishing battery percentage updates via zbus messages.
47

58
## Messages
69

10+
The Power module defines and communicates on the `POWER_CHAN` channel.
11+
12+
### Input Messages
13+
14+
- **POWER_BATTERY_PERCENTAGE_SAMPLE_REQUEST**
15+
Requests a battery percentage sample.
16+
17+
### Output Messages
18+
19+
- **POWER_BATTERY_PERCENTAGE_SAMPLE_RESPONSE**
20+
Contains the calculated battery percentage.
21+
22+
The power message structure is defined in `power.h`:
23+
24+
```c
25+
struct power_msg {
26+
enum power_msg_type type;
27+
28+
/** Contains the current charge of the battery in percentage. */
29+
double percentage;
30+
};
31+
```
32+
733
## Configurations
834

9-
Kconfig and device tree
35+
The following Kconfig options control this module’s behavior:
36+
37+
- **CONFIG_APP_POWER**
38+
Enables the Power module.
39+
40+
- **CONFIG_APP_POWER_DISABLE_UART_ON_VBUS_REMOVED**
41+
If enabled, suspends UART devices when VBUS is removed.
42+
43+
- **CONFIG_APP_POWER_THREAD_STACK_SIZE**
44+
Size of the Power module’s thread stack.
45+
46+
- **CONFIG_APP_POWER_WATCHDOG_TIMEOUT_SECONDS**
47+
Defines the watchdog timeout for the module. Must be larger than the message processing timeout.
48+
49+
- **CONFIG_APP_POWER_MSG_PROCESSING_TIMEOUT_SECONDS**
50+
Maximum time spent processing a single message.
51+
52+
See the `Kconfig.power` file in the module's directory for more details on the available Kconfig options.
53+
54+
## Kconfig and device tree
55+
56+
- The Power module uses `npm1300_charger` as specified by device tree.
57+
- The two UART devices `uart0_dev` and `uart1_dev` defined in device tree will be enabled or disabled based on VBUS events.
1058

1159
## State diagram
60+
61+
The Power module uses a minimal state machine with a single state, **STATE_RUNNING**. In this state, the module:
62+
1. Initializes the charger and optional fuel gauge in the state entry function.
63+
2. Waits for messages to arrive via zbus.
64+
3. Handles battery sample requests and publishes results.
65+
4. Monitors for VBUS events to enable or disable UART devices.

0 commit comments

Comments
 (0)