GCC Code Coverage Report


Directory: components/
File: power_button/src/power_button.c
Date: 2025-10-25 23:13:53
Coverage Exec Excl Total
Lines: 100.0% 40 0 40
Functions: 100.0% 2 0 2
Branches: 92.9% 13 0 14

Line Branch Exec Source
1 /**
2 * @file power_button.c
3 * @brief Module to interface with power button keyboard
4 */
5
6 #include "power_button.h"
7 #include "rte.h"
8
9 /**
10 * @enum KeyState
11 * @brief States for the debouncing state machine.
12 */
13 typedef enum
14 {
15 INIT, /**< Initial state, waiting for debounce timers. */
16 PRESSED, /**< Key has been debounced as pressed. */
17 RELEASED /**< Key has been debounced as released. */
18 } KeyState;
19
20 static KeyState currentState = INIT; /**< Current state of the debouncing state machine. */
21 static unsigned int pressCounter = 0; /**< Counter for key presses. */
22 static unsigned int releaseCounter = 0; /**< Counter for key releases. */
23
24 12 void powerButtonInit(void)
25 {
26 12 currentState = INIT;
27 12 pressCounter = 0;
28 12 releaseCounter = 0;
29 12 }
30
31 /**
32 * @brief Debounces key presses and releases.
33 *
34 * This function utilizes a state machine to debounce key presses and releases.
35 * It must be called periodically to process the debouncing. The behavior is controlled
36 * by two configuration parameters: POWER_BUTTON_PRESS_DEBOUNCE and POWER_BUTTON_RELEASE_DEBOUNCE which determine
37 * how many consecutive calls with the key pressed/released are required to acknowledge the
38 * state transition.
39 */
40 316 void powerButton(void)
41 {
42 316 boolean powerKeyPressed = FALSE;
43 316 boolean keyStatus = RteIsKeyPressed(POWER_BUTTON_KEY);
44
45 // Update the counters
46
2/2
✓ Branch 3 → 4 taken 190 times.
✓ Branch 3 → 5 taken 126 times.
316 if (keyStatus)
47 {
48 190 pressCounter++;
49 190 releaseCounter = 0; // reset release counter if key is pressed
50 }
51 else
52 {
53 126 releaseCounter++;
54 126 pressCounter = 0; // reset press counter if key is released
55 }
56
57
3/4
✓ Branch 6 → 7 taken 106 times.
✓ Branch 6 → 12 taken 90 times.
✓ Branch 6 → 15 taken 120 times.
✗ Branch 6 → 18 not taken.
316 switch (currentState)
58 {
59 106 case INIT:
60
2/2
✓ Branch 7 → 8 taken 7 times.
✓ Branch 7 → 9 taken 99 times.
106 if (pressCounter >= POWER_BUTTON_PRESS_DEBOUNCE)
61 {
62 7 powerKeyPressed = TRUE;
63 7 currentState = PRESSED;
64 7 releaseCounter = 0; // reset the counter after transition
65 7 pressCounter = 0; // reset the counter after transition
66 }
67
2/2
✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 11 taken 96 times.
99 else if (releaseCounter >= POWER_BUTTON_RELEASE_DEBOUNCE)
68 {
69 3 currentState = RELEASED;
70 3 releaseCounter = 0; // reset the counter after transition
71 3 pressCounter = 0; // reset the counter after transition
72 }
73 106 break;
74
75 90 case PRESSED:
76
2/2
✓ Branch 12 → 13 taken 3 times.
✓ Branch 12 → 14 taken 87 times.
90 if (releaseCounter >= POWER_BUTTON_RELEASE_DEBOUNCE)
77 {
78 3 currentState = RELEASED;
79 3 releaseCounter = 0; // reset the counter after transition
80 }
81 90 pressCounter = 0; // reset the counter after transition
82 90 break;
83
84 120 case RELEASED:
85
2/2
✓ Branch 15 → 16 taken 6 times.
✓ Branch 15 → 17 taken 114 times.
120 if (pressCounter >= POWER_BUTTON_PRESS_DEBOUNCE)
86 {
87 6 powerKeyPressed = TRUE;
88 6 currentState = PRESSED;
89 6 pressCounter = 0; // reset the counter after transition
90 }
91 120 releaseCounter = 0; // reset the counter after transition
92 120 break;
93 }
94
95 316 RteSetPowerKeyPressedEvent(powerKeyPressed);
96 316 }
97