Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ PackConstructorInitializers: NextLine
PointerAlignment: Left
ReflowComments: true
SpaceAfterCStyleCast: true
# Header include ordering — Google C++ Style Guide
# https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes
# Header include ordering
# 1. C system headers (<stdint.h>, <string.h>)
# 2. C++ standard library (<cstdint>, <vector>, <algorithm>)
# 3. Other libraries / project headers (Arduino, third-party, local)
# 3. Third-party libraries (Arduino, third-party)
# 4. Local project headers (local)
SortIncludes: CaseSensitive
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<[[:lower:]_/]+\.h>$'
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype|unistd|fcntl|dirent|pthread|sched|semaphore|sys/.+|netinet/.+|arpa/.+)\.h>$'
Priority: 1
- Regex: '^<[[:alpha:]_]+>$'
Priority: 2
- Regex: '.*'
- Regex: '^<.+\.h>$'
Priority: 3
- Regex: '.*'
Priority: 4
11 changes: 10 additions & 1 deletion include/v2/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <cstdint>

#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down Expand Up @@ -64,6 +64,15 @@ namespace pocketpd {
int delta = 0;
};

/**
* @brief Latest sensor reading from INA226.
*/
struct SensorSnapshot {
uint32_t timestamp_ms = 0;
uint32_t vbus_mv = 0;
uint32_t current_ma = 0;
};

/**
* @brief Published by SensorTask. Carries one bus reading.
*/
Expand Down
2 changes: 1 addition & 1 deletion include/v2/input/button_gesture.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <cstdint>
#include <optional>

#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down
2 changes: 1 addition & 1 deletion include/v2/input/two_buttons_gesture.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <optional>

#include "v2/input/button_gesture.h"
#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down
46 changes: 45 additions & 1 deletion include/v2/pocketpd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file pocketpd.h
* @brief PocketPD v2 product-level types and constants.
* @brief PocketPD v2 product-level types, configuration constants, etc.
*
* Header is kept dependency-free so it can be included from hardware adapters, stages, tasks, and
* native tests alike.
Expand Down Expand Up @@ -54,4 +54,48 @@ namespace pocketpd {
*/
constexpr uint32_t EEPROM_SAVE_DEBOUNCE_MS = 2000;

// —— Input types

/**
* @brief Identifier for the three physical buttons plus a synthetic L_R combo.
* `L` and `R` denote the left and right side buttons; `ENCODER` is the rotary push.
*/
enum class ButtonId : uint8_t {
ENCODER,
R,
L,
L_R,
};

inline const char* to_string(ButtonId btn_id) {
switch (btn_id) {
case ButtonId::ENCODER:
return "ENCODER_BTN";
case ButtonId::L:
return "L_BTN";
case ButtonId::R:
return "R_BTN";
case ButtonId::L_R:
return "L_R_SYNTHETIC";
default:
return "UNKNOWN";
}
}

enum class Gesture : uint8_t {
SHORT,
LONG,
};

inline const char* to_string(Gesture g) {
switch (g) {
case Gesture::SHORT:
return "SHORT";
case Gesture::LONG:
return "LONG";
default:
return "UNKNOWN";
}
}

} // namespace pocketpd
3 changes: 2 additions & 1 deletion include/v2/stages/energy/energy_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#include <cstdint>
#include <cstdio>

#include "v2/events.h"
#include "v2/images.h"
#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down
2 changes: 1 addition & 1 deletion include/v2/stages/energy_stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "v2/hal/output_gate.h"
#include "v2/images.h"
#include "v2/stages/energy/energy_view.h"
#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down
2 changes: 1 addition & 1 deletion include/v2/stages/normal/normal_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <cstdint>
#include <cstdio>

#include "v2/events.h"
#include "v2/images.h"
#include "v2/pocketpd.h"
#include "v2/state.h"

namespace pocketpd {

Expand Down
1 change: 0 additions & 1 deletion include/v2/stages/normal/pps_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "v2/events.h"
#include "v2/hal/pd_sink_controller.h"
#include "v2/pocketpd.h"
#include "v2/state.h"

namespace pocketpd {

Expand Down
2 changes: 1 addition & 1 deletion include/v2/stages/normal_stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "v2/stages/normal/fixed_mode.h"
#include "v2/stages/normal/normal_view.h"
#include "v2/stages/normal/pps_mode.h"
#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down
2 changes: 1 addition & 1 deletion include/v2/stages/profile_picker_stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "v2/app.h"
#include "v2/events.h"
#include "v2/hal/pd_sink_controller.h"
#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down
62 changes: 0 additions & 62 deletions include/v2/state.h

This file was deleted.

3 changes: 2 additions & 1 deletion include/v2/tasks/button_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "v2/events.h"
#include "v2/input/button_gesture.h"
#include "v2/input/two_buttons_gesture.h"
#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand All @@ -29,6 +29,7 @@ namespace pocketpd {

DetectorRef() = delete;
};

std::array<DetectorRef, 3> m_detector_refs;
TwoButtonsGestureDetector m_combo_detector;

Expand Down
2 changes: 1 addition & 1 deletion include/v2/tasks/energy_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "v2/app.h"
#include "v2/events.h"
#include "v2/hal/output_gate.h"
#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down
2 changes: 1 addition & 1 deletion include/v2/tasks/sensor_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "v2/app.h"
#include "v2/events.h"
#include "v2/hal/power_monitor.h"
#include "v2/state.h"
#include "v2/pocketpd.h"

namespace pocketpd {

Expand Down
51 changes: 46 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,68 @@ lib_deps =
mathertel/RotaryEncoder@^1.5.3
khoih-prog/RPI_PICO_TimerInterrupt@^1.3.1

[env:HW1_0]
extends = pico_base
extra_scripts = pre:scripts/configure_fmt_header_only.py
build_flags =
${pico_base.build_flags}
-DHW1_0
-DVERSION="\"1.0.0\""
build_src_filter =
-<*>
+<v1/**/*.cpp>

[env:HW1_3]
extends = pico_base
extra_scripts = pre:scripts/configure_fmt_header_only.py
build_flags =
${pico_base.build_flags}
-DHW1_3
-DVERSION="\"1.0.0\""
build_src_filter =
-<*>
+<main.cpp>
build_src_filter =
-<*>
+<v1/**/*.cpp>

[env:HW1_0_V2]
extends = pico_base
extra_scripts =
pre:scripts/configure_fmt_header_only.py
post:scripts/compiledb_inject_headers.py
build_flags =
${pico_base.build_flags}
-DHW_VERSION_MAJOR=1
-DHW_VERSION_MINOR=0
-DVERSION="\"2.0.0\""
build_src_filter =
-<*>
+<main.cpp>
+<v2/**/*.cpp>

[env:HW1_1_V2]
extends = pico_base
extra_scripts =
pre:scripts/configure_fmt_header_only.py
post:scripts/compiledb_inject_headers.py
build_flags =
${pico_base.build_flags}
-DHW_VERSION_MAJOR=1
-DHW_VERSION_MINOR=1
-DVERSION="\"2.0.0\""
build_src_filter =
-<*>
+<main.cpp>
+<v2/**/*.cpp>

[env:HW1_3_V2]
extends = pico_base
extra_scripts =
pre:scripts/configure_fmt_header_only.py
post:scripts/compiledb_inject_headers.py
build_flags =
${pico_base.build_flags}
-DHW1_3_V2
-DVERSION="\"2.0.0-dev\""
-DHW_VERSION_MAJOR=1
-DHW_VERSION_MINOR=3
-DVERSION="\"2.0.0\""
build_src_filter =
-<*>
+<main.cpp>
Expand Down
Loading
Loading