4. Explore C++ code intelligence#
Sense’s integration with pw_ide enables fast and accurate code navigation, autocompletion based on a deep understanding of the code structure, and instant compiler warnings and errors. Try intelligent code navigation features now:
Explanation#
PW_LOG is a facade. You can change out the
implementation of that logging function at compile-time. For example, on your
real hardware perhaps you use pw_log_tokenized to save code size,
but when simulating your firmware on your development host maybe you compile
with pw_log_string to make it easy to view debug log messages.
Let’s call the hardware target in our example rp2040 and the host target
host_simulator. The Select Code Analysis Target feature of Pigweed’s
VS Code extension lets you investigate these different code paths. Selecting
host_simulator as your target and drilling down via Go to Definition
would ultimately show you a PW_LOG implementation in pw_log_string.
Selecting the rp2040 target and drilling down again would show a completely
different implementation for PW_LOG in pw_log_tokenized.
flowchart LR
a["main.cc"] --> b["log.h"]
b["log.h"] -. rp2040 .-> c["pw_log_tokenized/.../log_backend.h"]
b["log.h"] -. host_simulator .-> d["pw_log_string/.../log_backend.h"]
Note
Currently all Sense targets use pw_log_tokenized as their backend so
it’s not possible to demonstrate this idea with the Sense repo.
Summary#
Portable, hardware-agnostic software abstractions such as pw_log make it easier to reuse code across projects and hardware platforms. But they also make it more difficult to correctly navigate references in your codebase. The Pigweed extension for VS Code can solve this problem; you just need to tell it what target within your codebase to focus on.
Next, head over to 5. Run host tests to learn how to run unit tests on your development host.