idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
cpu.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
16#include <soc/soc_caps.h>
17#include <string>
18
19namespace idfxx {
20
39enum class core_id : unsigned int {
40 core_0 = 0,
41#if SOC_CPU_CORES_NUM > 1
42 core_1 = 1,
43#endif
44};
45
52[[nodiscard]] inline std::string to_string(core_id c) {
53 switch (c) {
54 case core_id::core_0:
55 return "CORE_0";
56#if SOC_CPU_CORES_NUM > 1
57 case core_id::core_1:
58 return "CORE_1";
59#endif
60 default:
61 return "unknown(" + std::to_string(static_cast<unsigned int>(c)) + ")";
62 }
63}
64
// end of idfxx_cpu
66
67} // namespace idfxx
68
69#include "sdkconfig.h"
70#ifdef CONFIG_IDFXX_STD_FORMAT
72#include <algorithm>
73#include <format>
74namespace std {
75template<>
76struct formatter<idfxx::core_id> {
77 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
78
79 template<typename FormatContext>
80 auto format(idfxx::core_id c, FormatContext& ctx) const {
81 auto s = to_string(c);
82 return std::copy(s.begin(), s.end(), ctx.out());
83 }
84};
85} // namespace std
87#endif // CONFIG_IDFXX_STD_FORMAT
core_id
Identifies a specific CPU core.
Definition cpu.hpp:39
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
Definition cpu.hpp:52